部门、岗位接口开发;代码合并

pull/27/MERGE^2
dxfeng 3 years ago
parent 33f5ec9458
commit 92953661ff

@ -5,8 +5,6 @@ import com.engine.organization.entity.comp.dto.CompListDTO;
import com.engine.organization.entity.comp.param.CompSearchParam; import com.engine.organization.entity.comp.param.CompSearchParam;
import com.engine.organization.entity.comp.po.CompPO; import com.engine.organization.entity.comp.po.CompPO;
import com.engine.organization.entity.searchtree.SearchTree; import com.engine.organization.entity.searchtree.SearchTree;
import com.engine.organization.mapper.comp.CompMapper;
import com.engine.organization.util.db.MapperProxyFactory;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import weaver.crm.Maint.SectorInfoComInfo; import weaver.crm.Maint.SectorInfoComInfo;
import weaver.general.StringUtil; import weaver.general.StringUtil;
@ -63,23 +61,6 @@ public class CompBO {
} }
public static List<SearchTree> buildListToSearchTree(List<CompPO> comps) {
return comps.stream().map(item -> {
SearchTree tree = new SearchTree();
tree.setCanClick(true);
tree.setCanceled(false);
tree.setIcon("icon-coms-LargeArea");
tree.setId(item.getId().toString());
tree.setIsParent(MapperProxyFactory.getProxy(CompMapper.class).countChildByPID(item.getId()) > 0);
tree.setIsVirtual("0");
tree.setName(item.getCompName());
tree.setPid(null == item.getParentCompany() ? "0" : item.getParentCompany().toString());
tree.setSelected(false);
tree.setType("1");
return tree;
}).collect(Collectors.toList());
}
public static List<TreeNode> buildSetToSearchTree(Set<CompPO> comps) { public static List<TreeNode> buildSetToSearchTree(Set<CompPO> comps) {
return comps.stream().map(item -> { return comps.stream().map(item -> {
SearchTree tree = new SearchTree(); SearchTree tree = new SearchTree();

@ -63,7 +63,7 @@ public class DepartmentBO {
return Collections.emptyList(); return Collections.emptyList();
} }
List<SingleDeptTreeVO> singleDeptTreeVOS = departmentPOs.stream().map(e -> SingleDeptTreeVO.builder().id(e.getId()).deptName(e.getDeptName()).parentComp(e.getParentComp()).parentDept(e.getParentDept()).parentDeptName(e.getParentDept() == null ? "" : getDeptNameById(e.getParentDept().intValue())).deptPrincipalName(getEmployeeNameById((long) e.getDeptPrincipal())).build()).collect(Collectors.toList()); List<SingleDeptTreeVO> singleDeptTreeVOS = departmentPOs.stream().map(e -> SingleDeptTreeVO.builder().id(e.getId()).deptName(e.getDeptName()).parentComp(e.getParentComp()).parentDept(e.getParentDept()).parentDeptName(e.getParentDept() == null ? "" : getDeptNameById(e.getParentDept().intValue())).deptPrincipalName(getEmployeeNameById(e.getDeptPrincipal())).build()).collect(Collectors.toList());
//获取非一级部门 //获取非一级部门
Map<Long, List<SingleDeptTreeVO>> collects = singleDeptTreeVOS.stream().filter(item -> !parentComp.equals(item.getParentComp()) && null != item.getParentDept()).collect(Collectors.groupingBy(SingleDeptTreeVO::getParentDept)); Map<Long, List<SingleDeptTreeVO>> collects = singleDeptTreeVOS.stream().filter(item -> !parentComp.equals(item.getParentComp()) && null != item.getParentDept()).collect(Collectors.groupingBy(SingleDeptTreeVO::getParentDept));
@ -73,22 +73,6 @@ public class DepartmentBO {
}).filter(item -> parentComp.equals(item.getParentComp())).collect(Collectors.toList()); }).filter(item -> parentComp.equals(item.getParentComp())).collect(Collectors.toList());
} }
public static List<SearchTree> buildListToSearchTree(List<DepartmentPO> departmentPOS) {
return departmentPOS.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(MapperProxyFactory.getProxy(DepartmentMapper.class).countChildByPID(item.getId()) > 0);
tree.setIsVirtual("0");
tree.setName(item.getDeptName());
tree.setPid(null == item.getParentDept() ? (null == item.getParentComp() ? "0" : item.getParentComp().toString()) : item.getParentDept().toString());
tree.setSelected(false);
tree.setType("2");
return tree;
}).collect(Collectors.toList());
}
public static List<SearchTree> buildSetToSearchTree(Set<DepartmentPO> departmentPOS) { public static List<SearchTree> buildSetToSearchTree(Set<DepartmentPO> departmentPOS) {
return departmentPOS.stream().map(item -> { return departmentPOS.stream().map(item -> {
@ -97,7 +81,7 @@ public class DepartmentBO {
tree.setCanceled(false); tree.setCanceled(false);
tree.setIcon("icon-coms-Branch"); tree.setIcon("icon-coms-Branch");
tree.setId(item.getId().toString()); tree.setId(item.getId().toString());
tree.setIsParent(MapperProxyFactory.getProxy(DepartmentMapper.class).countChildByPID(item.getId()) > 0); tree.setIsParent(false);
tree.setIsVirtual("0"); tree.setIsVirtual("0");
tree.setName(item.getDeptName()); tree.setName(item.getDeptName());
tree.setPid(null == item.getParentDept() ? "0" : item.getParentDept().toString()); tree.setPid(null == item.getParentDept() ? "0" : item.getParentDept().toString());

@ -86,6 +86,14 @@ public interface CompMapper {
*/ */
List<Map<String, Object>> listCompsByIds(@Param("ids") Collection<Long> ids); List<Map<String, Object>> listCompsByIds(@Param("ids") Collection<Long> ids);
/**
* ID
* @param ids
* @return
*/
List<CompPO> getCompsByIds(@Param("ids") Collection<Long> ids);
/** /**
* / * /

@ -208,6 +208,7 @@
#{id} #{id}
</foreach> </foreach>
</select> </select>
<select id="listChildByPID" resultMap="BaseResultMap"> <select id="listChildByPID" resultMap="BaseResultMap">
SELECT SELECT
<include refid="baseColumns"/> <include refid="baseColumns"/>
@ -222,6 +223,16 @@
WHERE t.delete_type = 0 WHERE t.delete_type = 0
and parent_company = #{pid} and parent_company = #{pid}
</select> </select>
<select id="getCompsByIds" resultMap="BaseResultMap">
select
<include refid="baseColumns"/>
from jcl_org_comp t
WHERE delete_type = 0
AND id IN
<foreach collection="ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</select>
<update id="updateForbiddenTagById" parameterType="com.engine.organization.entity.sequence.po.SequencePO"> <update id="updateForbiddenTagById" parameterType="com.engine.organization.entity.sequence.po.SequencePO">
update jcl_org_comp update jcl_org_comp

@ -15,7 +15,7 @@ import java.util.Map;
**/ **/
public interface DepartmentMapper { public interface DepartmentMapper {
List<DepartmentPO> getDeptListByCompId(); List<DepartmentPO> getDeptListByCompId(@Param("parentComp") Integer parentComp);
List<DepartmentPO> getDeptListByPId(@Param("PId") Long PId); List<DepartmentPO> getDeptListByPId(@Param("PId") Long PId);

@ -38,6 +38,7 @@
select t.id, t.dept_name, t.parent_dept, t.dept_principal, t.parent_dept, t.parent_comp select t.id, t.dept_name, t.parent_dept, t.dept_principal, t.parent_dept, t.parent_comp
from jcl_org_dept t from jcl_org_dept t
where delete_type = 0 where delete_type = 0
and parent_comp = #{parentComp}
</select> </select>
<select id="getDeptListByPId" resultType="com.engine.organization.entity.department.po.DepartmentPO"> <select id="getDeptListByPId" resultType="com.engine.organization.entity.department.po.DepartmentPO">

@ -81,7 +81,7 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
//1.查询分部下所有部门 //1.查询分部下所有部门
//PageUtil.start(param.getCurrent(), param.getPageSize()); //PageUtil.start(param.getCurrent(), param.getPageSize());
List<DepartmentPO> departmentPOS = MapperProxyFactory.getProxy(DepartmentMapper.class).getDeptListByCompId(); List<DepartmentPO> departmentPOS = MapperProxyFactory.getProxy(DepartmentMapper.class).list();
PageInfo<DepartmentPO> pageInfo = new PageInfo<>(departmentPOS); PageInfo<DepartmentPO> pageInfo = new PageInfo<>(departmentPOS);
List<SingleDeptTreeVO> singleDeptTreeVOS = DepartmentBO.buildSingleDeptTreeVOS(departmentPOS,param.getParentComp()); List<SingleDeptTreeVO> singleDeptTreeVOS = DepartmentBO.buildSingleDeptTreeVOS(departmentPOS,param.getParentComp());
PageInfo<SingleDeptTreeVO> pageInfos = new PageInfo<>(singleDeptTreeVOS, SingleDeptTreeVO.class); PageInfo<SingleDeptTreeVO> pageInfos = new PageInfo<>(singleDeptTreeVOS, SingleDeptTreeVO.class);

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

Loading…
Cancel
Save