You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weaver-hrm-organization/src/com/engine/organization/service/impl/PersonnelResumeServiceImpl....

277 lines
14 KiB
Java

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.hrmresource.bo.ResourceBO;
import com.engine.organization.entity.hrmresource.po.ResourcePO;
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.enums.ModuleTypeEnum;
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.mapper.resource.HrmResourceMapper;
import com.engine.organization.service.PersonnelResumeService;
import com.engine.organization.util.MenuBtn;
import com.engine.organization.util.db.MapperProxyFactory;
import com.engine.organization.util.detach.DetachUtil;
import com.engine.organization.util.page.PageUtil;
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/12/28
* @version: 1.0
*/
public class PersonnelResumeServiceImpl extends Service implements PersonnelResumeService {
private DepartmentMapper getDepartmentMapper() {
return MapperProxyFactory.getProxy(DepartmentMapper.class);
}
private CompMapper getCompMapper() {
return MapperProxyFactory.getProxy(CompMapper.class);
}
private JobMapper getJobMapper() {
return MapperProxyFactory.getProxy(JobMapper.class);
}
private HrmResourceMapper getHrmResourceMapper() {
return MapperProxyFactory.getProxy(HrmResourceMapper.class);
}
@Override
public Map<String, Object> getSearchTree(SearchTreeParams params) {
String keyword = params.getKeyword();
String id = params.getId();
String type = Util.null2String(params.getType());
List<SearchTree> treeList = getFilterCompany(id, type, keyword);
return SearchTreeUtil.getSearchTree(type, treeList);
}
@Override
public Map<String, Object> hasRight() {
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("hasRight", true);
ArrayList<MenuBtn> topMenuList = new ArrayList<>();
ArrayList<MenuBtn> rightMenuList = new ArrayList<>();
// 新增
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("screening").menuIcon("icon-coms-New-Flow").menuName("人员筛选").type("BTN_Screening").build());
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("currentExport").menuIcon("icon-coms-edit").menuName("导出当前").type("BTN_CurrentExport").build());
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("MergeExport").menuIcon("icon-coms-Delete").menuName("全部导出(合并)").type("BTN_MergeExport").build());
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("AllExport").menuIcon("icon-coms-Delete").menuName("全部导出").type("BTN_AllExport").build());
resultMap.put("topMenu", topMenuList);
// 新增
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("screening").menuIcon("icon-coms-New-Flow").menuName("人员筛选").type("BTN_Screening").build());
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("currentExport").menuIcon("icon-coms-edit").menuName("导出当前").type("BTN_CurrentExport").build());
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("MergeExport").menuIcon("icon-coms-Delete").menuName("全部导出(合并)").type("BTN_MergeExport").build());
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("AllExport").menuIcon("icon-coms-Delete").menuName("全部导出").type("BTN_AllExport").build());
resultMap.put("rightMenu", rightMenuList);
return resultMap;
}
public List<SearchTree> getFilterCompany(String id, String type, String keyword) {
List<SearchTree> searchTree = new ArrayList<>();
// 通过分部、公司 组装数据
if (StringUtil.isEmpty(id) || ModuleTypeEnum.subcompanyfielddefined.getValue().toString().equals(type)) {
Integer subCompanyId1 = StringUtil.isEmpty(id) ? null : Integer.parseInt(id);
DepartmentPO departmentBuild = DepartmentPO.builder().departmentName(keyword).subCompanyId1(subCompanyId1).canceled(0).build();
CompPO compBuild = CompPO.builder().subCompanyName(keyword).supSubComId(subCompanyId1).canceled(0).build();
// 所属分部下的岗位
JobPO jobBuild = JobPO.builder().jobTitleName(keyword).ecCompany(subCompanyId1).forbiddenTag(0).build();
ResourcePO resourcePO = ResourcePO.builder().lastName(keyword).subcompanyid1(subCompanyId1).build();
searchTree = buildTreeByCompAndDept(departmentBuild, compBuild, jobBuild, resourcePO);
} else if (ModuleTypeEnum.departmentfielddefined.getValue().toString().equals(type)) {
Integer departmentId = Integer.parseInt(id);
DepartmentPO departmentBuild = DepartmentPO.builder().departmentName(keyword).supDepId(departmentId).canceled(0).build();
// 所属分部下的岗位
JobPO jobBuild = JobPO.builder().jobTitleName(keyword).ecDepartment(departmentId).forbiddenTag(0).build();
ResourcePO resourcePO = ResourcePO.builder().lastName(keyword).departmentid(departmentId).build();
searchTree = buildTreeByDeptAndJob(departmentBuild, jobBuild, resourcePO);
} else if (ModuleTypeEnum.jobfielddefined.getValue().toString().equals(type)) {
Long jobId = Long.parseLong(id);
JobPO jobById = getJobMapper().getJobById(jobId);
ResourcePO resourcePO = ResourcePO.builder().lastName(keyword).subcompanyid1(jobById.getEcCompany()).departmentid(jobById.getEcDepartment()).jobtitle(jobById.getEcJobTitle()).build();
List<ResourcePO> resourcePOS = getHrmResourceMapper().listByFilter(resourcePO);
searchTree = SearchTreeUtil.builderTreeMode(ResourceBO.buildSetToSearchTree(resourcePOS));
}
return searchTree;
}
/**
*
*
* @param departmentBuild
* @param compBuild
* @param jobBuild
* @return
*/
private List<SearchTree> buildTreeByCompAndDept(DepartmentPO departmentBuild, CompPO compBuild, JobPO jobBuild, ResourcePO resourcePO) {
// 查询人员数据
List<ResourcePO> resourcePOS = getHrmResourceMapper().listByFilter(resourcePO);
Set<JobPO> builderJobs = new HashSet<>();
// 补充人员所有岗位,关联人员及聚才林岗位
for (ResourcePO resource : resourcePOS) {
JobPO jobByResource = getJobMapper().getJobByResource(resource);
if (null != jobByResource) {
resource.setJobId(jobByResource.getId());
builderJobs.add(jobByResource);
}
}
List<SearchTree> resourceTrees = SearchTreeUtil.builderTreeMode(ResourceBO.buildSetToSearchTree(resourcePOS));
List<JobPO> jobPOS = getJobMapper().listPOsByFilter(jobBuild);
new DetachUtil(user).filterJobList(jobPOS);
List<DepartmentPO> filterDeparts = getDepartmentMapper().listByFilter(departmentBuild, "showorder");
new DetachUtil(user).filterDepartmentList(filterDeparts);
// 添加父级岗位
builderJobs.addAll(jobPOS);
// 添加岗位的上级部门或分部
List<SearchTree> jobTrees = SearchTreeUtil.builderTreeMode(JobBO.buildSetToSearchTree(builderJobs), resourceTrees);
String parentDeptS = jobTrees.stream().map(SearchTree::getParentComp).collect(Collectors.joining(","));
if (!StringUtil.isEmpty(parentDeptS)) {
// 兼容SQLServer每次最多in,2100条数据
List<Long> ids = DeleteParam.builder().ids(parentDeptS).build().getIds();
int ceilCount = (int) Math.ceil((double) ids.size() / 1000);
List<DepartmentPO> departmentsByIds = new ArrayList<>();
for (int i = 1; i < ceilCount + 1; i++) {
List<Long> longs = PageUtil.subList(i, 1000, ids);
List<DepartmentPO> departmentsById = getDepartmentMapper().getDeptsByIds(longs);
if (CollectionUtils.isNotEmpty(departmentsById)) {
departmentsByIds.addAll(departmentsById);
}
}
if (CollectionUtils.isNotEmpty(departmentsByIds)) {
filterDeparts.addAll(departmentsByIds);
}
}
// 查询分部信息
List<CompPO> filterComps = getCompMapper().listByFilter(compBuild, "showorder");
new DetachUtil(user).filterCompanyList(filterComps);
Set<DepartmentPO> builderDeparts = new HashSet<>();
for (DepartmentPO departmentPO : filterDeparts) {
buildParentDepts(departmentPO, builderDeparts);
}
List<SearchTree> departmentList = DepartmentBO.buildSetToSearchTree(builderDeparts);
List<SearchTree> deptTrees = SearchTreeUtil.builderTreeMode(departmentList);
List<SearchTree> searchTrees = SearchTreeUtil.builderTreeMode(departmentList, jobTrees);
// 添加部门的上级分部
String parentCompS = deptTrees.stream().map(SearchTree::getParentComp).collect(Collectors.joining(","));
if (!StringUtil.isEmpty(parentCompS)) {
List<CompPO> compsByIds = getCompMapper().getCompsByIds(DeleteParam.builder().ids(parentCompS).build().getIds());
if (CollectionUtils.isNotEmpty(compsByIds)) {
filterComps.addAll(compsByIds);
}
}
List<CompPO> allCompanys = getCompMapper().listAll("showorder");
new DetachUtil(user).filterCompanyList(allCompanys);
Map<Integer, CompPO> allMaps = allCompanys.stream().collect(Collectors.toMap(CompPO::getId, item -> item, (k1, k2) -> k1));
Set<CompPO> builderComps = new HashSet<>();
for (CompPO compPO : filterComps) {
buildParentComps(compPO, builderComps, allMaps);
}
return SearchTreeUtil.builderTreeMode(CompBO.buildSetToSearchTree(builderComps), searchTrees);
}
private List<SearchTree> buildTreeByDeptAndJob(DepartmentPO departmentBuild, JobPO jobBuild, ResourcePO resourcePO) {
// 查询人员数据
List<ResourcePO> resourcePOS = getHrmResourceMapper().listByFilter(resourcePO);
Set<JobPO> builderJobs = new HashSet<>();
// 补充人员所有岗位,关联人员及聚才林岗位
for (ResourcePO resource : resourcePOS) {
JobPO jobByResource = getJobMapper().getJobByResource(resource);
if (null != jobByResource) {
resource.setJobId(jobByResource.getId());
builderJobs.add(jobByResource);
}
}
List<SearchTree> resourceTrees = SearchTreeUtil.builderTreeMode(ResourceBO.buildSetToSearchTree(resourcePOS));
List<JobPO> jobPOS = getJobMapper().listPOsByFilter(jobBuild);
List<DepartmentPO> filterDeparts = getDepartmentMapper().listByFilter(departmentBuild, "showorder");
// 添加父级岗位
builderJobs.addAll(jobPOS);
// 添加岗位的上级部门或分部
List<SearchTree> jobTrees = SearchTreeUtil.builderTreeMode(JobBO.buildSetToSearchTree(builderJobs), resourceTrees);
String parentDeptS = jobTrees.stream().map(SearchTree::getParentComp).collect(Collectors.joining(","));
if (!StringUtil.isEmpty(parentDeptS)) {
// 兼容SQLServer每次最多in,2100条数据
List<Long> ids = (List<Long>) DeleteParam.builder().ids(parentDeptS).build().getIds();
int ceilCount = (int) Math.ceil((double) ids.size() / 1000);
List<DepartmentPO> departmentsByIds = new ArrayList<>();
for (int i = 0; i < ceilCount - 1; i++) {
List<DepartmentPO> departmentsById = getDepartmentMapper().getDeptsByIds(PageUtil.subList(i, 1000, ids));
if (CollectionUtils.isNotEmpty(departmentsById)) {
departmentsByIds.addAll(departmentsById);
}
}
if (CollectionUtils.isNotEmpty(departmentsByIds)) {
filterDeparts.addAll(departmentsByIds);
}
}
// 查询分部信息
Set<DepartmentPO> builderDeparts = new HashSet<>();
for (DepartmentPO departmentPO : filterDeparts) {
buildParentDepts(departmentPO, builderDeparts);
}
return SearchTreeUtil.builderTreeMode(DepartmentBO.buildSetToSearchTree(builderDeparts), jobTrees);
}
/**
*
*
* @param departmentPO
* @param builderDeparts
*/
private void buildParentDepts(DepartmentPO departmentPO, Set<DepartmentPO> builderDeparts) {
builderDeparts.add(departmentPO);
if (SearchTreeUtil.isTop(departmentPO.getSupDepId())) {
return;
}
DepartmentPO parentDept = getDepartmentMapper().getDeptById(departmentPO.getSupDepId());
if (null != parentDept) {
buildParentDepts(parentDept, builderDeparts);
}
}
/**
*
*
* @param compPO
* @param builderComps
*/
private void buildParentComps(CompPO compPO, Set<CompPO> builderComps, Map<Integer, CompPO> allMaps) {
builderComps.add(compPO);
CompPO parentComp = allMaps.get(compPO.getSupSubComId());
if (null != parentComp) {
buildParentComps(parentComp, builderComps, allMaps);
}
}
}