Simon 1 gadu atpakaļ
vecāks
revīzija
131f308760

+ 2 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TRegionController.java

@@ -42,7 +42,8 @@ public class TRegionController extends BaseController
     public TableDataInfo list(TRegion tRegion)
     {
         startPage();
-        List<TRegion> list = tRegionService.selectTRegionList(tRegion);
+//        List<TRegion> list = tRegionService.selectTRegionList(tRegion);
+        List<TRegion> list = tRegionService.selectTRegionListV2(tRegion);
         return getDataTable(list);
     }
 

+ 53 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/TRegionVo.java

@@ -0,0 +1,53 @@
+package com.ruoyi.system.domain;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.StringJoiner;
+
+/**
+ * @ClassName: TRegionVo
+ * @Author: 于学智
+ * @Description:
+ * @CreateDate: 2023/9/19 17:29
+ * @Version: 1.0
+ * @E-mail:18722650553@139.com
+ * @Link:https://github.com/18722650553
+ */
+public class TRegionVo implements Serializable {
+    private String code;
+    private String name;
+    private List<TRegionVo> child;
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public List<TRegionVo> getChild() {
+        return child;
+    }
+
+    public void setChild(List<TRegionVo> child) {
+        this.child = child;
+    }
+
+    @Override
+    public String toString() {
+        return new StringJoiner(", ", TRegionVo.class.getSimpleName() + "[", "]")
+                .add("code='" + code + "'")
+                .add("name='" + name + "'")
+                .add("child=" + child)
+                .toString();
+    }
+}

+ 44 - 9
ruoyi-system/src/main/java/com/ruoyi/system/mapper/TRegionMapper.java

@@ -5,18 +5,18 @@ import java.util.List;
 import com.ruoyi.common.annotation.DataSource;
 import com.ruoyi.common.enums.DataSourceType;
 import com.ruoyi.system.domain.TRegion;
+import com.ruoyi.system.domain.TRegionVo;
 
 /**
  * 行政区域Mapper接口
- * 
+ *
  * @author zhengjie
  * @date 2023-08-15
  */
