From bf8fa97694336defc961cd0124e58067438c6f0d Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期二, 29 七月 2025 16:04:20 +0800 Subject: [PATCH] 优化SQL语句,以提高查询速度 --- pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java | 3 +++ 2 files changed, 51 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 b1b6d29..8cc6e4e 100644 --- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml +++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml @@ -887,6 +887,24 @@ <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴鐢ㄦ按閲忚秴杩囨寚瀹氬�肩殑鍐滄埛鏁伴噺--> <select id="getLargeWaterConsumptionClientsCount" resultType="java.lang.Long"> + SELECT COUNT(*) + FROM se_client cli + inner join ( + SELECT client_id, SUM(cl_this_amount) AS waterConsumption + 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="waterConsumption != null and waterConsumption > 0"> + having waterConsumption > #{waterConsumption} + </if> + ) as his on his.client_id = cli.id + </select> + <!-- 2025-07-29 涓嬮潰SQL鏌ヨ澶參锛屽簾寮� --> + <select id="_getLargeWaterConsumptionClientsCount" resultType="java.lang.Long"> SELECT COUNT(*) AS recordCount FROM se_client cli <where> @@ -901,6 +919,36 @@ <!--鑾峰彇鎸囧畾鏃堕棿娈靛唴鐢ㄦ按閲忚秴杩囨寚瀹氬�肩殑鍐滄埛--> <select id="getLargeWaterConsumptionClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient"> + SELECT cli.id AS clientId, + cli.name AS clientName, + cli.clientNum, + cli.address, + cli.phone, + cli.idCard, + his.waterConsumption + FROM se_client cli + inner join ( + SELECT client_id, SUM(cl_this_amount) AS waterConsumption + 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="waterConsumption != null and waterConsumption > 0"> + having waterConsumption > #{waterConsumption} + </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="_getLargeWaterConsumptionClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient"> SELECT cli.id AS clientId, cli.name AS clientName, cli.clientNum, diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java index 061c0d3..9cf9321 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java @@ -95,6 +95,9 @@ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } try { + if(qo.getWaterConsumption() == null){ + qo.setWaterConsumption(0.0D); + } return BaseResponseUtils.buildSuccess(clientSv.getLargeWaterConsumptionClients(qo)); } catch (Exception e) { log.error("鑾峰彇寮�鍗¤褰曞紓甯�", e); -- Gitblit v1.8.0