|
@@ -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 {
|
|
|
}
|
|
|
|
|
|
}*/
|
|
|
+
|
|
|
}
|