-public interface TRegionMapper 
-{
+public interface TRegionMapper {
     /**
      * 查询行政区域
-     * 
+     *
      * @param id 行政区域主键
      * @return 行政区域
      */
@@ -32,15 +32,50 @@ public interface TRegionMapper
 
     /**
      * 查询行政区域列表
-     * 
+     *
      * @param tRegion 行政区域
      * @return 行政区域集合
      */
     public List<TRegion> selectTRegionList(TRegion tRegion);
 
+    /**
+     * 查询行政区域列表-省
+     *
+     * @return 行政区域集合
+     */
+    public List<TRegionVo> selectTRegionListV1();
+
+    /**
+     * 查询行政区域列表-市
+     *
+     * @return 行政区域集合
+     */
+    public List<TRegionVo> selectTRegionListV2(String province_code);
+
+    /**
+     * 查询行政区域列表-区
+     *
+     * @return 行政区域集合
+     */
+    public List<TRegionVo> selectTRegionListV3(String city_code);
+
+    /**
+     * 查询行政区域列表-办事处
+     *
+     * @return 行政区域集合
+     */
+    public List<TRegionVo> selectTRegionListV4(String county_code);
+
+    /**
+     * 查询行政区域列表-居委会
+     *
+     * @return 行政区域集合
+     */
+    public List<TRegionVo> selectTRegionListV5(String town_code);
+
     /**
      * 新增行政区域
-     * 
+     *
      * @param tRegion 行政区域
      * @return 结果
      */
@@ -48,7 +83,7 @@ public interface TRegionMapper
 
     /**
      * 修改行政区域
-     * 
+     *
      * @param tRegion 行政区域
      * @return 结果
      */
@@ -56,7 +91,7 @@ public interface TRegionMapper
 
     /**
      * 删除行政区域
-     * 
+     *
      * @param id 行政区域主键
      * @return 结果
      */
@@ -64,7 +99,7 @@ public interface TRegionMapper
 
     /**
      * 批量删除行政区域
-     * 
+     *
      * @param ids 需要删除的数据主键集合
      * @return 结果
      */

+ 7 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ITRegionService.java

@@ -26,6 +26,13 @@ public interface ITRegionService
      * @return 行政区域集合
      */
     public List<TRegion> selectTRegionList(TRegion tRegion);
+    /**
+     * 查询行政区域列表
+     *
+     * @param tRegion 行政区域
+     * @return 行政区域集合
+     */
+    public List<TRegion> selectTRegionListV2(TRegion tRegion);
 
     /**
      * 新增行政区域

+ 41 - 23
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TRegionServiceImpl.java

@@ -1,8 +1,11 @@
 package com.ruoyi.system.service.impl;
 
 import java.util.List;
+
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.system.domain.TRegionVo;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.SpringApplication;
 import org.springframework.stereotype.Service;
 import com.ruoyi.system.mapper.TRegionMapper;
 import com.ruoyi.system.domain.TRegion;
@@ -10,56 +13,74 @@ import com.ruoyi.system.service.ITRegionService;
 
 /**
  * 行政区域Service业务层处理
- * 
+ *
  * @author zhengjie
  * @date 2023-08-15
  */
 @Service
-public class TRegionServiceImpl implements ITRegionService 
-{
+public class TRegionServiceImpl implements ITRegionService {
     @Autowired
     private TRegionMapper tRegionMapper;
 
     /**
      * 查询行政区域
-     * 
+     *
      * @param id 行政区域主键
      * @return 行政区域
      */
     @Override
-    public TRegion selectTRegionById(Integer id)
-    {
+    public TRegion selectTRegionById(Integer id) {
         return tRegionMapper.selectTRegionById(id);
     }
 
     /**
      * 查询行政区域列表
-     * 
+     *
      * @param tRegion 行政区域
      * @return 行政区域
      */
     @Override
-    public List<TRegion> selectTRegionList(TRegion tRegion)
-    {
+    public List<TRegion> selectTRegionList(TRegion tRegion) {
+        return tRegionMapper.selectTRegionList(tRegion);
+    }
+
+    @Override
+    public List<TRegion> selectTRegionListV2(TRegion tRegion) {
+        List<TRegionVo> list_1 = tRegionMapper.selectTRegionListV1();
+        for (TRegionVo vo_1 : list_1) {
+            List<TRegionVo> list_2 = tRegionMapper.selectTRegionListV2(vo_1.getCode());
+            for (TRegionVo vo_2 : list_2) {
+                List<TRegionVo> list_3 = tRegionMapper.selectTRegionListV3(vo_2.getCode());
+                for (TRegionVo vo_3 : list_3) {
+                    List<TRegionVo> list_4 = tRegionMapper.selectTRegionListV4(vo_3.getCode());
+                    for (TRegionVo vo_4 : list_4) {
+                        List<TRegionVo> list_5 = tRegionMapper.selectTRegionListV5(vo_4.getCode());
+                        vo_4.setChild(list_5);
+                    }
+                    vo_3.setChild(list_4);
+                }
+                vo_2.setChild(list_3);
+            }
+            vo_1.setChild(list_2);
+        }
         return tRegionMapper.selectTRegionList(tRegion);
     }
 
     /**
      * 新增行政区域
-     * 
+     *
      * @param tRegion 行政区域
      * @return 结果
      */
     @Override
-    public int insertTRegion(TRegion tRegion)
-    {
-        if (tRegion.getParentId() == 0){
+    public int insertTRegion(TRegion tRegion) {
+        if (tRegion.getParentId() == 0) {
             TRegion t = tRegionMapper.selectTRegionById(1);
             tRegion.setCreateTime(DateUtils.getNowDate());
             tRegion.setParentId(1);
             tRegion.setAncestors("0,1");
             return tRegionMapper.insertTRegion(tRegion);
-        }else{
+        } else {
             TRegion t = tRegionMapper.selectTRegionById(tRegion.getParentId());
             tRegion.setCreateTime(DateUtils.getNowDate());
             tRegion.setAncestors(t.getAncestors() + "," + tRegion.getParentId());
@@ -69,38 +90,35 @@ public class TRegionServiceImpl implements ITRegionService
 
     /**
      * 修改行政区域
-     * 
+     *
      * @param tRegion 行政区域
      * @return 结果
      */
     @Override
-    public int updateTRegion(TRegion tRegion)
-    {
+    public int updateTRegion(TRegion tRegion) {
         tRegion.setUpdateTime(DateUtils.getNowDate());
         return tRegionMapper.updateTRegion(tRegion);
     }
 
     /**
      * 批量删除行政区域
-     * 
+     *
      * @param ids 需要删除的行政区域主键
      * @return 结果
      */
     @Override
-    public int deleteTRegionByIds(Integer[] ids)
-    {
+    public int deleteTRegionByIds(Integer[] ids) {
         return tRegionMapper.deleteTRegionByIds(ids);
     }
 
     /**
      * 删除行政区域信息
-     * 
+     *
      * @param id 行政区域主键
      * @return 结果
      */
     @Override
-    public int deleteTRegionById(Integer id)
-    {
+    public int deleteTRegionById(Integer id) {
         return tRegionMapper.deleteTRegionById(id);
     }
 }

+ 90 - 38
ruoyi-system/src/main/resources/mapper/system/TRegionMapper.xml

@@ -1,49 +1,70 @@
 <?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">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.system.mapper.TRegionMapper">
-    
+
     <resultMap type="TRegion" id="TRegionResult">
-        <result property="id"    column="id"    />
-        <result property="parentId"    column="parent_id"    />
-        <result property="ancestors"    column="ancestors"    />
-        <result property="deptName"    column="dept_name"    />
-        <result property="deptNum"    column="dept_num"    />
-        <result property="zoneName"    column="zone_name"    />
-        <result property="zoneNum"    column="zone_num"    />
-        <result property="kind"    column="kind"    />
-        <result property="orderNum"    column="order_num"    />
-        <result property="remarks"    column="remarks"    />
-        <result property="gpsLng"    column="gps_lng"    />
-        <result property="gpsLat"    column="gps_lat"    />
-        <result property="createBy"    column="create_by"    />
-        <result property="createTime"    column="create_time"    />
-        <result property="updateBy"    column="update_by"    />
-        <result property="updateTime"    column="update_time"    />
+        <result property="id" column="id"/>
+        <result property="parentId" column="parent_id"/>
+        <result property="ancestors" column="ancestors"/>
+        <result property="deptName" column="dept_name"/>
+        <result property="deptNum" column="dept_num"/>
+        <result property="zoneName" column="zone_name"/>
+        <result property="zoneNum" column="zone_num"/>
+        <result property="kind" column="kind"/>
+        <result property="orderNum" column="order_num"/>
+        <result property="remarks" column="remarks"/>
+        <result property="gpsLng" column="gps_lng"/>
+        <result property="gpsLat" column="gps_lat"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+    </resultMap>
+
+    <resultMap type="TRegionVo" id="TRegionVoResult">
+        <result property="code" column="code"/>
+        <result property="name" column="name"/>
     </resultMap>
 
     <sql id="selectTRegionVo">
-        select id, parent_id, ancestors, dept_name, dept_num, zone_name, zone_num, kind, order_num, remarks, gps_lng, gps_lat, create_by, create_time, update_by, update_time from t_region
+        select id,
+               parent_id,
+               ancestors,
+               dept_name,
+               dept_num,
+               zone_name,
+               zone_num,
+               kind,
+               order_num,
+               remarks,
+               gps_lng,
+               gps_lat,
+               create_by,
+               create_time,
+               update_by,
+               update_time
+        from t_region
     </sql>
 
     <select id="selectTRegionList" parameterType="TRegion" resultMap="TRegionResult">
         <include refid="selectTRegionVo"/>
-        <where>  
-            <if test="parentId != null "> and parent_id = #{parentId}</if>
-            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
-            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
-            <if test="deptNum != null  and deptNum != ''"> and dept_num = #{deptNum}</if>
-            <if test="zoneName != null  and zoneName != ''"> and zone_name like concat('%', #{zoneName}, '%')</if>
-            <if test="zoneNum != null  and zoneNum != ''"> and zone_num = #{zoneNum}</if>
-            <if test="kind != null "> and kind = #{kind}</if>
-            <if test="orderNum != null "> and order_num = #{orderNum}</if>
-            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
-            <if test="gpsLng != null "> and gps_lng = #{gpsLng}</if>
-            <if test="gpsLat != null "> and gps_lat = #{gpsLat}</if>
+        <where>
+            <if test="parentId != null ">and parent_id = #{parentId}</if>
+            <if test="ancestors != null  and ancestors != ''">and ancestors = #{ancestors}</if>
+            <if test="deptName != null  and deptName != ''">and dept_name like concat('%', #{deptName}, '%')</if>
+            <if test="deptNum != null  and deptNum != ''">and dept_num = #{deptNum}</if>
+            <if test="zoneName != null  and zoneName != ''">and zone_name like concat('%', #{zoneName}, '%')</if>
+            <if test="zoneNum != null  and zoneNum != ''">and zone_num = #{zoneNum}</if>
+            <if test="kind != null ">and kind = #{kind}</if>
+            <if test="orderNum != null ">and order_num = #{orderNum}</if>
+            <if test="remarks != null  and remarks != ''">and remarks = #{remarks}</if>
+            <if test="gpsLng != null ">and gps_lng = #{gpsLng}</if>
+            <if test="gpsLat != null ">and gps_lat = #{gpsLat}</if>
         </where>
     </select>
-    
+
     <select id="selectTRegionById" parameterType="Integer" resultMap="TRegionResult">
         <include refid="selectTRegionVo"/>
         where id = #{id}
@@ -53,7 +74,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectTRegionVo"/>
         where parent_id = #{parentId}
     </select>
-        
+    <select id="selectTRegionListV1" resultMap="TRegionVoResult">
+        SELECT DISTINCT SUBSTRING(province_code, 1, 2) AS code,
+                        province_name                  AS name
+        FROM position_village;
+    </select>
+    <select id="selectTRegionListV2" parameterType="string" resultMap="TRegionVoResult">
+        SELECT DISTINCT SUBSTRING(city_code, 1, 4) AS code,
+                        city_name                  AS name
+        FROM position_village
+        WHERE SUBSTRING(position_village.city_code, 1, 2) = #{province_code}
+    </select>
+    <select id="selectTRegionListV3" parameterType="string" resultMap="TRegionVoResult">
+        SELECT DISTINCT SUBSTRING(county_code, 1,6) AS code,
+                        county_name                  AS name
+        FROM position_village
+        WHERE SUBSTRING(position_village.city_code, 1, 4) = #{city_code}
+    </select>
+    <select id="selectTRegionListV4" parameterType="string" resultMap="TRegionVoResult">
+        SELECT DISTINCT SUBSTRING(town_code, 1,8) AS code,
+                        town_name                  AS name
+        FROM position_village
+        WHERE SUBSTRING(position_village.county_code, 1, 6) = #{county_code}
+    </select>
+    <select id="selectTRegionListV5" parameterType="string" resultMap="TRegionVoResult">
+        SELECT DISTINCT SUBSTRING(village_code, 1, 10) AS code,
+                        village_name                   AS name
+        FROM position_village
+        WHERE SUBSTRING(position_village.county_code, 1, 8) = #{county_code}
+    </select>
+
     <insert id="insertTRegion" parameterType="TRegion" useGeneratedKeys="true" keyProperty="id">
         insert into t_region
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -72,7 +122,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createTime != null">create_time,</if>
             <if test="updateBy != null">update_by,</if>
             <if test="updateTime != null">update_time,</if>
-         </trim>
+        </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="parentId != null">#{parentId},</if>
             <if test="ancestors != null">#{ancestors},</if>
@@ -89,7 +139,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createTime != null">#{createTime},</if>
             <if test="updateBy != null">#{updateBy},</if>
             <if test="updateTime != null">#{updateTime},</if>
-         </trim>
+        </trim>
     </insert>
 
     <update id="updateTRegion" parameterType="TRegion">
@@ -115,11 +165,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </update>
 
     <delete id="deleteTRegionById" parameterType="Integer">
-        delete from t_region where id = #{id}
+        delete
+        from t_region
+        where id = #{id}
     </delete>
 
     <delete id="deleteTRegionByIds" parameterType="String">
-        delete from t_region where id in 
+        delete from t_region where id in
         <foreach item="id" collection="array" open="(" separator="," close=")">
             #{id}
         </foreach>