合并代码

This commit is contained in:
2022-12-15 10:36:12 +08:00
parent c43b64faa5
commit 339cf9c75e
85 changed files with 4172 additions and 762 deletions

View File

@@ -0,0 +1,83 @@
package com.njcn.event.utils;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.njcn.event.pojo.vo.DeptLevelVO;
import com.njcn.user.pojo.dto.DeptDTO;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* <功能描述>
*
* @author wr
* @createTime: 2022-12-14
*/
public class DeptUtil {
/***
* 获取层级部门信息(展示下级部门)
* @param deptDTOList
* @param deptId
* @return
*/
public static List<DeptDTO> getDeptSubsetVOList(List<DeptDTO> deptDTOList, String deptId){
//获取子部门
List<DeptDTO> directDeptInfos = deptDTOList.stream()
.filter(deptDTO -> deptDTO.getPid().equals(deptId))
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(directDeptInfos)) {
//没有直接子部门,获取当前部门所有信息
List<DeptDTO> dept = deptDTOList.stream()
.filter(deptDTO -> deptDTO.getId().equals(deptId))
.collect(Collectors.toList());
return dept;
}
return directDeptInfos;
}
/***
* 获取层级部门信息(展示下级部门,但是数据是包含下部门的所有部门)
* @param deptDTOList
* @param deptId
* @return
*/
public static List<DeptLevelVO> getDeptLevelVOList(List<DeptDTO> deptDTOList, String deptId){
//获取子部门
List<DeptDTO> directDeptInfos = deptDTOList.stream()
.filter(deptDTO -> deptDTO.getPid().equals(deptId))
.collect(Collectors.toList());
List<DeptLevelVO> deptLevelVOS = new ArrayList<>();
if (CollectionUtil.isEmpty(directDeptInfos)) {
//没有直接子部门,获取当前部门所有信息
List<DeptDTO> dept = deptDTOList.stream()
.filter(deptDTO -> deptDTO.getId().equals(deptId))
.collect(Collectors.toList());
deptLevelVOS = BeanUtil.copyToList(dept, DeptLevelVO.class);
}else{
DeptLevelVO deptLevelVO;
for (DeptDTO deptDTO : directDeptInfos) {
//添加当前部门,添加当前部门下的子部门
deptLevelVO = BeanUtil.copyProperties(deptDTO, DeptLevelVO.class);
deptLevelVOS.add(deptLevelVO);
//筛选上级部门pids包含该id的所有部门
List<DeptDTO> descendantDeptDTO = deptDTOList.stream()
.filter(d -> d.getPids().contains(deptDTO.getId()))
.collect(Collectors.toList());
//获取当前部门
List<DeptDTO> dept = deptDTOList.stream()
.filter(dto -> dto.getId().equals(deptDTO.getId()))
.collect(Collectors.toList());
descendantDeptDTO.addAll(dept);
List<DeptLevelVO> seedList = BeanUtil.copyToList(descendantDeptDTO, DeptLevelVO.class);
deptLevelVO.setDeptList(seedList);
}
}
return deptLevelVOS;
}
}