Przeglądaj źródła

组织架构部门排序

cs 2 lat temu
rodzic
commit
10991311e9

+ 16 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/DepartmentController.java

@@ -1,6 +1,10 @@
 package com.management.platform.controller;
 
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.management.platform.entity.vo.DepartmentVO;
 import com.management.platform.service.DepartmentService;
 import com.management.platform.util.HttpRespMsg;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -10,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.util.List;
 
 /**
  * <p>
@@ -35,6 +40,17 @@ public class DepartmentController {
         return departmentService.getDepartmentList(request);
     }
 
+    /**
+     * 对部门进行排序
+     * @param request
+     * @return
+     */
+    @RequestMapping("/seqList")
+    public HttpRespMsg seqList(HttpServletRequest request,String list) {
+        List<DepartmentVO> departmentVOS = JSONArray.parseArray(list, DepartmentVO.class);
+        return departmentService.seqList(request,departmentVOS);
+    }
+
     @RequestMapping("/listAllMemb")
     public HttpRespMsg listAllMemb(HttpServletRequest request,String keyword,String cursor) throws Exception {
         return departmentService.listAllMemb(request,keyword,cursor);

+ 6 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/Department.java

@@ -37,6 +37,12 @@ public class Department extends Model<Department> {
     @TableField("department_name")
     private String departmentName;
 
+    /**
+     * 部门顺序
+     */
+    @TableField("seq")
+    private Integer seq;
+
     /**
      * 上级部门id
      */

+ 1 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/vo/DepartmentVO.java

@@ -13,6 +13,7 @@ import java.util.List;
 public class DepartmentVO {
     private Integer id;
     private String label;
+    private Integer seq;
     private Integer parentId;
     private Integer corpwxDeptid;
     private String managerId;

+ 3 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/DepartmentService.java

@@ -3,6 +3,7 @@ package com.management.platform.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.management.platform.entity.Department;
 import com.management.platform.entity.User;
+import com.management.platform.entity.vo.DepartmentVO;
 import com.management.platform.util.HttpRespMsg;
 
 import javax.servlet.http.HttpServletRequest;
@@ -58,4 +59,6 @@ public interface DepartmentService extends IService<Department> {
     String getWxDepartment(Department department,List<Department> departmentList);
 
     String exportWxDepartment(Department department,List<Department> departmentList);
+
+    HttpRespMsg seqList(HttpServletRequest request,List<DepartmentVO> list);
 }

+ 57 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DepartmentServiceImpl.java

@@ -363,12 +363,15 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
             List<DepartmentOtherManager> departmentOtherManagerList = departmentOtherManagerMapper.selectList(new QueryWrapper<DepartmentOtherManager>().eq("company_id", companyId));
             //结果列表
             List<DepartmentVO> list = new ArrayList<>();
+            //获取全部的顶层部门
             List<Department> rootDepartments = departmentList.stream().filter(dept -> dept.getSuperiorId() == null).collect(Collectors.toList());
             rootDepartments.forEach(root->{
                 DepartmentVO rootDeptVO = formatDepartmentToVO(root, departmentOtherManagerList);
                 list.add(rootDeptVO);
                 fillSubDepartmentList(departmentList, rootDeptVO, departmentOtherManagerList);
             });
+            //递归排序
+            seqResultDeptList(list);
             //返回数据
             httpRespMsg.data = list;
         } catch (NullPointerException e) {
@@ -427,6 +430,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
 
     //将部门PO转化为部门VO
     private DepartmentVO formatDepartmentToVO(Department department, List<DepartmentOtherManager> departmentOtherManagerList) {
+        //获取该部门的其他管理者
         List<String> collect = departmentOtherManagerList.stream().filter(dm -> dm.getDepartmentId().equals(department.getDepartmentId())).map(vo -> vo.getOtherManagerId()).collect(Collectors.toList());
         //这俩东西并没有继承关系
         return new DepartmentVO()
@@ -436,7 +440,8 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
                 .setParentId(department.getSuperiorId())
                 .setOtherManagerIds(collect)
                 .setReportAuditUserid(department.getReportAuditUserid())
-                .setDdDeptid(department.getDdDeptid());
+                .setDdDeptid(department.getDdDeptid())
+                .setSeq(department.getSeq());
     }
 
     //获取某个项目下的统计
@@ -1522,4 +1527,55 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
             return exportWxDepartment(supDept,departmentList) + "/" + depHierarchy;
         }
     }
+
+    /**
+     * 对部门进行排序
+     * @param request
+     * @param list
+     * @return
+     */
+    @Override
+    public HttpRespMsg seqList(HttpServletRequest request, List<DepartmentVO> list) {
+        HttpRespMsg msg = new HttpRespMsg();
+        ArrayList<Department> departments = new ArrayList<>();
+        seqDeptList(departments, list);
+        departmentService.updateBatchById(departments);
+        return msg;
+    }
+
+    /**
+     * 递归对返回的部门数据进行排序
+     * @param list
+     * @return
+     */
+    public List<DepartmentVO> seqResultDeptList(List<DepartmentVO> list){
+        list.sort(Comparator.comparing(dept->dept.getSeq()));
+        for (DepartmentVO departmentVO : list) {
+            if (departmentVO.getChildren()!=null){
+                seqResultDeptList(departmentVO.getChildren());
+            }
+        }
+        return list;
+    }
+
+    /**
+     * 递归对DepartmentVO进行拆分排序
+     * @return
+     */
+    public List<Department> seqDeptList(ArrayList<Department> departments,List<DepartmentVO> list){
+        Integer seq = 1;
+        for (DepartmentVO departmentVO : list) {
+            Department department = new Department();
+            department.setDepartmentId(departmentVO.getId());
+            department.setSeq(seq);
+            seq++;
+            departments.add(department);
+            if (departmentVO.getChildren()!=null){
+                seqDeptList(departments,departmentVO.getChildren());
+            }
+        }
+        return departments;
+    }
+
+
 }