Răsfoiți Sursa

获取土地类型

gushoubang 2 luni în urmă
părinte
comite
bf0bf4240e

+ 15 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/TdgyController.java

@@ -1,5 +1,6 @@
 package com.siwei.apply.controller;
 
+import com.siwei.apply.domain.res.LandTypeTreeRes;
 import com.siwei.apply.domain.res.TdgyRes;
 import com.siwei.apply.domain.vo.TdgyUpdateVo;
 import com.siwei.apply.domain.vo.TdgyVo;
@@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -72,4 +74,17 @@ public class TdgyController extends BaseController {
             return R.fail(e.getMessage());
         }
     }
+
+    /**
+     * 查询地块类型树结构
+     */
+    @GetMapping("/landTypeTree")
+    public R<List<LandTypeTreeRes>> getLandTypeTree() {
+        try {
+            List<LandTypeTreeRes> tree = tdgyService.getLandTypeTree();
+            return R.ok(tree);
+        } catch (Exception e) {
+            return R.fail(e.getMessage());
+        }
+    }
 }

+ 15 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/domain/LandType.java

@@ -0,0 +1,15 @@
+package com.siwei.apply.domain;
+
+import lombok.Data;
+
+/**
+ * 地块类型实体
+ */
+@Data
+public class LandType {
+    private String code;
+    private String name;
+    private String parentCode;
+    private Integer index;
+    private String source;
+}

+ 17 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/domain/res/LandTypeTreeRes.java

@@ -0,0 +1,17 @@
+package com.siwei.apply.domain.res;
+
+import lombok.Data;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * 地块类型树结构返回对象
+ */
+@Data
+public class LandTypeTreeRes {
+    private String code;
+    private String name;
+    private String parentCode;
+    private List<LandTypeTreeRes> children = new ArrayList<>();
+}

+ 13 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/mapper/LandTypeMapper.java

@@ -0,0 +1,13 @@
+package com.siwei.apply.mapper;
+
+import com.siwei.apply.domain.LandType;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import java.util.List;
+
+@Mapper
+public interface LandTypeMapper {
+    /** 查询所有地块类型 */
+    List<LandType> selectAll();
+}
+

+ 8 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/TdgyService.java

@@ -1,9 +1,12 @@
 package com.siwei.apply.service;
 
+import com.siwei.apply.domain.res.LandTypeTreeRes;
 import com.siwei.apply.domain.res.TdgyRes;
 import com.siwei.apply.domain.vo.TdgyUpdateVo;
 import com.siwei.apply.domain.vo.TdgyVo;
 
+import java.util.List;
+
 /**
  * 土地供应 服务接口
  */
@@ -35,4 +38,9 @@ public interface TdgyService {
      * @param tdgyUpdateVo 土地供应更新视图对象
      */
     void update(TdgyUpdateVo tdgyUpdateVo);
+
+    /**
+     * 查询地块类型树结构
+     */
+    List<LandTypeTreeRes> getLandTypeTree();
 }

+ 31 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/TdgyImpl.java

@@ -11,6 +11,13 @@ import com.siwei.apply.service.TdgyService;
 import com.siwei.common.core.utils.bean.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import com.siwei.apply.domain.LandType;
+import com.siwei.apply.domain.res.LandTypeTreeRes;
+import com.siwei.apply.mapper.LandTypeMapper;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 import static com.siwei.apply.common.Common.UserId;
 
@@ -23,6 +30,8 @@ public class TdgyImpl implements TdgyService {
     private TdgyMapper tdgyMapper;
     @Autowired
     private ProjectMapper projectMapper;
+    @Autowired
+    private LandTypeMapper landTypeMapper;
 
     @Override
     public Boolean isExit(String projectId) {
@@ -58,4 +67,26 @@ public class TdgyImpl implements TdgyService {
     public void update(TdgyUpdateVo tdgyUpdateVo) {
         tdgyMapper.update(tdgyUpdateVo);
     }
+
+    @Override
+    public List<LandTypeTreeRes> getLandTypeTree() {
+        List<LandType> all = landTypeMapper.selectAll();
+        // 转换为节点
+        List<LandTypeTreeRes> nodes = all.stream().map(type -> {
+            LandTypeTreeRes node = new LandTypeTreeRes();
+            node.setCode(type.getCode());
+            node.setName(type.getName());
+            node.setParentCode(type.getParentCode());
+            return node;
+        }).collect(Collectors.toList());
+        // 构建树
+        Map<String, LandTypeTreeRes> nodeMap = nodes.stream().collect(Collectors.toMap(LandTypeTreeRes::getCode, n -> n));
+        List<LandTypeTreeRes> roots = nodes.stream().filter(n -> n.getParentCode() == null || n.getParentCode().isEmpty() || !nodeMap.containsKey(n.getParentCode())).collect(Collectors.toList());
+        nodes.forEach(n -> {
+            if (n.getParentCode() != null && nodeMap.containsKey(n.getParentCode())) {
+                nodeMap.get(n.getParentCode()).getChildren().add(n);
+            }
+        });
+        return roots;
+    }
 }

+ 15 - 0
siwei-modules/siwei-apply/src/main/resources/mapper/LandTypeMapper.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.siwei.apply.mapper.LandTypeMapper">
+    <resultMap id="LandTypeResultMap" type="com.siwei.apply.domain.LandType">
+        <id property="code" column="code" />
+        <result property="name" column="name" />
+        <result property="parentCode" column="parent_code" />
+        <result property="index" column="index" />
+        <result property="source" column="source" />
+    </resultMap>
+
+    <select id="selectAll" resultMap="LandTypeResultMap">
+        SELECT code, name, parent_code, index, source FROM land_type ORDER BY index
+    </select>
+</mapper>