liurunyu
2025-07-29 601940ec9fc44c41a965c51b2cdcac728a05d61e
优化SQL语句,以提高查询速度
2个文件已修改
51 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml
@@ -983,6 +983,24 @@
    <!--获取指定时间段内用水量低于指定值的农户数量-->
    <select id="getSmallWaterConsumptionClientsCount" 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 &lt; #{waterConsumption}
        </if>
        ) as his on his.client_id = cli.id
    </select>
    <!-- 2025-07-29 下面SQL查询太慢,废弃  -->
    <select id="_getSmallWaterConsumptionClientsCount" resultType="java.lang.Long">
        SELECT COUNT(*) AS recordCount
        FROM se_client cli
        <where>
@@ -997,6 +1015,36 @@
    <!--获取指定时间段内用水量低于指定值的农户-->
    <select id="getSmallWaterConsumptionClients" 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 &lt; #{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="_getSmallWaterConsumptionClients" resultType="com.dy.pipIrrGlobal.voSt.VoClient">
        SELECT cli.id                                 AS clientId,
        cli.name                               AS clientName,
        cli.clientNum,
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java
@@ -118,6 +118,9 @@
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        try {
            if(qo.getWaterConsumption() == null){
                qo.setWaterConsumption(0.0D);
            }
            return BaseResponseUtils.buildSuccess(clientSv.getSmallWaterConsumptionClients(qo));
        } catch (Exception e) {
            log.error("获取记录异常", e);