Commit cdefa510 authored by 赵啸非's avatar 赵啸非

Merge remote-tracking branch 'origin/master'

parents 655971e4 53e29ed6
...@@ -136,64 +136,51 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity ...@@ -136,64 +136,51 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity
@Override @Override
public List<DeptTreeSelect> buildDeptTreeSelect(List<DeptEntity> list) { public List<DeptTreeSelect> buildDeptTreeSelect(List<DeptEntity> list) {
List<DeptEntity> returnList = new ArrayList<>(); //获取父节点
List<Long> tempList = list.stream().map(DeptEntity::getId).collect(Collectors.toList()); List<DeptEntity> returnList = list.stream().filter(t -> t.getParentId() == 0).map(
m -> {
for (Iterator<DeptEntity> iterator = list.iterator(); iterator.hasNext(); ) { m.setChildren(getChildren(m, list));
DeptEntity deptEntity = iterator.next();
List<StaffEntity> staffEntities = staffService.find(new StaffQuery().deptId(deptEntity.getId())); StaffEntity query = new StaffQuery();
List<Map<String, Object>> personList = new ArrayList<>(); query.setDeptIdList(getChildrenId(m, list));
staffEntities.forEach(item -> { int count = staffService.count(query,null);
Map<String, Object> map = new HashMap<>(); m.setPersonNum(count);
map.put("staffId", item.getId()); return m;
map.put("staffName", item.getName()); }
map.put("deptId", item.getDeptId()); ).collect(Collectors.toList());
personList.add(map);
});
deptEntity.setPersonList(personList);
if (!tempList.contains(deptEntity.getParentId())) {
recursionFn(list, deptEntity);
returnList.add(deptEntity);
}
}
if (returnList.isEmpty()) {
returnList = list;
}
return returnList.stream().map(DeptTreeSelect::new).collect(Collectors.toList()); return returnList.stream().map(DeptTreeSelect::new).collect(Collectors.toList());
} }
/** /**
* 递归列表 * 递归查询子节点
* @param root 根节点
* @param all 所有节点
* @return 根节点信息
*/ */
private void recursionFn(List<DeptEntity> list, DeptEntity t) { private List<DeptEntity> getChildren(DeptEntity root, List<DeptEntity> all) {
// 得到子节点列表 List<DeptEntity> children = all.stream().filter(t -> {
List<DeptEntity> childList = getChildList(list, t); return Objects.equals(t.getParentId(), root.getId());
t.setChildren(childList); }).map(
for (DeptEntity tChild : childList) { m -> {
if (hasChild(list, tChild)) { m.setChildren(getChildren(m, all));
recursionFn(list, tChild); StaffEntity query = new StaffQuery();
} query.setDeptIdList(getChildrenId(m, all));
} int count = staffService.count(query,null);
} m.setPersonNum(count);
return m;
/** }
* 判断是否有子节点 ).collect(Collectors.toList());
*/ return children;
private boolean hasChild(List<DeptEntity> list, DeptEntity t) {
return getChildList(list, t).size() > 0 ? true : false;
} }
/** private List<Long> getChildrenId(DeptEntity root, List<DeptEntity> all){
* 得到子节点列表 List<Long> idList = new ArrayList<>();
*/ idList.add(root.getId());
private List<DeptEntity> getChildList(List<DeptEntity> list, DeptEntity t) { all.forEach(item ->{
return list.stream().map(item -> { if(Objects.equals(item.getParentId(), root.getId())){
if (!ObjectUtils.isEmpty(item.getParentId()) && item.getParentId() == t.getId()) { idList.addAll(getChildrenId(item,all));
return item;
} }
return null; });
}).filter(f -> f != null).collect(Collectors.toList()); return idList;
} }
@Override @Override
...@@ -260,5 +247,4 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity ...@@ -260,5 +247,4 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity
return dao.getAllChildrenDept(deptId); return dao.getAllChildrenDept(deptId);
} }
} }
...@@ -95,7 +95,7 @@ public class DeptController extends BaseCRUDJsonBodyMappingController<DeptServic ...@@ -95,7 +95,7 @@ public class DeptController extends BaseCRUDJsonBodyMappingController<DeptServic
int code = VALUE_RESULT_SUCCESS; int code = VALUE_RESULT_SUCCESS;
try { try {
DeptQuery deptQuery = new DeptQuery(); DeptQuery deptQuery = new DeptQuery();
deptQuery.setOrderColList(Arrays.asList(new OrderCol("orderNum","desc"))); deptQuery.setOrderColList(Arrays.asList(new OrderCol("deptName")));
List<DeptEntity> list = this.service.find(deptQuery); List<DeptEntity> list = this.service.find(deptQuery);
List<DeptTreeSelect> treeSelects = this.service.buildDeptTreeSelect(list); List<DeptTreeSelect> treeSelects = this.service.buildDeptTreeSelect(list);
model.put("result", treeSelects); model.put("result", treeSelects);
......
...@@ -269,6 +269,7 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta ...@@ -269,6 +269,7 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
List<DeptEntity> deptList = deptService.getAllChildrenDept(params.getDeptId()); List<DeptEntity> deptList = deptService.getAllChildrenDept(params.getDeptId());
if(CollectionUtils.isNotEmpty(deptList)){ if(CollectionUtils.isNotEmpty(deptList)){
List<Long> deptIdList = new ArrayList<>(); List<Long> deptIdList = new ArrayList<>();
deptIdList.add(params.getDeptId());
deptList.forEach(item -> { deptList.forEach(item -> {
deptIdList.add(item.getId()); deptIdList.add(item.getId());
}); });
......
...@@ -14,18 +14,18 @@ ...@@ -14,18 +14,18 @@
</select> </select>
<!--查询所有子部门--> <!--查询所有子部门-->
<select id="getAllChildrenDept" resultType="com.mortals.xhx.module.dept.model.DeptEntity"> <select id="getAllChildrenDept" resultType="com.mortals.xhx.module.dept.model.DeptEntity">
SELECT * FROM ( SELECT T3.id,T3.parentId, T3.deptName,T3.deptCode,T3.deptStatus
SELECT id, parentId, deptName,deptCode,deptStatus FROM mortals_xhx_dept WHERE id = #{deptId} FROM(
UNION ALL SELECT
SELECT i.id, i.parentId, i.deptName,i.deptCode,i.deptStatus @codes as _ids,
FROM mortals_xhx_dept i ( SELECT @codes := GROUP_CONCAT(id)
INNER JOIN ( FROM mortals_xhx_dept
SELECT * FROM ( WHERE FIND_IN_SET(parentId, @codes)
SELECT id, parentId, deptName,deptCode,deptStatus FROM mortals_xhx_dept WHERE id = #{deptId} ) as T1,
UNION ALL @l := @l+1 as level_
SELECT id, parentId, deptName,deptCode,deptStatus FROM mortals_xhx_dept WHERE parentId = #{deptId} FROM mortals_xhx_dept, (SELECT @codes := #{deptId}, @l := 0 ) T4
) t1 WHERE @codes IS NOT NULL
) t2 ON i.parentId = t2.id ) T2, mortals_xhx_dept T3
) t3 WHERE FIND_IN_SET(T3.parentId, T2._ids)
</select> </select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment