Browse Source

优化部门获取

anderx 3 years ago
parent
commit
7358b18e70

+ 1 - 1
src/main/java/com/goafanti/common/mapper/DepartmentMapper.xml

@@ -302,7 +302,7 @@
   </select>
   <select id="selectSuperId"  resultType="com.goafanti.organization.bo.DepOut">
     select
-    id,name,dep_no as depNo,lvl
+    id,name,dep_no as depNo,lvl,super_id superId
     from department
     where status ='0'
     <if test="lvl != null ">

+ 10 - 0
src/main/java/com/goafanti/organization/bo/DepOut.java

@@ -10,10 +10,20 @@ public class DepOut {
 
     private String depNo;
 
+    private String superId;
+
     private Integer lvl;
 
     private List<DepOut> list;
 
+    public String getSuperId() {
+        return superId;
+    }
+
+    public void setSuperId(String superId) {
+        this.superId = superId;
+    }
+
     public String getDepNo() {
         return depNo;
     }

+ 20 - 23
src/main/java/com/goafanti/organization/service/impl/OrganizationServiceImpl.java

@@ -1,10 +1,6 @@
 package com.goafanti.organization.service.impl;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
 
 import com.goafanti.common.dao.DepartmentMapper;
 import com.goafanti.common.model.Department;
@@ -74,30 +70,31 @@ public class OrganizationServiceImpl extends BaseMybatisDao<DepartmentMapper> im
 		if (hideSign>1){
 			hideSign=null;
 		}
-		List<DepOut> depList=departmentMapper.selectSuperId(hideSign,3,null);
-		depList.forEach(e ->{
-			List<DepOut> list=getSubordinateDep(1,e.getId());
-			if (!list.isEmpty()){
-				e.setList(list);
+		List<DepOut> allDep=departmentMapper.selectSuperId(hideSign,null,null);
+
+		List<DepOut> dep1=new ArrayList<>();
+		Integer x=3;//设置顶级
+		for (DepOut e : allDep) {
+			if (e.getLvl()==x){
+				e.setList(selectDepLvl(allDep,e.getId(),x+1));
+				dep1.add(e);
 			}
-		});
-		return depList;
+		}
+		return dep1;
 	}
 
-	/**
-	 *
-	 */
-	public List<DepOut> getSubordinateDep(Integer hideSign,String id){
-		List<DepOut> depList=departmentMapper.selectSuperId(hideSign,null,id);
-		depList.forEach(e ->{
-			List<DepOut> list=getSubordinateDep(1,e.getId());
-			if (!list.isEmpty()){
-				e.setList(list);
+	private List<DepOut> selectDepLvl(List<DepOut> allDep,String id, Integer i) {
+		List<DepOut> newDep=new ArrayList<>();
+		for (DepOut depOut : allDep) {
+			if (depOut.getLvl()==i&&depOut.getSuperId().equals(id)){
+				if (i<7)depOut.setList(selectDepLvl(allDep,depOut.getId(),i+1));
+				newDep.add(depOut);
 			}
-		});
-		return depList;
+		}
+		return newDep;
 	}
 
+
 	/**
 	 *   XXIn form 提交 ,bo包中
 	 *   xxOut 输出 bo包中