瀏覽代碼

fix 四维部门数据同步改造

459242451@qq.com 2 年之前
父節點
當前提交
0851c42211

+ 53 - 15
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java

@@ -1,7 +1,9 @@
 package com.ruoyi.web.controller.system;
 
+import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ArrayUtil;
-import cn.hutool.json.JSONObject;
+import cn.hutool.core.util.StrUtil;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.annotation.Security;
 import com.ruoyi.common.constant.UserConstants;
@@ -9,15 +11,16 @@ import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.FindsDepartsChildrenUtil;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.system.service.ISysDeptService;
+import com.ruoyi.zhdd.domain.GatewayDeptList;
 import com.ruoyi.zhdd.feign.FeignUserManageService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -151,23 +154,57 @@ public class SysDeptController extends BaseController {
         return toAjax(deptService.deleteDeptById(deptId));
     }
 
-    @PostMapping("/syncUc")
-    public void syncUc() {
-        List<JSONObject> list = deptService.queryTUcDept();
+    @PostMapping("/syncDept")
+    public void syncDept() {
+        GatewayDeptList list = feignUserManageService.deptList();
         List<SysDept> sysDepts = new ArrayList<>();
-        for (JSONObject jsonObject : list) {
+        for (GatewayDeptList.DeptDetail deptDetail : list.getData()) {
             SysDept sysDept = new SysDept();
-            sysDept.setDeptId(jsonObject.getStr("deptId"));
-            sysDept.setParentId(jsonObject.getStr("orgId"));
-            sysDept.setDeptName(jsonObject.getStr("deptName"));
-            sysDept.setCreateBy("system");
-            sysDept.setUpdateBy("system");
-            sysDept.setCreateTime(new Date());
-            sysDept.setUpdateTime(new Date());
+            sysDept.setDeptId(deptDetail.getId());
+            sysDept.setParentId(StrUtil.emptyToDefault(deptDetail.getParentId(), "0"));
+            sysDept.setDeptName(deptDetail.getName());
+            sysDept.setOrderNum(deptDetail.getOrdinal());
+            sysDept.setCreateBy(deptDetail.getCreateUser());
+            sysDept.setUpdateBy("hs");
+            sysDept.setCreateTime(DateUtil.parseDateTime(deptDetail.getCreateTime()));
+            sysDept.setUpdateTime(DateUtil.parseDateTime(deptDetail.getUpdateTime()));
+            sysDept.setFlag(Convert.toStr(deptDetail.getFlag()));
             sysDepts.add(sysDept);
         }
-        deptService.saveBatch(sysDepts);
-
+        deptService.saveOrUpdateBatch(sysDepts);
+        // 统一处理Ancestors、FullName
+        List<SysDept> allList = deptService.list();
+        // 先算第一级的
+        for (SysDept dept : allList) {
+            if (StrUtil.split(dept.getAncestors(), ',').size() == 1) {
+                dept.setFullName(dept.getDeptName());
+                deptService.updateById(dept);
+            }
+        }
+        for (SysDept dept : allList) {
+            if (StrUtil.split(dept.getAncestors(), ',').size() == 2) {
+                SysDept newParentDept = deptService.getById(dept.getParentId());
+                if (StringUtils.isNotNull(newParentDept)) {
+                    String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
+                    dept.setAncestors(newAncestors);
+                }
+                String departFullNamePrefix = FindsDepartsChildrenUtil.departFullName(deptService.list(), dept.getParentId());
+                dept.setFullName(StrUtil.isBlank(departFullNamePrefix) ? dept.getDeptName() : departFullNamePrefix + dept.getDeptName());
+                deptService.updateById(dept);
+            }
+        }
+        for (SysDept dept : allList) {
+            if (StrUtil.split(dept.getAncestors(), ',').size() == 3) {
+                SysDept newParentDept = deptService.getById(dept.getParentId());
+                if (StringUtils.isNotNull(newParentDept)) {
+                    String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
+                    dept.setAncestors(newAncestors);
+                }
+                String departFullNamePrefix = FindsDepartsChildrenUtil.departFullName(deptService.list(), dept.getParentId());
+                dept.setFullName(StrUtil.isBlank(departFullNamePrefix) ? dept.getDeptName() : departFullNamePrefix + dept.getDeptName());
+                deptService.updateById(dept);
+            }
+        }
     }
 
     /*@PostMapping("/syncDept")
@@ -182,4 +219,5 @@ public class SysDeptController extends BaseController {
         }
 
     }*/
+
 }

+ 3 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/SysGatewayUserTask.java

@@ -12,7 +12,7 @@ import com.ruoyi.common.utils.FindsDepartsChildrenUtil;
 import com.ruoyi.system.service.ISysDeptService;
 import com.ruoyi.system.service.ISysDictTypeService;
 import com.ruoyi.system.service.ISysUserService;
-import com.ruoyi.zhdd.domain.GatewayDept;
+import com.ruoyi.zhdd.domain.GatewayDeptList;
 import com.ruoyi.zhdd.domain.GatewaySUser;
 import com.ruoyi.zhdd.domain.SingleDevice;
 import com.ruoyi.zhdd.domain.bo.SingleDeviceBo;
@@ -134,7 +134,7 @@ public class SysGatewayUserTask {
     public void onDeptMessage(String message) {
         log.info("kafka部门信息消费:{}", message);
         try {
-            GatewayDept gatewayDept = JSONUtil.toBean(message, GatewayDept.class);
+            GatewayDeptList.DeptDetail gatewayDept = JSONUtil.toBean(message, GatewayDeptList.DeptDetail.class);
             if (gatewayDept != null) {
                 if ("2".equals(gatewayDept.getDelFlag())) {
                     // 2为删除部门
@@ -145,6 +145,7 @@ public class SysGatewayUserTask {
                 qdept.setDeptId(gatewayDept.getId());
                 qdept.setParentId(StrUtil.emptyToDefault(gatewayDept.getParentId(), "0"));
                 qdept.setDeptName(gatewayDept.getName());
+                qdept.setOrderNum(gatewayDept.getOrdinal());
                 qdept.setUpdateBy(gatewayDept.getUpdateUser());
                 qdept.setUpdateTime(DateUtil.parseDateTime(gatewayDept.getUpdateTime()));
                 qdept.setCreateBy(gatewayDept.getCreateUser());

+ 0 - 5
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java

@@ -1,10 +1,8 @@
 package com.ruoyi.system.mapper;
 
-import cn.hutool.json.JSONObject;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus;
 import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
 
 import java.util.List;
 
@@ -40,8 +38,5 @@ public interface SysDeptMapper extends BaseMapperPlus<SysDept> {
      */
     public int updateDeptChildren(@Param("depts") List<SysDept> depts);
 
-    @Select("select * from t_uc_dept")
-    List<JSONObject> queryTUcDept();
-
     List<String> queryChildDeptId(@Param("deptId") String deptId);
 }

+ 0 - 3
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java

@@ -1,6 +1,5 @@
 package com.ruoyi.system.service;
 
-import cn.hutool.json.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.domain.TreeSelect;
 import com.ruoyi.common.core.domain.entity.SysDept;
@@ -116,8 +115,6 @@ public interface ISysDeptService extends IService<SysDept> {
      */
     public int deleteDeptById(String deptId);
 
-    List<JSONObject> queryTUcDept();
-
     /**
      * 寻找该部门的机构部门
      *

+ 2 - 8
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

@@ -2,7 +2,6 @@ package com.ruoyi.system.service.impl;
 
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.util.StrUtil;
-import cn.hutool.json.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -235,11 +234,11 @@ public class SysDeptServiceImpl extends ServicePlusImpl<SysDeptMapper, SysDept,
         String departFullNamePrefix = FindsDepartsChildrenUtil.departFullName(this.list(), dept.getParentId());
         dept.setFullName(StrUtil.isBlank(departFullNamePrefix) ? dept.getDeptName() : departFullNamePrefix + dept.getDeptName());
         int result = baseMapper.updateById(dept);
-        if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
+        /*if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
             && !StringUtils.equals("0", dept.getAncestors())) {
             // 如果该部门是启用状态,则启用该部门的所有上级部门
             updateParentDeptStatusNormal(dept);
-        }
+        }*/
         return result;
     }
 
@@ -322,11 +321,6 @@ public class SysDeptServiceImpl extends ServicePlusImpl<SysDeptMapper, SysDept,
     }
 
     @Override
-    public List<JSONObject> queryTUcDept() {
-        return baseMapper.queryTUcDept();
-    }
-
-    @Override
     public SysDept getOrgDept(SysDept sysDept) {
         if ("0".equals(sysDept.getFlag())) {
             return sysDept;

+ 2 - 2
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/domain/GatewayDeptDetail.java

@@ -12,9 +12,9 @@ public class GatewayDeptDetail {
     public static class DeptDetail {
         private String id;
         private String name;
-        private String fullName;
+        //        private String fullName;
         private String parentId;
-        private String parentName;
+        //        private String parentName;
         // 组织部门标志(0:组织,1:部门)
         private Integer flag;
         private String createTime;

+ 2 - 2
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/domain/GatewayDeptList.java

@@ -14,9 +14,9 @@ public class GatewayDeptList {
     public static class DeptDetail {
         private String id;
         private String name;
-        private String fullName;
+        //        private String fullName;
         private String parentId;
-        private String parentName;
+        //        private String parentName;
         // 组织部门标志(0:组织,1:部门)
         private Integer flag;
         private String createTime;