From 8b7258c9427882bb1798f1502eaa35184c6e374e Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Fri, 09 Aug 2024 14:29:18 +0800
Subject: [PATCH] 短信指定楼栋发送

---
 src/main/java/org/springblade/modules/doorplateAddress/mapper/DoorplateAddressMapper.xml |  145 ++++++++++++++++++++++++++++++++++++------------
 1 files changed, 108 insertions(+), 37 deletions(-)

diff --git a/src/main/java/org/springblade/modules/doorplateAddress/mapper/DoorplateAddressMapper.xml b/src/main/java/org/springblade/modules/doorplateAddress/mapper/DoorplateAddressMapper.xml
index 9f8ff0b..48f095c 100644
--- a/src/main/java/org/springblade/modules/doorplateAddress/mapper/DoorplateAddressMapper.xml
+++ b/src/main/java/org/springblade/modules/doorplateAddress/mapper/DoorplateAddressMapper.xml
@@ -5,7 +5,7 @@
     <!--过滤网格数据-->
     <sql id="filterHouseGrid">
         <if test="houseParam.roleName!=null and houseParam.roleName!=''">
-            <if test="houseParam.roleName=='网格员' and houseParam.userId!='1726859808689696770'">
+            <if test="houseParam.roleName=='wgy' and houseParam.userId!='1726859808689696770'">
                 <choose>
                     <when test="list != null and list.size()>0">
                         and address_code in
@@ -21,12 +21,31 @@
         </if>
     </sql>
 
+    <!--过滤网格编号-->
+    <sql id="filterGrid">
+        <if test="houseParam.roleName!=null and houseParam.roleName!=''">
+            <if test="houseParam.roleName=='wgy' and houseParam.userId!='1726859808689696770'">
+                <choose>
+                    <when test="list != null and list.size()>0">
+                        and jgr.grid_code in
+                        <foreach collection="list" item="gridCode" separator ="," open="("  close=")">
+                            #{gridCode}
+                        </foreach>
+                    </when>
+                    <otherwise>
+                        and jgr.grid_code in ('')
+                    </otherwise>
+                </choose>
+            </if>
+        </if>
+    </sql>
+
 
 
     <!--过滤社区数据-->
     <sql id="filterCommunity">
         <if test="houseParam.roleName!=null and houseParam.roleName!=''">
-            <if test="houseParam.roleName=='民警' and houseParam.userId!='1726859808689696770'">
+            <if test="houseParam.roleName=='mj' and houseParam.userId!='1726859808689696770'">
                 <choose>
                     <when test="communityList != null and communityList.size()>0">
                         and nei_code in
@@ -57,15 +76,38 @@
 
     <!--自定义分页查询-->
     <select id="selectDoorplateAddressPage" resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVO">
-        select * from jczz_doorplate_address where 1=1
+        SELECT
+        jda.*
+        FROM
+        jczz_doorplate_address jda LEFT JOIN jczz_district jd on jda.aoi_code=jd.aoi_code
+        where 1=1
         <if test="doorplateAddress.aoiName!=null and doorplateAddress.aoiName!=''">
