<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tofly.xrtygis.custom.mapper.CustomDisplayMapper">

    <select id="viewHistory" resultType="map">
        select ID,SCADA_TIME,ITNUM_VAL ITVAL from TF_YWPN_SCADAHISTORY_R_VIEW
        <where>
            ITCD = #{itcd}
            and (ITNUM_VAL &lt; #{outlier} or ITNUM_VAL > #{outlier})
            <if test="startTime == null and endTime == null">
                and SCADA_TIME between sysdate - 1 and sysdate
            </if>
            <if test="startTime != null and endTime != null">
                and SCADA_TIME > to_date(#{startTime},'yyyy-MM-dd hh24:mi:ss')
                 and scada_time &lt; to_date(#{endTime},'yyyy-MM-dd hh24:mi:ss')
            </if>
        </where>
        order by SCADA_TIME desc
    </select>

    <select id="viewHistory2" resultType="map" fetchSize="1000">
        select ID,SCADA_TIME,VALUE ITVAL from SCADA_HISTORY
        <where>
            CODE = #{itcd,jdbcType=VARCHAR}
            and (VALUE &lt; #{outlier} or VALUE > #{outlier})
            <if test="startTime == null and endTime == null">
                and SCADA_TIME between sysdate - 1 and sysdate
            </if>
            <if test="startTime != null and endTime != null">
                and SCADA_TIME > to_date(#{startTime},'yyyy-MM-dd hh24:mi:ss')
                and SCADA_TIME &lt; to_date(#{endTime},'yyyy-MM-dd hh24:mi:ss')
            </if>
        </where>
        order by SCADA_TIME
    </select>

    <select id="viewItValue" resultType="com.tofly.xrtygis.entity.Scadahistory" fetchSize="1000">
        select ID,SCADA_TIME,ITNUM_VAL ITVAL from TF_YWPN_SCADAHISTORY_R_VIEW
        <where>
            ITCD = #{itcd}
            and (ITNUM_VAL &lt; #{outlier} or ITNUM_VAL > #{outlier})
            <if test="startTime == null and endTime == null">
                and SCADA_TIME > to_date(sysdate - 1,'yyyy-mm-dd hh24:mi:ss')
                and scada_time &lt; to_date(sysdate,'yyyy-mm-dd hh24:mi:ss')
            </if>
            <if test="startTime != null and endTime != null">
                and SCADA_TIME > to_date(#{startTime},'yyyy-MM-dd hh24:mi:ss')
                and scada_time &lt; to_date(#{endTime},'yyyy-MM-dd hh24:mi:ss')
            </if>
            order by SCADA_TIME asc
        </where>
    </select>


    <select id="getRealtime" resultType="com.tofly.xrtygis.custom.entity.dto.IndexInfoDto" fetchSize="1000">
        select ITCD,decode(substr(ITVAL, 1, 1), '.', '0' || ITVAL, ITVAL) ITVAL from (
        select ITCD,decode(ITNUM_VAL,'99999',ITVAL,ITNUM_VAL) ITVAL
        from TF_YWPN_SCADAREALTIME_R
        where ITCD in
        <foreach collection="list" item="code" open="(" separator="," close=")">
            #{code}
        </foreach>
        )
    </select>

    <select id="getMaxHistoryVal" resultType="com.tofly.xrtygis.custom.entity.dto.IndexInfoDto" fetchSize="1000">
        select *
        from (SELECT ITCD,
        ITNUM_VAL ITVAL,
        row_number() over (partition by ITCD order by SCADA_TIME desc) row_num
        FROM ${tableName}
        where ITCD in
        <foreach collection="itcdList" item="itcd" open="(" separator="," close=")">
            #{itcd}
        </foreach>)
        where row_num = 1
    </select>


    <select id="waterByHour" resultType="map">
        select sum(qsl) qsl, sum(gsl) gsl, uhour time
        from TF_YWPN_WATERTREND_W
        <where>
            <if test="scid != null">
                SCID = #{scid}
            </if>
            <if test="start != null and end != null">
                and to_char(uhour,'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
            </if>
            <!--            <if test="start == null and end == null">-->
            <!--                and uhour between sysdate - 30 and sysdate-->
            <!--            </if>-->
        </where>
        group by uhour
        order by time desc
    </select>

    <select id="waterByDay" resultType="map">
        select sum(qsl) qsl, sum(gsl) gsl, to_char(UHOUR,'yyyy-mm-dd') time
        from TF_YWPN_WATERTREND_W
        <where>
            <if test="scid != null">
                SCID = #{scid}
            </if>
            <if test="start != null and end != null">
                and to_char(uhour,'yyyy-mm-dd') between substr(#{start},1,10) and substr(#{end},1,10)
            </if>
            <!--            <if test="start == null and end == null">-->
            <!--                and to_char(uhour,'yyyy-mm') between to_char(add_months(sysdate,-3),'yyyy-mm') and-->
            <!--                to_char(sysdate,'yyyy-mm')-->
            <!--            </if>-->
        </where>
        group by to_char(UHOUR,'yyyy-mm-dd')
        order by time desc
    </select>


    <select id="waterByMonth" resultType="map">
        select sum(qsl) qsl, sum(gsl) gsl, to_char(UHOUR,'yyyy-mm') time
        from TF_YWPN_WATERTREND_W
        <where>
            <if test="scid != null">
                SCID = #{scid}
            </if>

            <!--            <if test="start == null and end == null">-->
            <!--                and to_char(UHOUR,'yyyy-mm') between to_char(add_months(sysdate,-36),'yyyymm') and-->
            <!--                to_char(sysdate,'yyyymm')-->
            <!--            </if>-->
            <if test="start != null and end != null">
                and to_char(UHOUR,'yyyy-mm') between substr(#{start},1,7) and substr(#{end},1,7)
            </if>
        </where>
        group by to_char(UHOUR,'yyyy-mm')
        order by time desc
    </select>

    <select id="waterContrast" resultType="map">
        select sum(qsl) qsl, sum(gsl) gsl, to_char(uhour,'yyyy-mm') time
        from TF_YWPN_WATERTREND_W
        <where>
            <if test="scid != null">
                SCID = #{scid} and
            </if>
            <!--            <if test="start == null and end == null">-->
            <!--                and to_char(uhour,'yyyy-mm') between to_char(add_months(sysdate,-12),'yyyy-mm') and-->
            <!--                to_char(sysdate,'yyyy-mm')-->
            <!--            </if>-->
            to_char(uhour,'yyyymm') in
            <foreach collection="list" item="value" open="(" separator="," close=")">
                #{value}
            </foreach>
        </where>
        group by to_char(uhour,'yyyy-mm')
        order by time desc
    </select>

    <select id="getCoordinate" resultType="map">
        select sid, x, y
        from TF_YWPN_WATERMETER_W
        where SID in
        <foreach collection="list" item="number" separator="," open="(" close=")">
            #{number}
        </foreach>
    </select>

    <select id="getPrimaryInfo" resultType="map" databaseId="oracle">
        select v.ITCD, ITNUM_VAL ITVAL, SCADA_TIME CREATE_TIME,
        w.itnm
        from TF_YWPN_SCADAHISTORY_R_VIEW v left join TF_YWPN_SCADASTAITEM_W w on v.ITCD = w.ITCD
        where v.ITCD in
        <foreach collection="list" item="itcd" open="(" separator="," close=")">
            #{itcd}
        </foreach>
        <if test="start != null and end != null">
            and SCADA_TIME > to_date(#{start},'yyyy-MM-dd hh24:mi:ss')
            and scada_time &lt; to_date(#{end},'yyyy-MM-dd hh24:mi:ss')
        </if>
        <if test="start == null and end == null">
            and SCADA_TIME between add_months(sysdate,-1) and sysdate
        </if>
        order by v.itcd,scada_time
    </select>

    <select id="getPacDensity" resultType="map" fetchSize="100">
        select round(${param},4) unit,to_char(UP_DATE,'yyyy-mm-dd') year
        from TF_YWPN_COSTRLUNIT_W
        where MARK = 0
        <if test="start != null and end != null">
            and to_char(UP_DATE,'yyyy-mm-dd') between #{start} and #{end}
        </if>
        order by year
    </select>

    <select id="totalConsumption" resultType="map">
        select
        <if test="dto.cnOne != null and dto.cnOne != ''">
            round(CN,4) cn_two,
        </if>
        <if test="dto.pam != null and dto.pam != ''">
            round(PAM,4) pam,
        </if>
        <if test="dto.gmsjfhy != null and dto.gmsjfhy != ''">
            round(GMSJFHY,4) gmsjfhy,
        </if>
        <if test="dto.ft != null and dto.ft != ''">
            round(FT,4) ft,
        </if>
        to_char(UP_DATE,'yyyy-mm-dd') month
        from TF_YWPN_COSTRLWATER_W
        where MARK = 0
        <if test="dto.start != null and dto.end != null">
            and to_char(UP_DATE,'yyyy-mm-dd') between #{dto.start} and #{dto.end}
        </if>
    </select>

    <select id="getCostAndWater" resultType="map" fetchSize="100">
        select ${param} to_char(f.UP_DATE,'yyyy-mm-dd') up_date
        from TF_YWPN_COSTRLFIXED_W f full join TF_YWPN_COSTRLWATER_W w on to_char(f.UP_DATE,'yyyy-mm-dd') =
        to_char(w.UP_DATE,'yyyy-mm-dd')
        where f.MARK = 0
        <if test="start == null and end == null">
            and to_char(f.UP_DATE,'yyyy-mm-dd') between to_char(add_months(sysdate,-1),'yyyy-mm-dd') and
            to_char(sysdate,'yyyy-mm-dd')
        </if>
        <if test="start != null and end != null">
            and to_char(f.UP_DATE,'yyyy-mm-dd') between #{start} and #{end}
        </if>
        order by up_date
    </select>

    <select id="getCoordinateInfo" resultType="map">
        select x, y
        from TF_YWPN_WATERMETER_W
        where SID = #{sbbh}
    </select>

    <select id="getWaterVolume" resultType="map" fetchSize="100">
        select
        <choose>
            <when test="code == 0">
                GSL_ONE,
            </when>
            <when test="code == 1">
                GSL_TWO,
            </when>
            <when test="code == 2">
                GSL_ONE,
                GSL_TWO,
                GSL_TOTAL,
            </when>
        </choose>
        to_char(up_date,'yyyy-mm-dd') up_date
        from tf_ywpn_costrlwater_w
        where to_char(UP_DATE, 'yyyy-mm-dd') between #{start} and #{end} and mark = 0
        order by UP_DATE
    </select>

    <select id="getCodeInfo" resultType="map" fetchSize="100">
        select *
        from tf_ywpn_syschildcode_d
        start with pcid in
        <foreach collection="list" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        connect by prior id = pcid
    </select>

    <select id="getItvalHistory" resultType="map" fetchSize="100" databaseId="oracle">
        select ID,ITCD,ITNUM_VAL ITVAL,SCADA_TIME from TF_YWPN_SCADAHISTORY_R_VIEW
        where to_char(SCADA_TIME,'yyyy-MM-dd hh24:mi:ss`') between #{start} and #{end}
        and ITNUM_VAL != #{outlier}
        and ITCD in
        <foreach collection="itcdList" item="itcd" open="(" separator="," close=")">
            #{itcd}
        </foreach>
        <if test="itidList != null and itidList.size() != 0">
            and id not in
            <foreach collection="itidList" item="itid" open="(" separator="," close=")">
                #{itid}
            </foreach>
        </if>
        order by SCADA_TIME
    </select>

    <select id="getItvalHistoryAll" resultType="map" fetchSize="1000">
        select ID,ITCD,ITNUM_VAL ITVAL,SCADA_TIME from TF_YWPN_SCADAHISTORY_R_VIEW
        where to_char(SCADA_TIME,'yyyy-MM-dd hh24:mi:ss') between #{start} and #{end}
        and ITCD in
        <foreach collection="itcdList" item="itcd" open="(" separator="," close=")">
            #{itcd}
        </foreach>
        <if test="itidList != null and itidList.size() != 0">
            and id not in
            <foreach collection="itidList" item="itid" open="(" separator="," close=")">
                #{itid}
            </foreach>
        </if>
        order by SCADA_TIME
    </select>

    <select id="itemValInfo" resultType="map" fetchSize="100">
        select
        (select ITNM from TF_YWPN_SCADASTAITEM_W s where s.ITCD = v.ITCD) ITNM,
        ITNUM_VAL ITVAL,
        SCADA_TIME
        from TF_YWPN_SCADAHISTORY_R_VIEW v
        where to_char(SCADA_TIME,'yyyy-MM-dd hh24:mi:ss') between #{start} and #{end}
        and ITNUM_VAL != #{outlier}
        and ITCD in
        <foreach collection="itcdList" item="itcd" open="(" separator="," close=")">
            #{itcd}
        </foreach>
        order by SCADA_TIME
    </select>

    <select id="reportFormCensusY" resultType="map">
        select  to_char(a.END_TIME,'yyyy') TIME,
        max(a.VALUE) as value,
        max(a.MAX) as MAX,
        max(a.MIN) as MIN,
        max(a.AVE) as AVE,
        c.NAME,
        b.VARIABLE_CODE,
        b.VARIABLE_NAME,
        b.DISPLAY_NAME,
        b.ACCURACY
        from STATISTICS_SCADA a
        LEFT JOIN TF_INDEX_ALLOCATION b ON a.CODE = b.VARIABLE_CODE
        LEFT JOIN TF_DEVICE_ARCHIVE_MANAGE c ON b.DEVICE_ID = c.ID
        LEFT JOIN TF_WATER_INFO d ON c.WATER_ID = d.ID
        WHERE
        1=1
        AND a.STATISTICS_TYPE = '2'
        <if test="dto.indexId != null">
            AND b.ID in
            <foreach item="item" index="index" collection="dto.indexId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.type != null and dto.type.trim() != ''">
            AND c.TYPE = #{dto.type}
        </if>
        <if test="dto.deviceId != null and dto.deviceId.size()>0 ">
            AND c.id in
            <foreach collection="dto.deviceId" item="index" open="(" close=")" separator=",">
                #{index}
            </foreach>
            <if test="dto.indexType!= null  and dto.indexType.trim() != ''">
                AND b.type in
                <foreach collection="dto.indexType.split(',')" item="index" open="(" close=")" separator=",">
                    #{index}
                </foreach>
            </if>
        </if>
        <if test="dto.startDate != null and dto.endDate != null">
            AND to_char(a.START_TIME,'yyyy') between #{dto.startDate} and #{dto.endDate}
            AND to_char(a.END_TIME,'yyyy') between #{dto.startDate} and #{dto.endDate}
        </if>
        <if test="dto.stationIds != null and dto.stationIds.trim() != ''">
            AND d.ID in
            <foreach collection="dto.stationIds.split(',')" item="index" open="(" close=")" separator=",">
                #{index}
            </foreach>
        </if>
        GROUP BY to_char(a.END_TIME,'yyyy'),b.VARIABLE_CODE,c.NAME, b.VARIABLE_NAME,b.DISPLAY_NAME
        ORDER BY TIME DESC
    </select>

    <select id="reportFormCensusM" resultType="map">
        select  to_char(a.END_TIME,'yyyy-mm') TIME,
        a.MAX,
        a.MIN,
        a.PASS,
        a.ERROR_COUNT,
        a.ERROR_TIME_TOTAL,
        a.TIME_TOTAL,
        a.VALUE,
        a.AVE,
        a.FOLD,
        c.CODE,
        c.NAME,
        b.UNIT,
        b.VARIABLE_CODE,
        b.VARIABLE_NAME,
        b.DISPLAY_NAME,
        b.ACCURACY,
        decode(b.TYPE, '0', '压力', '1', '流量', '2', 'COD', '3', '氨氮') TYPE,
        decode(b.MODEL, '1', '出口', '2', '入口', '3', '加药') MODEL
        from STATISTICS_SCADA a
        LEFT JOIN TF_INDEX_ALLOCATION b ON a.CODE = b.VARIABLE_CODE
        LEFT JOIN TF_DEVICE_ARCHIVE_MANAGE c ON b.DEVICE_ID = c.ID
        LEFT JOIN TF_WATER_INFO d ON c.WATER_ID = d.ID
        WHERE
        1=1
        AND a.STATISTICS_TYPE = '2'
        <if test="dto.indexId != null">
            AND b.ID in
            <foreach item="item" index="index" collection="dto.indexId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.type != null and dto.type.trim() != ''">
            AND c.TYPE = #{dto.type}
        </if>
        <if test="dto.deviceId != null and dto.deviceId.size()>0 ">
            AND c.id in
            <foreach collection="dto.deviceId" item="index" open="(" close=")" separator=",">
                #{index}
            </foreach>
        </if>
        <if test="dto.indexType!= null  and dto.indexType.trim() != ''">
            AND b.type in
            <foreach collection="dto.indexType.split(',')" item="index" open="(" close=")" separator=",">
                #{index}
            </foreach>
        </if>

        <!--        <if test="dto.startDate != null and dto.endDate != null">-->
        <!--            AND to_char(a.START_TIME,'yyyy-mm') between #{dto.startDate} and #{dto.endDate}-->
        <!--            AND to_char(a.END_TIME,'yyyy-mm') between #{dto.startDate} and #{dto.endDate}-->
        <!--        </if>-->
        <if test="dto.censusDate != null and dto.censusDate.trim() != ''">
            AND to_char(a.START_TIME,'yyyy') = #{dto.censusDate}
            AND to_char(a.END_TIME,'yyyy') = #{dto.censusDate}
        </if>
        <if test="dto.stationIds != null and dto.stationIds.trim() != ''">
            AND d.ID in
            <foreach collection="dto.stationIds.split(',')" item="index" open="(" close=")" separator=",">
                #{index}
            </foreach>
        </if>
        ORDER BY TIME DESC
    </select>

    <select id="reportFormCensusD" resultType="map">
        select  to_char(a.END_TIME,'yyyy-mm-dd') TIME,
        a.MAX,
        a.MIN,
        a.PASS,
        a.ERROR_COUNT,
        a.ERROR_TIME_TOTAL,
        a.TIME_TOTAL,
        a.VALUE,
        a.AVE,
        a.FOLD,
        c.CODE,
        c.NAME,
        b.UNIT,
        b.VARIABLE_CODE,
        b.VARIABLE_NAME,
        b.DISPLAY_NAME,
        b.ACCURACY,
        decode(b.TYPE, '0', '压力', '1', '流量', '2', 'COD', '3', '氨氮') TYPE,
        decode(b.MODEL, '1', '出口', '2', '入口', '3', '加药') MODEL
        from STATISTICS_SCADA a
        LEFT JOIN TF_INDEX_ALLOCATION b ON a.CODE = b.VARIABLE_CODE
        LEFT JOIN TF_DEVICE_ARCHIVE_MANAGE c ON b.DEVICE_ID = c.ID
        LEFT JOIN TF_WATER_INFO d ON c.WATER_ID = d.ID
        WHERE
        1=1
        AND a.STATISTICS_TYPE = '1'
        <if test="dto.indexId != null">
            AND b.ID in
            <foreach item="item" index="index" collection="dto.indexId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.type != null and dto.type.trim() != ''">
            AND c.TYPE = #{dto.type}
        </if>
        <if test="dto.deviceId != null and dto.deviceId.size()>0 ">
            AND c.id in
            <foreach collection="dto.deviceId" item="index" open="(" close=")" separator=",">
                #{index}
            </foreach>
        </if>

        <if test="dto.indexType!= null  and dto.indexType.trim() != ''">
            AND b.type in
            <foreach collection="dto.indexType.split(',')" item="index" open="(" close=")" separator=",">
                #{index}
            </foreach>
        </if>

        <if test="dto.censusDate != null and dto.censusDate.trim() != ''">
            AND to_char(a.START_TIME,'yyyy-mm') = #{dto.censusDate}
            AND to_char(a.END_TIME,'yyyy-mm') = #{dto.censusDate}
        </if>
        <if test="dto.stationIds != null and dto.stationIds.trim() != ''">
            AND d.ID in
            <foreach collection="dto.stationIds.split(',')" item="index" open="(" close=")" separator=",">
                #{index}
            </foreach>
        </if>
        ORDER BY TIME DESC
    </select>

    <select id="getYesterdaySupplyWater" resultType="BigDecimal">
        select sum(max - min) as fold
        from TF_WATER_INFO w
        left JOIN TF_DEVICE_ARCHIVE_MANAGE dm
        ON dm.WATER_ID = w.ID
        left join TF_INDEX_ALLOCATION ia
        ON ia.DEVICE_ID = dm.ID
        LEFT JOIN STATISTICS_SCADA sm
        ON sm.code = ia.VARIABLE_CODE
        and sm.statistics_type =1
        AND TO_CHAR(sm.START_TIME, 'yyyy-MM-dd') =
        TO_CHAR(SYSDATE - 1, 'yyyy-MM-dd')
        <if test="codes != null">
            and sm.CODE in
            <foreach item="item" collection="codes" separator="," open="(" close=")" index="">
                #{item}
            </foreach>
        </if>
        <if test="waterType!=null and waterType!=''">
            and w.water_Type = #{waterType}
        </if>
    </select>

    <select id="getWaterAmount" resultType="int">
        select count( * )
        from TF_WATER_INFO where 1=1
        <if test="waterType!=null and waterType!=''">
            and water_Type = #{waterType}
        </if>
    </select>

    <select id="getNearYearStatistical" resultType="map">
        select  LEAKAGE_RATE LEAKAGE_RATE,
        POOR_PRODUCTION_RATE POOR_PRODUCTION_RATE
        from TF_TOTAL_STATISTICAL
        WHERE 1=1
        <if test="startDate != null and endDate != null">
            AND to_char(STATISTICAL_DATE,'yyyy-mm') between #{startDate} and #{endDate}
        </if>
        ORDER BY to_char(STATISTICAL_DATE,'yyyy-mm') DESC
    </select>

    <select id="getTableUserListNum" resultType="java.lang.Integer">
        select count(1)
        FROM TF_YWPN_QFKHJBXX_W
        --WHERE YHZT = '1'
    </select>

    <select id="getDesignProcessCapacity" resultType="BigDecimal">
        select case WHEN(NVL(SUM ( DESIGN_PROCESSING_CAPACITY ), 0)) != 0 THEN round( SUM ( DESIGN_PROCESSING_CAPACITY ), 2 ) ELSE 0 END DESIGN_PROCESSING_CAPACITY
        from TF_WATER_INFO
        where 1=1 AND WATER_TYPE = '1'
        <if test="name != null and name.trim() != ''">
            AND NAME like '%'||#{name}||'%'
        </if>
    </select>

    <select id="getDmaStatisticalList" resultType="map">
        SELECT
        <choose>
            <when test="statisticsType == 0">
                to_char(STATISTICAL_DATE,'yyyy-mm-dd hh24') STATISTICAL_DATE,
            </when>
            <when test="statisticsType == 1">
                to_char(STATISTICAL_DATE,'yyyy-mm-dd') STATISTICAL_DATE,
            </when>
            <when test="statisticsType == 2">
                to_char(STATISTICAL_DATE,'yyyy-mm') STATISTICAL_DATE,
            </when>
            <when test="statisticsType == 3">
                to_char(STATISTICAL_DATE,'yyyy') STATISTICAL_DATE,
            </when>
        </choose>
            SUM( a.BILLING_WATER_VOLUME ) BILLING_WATER_VOLUME,
            SUM( a.FREE_WATER_VOLUME ) FREE_WATER_VOLUME,
            SUM( a.OUTFLOW_WATER_VOLUME ) OUTFLOW_WATER_VOLUME,
            SUM( a.LOSS_WATER_VOLUME ) LOSS_WATER_VOLUME,
            SUM( a.OTHER_WATER_VOLUME ) OTHER_WATER_VOLUME,
            SUM( a.REMOTE_WATER ) REMOTE_WATER,
            CASE WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( a.LEAKAGE_RATE ) / COUNT(*),2) ELSE 0 END LEAKAGE_RATE,
            CASE WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( a.POOR_PRODUCTION_RATE ) / COUNT(*),2) ELSE 0 END POOR_PRODUCTION_RATE,
            SUM( a.WATER_SUPPLY ) WATER_SUPPLY,
            SUM( a.USER_WATER ) USER_WATER,
            b.DMA_NAME,
            b.PARTITION_LEVEL
        FROM TF_DMA_STATISTICAL a
        LEFT JOIN TF_YWPN_DMAREGION_W b ON a.DMA_ID = b.ID
        WHERE
            1=1
        <if test="dmaIdList != null">
            AND a.DMA_ID IN
            <foreach item="item" index="index" collection="dmaIdList" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="startDate != null and endDate != null">
            AND to_char(a.STATISTICAL_DATE,'yyyy-mm-dd hh24:mi:ss') BETWEEN #{startDate} AND #{endDate}
        </if>
        GROUP BY STATISTICAL_DATE, b.DMA_NAME, b.PARTITION_LEVEL
        ORDER BY STATISTICAL_DATE DESC
    </select>
</mapper>