From bb758220283deccd1ae7ea79a7c635d8828c71be Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Mon, 05 Feb 2024 11:23:35 +0800
Subject: [PATCH] 用户机构调整绑定警格处理

---
 src/main/java/org/springblade/modules/system/mapper/RegionMapper.xml |   92 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 84 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/springblade/modules/system/mapper/RegionMapper.xml b/src/main/java/org/springblade/modules/system/mapper/RegionMapper.xml
index b22f708..3493418 100644
--- a/src/main/java/org/springblade/modules/system/mapper/RegionMapper.xml
+++ b/src/main/java/org/springblade/modules/system/mapper/RegionMapper.xml
@@ -103,16 +103,55 @@
     </select>
 
     <!--根据父编号查询所有的下级-->
+<!--    <select id="getTreeList" resultType="org.springblade.common.node.TreeStringNode">-->
+<!--        <if test="region.cityCode!=null and region.cityCode!=''">-->
+<!--        SELECT-->
+<!--        code as id,-->
+<!--        parent_code as parentId,-->
+<!--        name,-->
+<!--        sort-->
+<!--        FROM blade_region-->
+<!--        where code = #{region.cityCode}-->
+<!--        union all-->
+<!--        select-->
+<!--        grid_code as id,-->
+<!--        community_code as parentId,-->
+<!--        grid_name as name,-->
+<!--        jg.sort-->
+<!--        FROM jczz_grid jg-->
+<!--        left join blade_region br on br.village_code = jg.community_code and br.region_level = 5-->
+<!--        where jg.is_deleted = 0 and br.city_code = #{region.cityCode}-->
+<!--        union all-->
+<!--        </if>-->
+<!--        SELECT-->
+<!--        code as id,-->
+<!--        parent_code as parentId,-->
+<!--        name,-->
+<!--        sort-->
+<!--        FROM blade_region-->
+<!--        where 1=1-->
+<!--        and district_code = '361102'-->
+<!--        <if test="region.parentCode!=null and region.parentCode!=''">-->
+<!--            and parent_code = #{region.parentCode}-->
+<!--        </if>-->
+<!--        <if test="isAdministrator==2">-->
+<!--            <choose>-->
+<!--                <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">-->
+<!--                    and code in-->
+<!--                    <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">-->
+<!--                        #{code}-->
+<!--                    </foreach>-->
+<!--                </when>-->
+<!--                <otherwise>-->
+<!--                    and 1=1-->
+<!--                </otherwise>-->
+<!--            </choose>-->
+<!--        </if>-->
+<!--    </select>-->
+
+    <!--根据父编号查询所有的下级-->
     <select id="getTreeList" resultType="org.springblade.common.node.TreeStringNode">
         <if test="region.cityCode!=null and region.cityCode!=''">
-        SELECT
-        code as id,
-        parent_code as parentId,
-        name,
-        sort
-        FROM blade_region
-        where code = #{region.cityCode}
-        union all
         select
         grid_code as id,
         community_code as parentId,
@@ -207,6 +246,43 @@
         right join jczz_grid jg on jg.community_code = br.village_code and jg.is_deleted = 0
         where br.ancestors like concat('%',#{regionCode},'%')
         )
+        union all
+        (
+            SELECT
+            t1.id,t1.parentId,t1.name
+            FROM
+                (
+                SELECT
+                    @ids AS ids,
+                    ( SELECT @ids := GROUP_CONCAT( id ) FROM police_region WHERE FIND_IN_SET( parentId, @ids ) ) AS cids
+                FROM
+                    police_region
+                WHERE
+                    @ids IS NOT NULL
+                    AND @ids := #{regionCode}
+                ) id,
+                police_region t1
+            WHERE
+                FIND_IN_SET(t1.parentId,ids)
+        )
+    </select>
+
+
+    <!--查询公安对应的辖区树-->
+    <select id="getPoliceTreeList" resultType="org.springblade.common.node.TreeStringNode">
+        SELECT
+            CODE AS id,
+            parent_code AS parentId,
+            NAME
+        FROM jczz_police_station
+        WHERE is_deleted = 0
+        UNION ALL
+        SELECT
+            jw_grid_code AS id,
+            pcs_code AS parentId,
+            community_name AS NAME
+        FROM jczz_police_affairs_grid
+        WHERE is_deleted = 0  AND pcs_code IS NOT NULL
     </select>
 
 </mapper>

--
Gitblit v1.9.3