Ver Fonte

整理数据 2

shiqian há 3 anos atrás
pai
commit
667bf350eb

+ 33 - 0
boman-modules/boman-system/src/main/java/com/boman/system/controller/SysDeptController.java

@@ -7,6 +7,7 @@ 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;
@@ -262,4 +263,36 @@ public class SysDeptController extends BaseController
     public List<SysDept> getByParentId(@PathVariable("parentId") Long parentId) {
         return deptService.getByParentId(parentId);
     }
+
+    public AjaxResult setAncestors(){
+        List<SysDept> sysDepts = deptService.selectDepts(new SysDept());
+        for (SysDept sysDept : sysDepts) {
+            String ancestors = sysDept.getAncestors();
+            if (StringUtils.isEmpty(ancestors)) {
+                Long id = sysDept.getId();
+                SysDept parent1 = deptService.getParentById(id);
+                if (parent1 == null) {
+                    continue;
+                }
+                // 村
+                Long id1 = parent1.getId();
+                SysDept parent2 = deptService.getParentById(id1);
+                if (parent2 == null) {
+                    continue;
+                }
+                // 镇
+                Long id2 = parent2.getId();
+                SysDept parent3 = deptService.getParentById(id2);
+                if (parent3 == null) {
+                    continue;
+                }
+                // 潜山市
+                Long id3 = parent3.getId();
+                sysDept.setAncestors(id3 + "," + id2 + "," + id1);
+                System.out.println(JSON.toJSONString(sysDept));
+            }
+        }
+
+        return AjaxResult.success();
+    }
 }

+ 8 - 0
boman-modules/boman-system/src/main/java/com/boman/system/mapper/SysDeptMapper.java

@@ -130,4 +130,12 @@ public interface SysDeptMapper
      * @return 结果
      */
     public int deleteDeptById(Long id);
+
+    /**
+     * 功能描述: 只找父亲,不招爷爷
+     *
+     * @param deptId deptId
+     * @return com.boman.domain.SysDept
+     */
+    SysDept getParentById(Long deptId);
 }

+ 8 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/ISysDeptService.java

@@ -135,4 +135,12 @@ public interface ISysDeptService
     List<SysDept> getByParentId(Long deptId);
 
     public List<JSONObject> syncData() throws Exception;
+
+    /**
+     * 功能描述: 只找父亲,不招爷爷
+     *
+     * @param deptId deptId
+     * @return com.boman.domain.SysDept
+     */
+    SysDept getParentById(Long deptId);
 }

+ 11 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/SysDeptServiceImpl.java

@@ -492,4 +492,15 @@ public class SysDeptServiceImpl implements ISysDeptService {
 
         return deptMapper.getByParentId(deptId);
     }
+
+    /**
+     * 功能描述: 只找父亲,不招爷爷
+     *
+     * @param deptId deptId
+     * @return com.boman.domain.SysDept
+     */
+    @Override
+    public SysDept getParentById(Long deptId) {
+        return deptMapper.getParentById(deptId);
+    }
 }

+ 6 - 0
boman-modules/boman-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -175,4 +175,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		update sys_dept set del_flag = '2' where id = #{id}
 	</delete>
 
+
+	<select id="getParentById" resultMap="SysDeptResult">
+		<include refid="selectDeptVo"/>
+		where d.parent_id = #{deptId}
+	</select>
+
 </mapper>