From 0b3cd0641b50c5bdaf32b79796312fdfe24b8ca2 Mon Sep 17 00:00:00 2001 From: dxfeng Date: Fri, 28 Oct 2022 17:43:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E6=9D=83=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/company/bo/CompBO.java | 7 ++- .../organization/mapper/comp/CompMapper.java | 2 +- .../mapper/detach/ManagerDetachMapper.java | 2 + .../mapper/detach/ManagerDetachMapper.xml | 7 +++ .../service/impl/CompServiceImpl.java | 4 ++ .../service/impl/DepartmentServiceImpl.java | 19 ++++--- .../impl/ManagerDetachServiceImpl.java | 23 ++++++++ .../organization/util/detach/DetachUtil.java | 52 +++++++++++++++++++ .../util/tree/SearchTreeUtil.java | 14 +++-- 9 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 src/com/engine/organization/util/detach/DetachUtil.java diff --git a/src/com/engine/organization/entity/company/bo/CompBO.java b/src/com/engine/organization/entity/company/bo/CompBO.java index 53ad65c1..d26b8bd9 100644 --- a/src/com/engine/organization/entity/company/bo/CompBO.java +++ b/src/com/engine/organization/entity/company/bo/CompBO.java @@ -48,8 +48,10 @@ public class CompBO { // 兼容MySQL usedIds.addAll(MapperProxyFactory.getProxy(CompMapper.class).listUsedIds()); List collect = Arrays.stream(String.join(",", usedIds).split(",")).collect(Collectors.toList()); - return dtoList.stream().peek(e -> { + Set leafs = new HashSet<>(); + List collectTree = dtoList.stream().peek(e -> { List childList = collects.get(e.getId()); + leafs.add(e.getId()); if (CollectionUtils.isNotEmpty(childList)) { e.setChildren(childList); e.setIsUsed(1); @@ -60,7 +62,8 @@ public class CompBO { e.setIsUsed(0); } } - }).filter(item -> null == item.getParentCompany() || 0 == item.getParentCompany()).collect(Collectors.toList()); + }).collect(Collectors.toList()); + return collectTree.stream().filter(item->!leafs.contains(item.getParentCompany())).collect(Collectors.toList()); } public static List buildCompDTOList(Collection list, List filterList) { diff --git a/src/com/engine/organization/mapper/comp/CompMapper.java b/src/com/engine/organization/mapper/comp/CompMapper.java index aad7c06f..919b0cdc 100644 --- a/src/com/engine/organization/mapper/comp/CompMapper.java +++ b/src/com/engine/organization/mapper/comp/CompMapper.java @@ -77,7 +77,7 @@ public interface CompMapper { * @param id * @return */ - CompPO listById(@Param("id") long id); + CompPO listById(@Param("id") Long id); /** * 根据UUID查询数据 diff --git a/src/com/engine/organization/mapper/detach/ManagerDetachMapper.java b/src/com/engine/organization/mapper/detach/ManagerDetachMapper.java index 5cd47c4c..df66bdb6 100644 --- a/src/com/engine/organization/mapper/detach/ManagerDetachMapper.java +++ b/src/com/engine/organization/mapper/detach/ManagerDetachMapper.java @@ -23,4 +23,6 @@ public interface ManagerDetachMapper { List selectByIds(@Param("ids")Collection ids); ManagerDetachPO getDetachById(@Param("id") Integer id); + + List getDetachListById(@Param("ecManager") Integer ecManager); } diff --git a/src/com/engine/organization/mapper/detach/ManagerDetachMapper.xml b/src/com/engine/organization/mapper/detach/ManagerDetachMapper.xml index d1ddc927..9646bcb6 100644 --- a/src/com/engine/organization/mapper/detach/ManagerDetachMapper.xml +++ b/src/com/engine/organization/mapper/detach/ManagerDetachMapper.xml @@ -214,4 +214,11 @@ WHERE delete_type = 0 AND id = #{id} + \ No newline at end of file diff --git a/src/com/engine/organization/service/impl/CompServiceImpl.java b/src/com/engine/organization/service/impl/CompServiceImpl.java index ca87a50e..a00b4bf7 100644 --- a/src/com/engine/organization/service/impl/CompServiceImpl.java +++ b/src/com/engine/organization/service/impl/CompServiceImpl.java @@ -34,6 +34,7 @@ import com.engine.organization.thread.OrganizationSyncEc; import com.engine.organization.util.*; import com.engine.organization.util.coderule.CodeRuleUtil; import com.engine.organization.util.db.MapperProxyFactory; +import com.engine.organization.util.detach.DetachUtil; import com.engine.organization.util.page.Column; import com.engine.organization.util.page.PageInfo; import com.engine.organization.util.page.PageUtil; @@ -113,10 +114,13 @@ public class CompServiceImpl extends Service implements CompService { PageInfo pageInfos; String orderSql = PageInfoSortUtil.getSortSql(params.getSortParams()); List allList = getCompMapper().list(orderSql); + new DetachUtil(user.getUID()).filterCompanyList(allList); // 通过子级遍历父级元素 if (filter) { // 根据条件获取元素 List filterCompPOs = getCompMapper().listByFilter(compPO, orderSql); + new DetachUtil(user.getUID()).filterCompanyList(filterCompPOs); + // 添加父级元素 List compListDTOS = CompBO.buildCompDTOList(allList, filterCompPOs); List subList = PageUtil.subList(params.getCurrent(), params.getPageSize(), compListDTOS); diff --git a/src/com/engine/organization/service/impl/DepartmentServiceImpl.java b/src/com/engine/organization/service/impl/DepartmentServiceImpl.java index ef4c824c..19b72323 100644 --- a/src/com/engine/organization/service/impl/DepartmentServiceImpl.java +++ b/src/com/engine/organization/service/impl/DepartmentServiceImpl.java @@ -48,6 +48,7 @@ import com.engine.organization.thread.OrganizationSyncEc; import com.engine.organization.util.*; import com.engine.organization.util.coderule.CodeRuleUtil; import com.engine.organization.util.db.MapperProxyFactory; +import com.engine.organization.util.detach.DetachUtil; import com.engine.organization.util.page.Column; import com.engine.organization.util.page.PageInfo; import com.engine.organization.util.page.PageUtil; @@ -177,10 +178,12 @@ public class DepartmentServiceImpl extends Service implements DepartmentService PageInfo pageInfos; String orderSql = PageInfoSortUtil.getSortSql(param.getSortParams()); List allList = getDepartmentMapper().list(orderSql); + new DetachUtil(user.getUID()).filterDepartmentList(allList); // 通过子级遍历父级元素 if (filter) { // 根据条件获取元素 List filterDeptPOs = getDepartmentMapper().listByFilter(departmentPO, orderSql); + new DetachUtil(user.getUID()).filterDepartmentList(filterDeptPOs); // 添加父级元素 List compListDTOS = DepartmentBO.buildDeptDTOList(allList, filterDeptPOs); List subList = PageUtil.subList(param.getCurrent(), param.getPageSize(), compListDTOS); @@ -835,11 +838,16 @@ public class DepartmentServiceImpl extends Service implements DepartmentService // 查询部门信息 Long parentCompId = StringUtil.isEmpty(id) ? null : Long.parseLong(id); CompPO compBuild = CompPO.builder().compName(keyword).parentCompany(parentCompId).forbiddenTag(0).build(); + List allCompanys = getCompMapper().list("show_order"); + new DetachUtil(user.getUID()).filterCompanyList(allCompanys); List filterComps = getCompMapper().listByFilter(compBuild, "show_order"); + new DetachUtil(user.getUID()).filterCompanyList(filterComps); + + Map allMaps = allCompanys.stream().collect(Collectors.toMap(CompPO::getId, item -> item, (k1, k2) -> k1)); Set builderComps = new HashSet<>(); for (CompPO compPO : filterComps) { - buildParentComps(compPO, builderComps); + buildParentComps(compPO, builderComps,allMaps); } return SearchTreeUtil.builderTreeMode(CompBO.buildSetToSearchTree(builderComps)); @@ -851,14 +859,11 @@ public class DepartmentServiceImpl extends Service implements DepartmentService * @param compPO * @param builderComps */ - private void buildParentComps(CompPO compPO, Set builderComps) { + private void buildParentComps(CompPO compPO, Set builderComps, Map allMaps) { builderComps.add(compPO); - if (SearchTreeUtil.isTop(compPO.getParentCompany())) { - return; - } - CompPO parentComp = getCompMapper().listById(compPO.getParentCompany()); + CompPO parentComp = allMaps.get(compPO.getParentCompany()); if (null != parentComp && 0 == parentComp.getForbiddenTag()) { - buildParentComps(parentComp, builderComps); + buildParentComps(parentComp, builderComps, allMaps); } } diff --git a/src/com/engine/organization/service/impl/ManagerDetachServiceImpl.java b/src/com/engine/organization/service/impl/ManagerDetachServiceImpl.java index 5aa68e4e..f318657f 100644 --- a/src/com/engine/organization/service/impl/ManagerDetachServiceImpl.java +++ b/src/com/engine/organization/service/impl/ManagerDetachServiceImpl.java @@ -21,10 +21,13 @@ import com.engine.organization.util.OrganizationFormItemUtil; import com.engine.organization.util.db.DBType; import com.engine.organization.util.db.MapperProxyFactory; import com.engine.organization.util.relation.EcHrmRelationUtil; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import weaver.conn.RecordSet; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @Author weaver_cl @@ -118,6 +121,7 @@ public class ManagerDetachServiceImpl extends Service implements ManagerDetachSe .ecManager(param.getEcManager()) .jclManager(getHrmResourceMapper().getJclResourceId(String.valueOf(param.getEcManager())).intValue()) .ecRolelevel(param.getEcRolelevel()) + // TODO 遍历存储 .jclRolelevel(EcHrmRelationUtil.getJclCompanyId(param.getEcRolelevel()) != null ? String.valueOf(EcHrmRelationUtil.getJclCompanyId(param.getEcRolelevel()).getId()) : null) .manageModule("组织管理") .creator((long)user.getUID()) @@ -156,4 +160,23 @@ public class ManagerDetachServiceImpl extends Service implements ManagerDetachSe } return sqlWhere; } + + + /** + * 查询当前人员所辖分部JCL_ID + * @param uId + * @return + */ + public static List getJclRoleLevels(Integer uId) { + List ecRoleLevels = new ArrayList<>(); + ManagerDetachMapper mangeDetachMapper = MapperProxyFactory.getProxy(ManagerDetachMapper.class); + List detachListById = mangeDetachMapper.getDetachListById(uId); + for (ManagerDetachPO managerDetachPO : detachListById) { + List ids = Stream.of(managerDetachPO.getJclRolelevel().split(",")).map(Long::parseLong).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(ids)) { + ecRoleLevels.addAll(ids); + } + } + return ecRoleLevels; + } } diff --git a/src/com/engine/organization/util/detach/DetachUtil.java b/src/com/engine/organization/util/detach/DetachUtil.java new file mode 100644 index 00000000..13b40b04 --- /dev/null +++ b/src/com/engine/organization/util/detach/DetachUtil.java @@ -0,0 +1,52 @@ +package com.engine.organization.util.detach; + +import com.engine.organization.entity.company.po.CompPO; +import com.engine.organization.entity.department.po.DepartmentPO; +import com.engine.organization.entity.job.po.JobPO; +import com.engine.organization.service.impl.ManagerDetachServiceImpl; +import org.apache.commons.collections.CollectionUtils; + +import java.util.List; + +/** + * @author:dxfeng + * @createTime: 2022/10/28 + * @version: 1.0 + */ +public class DetachUtil { + // private static final boolean IS_DETACH = "true".equals(new BaseBean().getPropValue("", "")); + private boolean IS_DETACH = true; + + private static List ecRoleLevels = null; + + public DetachUtil(Integer uId) { + ecRoleLevels = ManagerDetachServiceImpl.getJclRoleLevels(uId); + } + + /** + * 根据分权配置过滤分部 + */ + public void filterCompanyList(List companyList) { + if (IS_DETACH && CollectionUtils.isNotEmpty(companyList)) { + companyList.removeIf(item -> !ecRoleLevels.contains(item.getId())); + } + } + + /** + * 根据分权配置过滤分部 + */ + public void filterDepartmentList(List departmentList) { + if (IS_DETACH && CollectionUtils.isNotEmpty(departmentList)) { + departmentList.removeIf(item -> !ecRoleLevels.contains(item.getParentComp())); + } + } + + /** + * 根据分权配置过滤分部 + */ + public void filterJobList(List jobList) { + if (IS_DETACH && CollectionUtils.isNotEmpty(jobList)) { + jobList.removeIf(item -> !ecRoleLevels.contains(item.getParentComp())); + } + } +} diff --git a/src/com/engine/organization/util/tree/SearchTreeUtil.java b/src/com/engine/organization/util/tree/SearchTreeUtil.java index 2ec73a8c..d15b88e1 100644 --- a/src/com/engine/organization/util/tree/SearchTreeUtil.java +++ b/src/com/engine/organization/util/tree/SearchTreeUtil.java @@ -89,11 +89,15 @@ public class SearchTreeUtil { public static List builderTreeMode(List treeList) { List sortedList = treeList.stream().sorted(Comparator.comparing(SearchTree::getOrderNum)).collect(Collectors.toList()); Map> collects = sortedList.stream().collect(Collectors.groupingBy(TreeNode::getPid)); - return sortedList.stream().peek(e -> e.setSubs(collects.get(e.getId()))).peek(item -> { - if (CollectionUtils.isNotEmpty(item.getSubs())) { - item.setIsParent(true); + Set leafIds = new HashSet<>(); + List collect = sortedList.stream().peek(e -> { + e.setSubs(collects.get(e.getId())); + leafIds.add(e.getId()); + if (CollectionUtils.isNotEmpty(e.getSubs())) { + e.setIsParent(true); } - }).filter(item -> isTop(item.getPid())).collect(Collectors.toList()); + }).collect(Collectors.toList()); + return collect.stream().filter(item -> !leafIds.contains(item.getPid())).collect(Collectors.toList()); } /** @@ -119,7 +123,7 @@ public class SearchTreeUtil { if (CollectionUtils.isNotEmpty(e.getSubs())) { treeNodes.addAll(e.getSubs()); } - e.setSubs( new ArrayList<>(treeNodes)); + e.setSubs(new ArrayList<>(treeNodes)); }).peek(item -> { if (CollectionUtils.isNotEmpty(item.getSubs())) { item.setIsParent(true);