Commit cb473df3 authored by 廖旭伟's avatar 廖旭伟

修改花名册部门组织架构bug

parent 54265eb5
......@@ -136,64 +136,51 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity
@Override
public List<DeptTreeSelect> buildDeptTreeSelect(List<DeptEntity> list) {
List<DeptEntity> returnList = new ArrayList<>();
List<Long> tempList = list.stream().map(DeptEntity::getId).collect(Collectors.toList());
for (Iterator<DeptEntity> iterator = list.iterator(); iterator.hasNext(); ) {
DeptEntity deptEntity = iterator.next();
List<StaffEntity> staffEntities = staffService.find(new StaffQuery().deptId(deptEntity.getId()));
List<Map<String, Object>> personList = new ArrayList<>();
staffEntities.forEach(item -> {
Map<String, Object> map = new HashMap<>();
map.put("staffId", item.getId());
map.put("staffName", item.getName());
map.put("deptId", item.getDeptId());
personList.add(map);
});
deptEntity.setPersonList(personList);
if (!tempList.contains(deptEntity.getParentId())) {
recursionFn(list, deptEntity);
returnList.add(deptEntity);
}
}
if (returnList.isEmpty()) {
returnList = list;
//获取父节点
List<DeptEntity> returnList = list.stream().filter(t -> t.getParentId() == 0).map(
m -> {
m.setChildren(getChildren(m, list));
StaffEntity query = new StaffQuery();
query.setDeptIdList(getChildrenId(m, list));
int count = staffService.count(query,null);
m.setPersonNum(count);
return m;
}
).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) {
// 得到子节点列表
List<DeptEntity> childList = getChildList(list, t);
t.setChildren(childList);
for (DeptEntity tChild : childList) {
if (hasChild(list, tChild)) {
recursionFn(list, tChild);
}
}
private List<DeptEntity> getChildren(DeptEntity root, List<DeptEntity> all) {
List<DeptEntity> children = all.stream().filter(t -> {
return Objects.equals(t.getParentId(), root.getId());
}).map(
m -> {
m.setChildren(getChildren(m, all));
StaffEntity query = new StaffQuery();
query.setDeptIdList(getChildrenId(m, all));
int count = staffService.count(query,null);
m.setPersonNum(count);
return m;
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<DeptEntity> list, DeptEntity t) {
return getChildList(list, t).size() > 0 ? true : false;
).collect(Collectors.toList());
return children;
}
/**
* 得到子节点列表
*/
private List<DeptEntity> getChildList(List<DeptEntity> list, DeptEntity t) {
return list.stream().map(item -> {
if (!ObjectUtils.isEmpty(item.getParentId()) && item.getParentId() == t.getId()) {
return item;
private List<Long> getChildrenId(DeptEntity root, List<DeptEntity> all){
List<Long> idList = new ArrayList<>();
idList.add(root.getId());
all.forEach(item ->{
if(Objects.equals(item.getParentId(), root.getId())){
idList.addAll(getChildrenId(item,all));
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
});
return idList;
}
@Override
......@@ -260,5 +247,4 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity
return dao.getAllChildrenDept(deptId);
}
}
......@@ -269,6 +269,7 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
List<DeptEntity> deptList = deptService.getAllChildrenDept(params.getDeptId());
if(CollectionUtils.isNotEmpty(deptList)){
List<Long> deptIdList = new ArrayList<>();
deptIdList.add(params.getDeptId());
deptList.forEach(item -> {
deptIdList.add(item.getId());
});
......
......@@ -14,18 +14,18 @@
</select>
<!--查询所有子部门-->
<select id="getAllChildrenDept" resultType="com.mortals.xhx.module.dept.model.DeptEntity">
SELECT * FROM (
SELECT id, parentId, deptName,deptCode,deptStatus FROM mortals_xhx_dept WHERE id = #{deptId}
UNION ALL
SELECT i.id, i.parentId, i.deptName,i.deptCode,i.deptStatus
FROM mortals_xhx_dept i
INNER JOIN (
SELECT * FROM (
SELECT id, parentId, deptName,deptCode,deptStatus FROM mortals_xhx_dept WHERE id = #{deptId}
UNION ALL
SELECT id, parentId, deptName,deptCode,deptStatus FROM mortals_xhx_dept WHERE parentId = #{deptId}
) t1
) t2 ON i.parentId = t2.id
) t3
SELECT T3.id,T3.parentId, T3.deptName,T3.deptCode,T3.deptStatus
FROM(
SELECT
@codes as _ids,
( SELECT @codes := GROUP_CONCAT(id)
FROM mortals_xhx_dept
WHERE FIND_IN_SET(parentId, @codes)
) as T1,
@l := @l+1 as level_
FROM mortals_xhx_dept, (SELECT @codes := #{deptId}, @l := 0 ) T4
WHERE @codes IS NOT NULL
) T2, mortals_xhx_dept T3
WHERE FIND_IN_SET(T3.parentId, T2._ids)
</select>
</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