From 311a9b371845bb716c182e530e015259834754ad Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期二, 29 七月 2025 15:26:35 +0800
Subject: [PATCH] 优化SQL语句,以提高查询速度

---
 pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml |   96 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 94 insertions(+), 2 deletions(-)

diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml
index 303e180..a7f745d 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml
@@ -689,6 +689,24 @@
 
     <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴寮�闃�娆℃暟瓒呰繃鎸囧畾鍊肩殑鍐滄埛鏁伴噺-->
     <select id="getLargeOpenCountClientsCount" resultType="java.lang.Long">
+        SELECT COUNT(*)
+        FROM se_client cli
+        inner join (
+            SELECT client_id, COUNT(*) AS openCount
+            FROM rm_open_close_valve_history
+            <where>
+                <if test="timeStart != null and timeStart != '' and timeStop != null and timeStop != ''">
+                    op_dt BETWEEN #{timeStart} AND #{timeStop}
+                </if>
+            </where>
+            group by client_id
+            <if test="openCount != null and openCount > 0">
+                having openCount &gt; #{openCount}
+            </if>
+        ) as his on his.client_id = cli.id
+    </select>
+    <!-- 2025-07-29 涓嬮潰SQL鏌ヨ澶參锛屽簾寮�  -->
+    <select id="_getLargeOpenCountClientsCount" resultType="java.lang.Long">
         SELECT COUNT(*) AS recordCount
         FROM se_client cli
         <where>
@@ -698,12 +716,42 @@
             <if test="timeStart != null and timeStart != '' and timeStop != null and timeStop != ''">
                 AND his.op_dt BETWEEN #{timeStart} AND #{timeStop}
             </if>
-            ) > #{openCount}
+            ) &gt; #{openCount}
         </where>
     </select>
 
     <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴寮�闃�娆℃暟瓒呰繃鎸囧畾鍊肩殑鍐滄埛-->
     <select id="getLargeOpenCountClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
+        SELECT cli.id  AS clientId,
+        cli.name       AS clientName,
+        cli.clientNum,
+        cli.address,
+        cli.phone,
+        cli.idCard,
+        his.openCount
+        FROM se_client cli
+        inner join (
+            SELECT client_id, COUNT(*) AS openCount
+            FROM rm_open_close_valve_history
+            <where>
+                <if test="timeStart != null and timeStart != '' and timeStop != null and timeStop != ''">
+                    op_dt BETWEEN #{timeStart} AND #{timeStop}
+                </if>
+            </where>
+            group by client_id
+            <if test="openCount != null and openCount > 0">
+                having openCount &gt; #{openCount}
+            </if>
+        ) as his on his.client_id = cli.id
+        ORDER BY cli.id
+        <trim prefix="limit ">
+            <if test="start != null and count != null">
+                #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
+            </if>
+        </trim>
+    </select>
+    <!-- 2025-07-29 涓嬮潰SQL鏌ヨ澶參锛屽簾寮�  -->
+    <select id="_getLargeOpenCountClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
         SELECT cli.id                                 AS clientId,
                cli.name                               AS clientName,
                cli.clientNum,
@@ -726,7 +774,7 @@
             <if test="timeStart != null and timeStart != '' and timeStop != null">
                 AND his.op_dt BETWEEN #{timeStart} AND #{timeStop}
             </if>
-            ) > #{openCount}
+            ) &gt; #{openCount}
         </where>
         ORDER BY cli.id
         <trim prefix="limit ">
@@ -747,6 +795,20 @@
             <if test="timeStart != null and timeStart != '' and timeStop != null and timeStop != ''">
                 AND his.op_dt BETWEEN #{timeStart} AND #{timeStop}
             </if>
+            ) &lt; #{openCount}
+        </where>
+    </select>
+    <!-- 2025-07-29 涓嬮潰SQL鏌ヨ澶參锛屽簾寮�  -->
+    <select id="_getSmallOpenCountClientsCount" resultType="java.lang.Long">
+        SELECT COUNT(*) AS recordCount
+        FROM se_client cli
+        <where>
+            (SELECT COUNT(*)
+            FROM rm_open_close_valve_history his
+            WHERE his.client_id = cli.id
+            <if test="timeStart != null and timeStart != '' and timeStop != null and timeStop != ''">
+                AND his.op_dt BETWEEN #{timeStart} AND #{timeStop}
+            </if>
             <if test="openCount != null">
                 ) &lt; #{openCount}
             </if>
@@ -755,6 +817,36 @@
 
     <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴寮�闃�娆℃暟浣庝簬鎸囧畾鍊肩殑鍐滄埛-->
     <select id="getSmallOpenCountClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
+        SELECT cli.id  AS clientId,
+        cli.name       AS clientName,
+        cli.clientNum,
+        cli.address,
+        cli.phone,
+        cli.idCard,
+        his.openCount
+        FROM se_client cli
+        inner join (
+        SELECT client_id, COUNT(*) AS openCount
+        FROM rm_open_close_valve_history
+        <where>
+            <if test="timeStart != null and timeStart != '' and timeStop != null and timeStop != ''">
+                op_dt BETWEEN #{timeStart} AND #{timeStop}
+            </if>
+        </where>
+        group by client_id
+        <if test="openCount != null and openCount > 0">
+            having openCount &lt; #{openCount}
+        </if>
+        ) as his on his.client_id = cli.id
+        ORDER BY cli.id
+        <trim prefix="limit ">
+            <if test="start != null and count != null">
+                #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
+            </if>
+        </trim>
+    </select>
+    <!-- 2025-07-29 涓嬮潰SQL鏌ヨ澶參锛屽簾寮�  -->
+    <select id="_getSmallOpenCountClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
         SELECT cli.id                                 AS clientId,
                cli.name                               AS clientName,
                cli.clientNum,

--
Gitblit v1.8.0