Parcourir la source

整理数据 4

shiqian il y a 3 ans
Parent
commit
b72c7471df

+ 25 - 22
boman-modules/boman-system/src/main/java/com/boman/system/controller/SysDeptController.java

@@ -1,35 +1,28 @@
 package com.boman.system.controller;
 
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import org.apache.commons.lang3.ArrayUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import com.boman.domain.constant.UserConstants;
 import com.boman.common.core.utils.SecurityUtils;
 import com.boman.common.core.utils.StringUtils;
 import com.boman.common.core.web.controller.BaseController;
-import com.boman.domain.dto.AjaxResult;
 import com.boman.common.log.annotation.Log;
 import com.boman.common.log.enums.BusinessType;
 import com.boman.common.security.annotation.PreAuthorize;
 import com.boman.domain.SysDept;
+import com.boman.domain.constant.UserConstants;
+import com.boman.domain.dto.AjaxResult;
+import com.boman.system.mapper.SysDeptMapper;
 import com.boman.system.service.ISysDeptService;
+import org.apache.commons.lang3.ArrayUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 /**
  * 部门信息
@@ -42,6 +35,8 @@ public class SysDeptController extends BaseController
 {
     @Autowired
     private ISysDeptService deptService;
+    @Autowired // 整理数据测试用的
+    private SysDeptMapper deptMapper;
 
     /**
      * 获取部门列表
@@ -264,6 +259,11 @@ public class SysDeptController extends BaseController
         return deptService.getByParentId(parentId);
     }
 
+    /**
+     * 功能描述: 把部门表中的ancestors按照规则塞进值
+     *
+     * @return com.boman.domain.dto.AjaxResult
+     */
     @GetMapping("/auth")
     public AjaxResult setAncestors() {
         List<SysDept> sysDepts = deptService.selectDeptsList();
@@ -282,6 +282,7 @@ public class SysDeptController extends BaseController
                 SysDept parent2 = deptService.getParentById(parentId1);
                 if (parent2 == null) {
                     sysDept.setAncestors(id1 + "");
+                    deptMapper.updateDept(sysDept);
                     continue;
                 }
 
@@ -290,15 +291,17 @@ public class SysDeptController extends BaseController
                 SysDept parent3 = deptService.getParentById(parentId2);
                 if (parent3 == null) {
                     sysDept.setAncestors(id2 + "," + id1);
+                    deptMapper.updateDept(sysDept);
                     continue;
                 }
 
                 Long id3 = parent3.getId();
                 sysDept.setAncestors(id3 + "," + id2 + "," + id1);
+                deptMapper.updateDept(sysDept);
             }
         }
         
-        System.out.println(JSON.toJSONString(sysDepts));
+//        System.out.println(JSON.toJSONString(sysDepts));
         return AjaxResult.success();
     }
 }