From 2132a4073fdd350ddce3fc5f999b305fffae1b01 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期二, 29 七月 2025 15:33:58 +0800
Subject: [PATCH] 优化SQL语句,以提高查询速度
---
pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml | 34 +++++++++++++++++++---------------
1 files changed, 19 insertions(+), 15 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 a7f745d..e6cad81 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml
@@ -786,17 +786,21 @@
<!--鑾峰彇鎸囧畾鏃堕棿娈靛唴寮�闃�娆℃暟浣庝簬鎸囧畾鍊肩殑鍐滄埛鏁伴噺-->
<select id="getSmallOpenCountClientsCount" resultType="java.lang.Long">
- SELECT COUNT(*) AS recordCount
+ SELECT COUNT(*)
FROM se_client cli
+ inner join (
+ SELECT client_id, COUNT(*) AS openCount
+ FROM rm_open_close_valve_history
<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}
+ op_dt BETWEEN #{timeStart} AND #{timeStop}
</if>
- ) < #{openCount}
</where>
+ group by client_id
+ <if test="openCount != null and openCount > 0">
+ having openCount < #{openCount}
+ </if>
+ ) as his on his.client_id = cli.id
</select>
<!-- 2025-07-29 涓嬮潰SQL鏌ヨ澶參锛屽簾寮� -->
<select id="_getSmallOpenCountClientsCount" resultType="java.lang.Long">
@@ -827,16 +831,16 @@
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}
+ 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 < #{openCount}
</if>
- </where>
- group by client_id
- <if test="openCount != null and openCount > 0">
- having openCount < #{openCount}
- </if>
) as his on his.client_id = cli.id
ORDER BY cli.id
<trim prefix="limit ">
--
Gitblit v1.8.0