-            and aoi_name like concat('%',#{doorplateAddress.aoiName},'%')
+            and jda.aoi_name like concat('%',#{doorplateAddress.aoiName},'%')
         </if>
         <if test="doorplateAddress.addressName!=null and doorplateAddress.addressName!=''">
-            and address_name like concat('%',#{doorplateAddress.addressName},'%')
+            and jda.address_name like concat('%',#{doorplateAddress.addressName},'%')
         </if>
         <if test="doorplateAddress.townStreetCode != null and doorplateAddress.townStreetCode != ''">
-            and town_street_code like concat('%',#{doorplateAddress.townStreetCode},'%')
+            and jda.town_street_code like concat('%',#{doorplateAddress.townStreetCode},'%')
+        </if>
+
+        <if test="doorplateAddress.houseName != null and doorplateAddress.houseName != ''">
+            and jda.house_name like concat('%',#{doorplateAddress.houseName},'%')
+        </if>
+
+        <if test="doorplateAddress.buildingName != null and doorplateAddress.buildingName != ''">
+            and jda.building_name like concat('%',#{doorplateAddress.buildingName},'%')
+        </if>
+
+        <if test="doorplateAddress.unitName != null and doorplateAddress.unitName != ''">
+            and jda.unit_name like concat('%',#{doorplateAddress.unitName},'%')
+        </if>
+
+        <if test="doorplateAddress.districtIds != null ">
+            and jd.id in
+        <foreach collection="doorplateAddress.districtIds" item="districtId" separator ="," open="("  close=")">
+            #{districtId}
+        </foreach>
         </if>
     </select>
 
@@ -84,9 +126,9 @@
 
     <!--过滤网格数据-->
     <sql id="filterHouseGridByTownOrCommunity">
-        <if test="houseParam.roleName!=null and houseParam.roleName!='' and houseParam.roleName!='系统管理员'">
+        <if test="houseParam.roleName!=null and houseParam.roleName!='' and houseParam.roleName!='admin'">
             <choose>
-                <when test="houseParam.roleName=='网格员' and houseParam.userId!='1726859808689696770'">
+                <when test="(houseParam.roleName=='wgy' or houseParam.roleName=='wzcj') and houseParam.userId!='1726859808689696770'">
                     <choose>
                         <when test="list != null and list.size()>0">
                             and jg.grid_code in
@@ -115,18 +157,20 @@
             and br.name = '万达社区居民委员会'
         </if>
         <include refid="filterHouseGridByTownOrCommunity"/>
+        group by br.town_code,br.town_name
         union
         select br.town_code as id,br.town_name as name from jczz_police_affairs_grid jpag
         left join blade_region br on jpag.community_code = br.code
-        where jpag.is_deleted = 0
+        where jpag.is_deleted = 0 and br.town_code is not null
         <include refid="filterCommunityByTownOrCommunity"/>
+        group by br.town_code,br.town_name
     </select>
 
     <!--过滤社区数据-->
     <sql id="filterCommunityByTownOrCommunity">
         <if test="houseParam.roleName!=null and houseParam.roleName!=''">
             <choose>
-                <when test="houseParam.roleName=='民警' and houseParam.userId!='1726859808689696770'">
+                <when test="houseParam.roleName=='mj'">
                     <choose>
                         <when test="communityList != null and communityList.size()>0">
                             and jpag.jw_grid_code in
@@ -158,15 +202,15 @@
         union
         select br.village_code as id,br.village_name as name,br.town_code as parentId from jczz_police_affairs_grid jpag
         left join blade_region br on jpag.community_code = br.code
-        where jpag.is_deleted = 0
+        where jpag.is_deleted = 0 and br.village_code is not null
         <include refid="filterCommunityByTownOrCommunity"/>
     </select>
 
     <!--根据社区名称查询小区集合-->
     <select id="getDistrictList" resultType="org.springblade.common.node.TreeStringNode" >
-        select aoi_code as id,aoi_name as name,1 as addressType from jczz_doorplate_address
-        where 1=1
-        and aoi_name !=''
+        select aoi_code as id,aoi_name as name,1 as addressType from jczz_doorplate_address jda
+        left join jczz_grid_range jgr on jda.address_code = jgr.house_code
+        where aoi_name !=''
         and aoi_code !=''
         <if test="houseParam.name != null and houseParam.name!=''">
             and nei_name = #{houseParam.name}
@@ -174,14 +218,14 @@
         <if test="houseParam.code != null and houseParam.code!=''">
             and nei_code = #{houseParam.code}
         </if>
-        <include refid="filterHouseGrid"/>
+        <include refid="filterGrid"/>
         <include refid="filterCommunity"/>
         group by aoi_code,aoi_name
         union all
         (
-        select aoi_code as id,sub_aoi as name,1 as addressType from jczz_doorplate_address
-        where 1=1
-        and aoi_code !=''
+        select aoi_code as id,sub_aoi as name,1 as addressType from jczz_doorplate_address jda
+        left join jczz_grid_range jgr on jda.address_code = jgr.house_code
+        where aoi_code !=''
         and aoi_name is null
         and sub_aoi != ''
         <if test="houseParam.name != null and houseParam.name!=''">
@@ -190,22 +234,22 @@
         <if test="houseParam.code != null and houseParam.code!=''">
             and nei_code = #{houseParam.code}
         </if>
-        <include refid="filterHouseGrid"/>
+        <include refid="filterGrid"/>
         <include refid="filterCommunity"/>
         group by aoi_code,sub_aoi
         )
         union all
         (
-        select nei_code as id,'自建房/商铺' as name,2 as addressType from jczz_doorplate_address
-        where 1=1
-        and aoi_code is null
+        select nei_code as id,'自建房/商铺' as name,2 as addressType from jczz_doorplate_address jda
+        left join jczz_grid_range jgr on jda.address_code = jgr.house_code
+        where aoi_code is null
         <if test="houseParam.name != null and houseParam.name!=''">
             and nei_name = #{houseParam.name}
         </if>
         <if test="houseParam.code != null and houseParam.code!=''">
             and nei_code = #{houseParam.code}
         </if>
-        <include refid="filterHouseGrid"/>
+        <include refid="filterGrid"/>
         <include refid="filterCommunity"/>
         group by nei_code
         )
@@ -227,23 +271,23 @@
     <!--根据小区名称查询楼栋/商铺集合-->
     <select id="getBuildingList" resultType="org.springblade.common.node.TreeStringNode" >
         (
-            select building_code as id,ifnull(building_name,'1栋') as name,1 as addressType from jczz_doorplate_address
-            where 1=1
-            and aoi_code = #{houseParam.code}
+            select building_code as id,ifnull(building_name,'1栋') as name,1 as addressType from jczz_doorplate_address jda
+            left join jczz_grid_range jgr on jda.address_code = jgr.house_code
+            where aoi_code = #{houseParam.code}
             and building_code !=''
             and doorplate_type = '户室牌'
-            <include refid="filterHouseGrid"/>
+            <include refid="filterGrid"/>
             group by building_code,building_name
             order by building_name
         )
         union all
         (
-            select address_code as id,doorplate_name as name,2 as addressType from jczz_doorplate_address
-            where 1=1
-            and aoi_code = #{houseParam.code}
+            select address_code as id,doorplate_name as name,2 as addressType from jczz_doorplate_address jda
+            left join jczz_grid_range jgr on jda.address_code = jgr.house_code
+            where aoi_code = #{houseParam.code}
             and building_name is null
             and (doorplate_type = '小门牌' or (doorplate_type = '中门牌' and address_level = 1))
-            <include refid="filterHouseGrid"/>
+            <include refid="filterGrid"/>
         )
     </select>
 
@@ -266,6 +310,7 @@
             juhl.id as cid,juhl.house_code,juhl.label_id,juhl.label_name,juhl.color,juhl.household_id,
             juhlh.color as houseColor
             from jczz_doorplate_address jda
+            left join jczz_grid_range jgr on jda.address_code = jgr.house_code
             left join
             (
                 SELECT house_code, NAME, relationship FROM jczz_household WHERE id in(
@@ -283,7 +328,7 @@
             <if test="houseParam.searchKey!=null and houseParam.searchKey!=''">
                 and jh.name like concat('%',#{houseParam.searchKey},'%')
             </if>
-            <include refid="filterHouseGrid"/>
+            <include refid="filterGrid"/>
         )
         union all
         (
@@ -292,13 +337,14 @@
             juhl.id as cid,juhl.house_code,juhl.label_id,juhl.label_name,juhl.color,juhl.household_id,
             juhlh.color as houseColor
             from jczz_doorplate_address jda2
+            left join jczz_grid_range jgr on jda2.address_code = jgr.house_code
             left join jczz_user_house_label juhl on juhl.house_code = jda2.address_code and juhl.lable_type=1
             left join jczz_user_house_label juhlh on juhlh.house_code = jda2.address_code and juhlh.lable_type=2
             where 1=1
             and building_code = #{houseParam.code}
             and building_name != ''
             and (doorplate_type = '小门牌' or (doorplate_type = '中门牌' and address_level = 1))
-            <include refid="filterHouseGrid"/>
+            <include refid="filterGrid"/>
         )
     </select>
 
@@ -347,7 +393,8 @@
 
     <!--根据社区查询街路巷集合-->
     <select id="getStreetRuList" resultType="org.springblade.common.node.TreeStringNode" >
-        select street_ru_code as id,street_ru_name as name,3 as addressType from jczz_doorplate_address
+        select street_ru_code as id,street_ru_name as name,3 as addressType from jczz_doorplate_address jda
+        left join jczz_grid_range jgr on jda.address_code = jgr.house_code
         where 1=1
         and aoi_code is null
         <if test="houseParam.name != null and houseParam.name!=''">
@@ -356,7 +403,7 @@
         <if test="houseParam.code != null and houseParam.code!=''">
             and nei_code = #{houseParam.code}
         </if>
-        <include refid="filterHouseGrid"/>
+        <include refid="filterGrid"/>
         group by street_ru_code,street_ru_name
     </select>
 
@@ -365,13 +412,14 @@
       select address_code as addressCode,
       IFNULL(CONCAT(doorplate_num,sub_door_plate_no), IF(doorplate_num IS NULL, sub_door_plate_no, doorplate_num)) as floor,
       3 as addressType
-      from jczz_doorplate_address
+      from jczz_doorplate_address jda
+      left join jczz_grid_range jgr on jda.address_code = jgr.house_code
       where 1=1
       and street_ru_code = #{houseParam.code}
       and nei_code = #{houseParam.name}
       and aoi_code is null
       and doorplate_type = '中门牌'
-      <include refid="filterHouseGrid"/>
+      <include refid="filterGrid"/>
       order by doorplate_num,sub_door_plate_no
     </select>
 
@@ -563,6 +611,19 @@
     <!--查询所有的地址表和场所表差集集合(小区和非小区的)-->
     <select id="getNotInPlaceList" resultType="org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity">
         select jda.* from jczz_doorplate_address jda
+        left join jczz_place jp on jda.address_code=jp.house_code and jp.is_deleted = 0
+        where 1=1
+        and (doorplate_type = '小门牌' or (doorplate_type = '中门牌' and address_level = 1))
+        and jp.id is null
+        <if test="townName!=null and townName!=''">
+            and jda.town_street_name like concat('%',#{townName},'%')
+        </if>
+        limit 0,1000
+    </select>
+
+    <!--查询未入库的场所-->
+    <select id="getNotPlaceListCount" resultType="java.lang.Integer">
+        select count(*) from jczz_doorplate_address jda
         left join jczz_place jp on jda.address_code=jp.house_code and jp.is_deleted = 0
         where 1=1
         and (doorplate_type = '小门牌' or (doorplate_type = '中门牌' and address_level = 1))
@@ -778,4 +839,14 @@
         </if>
         limit 0,1000
     </select>
+
+    <!--查询所有未匹配的网格范围地址数据-->
+    <select id="getDoorplateAddressDetailByHouseId" resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVO">
+        select
+        jda.*
+        from jczz_doorplate_address jda
+        left join jczz_house jh on jh.house_code = jda.address_code and jh.is_deleted = 0
+        where 1=1
+        and jh.id = #{houseId}
+    </select>
 </mapper>

--
Gitblit v1.9.3