Browse Source

树结构工具类提取

lyq 1 year ago
parent
commit
da00f1ccfa

+ 12 - 15
src/main/java/com/sooka/sponest/data/digitalresource/controller/CenterdataTFarmGridController.java

@@ -1,6 +1,7 @@
 package com.sooka.sponest.data.digitalresource.controller;
 
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.utils.BuildTreeUtil;
 import com.ruoyi.common.core.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.web.controller.BaseController;
 import com.ruoyi.common.core.web.domain.AjaxResult;
@@ -44,8 +45,7 @@ public class CenterdataTFarmGridController extends BaseController {
     /**
      * 查询农业网格管理列表
      */
-
-    @ApiOperation(value = "查询农业网格管理列表",notes = "查询农业网格管理列表")
+    @ApiOperation(value = "查询农业网格管理列表", notes = "查询农业网格管理列表")
     @RequiresPermissions("farm:grid:list")
     @GetMapping("/list")
     public TableDataInfo list(CenterdataTFarmGrid centerdataTFarmGrid) {
@@ -53,17 +53,17 @@ public class CenterdataTFarmGridController extends BaseController {
         List<CenterdataTFarmGrid> list = centerdataTFarmGridService.selectCenterdataTFarmGridList(centerdataTFarmGrid);
         return getDataTable(list);
     }
-    @ApiOperation(value = "查询农业网格管理列表",notes = "查询农业网格管理列表")
+
+    @ApiOperation(value = "查询农业网格管理列表", notes = "查询农业网格管理列表")
     @PostMapping("/listAll")
     public List listAll(CenterdataTFarmGrid centerdataTFarmGrid) {
-        return centerdataTFarmGridService.buildDeptTree(centerdataTFarmGridService.selectCenterdataTFarmGridListTree(centerdataTFarmGrid));
+        return BuildTreeUtil.buildDeptTree(centerdataTFarmGridService.selectCenterdataTFarmGridListTree(centerdataTFarmGrid));
     }
 
     /**
      * 导出农业网格管理列表
      */
-
-    @ApiOperation(value = "导出农业网格管理列表",notes = "导出农业网格管理列表")
+    @ApiOperation(value = "导出农业网格管理列表", notes = "导出农业网格管理列表")
     @RequiresPermissions("farm:grid:export")
     @Log(title = "农业网格管理", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
@@ -76,10 +76,10 @@ public class CenterdataTFarmGridController extends BaseController {
     /**
      * 获取农业网格管理详细信息
      */
-    @ApiOperation(value = "获取农业网格管理详细信息",notes = "获取农业网格管理详细信息")
+    @ApiOperation(value = "获取农业网格管理详细信息", notes = "获取农业网格管理详细信息")
     @RequiresPermissions("farm:grid:query")
     @GetMapping(value = "/{id}/{type}")
-    public AjaxResult getInfo(@PathVariable("id") String id ,  @PathVariable(value = "type") String type) {
+    public AjaxResult getInfo(@PathVariable("id") String id, @PathVariable(value = "type") String type) {
         // 判断是否存在下级
         Integer num = centerdataTFarmGridService.getInteger(id, type);
         if (num != null) {
@@ -91,9 +91,7 @@ public class CenterdataTFarmGridController extends BaseController {
     /**
      * 新增农业网格管理
      */
-
-
-    @ApiOperation(value = "新增农业网格管理",notes = "新增农业网格管理")
+    @ApiOperation(value = "新增农业网格管理", notes = "新增农业网格管理")
     @RequiresPermissions("farm:grid:add")
     @Log(title = "农业网格管理", businessType = BusinessType.INSERT)
     @PostMapping
@@ -110,8 +108,7 @@ public class CenterdataTFarmGridController extends BaseController {
     /**
      * 修改农业网格管理
      */
-
-    @ApiOperation(value = "修改农业网格管理",notes = "修改农业网格管理")
+    @ApiOperation(value = "修改农业网格管理", notes = "修改农业网格管理")
     @RequiresPermissions("farm:grid:edit")
     @Log(title = "农业网格管理", businessType = BusinessType.UPDATE)
     @PutMapping
@@ -135,7 +132,7 @@ public class CenterdataTFarmGridController extends BaseController {
     /**
      * 删除农业网格管理
      */
-    @ApiOperation(value = "删除农业网格管理",notes = "删除农业网格管理")
+    @ApiOperation(value = "删除农业网格管理", notes = "删除农业网格管理")
     @RequiresPermissions("farm:grid:remove")
     @Log(title = "农业网格管理", businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}/{type}")
@@ -150,7 +147,7 @@ public class CenterdataTFarmGridController extends BaseController {
         return toAjax(centerdataTFarmGridService.deleteCenterdataTFarmGridByIds(ids, type));
     }
 
-    @ApiOperation(value = "查询负责网格列表",notes = "查询负责网格列表")
+    @ApiOperation(value = "查询负责网格列表", notes = "查询负责网格列表")
     @PostMapping("/selectGridLandInfo")
     public R<Map> selectGridLandInfo(@RequestBody VisuGridBO visuGridBO) {
         return R.ok(centerdataTFarmGridService.selectGridLandInfo(visuGridBO));

+ 0 - 4
src/main/java/com/sooka/sponest/data/digitalresource/mapper/CenterdataTFarmGridMapper.java

@@ -22,7 +22,6 @@ public interface CenterdataTFarmGridMapper {
      */
     List<CenterdataTFarmGrid> selectCenterdataTFarmGridList(CenterdataTFarmGrid centerdataTFarmGrid);
 
-
     List<Map<String, Object>> selectCenterdataTFarmGridListTree(CenterdataTFarmGrid centerdataTFarmGrid);
 
     /**
@@ -77,8 +76,5 @@ public interface CenterdataTFarmGridMapper {
 
     List<VisuGridBO> selectGridFarmLand(VisuGridBO visuGridBO);
 
-    List<Map<String, Object>> selectCommunicationList(CenterdataTFarmGrid grid);
-
     List<CenterdataTFarmGrid> select(CenterdataTFarmGrid centerdataTFarmGrid);
-
 }

+ 2 - 5
src/main/java/com/sooka/sponest/data/digitalresource/service/ICenterdataTFarmGridService.java

@@ -23,10 +23,8 @@ public interface ICenterdataTFarmGridService extends IBaseService {
      */
     List<CenterdataTFarmGrid> selectCenterdataTFarmGridList(CenterdataTFarmGrid centerdataTFarmGrid);
 
-
     List<Map<String, Object>> selectCenterdataTFarmGridListTree(CenterdataTFarmGrid centerdataTFarmGrid);
 
-    List<Map<String, Object>> buildDeptTree(List<Map<String, Object>> depts);
     /**
      * 查询农业网格管理
      *
@@ -57,12 +55,10 @@ public interface ICenterdataTFarmGridService extends IBaseService {
      * @param ids 需要删除的农业网格管理主键集合
      * @return 结果
      */
-    int deleteCenterdataTFarmGridByIds(String[] ids,String type);
+    int deleteCenterdataTFarmGridByIds(String[] ids, String type);
 
     Map selectGridLandInfo(VisuGridBO visuGridBO);
 
-    List<Map<String, Object>> selectCommunicationList(CenterdataTFarmGrid grid);
-
     /**
      * 判断是否存在下级
      *
@@ -71,5 +67,6 @@ public interface ICenterdataTFarmGridService extends IBaseService {
      * @return
      */
     Integer getInteger(String type, String id);
+
     List<CenterdataTFarmGrid> select(CenterdataTFarmGrid centerdataTFarmGrid);
 }

+ 0 - 76
src/main/java/com/sooka/sponest/data/digitalresource/service/impl/CenterdataTFarmGridServiceImpl.java

@@ -9,11 +9,9 @@ import com.sooka.sponest.data.base.service.impl.BaseServiceImpl;
 import com.sooka.sponest.data.digitalresource.domain.CenterdataTFarmGrid;
 import com.sooka.sponest.data.digitalresource.domain.bo.VisuGridBO;
 import com.sooka.sponest.data.digitalresource.mapper.CenterdataTFarmGridMapper;
-import com.sooka.sponest.data.digitalresource.service.ICenterdataTFarmGridLengthService;
 import com.sooka.sponest.data.digitalresource.service.ICenterdataTFarmGridService;
 import com.sooka.sponest.data.digitalwater.domain.CenterdataTHydraulicRiverLength;
 import com.sooka.sponest.data.digitalwater.service.ICenterdataTHydraulicRiverLengthService;
-import org.apache.commons.collections4.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -32,14 +30,8 @@ public class CenterdataTFarmGridServiceImpl extends BaseServiceImpl implements I
     private CenterdataTFarmGridMapper centerdataTFarmGridMapper;
 
     @Autowired
-    private ICenterdataTFarmGridLengthService centerdataTFarmGridLengthService;
-
-    @Autowired
     private ICenterdataTHydraulicRiverLengthService iCenterdataTHydraulicRiverLengthService;
 
-    private static final String PARENTID = "parentId";
-    private static final String ID = "id";
-
     /**
      * 查询农业网格管理列表
      *
@@ -58,69 +50,6 @@ public class CenterdataTFarmGridServiceImpl extends BaseServiceImpl implements I
         return centerdataTFarmGridMapper.selectCenterdataTFarmGridListTree(centerdataTFarmGrid);
     }
 
-    /**
-     * 构建前端所需要树结构
-     *
-     * @param depts 部门列表
-     * @return 树结构列表
-     */
-    @Override
-    public List<Map<String, Object>> buildDeptTree(List<Map<String, Object>> depts) {
-        List<Map<String, Object>> returnList = new ArrayList<>();
-        List<String> tempList = new ArrayList<>();
-        for (Map<String, Object> dept : depts) {
-            tempList.add(MapUtils.getString(dept, ID));
-        }
-        for (Map<String, Object> dept : depts) {
-            // 如果是顶级节点, 遍历该父节点的所有子节点
-            if (!tempList.contains(MapUtils.getString(dept, PARENTID))) {
-                recursionFn(depts, dept);
-                returnList.add(dept);
-            }
-        }
-        if (returnList.isEmpty()) {
-            returnList = depts;
-        }
-        return returnList;
-    }
-
-
-    /**
-     * 递归列表
-     */
-    private void recursionFn(List<Map<String, Object>> list, Map<String, Object> t) {
-        // 得到子节点列表
-        List<Map<String, Object>> childList = getChildList(list, t);
-        t.put("children", childList);
-        for (Map<String, Object> tChild : childList) {
-            if (hasChild(list, tChild)) {
-                recursionFn(list, tChild);
-            }
-        }
-    }
-
-    /**
-     * 得到子节点列表
-     */
-    private List<Map<String, Object>> getChildList(List<Map<String, Object>> list, Map<String, Object> t) {
-        List<Map<String, Object>> tlist = new ArrayList<>();
-        Iterator<Map<String, Object>> it = list.iterator();
-        while (it.hasNext()) {
-            Map<String, Object> n = it.next();
-            if (StringUtils.isNotNull(MapUtils.getString(n, PARENTID)) && MapUtils.getString(n, PARENTID).equals(MapUtils.getString(t, ID))) {
-                tlist.add(n);
-            }
-        }
-        return tlist;
-    }
-
-    /**
-     * 判断是否有子节点
-     */
-    private boolean hasChild(List<Map<String, Object>> list, Map<String, Object> t) {
-        return !getChildList(list, t).isEmpty();
-    }
-
     @Override
     public CenterdataTFarmGrid selectCenterdataTFarmGridById(String id) {
         CenterdataTFarmGrid centerdataTFarmGrid = centerdataTFarmGridMapper.selectCenterdataTFarmGridById(id);
@@ -207,7 +136,6 @@ public class CenterdataTFarmGridServiceImpl extends BaseServiceImpl implements I
         return null;
     }
 
-
     @Override
     public Map selectGridLandInfo(VisuGridBO visuGridBO) {
         Map result = new HashMap();
@@ -217,10 +145,6 @@ public class CenterdataTFarmGridServiceImpl extends BaseServiceImpl implements I
     }
 
     @Override
-    public List<Map<String, Object>> selectCommunicationList(CenterdataTFarmGrid grid) {
-        return centerdataTFarmGridMapper.selectCommunicationList(grid);
-    }
-    @Override
     public List<CenterdataTFarmGrid> select(CenterdataTFarmGrid centerdataTFarmGrid) {
         return centerdataTFarmGridMapper.select(centerdataTFarmGrid);
     }

+ 1 - 7
src/main/resources/mapper/digitalresource/CenterdataTFarmGridMapper.xml

@@ -203,13 +203,7 @@
         where a.grid_land_id = b.id and a.id = #{gridId}
     </select>
 
-    <select id="selectCommunicationList" parameterType="CenterdataTFarmGrid" resultType="map">
-        select *, "" as mobile from centerdata_t_farm_grid_view where `type` in ( '0', #{type} )
-        ORDER BY
-            cast( parentId AS signed ),
-            cast( order_num AS signed)
-    </select>
-    <select id="select"  parameterType="CenterdataTFarmGrid" resultMap="CenterdataTFarmGridResult">
+    <select id="select" parameterType="CenterdataTFarmGrid" resultMap="CenterdataTFarmGridResult">
         select * from centerdata_t_farm_grid
         <where>
             <if test="gridFarmId != null  and gridFarmId != ''">and grid_farm_id = #{gridFarmId}</if>