dev:岗位管理-联查部门名称
parent
87783b3238
commit
329cc2f053
|
|
@ -2,15 +2,19 @@ package com.zcloud.basic.info.command.query;
|
|||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.alibaba.cola.dto.MultiResponse;
|
||||
import com.zcloud.basic.info.command.convertor.DepartmentCoConvertor;
|
||||
import com.zcloud.basic.info.command.convertor.PostCoConvertor;
|
||||
import com.zcloud.basic.info.command.convertor.PostDepartmentCoConvertor;
|
||||
import com.zcloud.basic.info.dto.PostDepartmentPageQry;
|
||||
import com.zcloud.basic.info.dto.PostListQry;
|
||||
import com.zcloud.basic.info.dto.PostPageQry;
|
||||
import com.zcloud.basic.info.dto.clientobject.DepartmentCO;
|
||||
import com.zcloud.basic.info.dto.clientobject.PostCO;
|
||||
import com.zcloud.basic.info.dto.clientobject.PostDepartmentCO;
|
||||
import com.zcloud.basic.info.persistence.dataobject.DepartmentDO;
|
||||
import com.zcloud.basic.info.persistence.dataobject.PostDO;
|
||||
import com.zcloud.basic.info.persistence.dataobject.PostDepartmentDO;
|
||||
import com.zcloud.basic.info.persistence.repository.DepartmentRepository;
|
||||
import com.zcloud.basic.info.persistence.repository.PostDepartmentRepository;
|
||||
import com.zcloud.basic.info.persistence.repository.PostRepository;
|
||||
import com.zcloud.gbscommon.utils.PageQueryHelper;
|
||||
|
|
@ -20,6 +24,7 @@ import lombok.AllArgsConstructor;
|
|||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -37,6 +42,8 @@ import java.util.stream.Collectors;
|
|||
public class PostQueryExe {
|
||||
private final PostRepository postRepository;
|
||||
private final PostDepartmentRepository postDepartmentRepository;
|
||||
private final DepartmentRepository departmentRepository;
|
||||
private final DepartmentCoConvertor departmentCoConvertor;
|
||||
private final PostCoConvertor postCoConvertor;
|
||||
private final PostDepartmentCoConvertor postDepartmentCoConvertor;
|
||||
|
||||
|
|
@ -49,8 +56,30 @@ public class PostQueryExe {
|
|||
public PageResponse<PostCO> execute(PostPageQry postPageQry) {
|
||||
Map<String, Object> params = PageQueryHelper.toHashMap(postPageQry);
|
||||
PageResponse<PostDO> pageResponse = postRepository.listPage(params);
|
||||
List<PostCO> examCenterCOS = postCoConvertor.converDOsToCOs(pageResponse.getData());
|
||||
return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
|
||||
|
||||
Long[] departmentIds = pageResponse.getData().stream().map(PostDO::getDepartmentId).toArray(Long[]::new);
|
||||
List<DepartmentDO> departmentDOList = departmentRepository.listByIds(Arrays.asList(departmentIds));
|
||||
|
||||
// Map<部门id, 部门名称>
|
||||
Map<Long, String> departmentMap = new HashMap<>();
|
||||
if(CollUtil.isNotEmpty(departmentDOList)) {
|
||||
List<DepartmentCO> departmentCOList = departmentCoConvertor.converDOsToCOs(departmentDOList);
|
||||
departmentMap = departmentCOList.stream().collect(Collectors.toMap(
|
||||
DepartmentCO::getId,
|
||||
DepartmentCO::getName
|
||||
));
|
||||
}
|
||||
|
||||
List<PostCO> postCOList = postCoConvertor.converDOsToCOs(pageResponse.getData());
|
||||
if(CollUtil.isNotEmpty(postCOList)) {
|
||||
for (PostCO postCO : postCOList) {
|
||||
if(CollUtil.isNotEmpty(departmentMap)) {
|
||||
postCO.setDepartmentName(departmentMap.get(postCO.getDepartmentId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return PageResponse.of(postCOList, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
|
||||
}
|
||||
|
||||
public MultiResponse<PostCO> execute(PostListQry qry) {
|
||||
|
|
@ -62,8 +91,10 @@ public class PostQueryExe {
|
|||
return new MultiResponse<>();
|
||||
}
|
||||
Long[] postIds = postMRDO.getData().stream().map(PostDO::getId).toArray(Long[]::new);
|
||||
Long[] departmentIds = postMRDO.getData().stream().map(PostDO::getDepartmentId).toArray(Long[]::new);
|
||||
// 岗位部门集合
|
||||
List<PostDepartmentDO> postDepartmentDOList = postDepartmentRepository.list(postIds);
|
||||
List<DepartmentDO> departmentDOList = departmentRepository.listByIds(Arrays.asList(departmentIds));
|
||||
|
||||
// Map<岗位id, List<岗位部门对象>>
|
||||
Map<Long, List<PostDepartmentCO>> postDepartmentMap = new HashMap<>();
|
||||
|
|
@ -71,6 +102,15 @@ public class PostQueryExe {
|
|||
List<PostDepartmentCO> postDepartmentCOList = postDepartmentCoConvertor.converDOsToCOs(postDepartmentDOList);
|
||||
postDepartmentMap = postDepartmentCOList.stream().collect(Collectors.groupingBy(PostDepartmentCO::getPostId));
|
||||
}
|
||||
// Map<部门id, 部门名称>
|
||||
Map<Long, String> departmentMap = new HashMap<>();
|
||||
if(CollUtil.isNotEmpty(departmentDOList)) {
|
||||
List<DepartmentCO> departmentCOList = departmentCoConvertor.converDOsToCOs(departmentDOList);
|
||||
departmentMap = departmentCOList.stream().collect(Collectors.toMap(
|
||||
DepartmentCO::getId,
|
||||
DepartmentCO::getName
|
||||
));
|
||||
}
|
||||
|
||||
// 赋值
|
||||
List<PostDO> postDOList = postMRDO.getData();
|
||||
|
|
@ -80,6 +120,9 @@ public class PostQueryExe {
|
|||
if(CollUtil.isNotEmpty(postDepartmentMap) && CollUtil.isNotEmpty(postDepartmentMap.get(postCO.getId()))) {
|
||||
postCO.setDepartmentList(postDepartmentMap.get(postCO.getId()));
|
||||
}
|
||||
if(CollUtil.isNotEmpty(departmentMap)) {
|
||||
postCO.setDepartmentName(departmentMap.get(postCO.getDepartmentId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,6 +139,10 @@ public class PostQueryExe {
|
|||
BeanUtils.copyProperties(postDO.getData(), co);
|
||||
postCO.setData(co);
|
||||
|
||||
// 查询部门名称
|
||||
DepartmentDO departmentDO = departmentRepository.getById(postDO.getData().getDepartmentId());
|
||||
postCO.getData().setDepartmentName(departmentDO.getName());
|
||||
|
||||
// 岗位-部门权限关联代码
|
||||
if(co.getSupervisionFlag() == 1){
|
||||
PostDepartmentPageQry qry = new PostDepartmentPageQry();
|
||||
|
|
|
|||
Loading…
Reference in New Issue