From 7bcd0d2d7510cb2ba67099cd768e1b2b6d047dc2 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Thu, 22 Feb 2024 17:16:27 +0800
Subject: [PATCH] 投票人员查询优化

---
 src/main/java/org/springblade/modules/place/mapper/PlaceExtMapper.xml |  107 ++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 77 insertions(+), 30 deletions(-)

diff --git a/src/main/java/org/springblade/modules/place/mapper/PlaceExtMapper.xml b/src/main/java/org/springblade/modules/place/mapper/PlaceExtMapper.xml
index 45dab58..c7da4f1 100644
--- a/src/main/java/org/springblade/modules/place/mapper/PlaceExtMapper.xml
+++ b/src/main/java/org/springblade/modules/place/mapper/PlaceExtMapper.xml
@@ -17,21 +17,81 @@
         jp.place_name AS placeName
         FROM
         jczz_place_ext jpe
-        LEFT JOIN jczz_place jp ON jpe.place_id = jp.id
-        AND jp.is_deleted = 0
-        LEFT JOIN jczz_grid_range jgr on jgr.house_code=jp.house_code
-        LEFT JOIN jczz_grid jg on jg.id = jgr.grid_id
-        WHERE
-        jpe.is_deleted = 0
-        <if test="placeExt.communityCode != null and placeExt.communityCode != ''">
-            and jg.community_code=#{placeExt.communityCode}
+        LEFT JOIN jczz_place jp ON jpe.place_id = jp.id AND jp.is_deleted = 0
+        LEFT JOIN jczz_grid jg ON jp.grid_code = jg.grid_code AND jg.is_deleted = 0
+        LEFT JOIN jczz_police_affairs_grid jpag ON jp.jw_grid_code = jpag.jw_grid_code AND jpag.is_deleted = 0
+        WHERE jpe.is_deleted = 0
+        and jp.place_name != ''
+        <if test="isAdministrator==2">
+            <choose>
+                <when test="placeExt.roleName != null and placeExt.roleName != ''">
+                    <if test="placeExt.roleName=='wgy'">
+                        <choose>
+                            <when test="gridCodeList !=null and gridCodeList.size()>0">
+                                and jp.grid_code in
+                                <foreach collection="gridCodeList" item="code" open="(" close=")" separator=",">
+                                    #{code}
+                                </foreach>
+                            </when>
+                            <otherwise>
+                                and jp.grid_code in ('')
+                            </otherwise>
+                        </choose>
+                    </if>
+                    <if test="placeExt.roleName=='mj'">
+                        <choose>
+                            <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
+                                and jpag.community_code in
+                                <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
+                                    #{code}
+                                </foreach>
+                            </when>
+                            <otherwise>
+                                and jpag.community_code in ('')
+                            </otherwise>
+                        </choose>
+                    </if>
+                </when>
+                <otherwise>
+                    <choose>
+                        <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
+                            and
+                            (
+                            jg.grid_code in
+                            <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
+                                #{code}
+                            </foreach>
+                            or
+                            jpag.community_code in
+                            <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
+                                #{code}
+                            </foreach>
+                            )
+                        </when>
+                        <otherwise>
+                            and
+                            (
+                            jg.grid_code in ('') or jpag.community_code in in ('')
+                            )
+                        </otherwise>
+                    </choose>
+                </otherwise>
+            </choose>
         </if>
-
         <if test="placeExt.placeName != null and placeExt.placeName != ''">
             and jp.place_name like concat('%',#{placeExt.placeName},'%')
         </if>
+        <if test="placeExt.communityCode != null and placeExt.communityCode != ''">
+            and jpag.community_code like concat('%',#{placeExt.communityCode},'%')
+        </if>
+        <if test="placeExt.placeId != null">
+            and jp.id = #{placeExt.placeId}
+        </if>
+        <if test="placeExt.isApp != null">
+            and jpe.confirm_flag != 4
+        </if>
         <if test="placeExt.houseCode != null and placeExt.houseCode != ''">
-            and jp.house_code = #{placeExt.houseCode}
+            and jp.house_code like concat('%',#{placeExt.houseCode},'%')
         </if>
         <if test="placeExt.confirmFlag != null">
             and jpe.confirm_flag = #{placeExt.confirmFlag}
@@ -39,24 +99,11 @@
         <if test="placeExt.startTime != null and placeExt.startTime != '' and placeExt.endTime != null and placeExt.endTime != '' ">
             AND jpe.create_time BETWEEN #{placeExt.startTime} and #{placeExt.endTime}
         </if>
-        <if test="placeExt.roleName!=null and placeExt.roleName!='' and placeExt.createUser!=null">
-            <choose>
-                <when test="placeExt.roleName=='网格员'">
-                    and
-                    (
-                    jp.create_user = #{placeExt.createUser}
-                    <if test="houseCodeList != null and houseCodeList.size()>0">
-                        or jp.house_code in
-                        <foreach collection="houseCodeList" item="houseCode" separator="," open="(" close=")">
-                            #{houseCode}
-                        </foreach>
-                    </if>
-                    )
-                </when>
-                <otherwise>
-                    and jp.principal_user_id = #{placeExt.createUser}
-                </otherwise>
-            </choose>
+        <if test="houseCodeList != null and houseCodeList.size()>0">
+            and jp.house_code in
+            <foreach collection="houseCodeList" item="houseCode" separator="," open="(" close=")">
+                #{houseCode}
+            </foreach>
         </if>
         order by jpe.create_time desc,jpe.id desc
     </select>
@@ -67,8 +114,8 @@
         count( 1 )
         FROM
         jczz_place_ext jpe
-        LEFT JOIN jczz_place jp ON jp.id = jpe.place_id
-        LEFT JOIN jczz_doorplate_address jda ON jp.house_code = jda.address_code
+        LEFT JOIN jczz_place jp ON jp.id = jpe.place_id and jp.is_deleted = 0
+        LEFT JOIN jczz_doorplate_address jda ON locate(jda.address_code,jp.house_code)>0
         <where>
             <if test="confirmFlag != null">
                 and jpe.confirm_flag = #{confirmFlag}

--
Gitblit v1.9.3