wuzeyu
2024-08-06 191ef9d695c421e8a1347cdfae312b6b633dfdc8
pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmOnHourReportHistoryMapper.xml
@@ -194,4 +194,160 @@
      water_price = #{waterPrice,jdbcType=FLOAT}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <!--根据指定条件获取整点报历史记录数量-->
  <select id="getOnHourReportsCount_history" resultType="java.lang.Long">
    SELECT
        COUNT(*) AS recordCount
    FROM rm_on_hour_report_history oh
    INNER JOIN pr_intake inta ON inta.id = oh.intake_id
    <where>
      <if test="intakeId != null and intakeId >0">
        AND oh.intake_id = #{intakeId}
      </if>
      <if test = "intakeName != null and intakeName !=''">
        AND inta.name LIKE CONCAT('%',#{intakeName},'%')
      </if>
      <if test = "rtuAddr != null and rtuAddr !=''">
        AND oh.rtu_addr LIKE CONCAT('%',#{rtuAddr},'%')
      </if>
      <if test = "timeStart != null and timeStop != null">
        AND oh.dt BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
  </select>
  <!--根据指定条件获取整点报历史记录-->
  <select id="getOnHourReports_history" resultType="com.dy.pipIrrGlobal.voRm.VoOnHour">
    SELECT
      oh.intake_id AS intakeId,
      inta.`name` AS intakeNum,
      oh.rtu_addr AS rtuAddr,
      oh.dt AS receiveTime,
      oh.instant_amount AS instantAmount,
      oh.total_amount AS totalAmount,
      oh.loss_amount AS lossAmount,
      oh.water_press AS waterPress,
      oh.battery_volt AS batteryVolt,
      oh.signal_value AS signalValue,
      oh.water_price AS waterPrice
    FROM rm_on_hour_report_history oh
        INNER JOIN pr_intake inta ON inta.id = oh.intake_id
    <where>
      <if test="intakeId != null and intakeId >0">
        AND oh.intake_id = #{intakeId}
      </if>
      <if test = "intakeNum != null and intakeNum !=''">
        AND inta.name LIKE CONCAT('%',#{intakeNum},'%')
      </if>
      <if test = "rtuAddr != null and rtuAddr !=''">
        AND oh.rtu_addr LIKE CONCAT('%',#{rtuAddr},'%')
      </if>
      <if test = "timeStart != null and timeStop != null">
        AND oh.dt BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
    ORDER BY oh.dt DESC
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
  <!--获取指定时间段内未上线取水口数量-->
  <select id="getNotOnlineIntakesCount" resultType="java.lang.Long">
    SELECT
        COUNT(*) AS recordCount
    FROM pr_intake inta
        LEFT JOIN (SELECT * FROM rm_on_hour_report_history WHERE dt BETWEEN #{timeStart} AND #{timeStop}) his ON his.intake_id = inta.id
        INNER JOIN ba_block blo ON blo.id = inta.blockId
    WHERE his.intake_id IS NULL AND inta.deleted = 0
  </select>
  <!--获取指定时间段内未上线的取水口-->
  <select id="getNotOnlineIntakes" resultType="com.dy.pipIrrGlobal.voSt.VoIntake">
    SELECT
      inta.id AS intakeId,
      inta.name AS intakeNum,
      blo.name AS blockName
    FROM pr_intake inta
           LEFT JOIN (SELECT * FROM rm_on_hour_report_history WHERE dt BETWEEN #{timeStart} AND #{timeStop}) his ON his.intake_id = inta.id
           INNER JOIN ba_block blo ON blo.id = inta.blockId
    WHERE his.intake_id IS NULL AND inta.deleted = 0
    ORDER BY inta.id
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
  <!--指定时间段内用水量超过指定值的取水口数量-->
  <select id="getUseWaterGtValueIntakesCount" resultType="java.lang.Long">
    select
    count(*)
    from
    (
    SELECT
    inta.id AS intakeId,
    inta.NAME AS intakeNum,
    blo.NAME AS blockName ,
    IFNULL(b.total_amount, 0)-IFNULL(a.total_amount, 0) AS value
    FROM
    pr_intake inta
    INNER JOIN ba_block blo ON blo.id = inta.blockId
    LEFT JOIN (SELECT
    intake_id,
    total_amount
    FROM
    rm_on_hour_report_history rohrs
    WHERE rohrs.rtu_dt = (    SELECT MAX(rtu_dt)
    FROM rm_on_hour_report_history
    WHERE rtu_dt &lt;= #{timeStart})) AS a ON inta.id = a.intake_id
    LEFT JOIN (    SELECT
    intake_id,
    total_amount
    FROM
    rm_on_hour_report_history rohrs
    WHERE rohrs.rtu_dt = (    SELECT MAX(rtu_dt)
    FROM rm_on_hour_report_history
    WHERE rtu_dt &lt;= #{timeStop})) AS b ON inta.id = b.intake_id
    WHERE IFNULL(b.total_amount, 0)-IFNULL(a.total_amount, 0) &gt; #{value} AND inta.deleted = 0
    ) c
    </select>
  <!--指定时间段内用水量超过指定值的取水口-->
  <select id="getUseWaterGtValueIntakes" resultType="com.dy.pipIrrGlobal.voSt.VoIntakeAccumulateAmount">
    SELECT
      inta.id AS intakeId,
      inta.NAME AS intakeNum,
      blo.NAME AS blockName ,
      IFNULL(b.total_amount, 0)-IFNULL(a.total_amount, 0) AS value
    FROM
      pr_intake inta
      INNER JOIN ba_block blo ON blo.id = inta.blockId
      LEFT JOIN (SELECT
      intake_id,
      total_amount
      FROM
      rm_on_hour_report_history rohrs
      WHERE rohrs.rtu_dt = (    SELECT MAX(rtu_dt)
      FROM rm_on_hour_report_history
      WHERE rtu_dt &lt;= #{timeStart})) AS a ON inta.id = a.intake_id
    LEFT JOIN (    SELECT
    intake_id,
    total_amount
    FROM
    rm_on_hour_report_history rohrs
    WHERE rohrs.rtu_dt = (    SELECT MAX(rtu_dt)
    FROM rm_on_hour_report_history
    WHERE rtu_dt &lt;= #{timeStop})) AS b ON inta.id = b.intake_id
    WHERE IFNULL(b.total_amount, 0)-IFNULL(a.total_amount, 0) &gt; #{value} AND inta.deleted = 0
    ORDER BY inta.id
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
</mapper>