diff --git a/src/com/engine/organization/entity/department/bo/DepartmentBO.java b/src/com/engine/organization/entity/department/bo/DepartmentBO.java index 1a960959..93ffbdae 100644 --- a/src/com/engine/organization/entity/department/bo/DepartmentBO.java +++ b/src/com/engine/organization/entity/department/bo/DepartmentBO.java @@ -39,7 +39,7 @@ public class DepartmentBO { .deptPrincipal(getEmployeeNameById(e.getDeptPrincipal())) .showOrder(null == e.getShowOrder() ? 0 : e.getShowOrder()) .forbiddenTag(e.getForbiddenTag()) - .build() ).collect(Collectors.toList()); + .build()).collect(Collectors.toList()); Map> collects = dtoList.stream().filter(item -> null != item.getParentDept() && 0 != item.getParentDept()).collect(Collectors.groupingBy(DepartmentListDTO::getParentDept)); // 处理被引用数据 List usedIds = MapperProxyFactory.getProxy(DepartmentMapper.class).listUsedId(); @@ -118,13 +118,17 @@ public class DepartmentBO { return singleDeptTreeVOS.stream().peek(e -> e.setChildren(collects.get(e.getId()))).filter(item -> parentComp.equals(item.getParentComp())).collect(Collectors.toList()); } - public static List buildSetToSearchTree(Set departmentPOS) { + return buildSetToSearchTree(departmentPOS, true); + } + + + public static List buildSetToSearchTree(Set departmentPOS, boolean isLeaf) { return departmentPOS.stream().map(item -> { SearchTree tree = new SearchTree(); tree.setCanClick(true); tree.setCanceled(false); - tree.setIcon("icon-coms-Branch"); + tree.setIcon(isLeaf ? "icon-coms-Branch" : "icon-coms-LargeArea"); tree.setId(item.getId().toString()); tree.setIsParent(false); tree.setIsVirtual("0"); diff --git a/src/com/engine/organization/entity/job/bo/JobBO.java b/src/com/engine/organization/entity/job/bo/JobBO.java index 5e8bec08..81992a63 100644 --- a/src/com/engine/organization/entity/job/bo/JobBO.java +++ b/src/com/engine/organization/entity/job/bo/JobBO.java @@ -4,6 +4,7 @@ import com.engine.organization.entity.job.dto.JobListDTO; import com.engine.organization.entity.job.param.JobSearchParam; import com.engine.organization.entity.job.po.JobPO; import com.engine.organization.entity.job.vo.SingleJobTreeVO; +import com.engine.organization.entity.searchtree.SearchTree; import com.engine.organization.mapper.job.JobMapper; import com.engine.organization.transmethod.JobTransMethod; import com.engine.organization.util.db.MapperProxyFactory; @@ -142,4 +143,22 @@ public class JobBO { } } + public static List buildSetToSearchTree(Set builderJobs) { + return builderJobs.stream().map(item -> { + SearchTree tree = new SearchTree(); + tree.setCanClick(true); + tree.setCanceled(false); + tree.setIcon("icon-coms-Branch"); + tree.setId(item.getId().toString()); + tree.setIsParent(false); + tree.setIsVirtual("0"); + tree.setName(item.getJobName()); + tree.setPid(null == item.getParentJob() ? "0" : item.getParentJob().toString()); + tree.setSelected(false); + tree.setType("3"); + tree.setParentComp(null == item.getParentDept() ? "0" : item.getParentDept().toString()); + return tree; + }).collect(Collectors.toList()); + + } } diff --git a/src/com/engine/organization/mapper/department/DepartmentMapper.java b/src/com/engine/organization/mapper/department/DepartmentMapper.java index 0df6b635..e9236362 100644 --- a/src/com/engine/organization/mapper/department/DepartmentMapper.java +++ b/src/com/engine/organization/mapper/department/DepartmentMapper.java @@ -52,6 +52,8 @@ public interface DepartmentMapper { */ List> listDeptsByIds(@Param("ids") Collection ids); + List getDeptsByIds(@Param("ids") Collection ids); + /** * 根据ID查询数据 * diff --git a/src/com/engine/organization/mapper/department/DepartmentMapper.xml b/src/com/engine/organization/mapper/department/DepartmentMapper.xml index e5ec0fff..2912552e 100644 --- a/src/com/engine/organization/mapper/department/DepartmentMapper.xml +++ b/src/com/engine/organization/mapper/department/DepartmentMapper.xml @@ -125,6 +125,16 @@ from JCL_ORG_STAFF where delete_type = 0 + listNoFilter(); + /** + * 根据搜索条件查询数据 + * @param jobPO + * @return + */ + List listPOsByFilter(JobPO jobPO); + /** * 查询所有数据 * diff --git a/src/com/engine/organization/mapper/job/JobMapper.xml b/src/com/engine/organization/mapper/job/JobMapper.xml index 5e8ce87a..7fc6e50c 100644 --- a/src/com/engine/organization/mapper/job/JobMapper.xml +++ b/src/com/engine/organization/mapper/job/JobMapper.xml @@ -295,6 +295,31 @@ from jcl_org_job t where delete_type = 0 + diff --git a/src/com/engine/organization/service/HrmResourceService.java b/src/com/engine/organization/service/HrmResourceService.java new file mode 100644 index 00000000..4440c006 --- /dev/null +++ b/src/com/engine/organization/service/HrmResourceService.java @@ -0,0 +1,21 @@ +package com.engine.organization.service; + +import com.engine.organization.entity.searchtree.SearchTreeParams; + +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2022/06/20 + * @version: 1.0 + */ +public interface HrmResourceService { + + /** + * 列表左侧树 + * + * @param params + * @return + */ + public Map getSearchTree(SearchTreeParams params); +} diff --git a/src/com/engine/organization/service/impl/ExtServiceImpl.java b/src/com/engine/organization/service/impl/ExtServiceImpl.java index bc1f8b5d..72dffa3d 100644 --- a/src/com/engine/organization/service/impl/ExtServiceImpl.java +++ b/src/com/engine/organization/service/impl/ExtServiceImpl.java @@ -205,6 +205,8 @@ public class ExtServiceImpl extends Service implements ExtService { } map.put(key, value); } + // 遍历Map + if (null != id) { // 判断更新还是插入 int count = getExtMapper().countExtById(tableName, id); diff --git a/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java b/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java new file mode 100644 index 00000000..607488b3 --- /dev/null +++ b/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java @@ -0,0 +1,213 @@ +package com.engine.organization.service.impl; + +import com.engine.core.impl.Service; +import com.engine.organization.entity.DeleteParam; +import com.engine.organization.entity.company.bo.CompBO; +import com.engine.organization.entity.company.po.CompPO; +import com.engine.organization.entity.department.bo.DepartmentBO; +import com.engine.organization.entity.department.po.DepartmentPO; +import com.engine.organization.entity.job.bo.JobBO; +import com.engine.organization.entity.job.po.JobPO; +import com.engine.organization.entity.searchtree.SearchTree; +import com.engine.organization.entity.searchtree.SearchTreeParams; +import com.engine.organization.mapper.comp.CompMapper; +import com.engine.organization.mapper.department.DepartmentMapper; +import com.engine.organization.mapper.job.JobMapper; +import com.engine.organization.service.HrmResourceService; +import com.engine.organization.util.db.MapperProxyFactory; +import com.engine.organization.util.tree.SearchTreeUtil; +import org.apache.commons.collections.CollectionUtils; +import weaver.general.StringUtil; +import weaver.general.Util; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author:dxfeng + * @createTime: 2022/06/20 + * @version: 1.0 + */ +public class HrmResourceServiceImpl extends Service implements HrmResourceService { + /** + * 左侧树 类型表示 + *

