|
|
@@ -13,6 +13,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
13
|
13
|
import cn.hutool.core.util.ObjectUtil;
|
|
14
|
14
|
import cn.hutool.core.util.StrUtil;
|
|
15
|
15
|
import com.sundot.airport.common.config.LevelConfig;
|
|
|
16
|
+import com.sundot.airport.common.core.domain.DeptAndUserTreeSelect;
|
|
16
|
17
|
import com.sundot.airport.common.dto.DeptInfo;
|
|
17
|
18
|
import com.sundot.airport.common.dto.UserOrgInfo;
|
|
18
|
19
|
import com.sundot.airport.common.enums.DeptType;
|
|
|
@@ -759,4 +760,89 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
759
|
760
|
result.setDeptInfo(getDeptInfoByDeptId(user.getDeptId()));
|
|
760
|
761
|
return result;
|
|
761
|
762
|
}
|
|
|
763
|
+
|
|
|
764
|
+ /**
|
|
|
765
|
+ * 查询部门及用户树结构信息新版
|
|
|
766
|
+ *
|
|
|
767
|
+ * @param dept 部门信息
|
|
|
768
|
+ * @return 部门及用户树信息集合
|
|
|
769
|
+ */
|
|
|
770
|
+ @Override
|
|
|
771
|
+ public List<DeptAndUserTreeSelect> selectDeptAndUserTreeList(SysDept dept) {
|
|
|
772
|
+ List<SysDept> depts;
|
|
|
773
|
+ // 如果指定了部门ID,则查询该部门及其所有子部门
|
|
|
774
|
+ if (dept.getDeptId() != null && dept.getDeptId() != 0) {
|
|
|
775
|
+ SysDept targetDept = deptMapper.selectDeptById(dept.getDeptId());
|
|
|
776
|
+ if (targetDept != null) {
|
|
|
777
|
+ // 查询所有部门
|
|
|
778
|
+ SysDept queryDept = new SysDept();
|
|
|
779
|
+ List<SysDept> allDepts = SpringUtils.getAopProxy(this).selectDeptList(queryDept);
|
|
|
780
|
+ // 构建完整的部门树
|
|
|
781
|
+ List<SysDept> deptTree = buildCompleteDeptTree(allDepts);
|
|
|
782
|
+ // 查找目标部门及其所有子部门
|
|
|
783
|
+ SysDept foundDept = findDeptWithChildren(deptTree, dept.getDeptId());
|
|
|
784
|
+ if (foundDept != null) {
|
|
|
785
|
+ List<SysDept> targetList = new ArrayList<>();
|
|
|
786
|
+ targetList.add(foundDept);
|
|
|
787
|
+ depts = targetList;
|
|
|
788
|
+ } else {
|
|
|
789
|
+ // 如果没找到,返回只包含目标部门的列表
|
|
|
790
|
+ List<SysDept> singleList = new ArrayList<>();
|
|
|
791
|
+ singleList.add(targetDept);
|
|
|
792
|
+ depts = singleList;
|
|
|
793
|
+ }
|
|
|
794
|
+ } else {
|
|
|
795
|
+ // 如果部门不存在,返回空列表
|
|
|
796
|
+ depts = new ArrayList<>();
|
|
|
797
|
+ }
|
|
|
798
|
+ } else {
|
|
|
799
|
+ // 如果没有指定部门ID,查询所有部门
|
|
|
800
|
+ depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
|
|
|
801
|
+ }
|
|
|
802
|
+ return buildDeptAndUserTreeSelect(depts);
|
|
|
803
|
+ }
|
|
|
804
|
+
|
|
|
805
|
+ /**
|
|
|
806
|
+ * 构建前端所需要下拉树结构(包含用户)新版
|
|
|
807
|
+ *
|
|
|
808
|
+ * @param depts 部门列表
|
|
|
809
|
+ * @return 下拉树结构列表(包含用户)
|
|
|
810
|
+ */
|
|
|
811
|
+ public List<DeptAndUserTreeSelect> buildDeptAndUserTreeSelect(List<SysDept> depts) {
|
|
|
812
|
+ List<SysDept> deptTrees = buildCompleteDeptTree(depts);
|
|
|
813
|
+ return deptTrees.stream().map(this::convertDeptToDeptAndUserTreeSelect).collect(Collectors.toList());
|
|
|
814
|
+ }
|
|
|
815
|
+
|
|
|
816
|
+ /**
|
|
|
817
|
+ * 将部门转换为包含用户的树节点新版
|
|
|
818
|
+ *
|
|
|
819
|
+ * @param dept 部门信息
|
|
|
820
|
+ * @return 树节点
|
|
|
821
|
+ */
|
|
|
822
|
+ private DeptAndUserTreeSelect convertDeptToDeptAndUserTreeSelect(SysDept dept) {
|
|
|
823
|
+ DeptAndUserTreeSelect treeSelect = new DeptAndUserTreeSelect(dept);
|
|
|
824
|
+
|
|
|
825
|
+ List<DeptAndUserTreeSelect> children = new ArrayList<>();
|
|
|
826
|
+
|
|
|
827
|
+ // 处理子部门
|
|
|
828
|
+ if (dept.getChildren() != null && !dept.getChildren().isEmpty()) {
|
|
|
829
|
+ children.addAll(dept.getChildren().stream()
|
|
|
830
|
+ .map(this::convertDeptToDeptAndUserTreeSelect)
|
|
|
831
|
+ .collect(Collectors.toList()));
|
|
|
832
|
+ }
|
|
|
833
|
+
|
|
|
834
|
+ List<SysUser> users = userMapper.selectUsersByDeptId(dept.getDeptId());
|
|
|
835
|
+ if (users != null && !users.isEmpty()) {
|
|
|
836
|
+ List<DeptAndUserTreeSelect> userChildren = users.stream()
|
|
|
837
|
+ .map(DeptAndUserTreeSelect::new)
|
|
|
838
|
+ .collect(Collectors.toList());
|
|
|
839
|
+ treeSelect.setUserList(userChildren);
|
|
|
840
|
+ }
|
|
|
841
|
+
|
|
|
842
|
+ if (!children.isEmpty()) {
|
|
|
843
|
+ treeSelect.setChildren(new ArrayList<>(children));
|
|
|
844
|
+ }
|
|
|
845
|
+
|
|
|
846
|
+ return treeSelect;
|
|
|
847
|
+ }
|
|
762
|
848
|
}
|