|
|
|
@ -2,6 +2,7 @@ package com.engine.organization.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.api.hrm.bean.TreeNode;
|
|
|
|
|
import com.engine.core.impl.Service;
|
|
|
|
|
import com.engine.organization.entity.QueryParam;
|
|
|
|
|
import com.engine.organization.entity.comp.bo.CompBO;
|
|
|
|
|
import com.engine.organization.entity.comp.po.CompPO;
|
|
|
|
|
import com.engine.organization.entity.department.bo.DepartmentBO;
|
|
|
|
@ -13,7 +14,6 @@ import com.engine.organization.mapper.department.DepartmentMapper;
|
|
|
|
|
import com.engine.organization.service.JobService;
|
|
|
|
|
import com.engine.organization.util.db.MapperProxyFactory;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import weaver.conn.RecordSet;
|
|
|
|
|
import weaver.general.StringUtil;
|
|
|
|
|
import weaver.general.Util;
|
|
|
|
@ -51,37 +51,20 @@ public class JobServiceImpl extends Service implements JobService {
|
|
|
|
|
String keyword = params.getKeyword();
|
|
|
|
|
String type = Util.null2String(params.getType());
|
|
|
|
|
String id = params.getId();
|
|
|
|
|
// 没有搜索条件查询
|
|
|
|
|
if (StringUtil.isEmpty(keyword)) {
|
|
|
|
|
// 无条件,初始化树结构
|
|
|
|
|
if (StringUtil.isEmpty(type)) {
|
|
|
|
|
dataMap.put("companys", companyList);
|
|
|
|
|
SearchTree rootCompany = getTopGroup();
|
|
|
|
|
rootCompany.setSubs(getCompany("", ""));
|
|
|
|
|
rootCompany.setIsParent(CollectionUtils.isNotEmpty(rootCompany.getSubs()));
|
|
|
|
|
Map<String, Object> rootCompanyMap = new HashMap<>();
|
|
|
|
|
rootCompanyMap.put("rootCompany", rootCompany);
|
|
|
|
|
dataMap.put("datas", rootCompanyMap);
|
|
|
|
|
} else {
|
|
|
|
|
// 根据ID查询
|
|
|
|
|
dataMap.put("datas", getCompany(id, type));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (StringUtil.isEmpty(type)) {
|
|
|
|
|
List<TreeNode> collect = getFilterCompany(id, type, keyword);
|
|
|
|
|
|
|
|
|
|
SearchTree rootCompany = getTopGroup();
|
|
|
|
|
rootCompany.setSubs(collect);
|
|
|
|
|
rootCompany.setIsParent(CollectionUtils.isNotEmpty(rootCompany.getSubs()));
|
|
|
|
|
Map<String, Object> rootCompanyMap = new HashMap<>();
|
|
|
|
|
rootCompanyMap.put("rootCompany", rootCompany);
|
|
|
|
|
dataMap.put("datas", rootCompanyMap);
|
|
|
|
|
|
|
|
|
|
dataMap.put("companys", companyList);
|
|
|
|
|
} else {
|
|
|
|
|
dataMap.put("datas", getFilterCompany(id, type, keyword));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<TreeNode> treeDatas = getFilterCompany(id, type, keyword);
|
|
|
|
|
// 未点击,初始化树结构
|
|
|
|
|
if (StringUtil.isEmpty(type)) {
|
|
|
|
|
dataMap.put("companys", companyList);
|
|
|
|
|
SearchTree rootCompany = getTopGroup();
|
|
|
|
|
rootCompany.setSubs(treeDatas);
|
|
|
|
|
rootCompany.setIsParent(CollectionUtils.isNotEmpty(rootCompany.getSubs()));
|
|
|
|
|
Map<String, Object> rootCompanyMap = new HashMap<>();
|
|
|
|
|
rootCompanyMap.put("rootCompany", rootCompany);
|
|
|
|
|
dataMap.put("datas", rootCompanyMap);
|
|
|
|
|
} else {
|
|
|
|
|
// 根据ID查询
|
|
|
|
|
dataMap.put("datas", treeDatas);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dataMap;
|
|
|
|
@ -99,9 +82,7 @@ public class JobServiceImpl extends Service implements JobService {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DepartmentPO parentDept = getDepartmentMapper().getDeptById(departmentPO.getParentDept());
|
|
|
|
|
if (null != parentDept) {
|
|
|
|
|
buildParentDepts(parentDept, builderDeparts);
|
|
|
|
|
}
|
|
|
|
|
buildParentDepts(parentDept, builderDeparts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -116,9 +97,7 @@ public class JobServiceImpl extends Service implements JobService {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CompPO parentComp = getCompMapper().listById(compPO.getParentCompany());
|
|
|
|
|
if (null != parentComp) {
|
|
|
|
|
buildParentComps(parentComp, builderComps);
|
|
|
|
|
}
|
|
|
|
|
buildParentComps(parentComp, builderComps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -146,99 +125,78 @@ public class JobServiceImpl extends Service implements JobService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取分部数据
|
|
|
|
|
* 根据keyword查询数据
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @param type
|
|
|
|
|
* @param keyword
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<TreeNode> getCompany(String id, String type) {
|
|
|
|
|
List<TreeNode> compSearchTree = new ArrayList<>();
|
|
|
|
|
List<CompPO> compPOS;
|
|
|
|
|
if (StringUtils.isAllEmpty(id, type)) {
|
|
|
|
|
compPOS = getCompMapper().listParent();
|
|
|
|
|
compSearchTree.addAll(CompBO.buildListToSearchTree(compPOS));
|
|
|
|
|
} else {
|
|
|
|
|
if (TYPE_COMP.equals(type)) {
|
|
|
|
|
compPOS = getCompMapper().listChildByPID(id);
|
|
|
|
|
// 获取该分部下的部门
|
|
|
|
|
List<DepartmentPO> deptListByCompId = getDepartmentMapper().getDeptListByCompId(Integer.parseInt(id)).stream().filter(item -> null == item.getParentDept()).collect(Collectors.toList());
|
|
|
|
|
compSearchTree.addAll(CompBO.buildListToSearchTree(compPOS));
|
|
|
|
|
compSearchTree.addAll(DepartmentBO.buildListToSearchTree(deptListByCompId));
|
|
|
|
|
} else if (TYPE_DEPT.equals(type)) {
|
|
|
|
|
List<DepartmentPO> deptListByCompId = getDepartmentMapper().getDeptListByPId(Long.parseLong(id));
|
|
|
|
|
compSearchTree.addAll(DepartmentBO.buildListToSearchTree(deptListByCompId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return compSearchTree;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<TreeNode> getFilterCompany(String id, String type, String keyword) {
|
|
|
|
|
List<TreeNode> compSearchTree = new ArrayList<>();
|
|
|
|
|
if (StringUtils.isAllEmpty(id, type)) {
|
|
|
|
|
// 通过分部、公司 组装数据
|
|
|
|
|
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();
|
|
|
|
|
buildTreeByCompAndDept(departmentBuild, compBuild, compSearchTree);
|
|
|
|
|
} else if (TYPE_DEPT.equals(type)) {
|
|
|
|
|
//
|
|
|
|
|
// 查询部门信息
|
|
|
|
|
List<DepartmentPO> filterDeparts = getDepartmentMapper().listByFilter(DepartmentPO.builder().deptName(keyword).build());
|
|
|
|
|
List<DepartmentPO> filterDeparts = getDepartmentMapper().listByFilter(DepartmentPO.builder().deptName(keyword).parentDept(Long.parseLong(id)).build());
|
|
|
|
|
Set<DepartmentPO> builderDeparts = new HashSet<>();
|
|
|
|
|
for (DepartmentPO departmentPO : filterDeparts) {
|
|
|
|
|
buildParentDepts(departmentPO, builderDeparts);
|
|
|
|
|
}
|
|
|
|
|
List<SearchTree> deptTrees = builderTreeMode(DepartmentBO.buildSetToSearchTree(builderDeparts));
|
|
|
|
|
|
|
|
|
|
// 查询分部信息
|
|
|
|
|
List<CompPO> filterComps = getCompMapper().listByFilter(CompPO.builder().compName(keyword).build());
|
|
|
|
|
Set<CompPO> builderComps = new HashSet<>();
|
|
|
|
|
for (CompPO compPO : filterComps) {
|
|
|
|
|
buildParentComps(compPO, builderComps);
|
|
|
|
|
}
|
|
|
|
|
List<TreeNode> compTrees = builderTreeMode(CompBO.buildSetToSearchTree(builderComps), deptTrees);
|
|
|
|
|
|
|
|
|
|
// 排序,设置是否为叶子节点
|
|
|
|
|
List<TreeNode> collect = compTrees.stream().peek(item ->
|
|
|
|
|
List<TreeNode> collect = deptTrees.stream().peek(item ->
|
|
|
|
|
item.setIsParent(CollectionUtils.isNotEmpty(item.getSubs()))
|
|
|
|
|
).sorted(Comparator.comparing(item -> Integer.parseInt(item.getId()))).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
|
|
compSearchTree.addAll(collect);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (TYPE_COMP.equals(type)) { // 查询部门信息
|
|
|
|
|
List<DepartmentPO> filterDeparts = getDepartmentMapper().listByFilter(DepartmentPO.builder().deptName(keyword).parentComp(Long.parseLong(id)).build());
|
|
|
|
|
Set<DepartmentPO> builderDeparts = new HashSet<>();
|
|
|
|
|
for (DepartmentPO departmentPO : filterDeparts) {
|
|
|
|
|
buildParentDepts(departmentPO, builderDeparts);
|
|
|
|
|
}
|
|
|
|
|
List<SearchTree> deptTrees = builderTreeMode(DepartmentBO.buildSetToSearchTree(builderDeparts));
|
|
|
|
|
|
|
|
|
|
// 查询分部信息
|
|
|
|
|
List<CompPO> filterComps = getCompMapper().listByFilter(CompPO.builder().compName(keyword).parentCompany(Long.parseLong(id)).build());
|
|
|
|
|
Set<CompPO> builderComps = new HashSet<>();
|
|
|
|
|
for (CompPO compPO : filterComps) {
|
|
|
|
|
buildParentComps(compPO, builderComps);
|
|
|
|
|
}
|
|
|
|
|
List<TreeNode> compTrees = builderTreeMode(CompBO.buildSetToSearchTree(builderComps), deptTrees);
|
|
|
|
|
}
|
|
|
|
|
return compSearchTree;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 排序,设置是否为叶子节点
|
|
|
|
|
List<TreeNode> collect = compTrees.stream().peek(item ->
|
|
|
|
|
item.setIsParent(CollectionUtils.isNotEmpty(item.getSubs()))
|
|
|
|
|
).sorted(Comparator.comparing(item -> Integer.parseInt(item.getId()))).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
|
|
compSearchTree.addAll(collect);
|
|
|
|
|
}
|
|
|
|
|
} else if (TYPE_DEPT.equals(type)) {
|
|
|
|
|
List<DepartmentPO> filterDeparts = getDepartmentMapper().listByFilter(DepartmentPO.builder().deptName(keyword).parentDept(Long.parseLong(id)).build());
|
|
|
|
|
Set<DepartmentPO> builderDeparts = new HashSet<>();
|
|
|
|
|
for (DepartmentPO departmentPO : filterDeparts) {
|
|
|
|
|
buildParentDepts(departmentPO, builderDeparts);
|
|
|
|
|
}
|
|
|
|
|
List<SearchTree> deptTrees = builderTreeMode(DepartmentBO.buildSetToSearchTree(builderDeparts));
|
|
|
|
|
// 排序,设置是否为叶子节点
|
|
|
|
|
List<TreeNode> collect = deptTrees.stream().peek(item ->
|
|
|
|
|
item.setIsParent(CollectionUtils.isNotEmpty(item.getSubs()))
|
|
|
|
|
).sorted(Comparator.comparing(item -> Integer.parseInt(item.getId()))).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
|
|
compSearchTree.addAll(collect);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 分部、部门 组装左侧树
|
|
|
|
|
*
|
|
|
|
|
* @param departmentBuild
|
|
|
|
|
* @param compBuild
|
|
|
|
|
* @param compSearchTree
|
|
|
|
|
*/
|
|
|
|
|
private void buildTreeByCompAndDept(DepartmentPO departmentBuild, CompPO compBuild, List<TreeNode> compSearchTree) {
|
|
|
|
|
List<DepartmentPO> filterDeparts = getDepartmentMapper().listByFilter(departmentBuild);
|
|
|
|
|
// 查询分部信息
|
|
|
|
|
List<CompPO> filterComps = getCompMapper().listByFilter(compBuild);
|
|
|
|
|
Set<DepartmentPO> builderDeparts = new HashSet<>();
|
|
|
|
|
for (DepartmentPO departmentPO : filterDeparts) {
|
|
|
|
|
buildParentDepts(departmentPO, builderDeparts);
|
|
|
|
|
}
|
|
|
|
|
List<SearchTree> deptTrees = builderTreeMode(DepartmentBO.buildSetToSearchTree(builderDeparts));
|
|
|
|
|
// 添加部门的上级分部
|
|
|
|
|
String parentCompS = deptTrees.stream().map(SearchTree::getParentComp).collect(Collectors.joining(","));
|
|
|
|
|
if (!StringUtil.isEmpty(parentCompS)) {
|
|
|
|
|
List<CompPO> compsByIds = getCompMapper().getCompsByIds(QueryParam.builder().ids(parentCompS).build().getIds());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(compsByIds)) {
|
|
|
|
|
filterComps.addAll(compsByIds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return compSearchTree;
|
|
|
|
|
Set<CompPO> builderComps = new HashSet<>();
|
|
|
|
|
for (CompPO compPO : filterComps) {
|
|
|
|
|
buildParentComps(compPO, builderComps);
|
|
|
|
|
}
|
|
|
|
|
List<TreeNode> compTrees = builderTreeMode(CompBO.buildSetToSearchTree(builderComps), deptTrees);
|
|
|
|
|
|
|
|
|
|
// 排序,设置是否为叶子节点
|
|
|
|
|
List<TreeNode> collect = compTrees.stream().peek(item ->
|
|
|
|
|
item.setIsParent(CollectionUtils.isNotEmpty(item.getSubs()))
|
|
|
|
|
).sorted(Comparator.comparing(item -> Integer.parseInt(item.getId()))).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
|
|
compSearchTree.addAll(collect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -270,7 +228,11 @@ public class JobServiceImpl extends Service implements JobService {
|
|
|
|
|
*/
|
|
|
|
|
private List<SearchTree> builderTreeMode(List<SearchTree> treeList) {
|
|
|
|
|
Map<String, List<TreeNode>> collects = treeList.stream().collect(Collectors.groupingBy(TreeNode::getPid));
|
|
|
|
|
return treeList.stream().peek(e -> e.setSubs(collects.get(e.getId()))).filter(item -> isTop(item.getPid())).collect(Collectors.toList());
|
|
|
|
|
return treeList.stream().peek(e -> e.setSubs(collects.get(e.getId()))).peek(item -> {
|
|
|
|
|
if (CollectionUtils.isNotEmpty(item.getSubs())) {
|
|
|
|
|
item.setIsParent(true);
|
|
|
|
|
}
|
|
|
|
|
}).filter(item -> isTop(item.getPid())).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -294,6 +256,10 @@ public class JobServiceImpl extends Service implements JobService {
|
|
|
|
|
treeNodes.addAll(childMap.get(e.getId()));
|
|
|
|
|
}
|
|
|
|
|
e.setSubs(treeNodes);
|
|
|
|
|
}).peek(item -> {
|
|
|
|
|
if (CollectionUtils.isNotEmpty(item.getSubs())) {
|
|
|
|
|
item.setIsParent(true);
|
|
|
|
|
}
|
|
|
|
|
}).filter(item -> isTop(item.getPid())).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|