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

---
 pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml |  192 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 192 insertions(+), 0 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 830a944..bf62b09 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml
@@ -1079,6 +1079,24 @@
 
     <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴娑堣垂閲戦瓒呰繃鎸囧畾鍊肩殑鍐滄埛鏁伴噺-->
     <select id="getLargeAmountSpentClientsCount" resultType="java.lang.Long">
+        SELECT COUNT(*)
+        FROM se_client cli
+        inner join (
+            SELECT client_id, SUM(cl_this_money) AS amountSpent
+            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="amountSpent != null and amountSpent > 0">
+                having amountSpent &gt; #{amountSpent}
+            </if>
+        ) as his on his.client_id = cli.id
+    </select>
+    <!-- 2025-07-29 涓嬮潰SQL鏌ヨ澶參锛屽簾寮�  -->
+    <select id="_getLargeAmountSpentClientsCount" resultType="java.lang.Long">
         SELECT COUNT(*) AS recordCount
         FROM se_client cli
         <where>
@@ -1092,6 +1110,36 @@
     </select>
     <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴娑堣垂閲戦瓒呰繃鎸囧畾鍊肩殑鍐滄埛-->
     <select id="getLargeAmountSpentClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
+        SELECT cli.id  AS clientId,
+        cli.name       AS clientName,
+        cli.clientNum,
+        cli.address,
+        cli.phone,
+        cli.idCard,
+        his.amountSpent
+        FROM se_client cli
+            inner join (
+            SELECT client_id, SUM(cl_this_money) AS amountSpent
+            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="amountSpent != null and amountSpent > 0">
+                having amountSpent &gt; #{amountSpent}
+            </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="_getLargeAmountSpentClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
         SELECT cli.id                                 AS clientId,
                cli.name                               AS clientName,
                cli.clientNum,
@@ -1126,6 +1174,24 @@
 
     <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴娑堣垂閲戦浣庝簬鎸囧畾鍊肩殑鍐滄埛鏁伴噺-->
     <select id="getSmallAmountSpentClientsCount" resultType="java.lang.Long">
+        SELECT COUNT(*)
+        FROM se_client cli
+        inner join (
+        SELECT client_id, SUM(cl_this_money) AS amountSpent
+        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="amountSpent != null and amountSpent > 0">
+            having amountSpent &lt; #{amountSpent}
+        </if>
+        ) as his on his.client_id = cli.id
+    </select>
+    <!-- 2025-07-29 涓嬮潰SQL鏌ヨ澶參锛屽簾寮�  -->
+    <select id="_getSmallAmountSpentClientsCount" resultType="java.lang.Long">
         SELECT COUNT(*) AS recordCount
         FROM se_client cli
         <where>
@@ -1139,6 +1205,36 @@
     </select>
     <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴娑堣垂閲戦浣庝簬鎸囧畾鍊肩殑鍐滄埛-->
     <select id="getSmallAmountSpentClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
+        SELECT cli.id  AS clientId,
+        cli.name       AS clientName,
+        cli.clientNum,
+        cli.address,
+        cli.phone,
+        cli.idCard,
+        his.amountSpent
+        FROM se_client cli
+        inner join (
+            SELECT client_id, SUM(cl_this_money) AS amountSpent
+            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="amountSpent != null and amountSpent > 0">
+                having amountSpent &lt; #{amountSpent}
+            </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="_getSmallAmountSpentClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
         SELECT cli.id                                 AS clientId,
         cli.name                               AS clientName,
         cli.clientNum,
@@ -1173,6 +1269,24 @@
 
     <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴鐢ㄦ按鏃堕暱瓒呰繃鎸囧畾鍊肩殑鍐滄埛鏁伴噺-->
     <select id="getLargeWaterDurationClientsCount" resultType="java.lang.Long">
+        SELECT COUNT(*)
+        FROM se_client cli
+        inner join (
+            SELECT client_id, SUM(cl_this_time) AS waterDuration
+            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="waterDuration != null and waterDuration > 0">
+                having waterDuration &gt; #{waterDuration}
+            </if>
+        ) as his on his.client_id = cli.id
+    </select>
+    <!-- 2025-07-29 涓嬮潰SQL鏌ヨ澶參锛屽簾寮�  -->
+    <select id="_getLargeWaterDurationClientsCount" resultType="java.lang.Long">
         SELECT COUNT(*) AS recordCount
         FROM se_client cli
         <where>
@@ -1187,6 +1301,36 @@
 
     <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴鐢ㄦ按鏃堕暱瓒呰繃鎸囧畾鍊肩殑鍐滄埛-->
     <select id="getLargeWaterDurationClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
+        SELECT cli.id  AS clientId,
+        cli.name       AS clientName,
+        cli.clientNum,
+        cli.address,
+        cli.phone,
+        cli.idCard,
+        his.waterDuration
+        FROM se_client cli
+        inner join (
+            SELECT client_id, SUM(cl_this_time) AS waterDuration
+            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="waterDuration != null and waterDuration > 0">
+                having waterDuration &gt; #{waterDuration}
+            </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="_getLargeWaterDurationClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
         SELECT cli.id                                 AS clientId,
                cli.name                               AS clientName,
                cli.clientNum,
@@ -1221,6 +1365,24 @@
 
     <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴鐢ㄦ按鏃堕暱浣庝簬鎸囧畾鍊肩殑鍐滄埛鏁伴噺-->
     <select id="getSmallWaterDurationClientsCount" resultType="java.lang.Long">
+        SELECT COUNT(*)
+        FROM se_client cli
+        inner join (
+            SELECT client_id, SUM(cl_this_time) AS waterDuration
+            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="waterDuration != null and waterDuration > 0">
+                having waterDuration &lt; #{waterDuration}
+            </if>
+        ) as his on his.client_id = cli.id
+    </select>
+    <!-- 2025-07-29 涓嬮潰SQL鏌ヨ澶參锛屽簾寮�  -->
+    <select id="_getSmallWaterDurationClientsCount" resultType="java.lang.Long">
         SELECT COUNT(*) AS recordCount
         FROM se_client cli
         <where>
@@ -1235,6 +1397,36 @@
 
     <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴鐢ㄦ按鏃堕暱浣庝簬鎸囧畾鍊肩殑鍐滄埛-->
     <select id="getSmallWaterDurationClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
+        SELECT cli.id  AS clientId,
+        cli.name       AS clientName,
+        cli.clientNum,
+        cli.address,
+        cli.phone,
+        cli.idCard,
+        his.waterDuration
+        FROM se_client cli
+        inner join (
+            SELECT client_id, SUM(cl_this_time) AS waterDuration
+            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="waterDuration != null and waterDuration > 0">
+                having waterDuration &lt; #{waterDuration}
+            </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="_getSmallWaterDurationClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
         SELECT cli.id                                 AS clientId,
         cli.name                               AS clientName,
         cli.clientNum,

--
Gitblit v1.8.0