From 5b33d886cb6da7a8b0f66f0c0bb0a3d0b2b19d6a Mon Sep 17 00:00:00 2001
From: lin <sbla5888@163.com>
Date: Mon, 15 Apr 2024 21:21:01 +0800
Subject: [PATCH] 报事报修查询优化

---
 src/main/java/org/springblade/modules/task/mapper/TaskReportForRepairsMapper.xml |   76 ++++++++++++++++----------------------
 1 files changed, 32 insertions(+), 44 deletions(-)

diff --git a/src/main/java/org/springblade/modules/task/mapper/TaskReportForRepairsMapper.xml b/src/main/java/org/springblade/modules/task/mapper/TaskReportForRepairsMapper.xml
index 704caba..ec82bde 100644
--- a/src/main/java/org/springblade/modules/task/mapper/TaskReportForRepairsMapper.xml
+++ b/src/main/java/org/springblade/modules/task/mapper/TaskReportForRepairsMapper.xml
@@ -353,6 +353,7 @@
         LEFT JOIN jczz_house jh ON jh.house_code = jtr.address_code
         LEFT JOIN jczz_place jp ON jtr.address_code = jp.house_code
         LEFT JOIN jczz_grid jg on (jh.grid_code = jg.grid_code or jp.grid_code = jg.grid_code )
+        LEFT JOIN jczz_police_affairs_grid jpag on jp.jw_grid_code= jpag.jw_grid_code and jpag.is_deleted = 0
         <where>
             and jtr.is_deleted = 0
             and jtr.confirm_flag = 1
@@ -360,50 +361,37 @@
                 and jg.community_code = #{neiCode}
             </if>
 
-            <if test="userId != null and roleName == 'wgy'">
-                AND (
-                jp.grid_code IN (
-                SELECT
-                jg.grid_code
-                FROM
-                jczz_grid jg
-                LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
-                WHERE
-                jg.is_deleted = 0
-                AND jgm.user_id = #{userId}
-                )
-                OR jh.grid_code IN (
-                SELECT
-                jg.grid_code
-                FROM
-                jczz_grid jg
-                LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
-                WHERE
-                jg.is_deleted = 0
-                AND jgm.user_id = #{userId}
-                ))
-            </if>
-
-            <if test="userId != null and roleName == 'mj'">
-                AND (
-                jp.jw_grid_code IN (
-                SELECT
-                jpag.jw_grid_code
-                FROM
-                jczz_police_affairs_grid jpag
-                WHERE
-                jpag.is_deleted = 0
-                AND jpag.police_user_id = #{userId}
-                )
-                OR jh.jw_grid_code IN (
-                SELECT
-                jpag.jw_grid_code
-                FROM
-                jczz_police_affairs_grid jpag
-                WHERE
-                jpag.is_deleted = 0
-                AND jpag.police_user_id = #{userId}
-                ))
+            <if test="roleName != null and roleName != ''">
+                <if test="roleName=='wgy'">
+                    <if test="isAdministrator==2">
+                        <choose>
+                            <when test="gridCodeList !=null and gridCodeList.size()>0">
+                                and jg.grid_code in
+                                <foreach collection="gridCodeList" item="code" open="(" close=")" separator=",">
+                                    #{code}
+                                </foreach>
+                            </when>
+                            <otherwise>
+                                and jg.grid_code in ('')
+                            </otherwise>
+                        </choose>
+                    </if>
+                </if>
+                <if test="roleName=='mj'">
+                    <if test="isAdministrator==2">
+                        <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>
+                </if>
             </if>
         </where>
 

--
Gitblit v1.9.3