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.dto.JobListDTO; import com.engine.organization.entity.job.po.JobPO; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import weaver.hrm.User; import weaver.hrm.moduledetach.ManageDetachComInfo; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; /** * @author:dxfeng * @createTime: 2022/10/28 * @version: 1.0 */ public class DetachUtil { private boolean DETACH; private List jclRoleLevels = new ArrayList<>(); public DetachUtil(User user) { ManageDetachComInfo manageDetachComInfo = new ManageDetachComInfo(); DETACH = manageDetachComInfo.isUseManageDetach(); if (1 == user.getUID()) { DETACH = false; } if (DETACH) { String detachableSubCompanyIds = manageDetachComInfo.getDetachableSubcompanyIds(user); if (StringUtils.isNotBlank(detachableSubCompanyIds)) { jclRoleLevels = Stream.of(detachableSubCompanyIds.split(",")).map(Integer::parseInt).collect(Collectors.toList()); } } } /** * 根据分权配置过滤分部 */ public void filterCompanyList(List companyList) { if (DETACH && CollectionUtils.isNotEmpty(companyList)) { companyList.removeIf(item -> !jclRoleLevels.contains(item.getId())); } } /** * 根据分权配置过滤分部 */ public void filterDepartmentList(List departmentList) { if (DETACH && CollectionUtils.isNotEmpty(departmentList)) { departmentList.removeIf(item -> !jclRoleLevels.contains(item.getSubCompanyId1())); } } /** * 根据分权配置过滤分部 */ public void filterJobDTOList(List jobList) { if (DETACH && CollectionUtils.isNotEmpty(jobList)) { jobList.removeIf(item -> !jclRoleLevels.contains(item.getEcCompany())); } } /** * 根据分权配置过滤分部 */ public void filterJobList(List jobList) { if (DETACH && CollectionUtils.isNotEmpty(jobList)) { jobList.removeIf(item -> !jclRoleLevels.contains(item.getEcCompany())); } } public String getJclRoleLevels() { return StringUtils.join(jclRoleLevels, ","); } public boolean isDETACH() { return DETACH; } }