+ * 0:集团 + * 1:分部 + * 2:部门 + * 3:岗位 + */ + private static final String TYPE_COMP = "1"; + private static final String TYPE_DEPT = "2"; + private static final String TYPE_JOB = "3"; + + private DepartmentMapper getDepartmentMapper() { + return MapperProxyFactory.getProxy(DepartmentMapper.class); + } + + private CompMapper getCompMapper() { + return MapperProxyFactory.getProxy(CompMapper.class); + } + + private JobMapper getJobMapper() { + return MapperProxyFactory.getProxy(JobMapper.class); + } + + @Override + public Map getSearchTree(SearchTreeParams params) { + String keyword = params.getKeyword(); + String id = params.getId(); + String type = Util.null2String(params.getType()); + List treeList = getFilterCompany(id, type, keyword); + return SearchTreeUtil.getSearchTree(type, treeList); + } + + public List getFilterCompany(String id, String type, String keyword) { + List searchTree = new ArrayList<>(); + // 通过分部、公司 组装数据 + if (StringUtil.isEmpty(id) || TYPE_COMP.equals(type)) { + Long parentCompId = StringUtil.isEmpty(id) ? null : Long.parseLong(id); + DepartmentPO departmentBuild = DepartmentPO.builder().deptName(keyword).parentComp(parentCompId).build(); + CompPO compBuild = CompPO.builder().compName(keyword).parentCompany(parentCompId).build(); + // 所属分部下的岗位 + JobPO jobBuild = JobPO.builder().jobName(keyword).parentComp(parentCompId).build(); + searchTree = buildTreeByCompAndDept(departmentBuild, compBuild, jobBuild); + } else if (TYPE_DEPT.equals(type)) { + Long parentDeptId = Long.parseLong(id); + DepartmentPO departmentBuild = DepartmentPO.builder().deptName(keyword).parentDept(parentDeptId).build(); + // 所属分部下的岗位 + JobPO jobBuild = JobPO.builder().jobName(keyword).parentDept(parentDeptId).build(); + searchTree = buildTreeByDeptAndJob(departmentBuild, jobBuild); + + } else if (TYPE_JOB.equals(type)) { + // 查询部门信息 + List filterDeparts = getJobMapper().listPOsByFilter(JobPO.builder().jobName(keyword).parentJob(Long.parseLong(id)).build()); + Set builderJobs = new HashSet<>(); + for (JobPO departmentPO : filterDeparts) { + buildParentJobs(departmentPO, builderJobs); + } + searchTree = SearchTreeUtil.builderTreeMode(JobBO.buildSetToSearchTree(builderJobs)); + } + return searchTree; + } + + /** + * 分部、部门 组装左侧树 + * + * @param departmentBuild + * @param compBuild + * @param jobBuild + * @return + */ + private List buildTreeByCompAndDept(DepartmentPO departmentBuild, CompPO compBuild, JobPO jobBuild) { + List jobPOS = getJobMapper().listPOsByFilter(jobBuild); + List filterDeparts = getDepartmentMapper().listByFilter(departmentBuild); + // 添加父级岗位 + Set builderJobs = new HashSet<>(); + for (JobPO jobPO : jobPOS) { + buildParentJobs(jobPO, builderJobs); + } + // 添加岗位的上级部门或分部 + List jobTrees = SearchTreeUtil.builderTreeMode(JobBO.buildSetToSearchTree(builderJobs)); + String parentDeptS = jobTrees.stream().map(SearchTree::getParentComp).collect(Collectors.joining(",")); + if (!StringUtil.isEmpty(parentDeptS)) { + List compsByIds = getDepartmentMapper().getDeptsByIds(DeleteParam.builder().ids(parentDeptS).build().getIds()); + if (CollectionUtils.isNotEmpty(compsByIds)) { + filterDeparts.addAll(compsByIds); + } + } + + // 查询分部信息 + List filterComps = getCompMapper().listByFilter(compBuild); + Set builderDeparts = new HashSet<>(); + for (DepartmentPO departmentPO : filterDeparts) { + buildParentDepts(departmentPO, builderDeparts); + } + List deptTrees = SearchTreeUtil.builderTreeMode(DepartmentBO.buildSetToSearchTree(builderDeparts,false)); + // 添加部门的上级分部 + String parentCompS = deptTrees.stream().map(SearchTree::getParentComp).collect(Collectors.joining(",")); + if (!StringUtil.isEmpty(parentCompS)) { + List compsByIds = getCompMapper().getCompsByIds(DeleteParam.builder().ids(parentCompS).build().getIds()); + if (CollectionUtils.isNotEmpty(compsByIds)) { + filterComps.addAll(compsByIds); + } + } + Set builderComps = new HashSet<>(); + for (CompPO compPO : filterComps) { + buildParentComps(compPO, builderComps); + } + List searchTrees = SearchTreeUtil.builderTreeMode(deptTrees, jobTrees); + return SearchTreeUtil.builderTreeMode(CompBO.buildSetToSearchTree(builderComps), searchTrees); + } + + private List buildTreeByDeptAndJob(DepartmentPO departmentBuild, JobPO jobBuild) { + List jobPOS = getJobMapper().listPOsByFilter(jobBuild); + List filterDeparts = getDepartmentMapper().listByFilter(departmentBuild); + // 添加父级岗位 + Set builderJobs = new HashSet<>(); + for (JobPO jobPO : jobPOS) { + buildParentJobs(jobPO, builderJobs); + } + // 添加岗位的上级部门或分部 + List jobTrees = SearchTreeUtil.builderTreeMode(JobBO.buildSetToSearchTree(builderJobs)); + String parentDeptS = jobTrees.stream().map(SearchTree::getParentComp).collect(Collectors.joining(",")); + if (!StringUtil.isEmpty(parentDeptS)) { + List compsByIds = getDepartmentMapper().getDeptsByIds(DeleteParam.builder().ids(parentDeptS).build().getIds()); + if (CollectionUtils.isNotEmpty(compsByIds)) { + filterDeparts.addAll(compsByIds); + } + } + + // 查询分部信息 + Set builderDeparts = new HashSet<>(); + for (DepartmentPO departmentPO : filterDeparts) { + buildParentDepts(departmentPO, builderDeparts); + } + return SearchTreeUtil.builderTreeMode(DepartmentBO.buildSetToSearchTree(builderDeparts,false), jobTrees); + } + + private void buildParentJobs(JobPO jobPO, Set builderJobs) { + builderJobs.add(jobPO); + if (SearchTreeUtil.isTop(jobPO.getParentJob())) { + return; + } + JobPO parentJob = getJobMapper().getJobById(jobPO.getParentJob()); + if (null != parentJob) { + buildParentJobs(parentJob, builderJobs); + } + } + + /** + * 添加查询元素的父级元素 + * + * @param departmentPO + * @param builderDeparts + */ + private void buildParentDepts(DepartmentPO departmentPO, Set builderDeparts) { + builderDeparts.add(departmentPO); + if (SearchTreeUtil.isTop(departmentPO.getParentDept())) { + return; + } + DepartmentPO parentDept = getDepartmentMapper().getDeptById(departmentPO.getParentDept()); + if (null != parentDept) { + buildParentDepts(parentDept, builderDeparts); + } + } + + /** + * 添加查询元素的父级元素 + * + * @param compPO + * @param builderComps + */ + private void buildParentComps(CompPO compPO, Set builderComps) { + builderComps.add(compPO); + if (SearchTreeUtil.isTop(compPO.getParentCompany())) { + return; + } + CompPO parentComp = getCompMapper().listById(compPO.getParentCompany()); + if (null != parentComp) { + buildParentComps(parentComp, builderComps); + } + } +}