liurunyu
2025-07-29 83c1bbca96beb5461fff56d861214444348e86d0
优化SQL语句,以提高查询速度
2个文件已修改
204 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOpenCloseValveHistoryMapper.xml 192 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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>
@@ -1238,6 +1400,36 @@
        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,
        CONCAT(cli.districtTitle, cli.address) AS address,
        cli.phone,
        cli.idCard,
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java
@@ -141,6 +141,9 @@
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        try {
            if(qo.getAmountSpent() == null){
                qo.setAmountSpent(0.0D);
            }
            return BaseResponseUtils.buildSuccess(clientSv.getLargeAmountSpentClients(qo));
        } catch (Exception e) {
            log.error("获取开卡记录异常", e);
@@ -161,6 +164,9 @@
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        try {
            if(qo.getAmountSpent() == null){
                qo.setAmountSpent(0.0D);
            }
            return BaseResponseUtils.buildSuccess(clientSv.getSmallAmountSpentClients(qo));
        } catch (Exception e) {
            log.error("获取记录异常", e);
@@ -181,6 +187,9 @@
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        try {
            if(qo.getWaterDuration() == null){
                qo.setWaterDuration(0);
            }
            return BaseResponseUtils.buildSuccess(clientSv.getLargeWaterDurationClients(qo));
        } catch (Exception e) {
            log.error("获取开卡记录异常", e);
@@ -201,6 +210,9 @@
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        try {
            if(qo.getWaterDuration() == null){
                qo.setWaterDuration(0);
            }
            return BaseResponseUtils.buildSuccess(clientSv.getSmallWaterDurationClients(qo));
        } catch (Exception e) {
            log.error("获取开卡记录异常", e);