<?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,ITVAL from TF_YWPN_SCADAHISTORY_R_VIEW
        <where>
            ITCD = #{itcd}
            <if test="startTime == null and endTime == null">
                and SCADA_TIME between sysdate - 1 and sysdate
            </if>
            <if test="startTime != null and endTime != null">
                and to_char(SCADA_TIME,'yyyy-mm-dd HH24:mi:ss') between #{startTime} and #{endTime}
            </if>
        </where>

    </select>

    <select id="viewHistory2" resultType="map" fetchSize="100000">
        select ID,SCADA_TIME,ITVAL from TF_YWPN_SCADAHISTORY_R_VIEW
        <where>
            ITCD = #{itcd,jdbcType=VARCHAR}
            <if test="startTime == null and endTime == null">
                and to_date(SCADA_TIME,'yyyy-mm-dd hh24:mi:ss') between to_date(sysdate - 1,'yyyy-mm-dd hh24:mi:ss') and
                to_date(sysdate,'yyyy-mm-dd hh24:mi:ss')
            </if>
            <if test="startTime != null and endTime != null">
                and to_char(SCADA_TIME,'yyyy-mm-dd HH24:mi:ss') between #{startTime,jdbcType=VARCHAR} and
                #{endTime,jdbcType=VARCHAR}
            </if>
        </where>
        order by scada_time
    </select>

    <select id="viewItValue" resultType="com.tofly.xrtygis.entity.Scadahistory" fetchSize="100000">
        select ID,SCADA_TIME,ITVAL from TF_YWPN_SCADAHISTORY_R_VIEW
        <where>
            ITCD = #{itcd}
            <if test="startTime == null and endTime == null">
                and SCADA_TIME between to_date(sysdate - 1,'yyyy-mm-dd HH24:mi:ss')and to_date(sysdate,'yyyy-mm-dd
                HH24:mi:ss')
            </if>
            <if test="startTime != null and endTime != null">
                and SCADA_TIME between to_date(#{startTime},'yyyy-mm-dd HH24:mi:ss')and to_date(#{endTime},'yyyy-mm-dd
                HH24:mi:ss')
            </if>
            order by SCADA_TIME asc
        </where>
    </select>

    <select id="countValue" resultType="long">
        select count(ITVAL)
        from TF_YWPN_SCADAHISTORY_R_VIEW
        where ITCD = #{itcd}
          and scada_time between #{startTime} and #{endTime}
          and itval not between #{downValue} and #{upValue}
    </select>

    <select id="getRealtime" resultType="com.tofly.xrtygis.custom.entity.dto.IndexInfoDto" fetchSize="100000">
        select ITCD,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="100000">
        SELECT a.ITCD,ITVAL
        FROM TF_YWPN_SCADAHISTORY_R_VIEW a,
        (select max(SCADA_TIME) time, ITCD
        from TF_YWPN_SCADAHISTORY_R_VIEW
        where ITCD in
        <foreach collection="list" item="itcd" open="(" separator="," close=")">
            #{itcd}
        </foreach>
        group by ITCD) b
        WHERE a.SCADA_TIME = b.time
        AND a.ITCD = b.ITCD
    </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" fetchSize="1000">
        select ITCD, ITVAL, CREATE_TIME,(select ITNM from TF_YWPN_SCADASTAITEM_W w where w.ITCD = v.ITCD) itnm
        from TF_YWPN_ITEMRATO_W_VIEW v
        where ITCD in
        <foreach collection="list" item="itcd" open="(" separator="," close=")">
            #{itcd}
        </foreach>
        <if test="start != null and end != null">
            and to_char(CREATE_TIME,'yyyy-mm-dd hh24:mi:ss') between #{start,jdbcType=VARCHAR} and
            #{end,jdbcType=VARCHAR}
        </if>
        <if test="start == null and end == null">
            and CREATE_TIME between add_months(sysdate,-1) and sysdate
        </if>
        order by itcd,scada_time
    </select>

    <select id="getPacDensity" resultType="map" fetchSize="10000">
        select round((flow * 1000 * #{density} / 100 * 1.25) / (nullif((select sum(itval) from TF_YWPN_ITEMRATO_W_VIEW
        where itcd in
        <foreach collection="map.entrySet()" index="index" item="item">
            <if test="'itcd2'==index">
                <foreach collection="item" item="item2" open="(" separator="," close=")">
                    #{item2}
                </foreach>
            </if>
        </foreach>
        and CREATE_TIME= time),0) * 1000),5) val,time
        from (select sum(ITVAL) flow,CREATE_TIME time
        from TF_YWPN_ITEMRATO_W_VIEW
        where to_char(CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        and itcd in
        <foreach collection="map.entrySet()" index="index" item="item">
            <if test="'itcd1'==index">
                <foreach collection="item" item="item2" open="(" separator="," close=")">
                    #{item2}
                </foreach>
            </if>
        </foreach>
        group by CREATE_TIME)
    </select>


    <select id="getPamDensity" resultType="map" fetchSize="10000">
        select round((flow * 1000 * #{density} / 1000) / (nullif((select itval from TF_YWPN_ITEMRATO_W_VIEW where itcd
        in
        <foreach collection="map.entrySet()" index="index" item="item">
            <if test="index == 'itcd2'">
                <foreach collection="item" item="item2" open="(" separator="," close=")">
                    #{item2}
                </foreach>
            </if>
        </foreach>
        and CREATE_TIME = time),0) * 1000),5) val,time
        from (select sum(ITVAL) flow,CREATE_TIME time
        from TF_YWPN_ITEMRATO_W_VIEW
        where to_char(CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        and itcd in
        <foreach collection="map.entrySet()" index="index" item="item">
            <if test="index == 'itcd1'">
                <foreach collection="item" item="item2" open="(" separator="," close=")">
                    #{item2}
                </foreach>
            </if>
        </foreach>
        group by CREATE_TIME)
    </select>

    <select id="getGmsjDensity" resultType="map" fetchSize="100000">
        select round((flow * 1000 * #{density} / 100) / nullif((select itval from TF_YWPN_ITEMRATO_W_VIEW where itcd in
        <foreach collection="map.entrySet()" index="index" item="item">
            <if test="index == 'itcd2'">
                <foreach collection="item" item="item2" open="(" separator="," close=")">
                    #{item2}
                </foreach>
            </if>
        </foreach>
        and CREATE_TIME = time),0) * 1000,5) val,time
        from (select sum(ITVAL) flow,CREATE_TIME time
        from TF_YWPN_ITEMRATO_W_VIEW
        where to_char(CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        and itcd in
        <foreach collection="map.entrySet()" index="index" item="item">
            <if test="index == 'itcd1'">
                <foreach collection="item" item="item2" open="(" separator="," close=")">
                    #{item2}
                </foreach>
            </if>
        </foreach>
        group by CREATE_TIME)
    </select>

    <select id="getYlDensity" resultType="map" fetchSize="100000">
        select round(flow / (nullif((select itval from TF_YWPN_ITEMRATO_W_VIEW where itcd in
        <foreach collection="map.entrySet()" index="index" item="item">
            <if test="index == 'itcd2'">
                <foreach collection="item" item="item2" open="(" separator="," close=")">
                    #{item2}
                </foreach>
            </if>
        </foreach>
        and CREATE_TIME = time),0) * 1000),5) val,time
        from (select sum(ITVAL) flow,CREATE_TIME time
        from TF_YWPN_ITEMRATO_W_VIEW
        where to_char(CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        and itcd in
        <foreach collection="map.entrySet()" index="index" item="item">
            <if test="index == 'itcd1'">
                <foreach collection="item" item="item2" open="(" separator="," close=")">
                    #{item2}
                </foreach>
            </if>
        </foreach>
        group by CREATE_TIME)
    </select>

    <select id="getPacTwo" resultType="map" fetchSize="100000">
        select sum(ITVAL) val,CREATE_TIME time from TF_YWPN_ITEMRATO_W_VIEW
        where to_char(CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        and itcd in
        <foreach collection="list" item="itcd" open="(" separator="," close=")">
            #{itcd}
        </foreach>
        group by CREATE_TIME
    </select>

    <select id="getCostAndWater" resultType="map" fetchSize="100000">
        select distinct f.UP_DATE,${param}
        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 substr(#{start},1,10) and substr(#{end},1,10)
        </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="100000">
        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>
            <otherwise>
            </otherwise>
        </choose>
        up_date
        from tf_ywpn_costrlwater_w
        where to_char(UP_DATE, 'yyyy-mm-dd') between substr(#{start}, 1, 10) and substr(#{end}, 1, 10)
        order by UP_DATE
    </select>

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

    <select id="getItvalHistory" resultType="map" fetchSize="100000">
        select ID,ITCD,ITVAL,SCADA_TIME from TF_YWPN_SCADAHISTORY_R_VIEW
        where to_char(SCADA_TIME,'yyyy-MM-dd hh24:mm:ss') between #{start} and #{end}
        and ITCD in
        <foreach collection="itcdList" item="itcd" open="(" separator="," close=")">
            #{itcd}
        </foreach>
        <if test="itidList != null">
            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="100000">
        select
        (select ITNM from TF_YWPN_SCADASTAITEM_W s where s.ITCD = v.ITCD) ITNM,
        ITVAL,
        SCADA_TIME
        from TF_YWPN_SCADAHISTORY_R_VIEW v
        where to_char(SCADA_TIME,'yyyy-MM-dd hh24:mm:ss') between #{start} and #{end}
        and ITCD in
        <foreach collection="itcdList" item="itcd" open="(" separator="," close=")">
            #{itcd}
        </foreach>
        order by SCADA_TIME
    </select>

    <select id="selectDmausertablePage" resultType="com.tofly.xrtygis.entity.Dmausertable">
        select *
        from TF_YWPN_DMAUSERTABLE_W
        where
        1=1
<!--        <if test="dmausertableDto.dmaId != null and dmausertableDto.dmaId != ''">-->
<!--            AND DMA_IDS like '%' || to_char(#{dmausertableDto.dmaId}) || '%'-->
<!--        </if>-->
        <if test="dmausertableDto.yhxm != null and dmausertableDto.yhxm.trim() != ''">
            AND YHXM = #{dmausertableDto.yhxm}
        </if>
        <if test="dmausertableDto.sbcj != null and dmausertableDto.sbcj.trim() != ''">
            AND SBCJ = #{dmausertableDto.sbcj}
        </if>
    </select>

    <select id="useWaterHistory" resultType="com.tofly.xrtygis.custom.entity.WaterHistory">
        select *
        from TF_YWPN_DMAUSERWATER_W
        where
        1=1
        <if test="yhbh != null and yhbh.trim() != ''">
            AND YHBH = #{yhbh}
        </if>
        <if test="startTime != null and startTime.trim() != ''">
            and to_char(CSRQ,'yyyy-MM') >= #{startTime}
        </if>
        <if test="endTime != null and endTime.trim() != ''">
            <![CDATA[ and to_char(CSRQ,'yyyy-MM') <= #{endTime}   ]]>
        </if>
        ORDER BY CSRQ DESC
    </select>

    <select id="getAllMainDma" resultType="com.tofly.xrtygis.custom.entity.vo.QueryVo">
        select to_char(ID) as id,
               DMA_NAME as label
        from TF_YWPN_DMAREGION_W
        where
            PARTITION_LEVEL = 1
        <if test="dmaName != null and dmaName.trim() != ''">
            AND DMA_NAME like '%'||#{dmaName}||'%'
        </if>
    </select>

    <select id="getDmaChild" resultType="com.tofly.xrtygis.custom.entity.vo.QueryVo">
        select to_char(ID) as id,
               DMA_NAME as label
        from TF_YWPN_DMAREGION_W
        where
        1=1
        <if test="id != null and id != ''">
            AND PID = #{id}
        </if>
        <if test="dmaName != null and dmaName.trim() != ''">
            AND DMA_NAME like '%'||#{dmaName}||'%'
        </if>
    </select>

    <select id="getDmaByLevel" resultType="map">
        select ID,
               DMA_NAME NAME,
               PARTITION_LEVEL DMA_LEVEL
        from TF_YWPN_DMAREGION_W
        where
            1=1
        <if test="dmaLevel != null and dmaLevel != ''">
            AND PARTITION_LEVEL = #{dmaLevel}
        </if>
    </select>

    <select id="getDmaAllLevelCount" resultType="Map">
        select PARTITION_LEVEL,COUNT( PARTITION_LEVEL ) AS levelCount
        from TF_YWPN_DMAREGION_W
        GROUP BY PARTITION_LEVEL
    </select>

    <select id="getDmaLevel" resultType="String">
        select to_char( PARTITION_LEVEL )
        from TF_YWPN_DMAREGION_W
        GROUP BY PARTITION_LEVEL
    </select>

    <select id="getDmaName" resultType="map">
        select ID,
               DMA_NAME
        from TF_YWPN_DMAREGION_W
        WHERE
            PARTITION_LEVEL = #{dmaLevel}
    </select>

    <select id="getAllScadaIndex" resultType="com.tofly.xrtygis.custom.entity.scada.StatisticsScada">
        select a.*
        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_DMA_DEVICE_ASSOCIATION d ON d.DEVICE_ID = c.ID
        WHERE
        1=1
        <if test="dataType != null and dataType.trim() != ''">
            AND a.DATA_TYPE = #{dataType}
        </if>
        <if test="model != null and model.trim() != ''">
            AND b.MODEL = #{model}
        </if>
        <if test="dmaId != null and dmaId != ''">
            AND d.DMA_ID = #{dmaId}
        </if>
            AND c.TYPE = '2'
            AND a.STATISTICS_TYPE = 0
        <if test="toDayTime != null and toDayTime.trim() != ''">
            AND to_char(a.START_TIME,'yyyy-MM-dd') = #{toDayTime}
        </if>
        <if test="toDayTime != null and toDayTime.trim() != ''">
            AND to_char(a.END_TIME,'yyyy-MM-dd') = #{toDayTime}
        </if>
        ORDER BY a.END_TIME DESC
    </select>

<!--    <select id="getLastMonthDmaWater" resultType="com.tofly.xrtygis.custom.entity.scada.StatisticsScada">-->
<!--        select a.*-->
<!--        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_DMA_DEVICE_ASSOCIATION d ON d.DEVICE_ID = c.ID-->
<!--        WHERE-->
<!--        1=1-->
<!--        AND a.DATA_TYPE = '3'-->
<!--        AND c.TYPE = '2'-->
<!--        AND a.STATISTICS_TYPE = 2-->
<!--        <if test="dmaId != null and dmaId != ''">-->
<!--            AND d.DMA_ID = #{dmaId}-->
<!--        </if>-->
<!--        AND TO_CHAR(a.START_TIME,'YYYY-MM') = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM')-->
<!--        AND TO_CHAR(a.END_TIME,'YYYY-MM') = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM')-->
<!--        ORDER BY START_TIME-->
<!--    </select>-->
    <select id="getLastMonthStatistical" resultType="map">
        select *
        from TF_DMA_STATISTICAL
        WHERE
        1=1
        <if test="dmaId != null and dmaId != ''">
            AND DMA_ID = #{dmaId}
        </if>
            AND TO_CHAR(STATISTICAL_DATE,'YYYY-MM')=TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM')
        ORDER BY STATISTICAL_DATE DESC
    </select>

    <select id="getDmaFlowPress" resultType="com.tofly.xrtygis.custom.entity.scada.StatisticsScada">
        select a.*
        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_DMA_DEVICE_ASSOCIATION d ON d.DEVICE_ID = c.ID
        WHERE
        1=1
            AND c.TYPE = '2'
            AND a.STATISTICS_TYPE = 0
        <if test="dataType != null and dataType.trim() != ''">
            AND a.DATA_TYPE = #{dataType}
        </if>
        <if test="dmaId != null and dmaId != ''">
            AND d.DMA_ID = #{dmaId}
        </if>
        <if test="startTime != null and startTime.trim() != ''">
            and to_char(a.START_TIME,'yyyy-MM-dd hh24:mm:ss') >= #{startTime}
        </if>
        <if test="endTime != null and endTime.trim() != ''">
            <![CDATA[       and to_char(a.END_TIME,'yyyy-MM-dd hh24:mm:ss') <= #{endTime}   ]]>
        </if>
        ORDER BY START_TIME
    </select>

<!--    <select id="getDmaPress" resultType="com.tofly.xrtygis.custom.entity.scada.StatisticsScada">-->
<!--        select a.*-->
<!--        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_DMA_DEVICE_ASSOCIATION d ON d.DEVICE_ID = c.ID-->
<!--        WHERE-->
<!--        1=1-->
<!--        AND c.TYPE = '2'-->
<!--        AND a.DATA_TYPE = '2'-->
<!--        AND a.STATISTICS_TYPE = 0-->
<!--        <if test="dmaId != null and dmaId != ''">-->
<!--            AND d.DMA_ID = #{dmaId}-->
<!--        </if>-->
<!--        <if test="startTime != null and startTime.trim() != ''">-->
<!--            and to_char(a.START_TIME,'yyyy-MM-dd hh:mm:ss') >= #{startTime}-->
<!--        </if>-->
<!--        <if test="endTime != null and endTime.trim() != ''">-->
<!--            <![CDATA[       and to_char(a.END_TIME,'yyyy-MM-dd hh:mm:ss') <= #{endTime}   ]]>-->
<!--        </if>-->
<!--        ORDER BY START_TIME-->
<!--    </select>-->

<!--    <select id="getDmaWater" resultType="com.tofly.xrtygis.custom.entity.scada.StatisticsScada">-->
<!--        select a.*-->
<!--        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_DMA_DEVICE_ASSOCIATION d ON d.DEVICE_ID = c.ID-->
<!--        WHERE-->
<!--        1=1-->
<!--        AND c.TYPE = '2'-->
<!--        AND a.DATA_TYPE = '3'-->
<!--        AND a.STATISTICS_TYPE = 2-->
<!--        <if test="dmaId != null and dmaId != ''">-->
<!--            AND d.DMA_ID = #{dmaId}-->
<!--        </if>-->
<!--        <if test="startTime != null and startTime.trim() != ''">-->
<!--            AND to_char(a.START_TIME,'yyyy') = #{startTime}-->
<!--        </if>-->
<!--        <if test="endTime != null and endTime.trim() != ''">-->
<!--            AND to_char(a.END_TIME,'yyyy') = #{endTime}-->
<!--        </if>-->
<!--        ORDER BY START_TIME-->
<!--    </select>-->
    <select id="getDmaCensusParam" resultType="map">
        select *
        from TF_DMA_STATISTICAL
        WHERE
        1=1
        <if test="dmaId != null and dmaId != ''">
            AND DMA_ID = #{dmaId}
        </if>
        <if test="startTime != null and endTime != null">
            AND to_char(STATISTICAL_DATE,'yyyy-mm-dd hh24:mm:ss') between #{startTime} and #{endTime}
        </if>
        ORDER BY STATISTICAL_DATE DESC
    </select>

    <select id="getYearReportForm" resultType="map">
        select  to_char(a.STATISTICAL_DATE,'yyyy') STATISTICAL_DATE,
                b.DMA_NAME,
                b.PARTITION_LEVEL,
                SUM( a.WATER_SUPPLY ) WATER_SUPPLY,
                SUM(a.BILLING_WATER_VOLUME) BILLING_WATER_VOLUME,
                (SUM(a.WATER_SUPPLY)- SUM(a.BILLING_WATER_VOLUME)) POOR_PRODUCTION_WATER,
                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( a.POOR_PRODUCTION_RATE ) / COUNT(*),2) ELSE 0 END POOR_PRODUCTION_RATE,
                (SUM(a.BILLING_WATER_VOLUME)+SUM(a.FREE_WATER_VOLUME)) USER_REGISTER_WATER,
                (SUM(a.WATER_SUPPLY)-(SUM(a.BILLING_WATER_VOLUME)+SUM(a.FREE_WATER_VOLUME))) LEAKAGE_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( (c.JMCB_XZZ+c.DWGS_XZZ+c.NPJYL_XZZ+c.ZDDTSD_XZZ) ) / COUNT(*),2) ELSE 0 END revised,
                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( a.LEAKAGE_RATE-(c.JMCB_XZZ+c.DWGS_XZZ+c.NPJYL_XZZ+c.ZDDTSD_XZZ) ) / COUNT(*),2) ELSE 0 END PRACTICAL_LEAKAGE_RATE,
                SUM( a.LEAKAGE_OVER_VAL ) LEAKAGE_OVER_VAL,
                CASE WHEN NVL( COUNT( * ), 0 ) != 0 AND NVL( SUM( a.LEAKAGE_VAL ), 0 ) != 0 THEN round( (SUM( a.LEAKAGE_OVER_VAL ) / SUM( a.LEAKAGE_VAL ) * 100 ) / COUNT( * ), 2 ) ELSE 0 END HANDLE_LEAK_EFF

        from TF_DMA_STATISTICAL a
        LEFT JOIN TF_YWPN_DMAREGION_W b ON a.DMA_ID = b.ID
        LEFT JOIN TF_YWPN_INDICATOR_CORRECTION_W c on a.DMA_ID = c.DMA_ID
        WHERE
        a.STATISTICAL_DATE = c.REVISE_DATE
<!--        <if test="dto.ids != null">-->
<!--            AND a.ID in-->
<!--            <foreach item="item" index="index" collection="dto.ids" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
        <if test="dto.dmaLevel != null">
            AND b.PARTITION_LEVEL in
            <foreach item="item" index="index" collection="dto.dmaLevel" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
<!--        <if test="dto.dmaLevel != null and dto.dmaLevel != ''">-->
<!--            AND b.PARTITION_LEVEL = #{dto.dmaLevel}-->
<!--        </if>-->
        <if test="dto.dmaName != null and dto.dmaName.trim() != ''">
            AND b.DMA_NAME like '%'||#{dto.dmaName}||'%'
        </if>
        <if test="dto.startDate != null and dto.endDate != null">
            AND to_char(a.STATISTICAL_DATE,'yyyy') between #{dto.startDate} and #{dto.endDate}
        </if>
<!--        <if test="dto.censusDate != null and dto.censusDate.trim() != ''">-->
<!--            AND to_char(a.STATISTICAL_DATE, 'yyyy') = #{dto.censusDate}-->
<!--        </if>-->
        GROUP BY to_char(a.STATISTICAL_DATE, 'yyyy'),b.DMA_NAME,b.PARTITION_LEVEL
        ORDER BY to_char(a.STATISTICAL_DATE, 'yyyy') DESC
    </select>

    <select id="getQuarterReportForm" resultType="map">
        select  to_char(a.STATISTICAL_DATE,'yyyy-q') STATISTICAL_DATE,
                b.DMA_NAME,
                b.PARTITION_LEVEL,
                SUM( a.WATER_SUPPLY ) WATER_SUPPLY,
                SUM(a.BILLING_WATER_VOLUME) BILLING_WATER_VOLUME,
                (SUM(a.WATER_SUPPLY)- SUM(a.BILLING_WATER_VOLUME)) POOR_PRODUCTION_WATER,
                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( a.POOR_PRODUCTION_RATE ) / COUNT(*),2) ELSE 0 END POOR_PRODUCTION_RATE,
                (SUM(a.BILLING_WATER_VOLUME)+SUM(a.FREE_WATER_VOLUME)) USER_REGISTER_WATER,
                (SUM(a.WATER_SUPPLY)-(SUM(a.BILLING_WATER_VOLUME)+SUM(a.FREE_WATER_VOLUME))) LEAKAGE_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( (c.JMCB_XZZ+c.DWGS_XZZ+c.NPJYL_XZZ+c.ZDDTSD_XZZ) ) / COUNT(*),2) ELSE 0 END revised,
                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( a.LEAKAGE_RATE-(c.JMCB_XZZ+c.DWGS_XZZ+c.NPJYL_XZZ+c.ZDDTSD_XZZ) ) / COUNT(*),2) ELSE 0 END PRACTICAL_LEAKAGE_RATE,
                SUM( a.LEAKAGE_OVER_VAL ) LEAKAGE_OVER_VAL,
                CASE WHEN NVL( COUNT( * ), 0 ) != 0 AND NVL( SUM( a.LEAKAGE_VAL ), 0 ) != 0 THEN round( (SUM( a.LEAKAGE_OVER_VAL ) / SUM( a.LEAKAGE_VAL ) * 100 ) / COUNT( * ), 2 ) ELSE 0 END HANDLE_LEAK_EFF

        from TF_DMA_STATISTICAL a
        LEFT JOIN TF_YWPN_DMAREGION_W b ON a.DMA_ID = b.ID
        LEFT JOIN TF_YWPN_INDICATOR_CORRECTION_W c on a.DMA_ID = c.DMA_ID
        WHERE
        a.STATISTICAL_DATE = c.REVISE_DATE
<!--        <if test="dto.ids != null">-->
<!--            AND a.ID in-->
<!--            <foreach item="item" index="index" collection="dto.ids" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
        <if test="dto.dmaLevel != null">
            AND b.PARTITION_LEVEL in
            <foreach item="item" index="index" collection="dto.dmaLevel" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
<!--        <if test="dto.dmaLevel != null and dto.dmaLevel != ''">-->
<!--            AND b.PARTITION_LEVEL = #{dto.dmaLevel}-->
<!--        </if>-->
        <if test="dto.dmaName != null and dto.dmaName.trim() != ''">
            AND b.DMA_NAME like '%'||#{dto.dmaName}||'%'
        </if>
        <if test="dto.startDate != null and dto.endDate != null">
            AND to_char(a.STATISTICAL_DATE,'yyyy-q') between #{dto.startDate} and #{dto.endDate}
        </if>
<!--        <if test="dto.censusDate != null and dto.censusDate.trim() != ''">-->
<!--            AND to_char(a.STATISTICAL_DATE, 'yyyy-q') = #{dto.censusDate}-->
<!--        </if>-->
        GROUP BY to_char(a.STATISTICAL_DATE, 'yyyy-q'),b.DMA_NAME,b.PARTITION_LEVEL
        ORDER BY to_char(a.STATISTICAL_DATE, 'yyyy-q') DESC
    </select>

    <select id="getMonthReportForm" resultType="map">
        select to_char(a.STATISTICAL_DATE, 'yyyy-mm') STATISTICAL_DATE,
                b.DMA_NAME,
                b.PARTITION_LEVEL,
                a.WATER_SUPPLY WATER_SUPPLY,
                a.BILLING_WATER_VOLUME BILLING_WATER_VOLUME,
                (a.WATER_SUPPLY-a.BILLING_WATER_VOLUME) POOR_PRODUCTION_WATER,
                a.POOR_PRODUCTION_RATE POOR_PRODUCTION_RATE,
                (a.BILLING_WATER_VOLUME+a.FREE_WATER_VOLUME) USER_REGISTER_WATER,
                (a.WATER_SUPPLY-(a.BILLING_WATER_VOLUME+a.FREE_WATER_VOLUME)) LEAKAGE_WATER,
                a.LEAKAGE_RATE LEAKAGE_RATE,
                (c.JMCB_XZZ+c.DWGS_XZZ+c.NPJYL_XZZ+c.ZDDTSD_XZZ) revised,
               (a.LEAKAGE_RATE-(c.JMCB_XZZ+c.DWGS_XZZ+c.NPJYL_XZZ+c.ZDDTSD_XZZ)) PRACTICAL_LEAKAGE_RATE,
                a.LEAKAGE_OVER_VAL LEAKAGE_OVER_VAL,
                case WHEN(NVL(a.LEAKAGE_VAL, 0)) != 0 THEN round((a.LEAKAGE_OVER_VAL / a.LEAKAGE_VAL ) * 100,2) ELSE 0 END HANDLE_LEAK_EFF
        from TF_DMA_STATISTICAL a
        LEFT JOIN TF_YWPN_DMAREGION_W b ON a.DMA_ID = b.ID
        LEFT JOIN TF_YWPN_INDICATOR_CORRECTION_W c on a.DMA_ID = c.DMA_ID
        WHERE
        a.STATISTICAL_DATE = c.REVISE_DATE
        <if test="dto.ids != null">
            AND a.ID in
            <foreach item="item" index="index" collection="dto.ids" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.dmaLevel != null">
            AND b.PARTITION_LEVEL in
            <foreach item="item" index="index" collection="dto.dmaLevel" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
<!--        <if test="dto.dmaLevel != null and dto.dmaLevel != ''">-->
<!--            AND b.PARTITION_LEVEL = #{dto.dmaLevel}-->
<!--        </if>-->
        <if test="dto.dmaName != null and dto.dmaName.trim() != ''">
            AND b.DMA_NAME like '%'||#{dto.dmaName}||'%'
        </if>
        <if test="dto.startDate != null and dto.endDate != null">
            AND to_char(a.STATISTICAL_DATE,'yyyy-mm') between #{dto.startDate} and #{dto.endDate}
        </if>
<!--        <if test="dto.censusDate != null and dto.censusDate.trim() != ''">-->
<!--            AND to_char(a.STATISTICAL_DATE, 'yyyy-mm') = #{dto.censusDate}-->
<!--        </if>-->
        ORDER BY a.STATISTICAL_DATE DESC
    </select>

    <select id="getLeakageRate" resultType="map">
        select a.ID,
               a.LEAKAGE_RATE,
               a.WATER_SUPPLY,
               a.USER_WATER BILLING_WATER_VOLUME,
               ( a.FREE_WATER_VOLUME + a.BILLING_WATER_VOLUME + a.OUTFLOW_WATER_VOLUME + a.LOSS_WATER_VOLUME + a.OTHER_WATER_VOLUME ) FREE_WATER_VOLUME,
               to_char(a.STATISTICAL_DATE,'yyyy-mm') STATISTICAL_DATE,
               a.DMA_ID,
               c.DMA_NAME,
               c.PARTITION_LEVEL DMA_LEVEL,
               decode(c.PARTITION_LEVEL,'1','一级分区','2','二级分区','3','三级分区') DMA_LEVEL_NAME,
               b.STATUS,
               decode(b.STATUS,'0','异常','1','正常') STATUS_NAME,
               b.LEAK_UP,
               b.LEAK_DOWN
        from TF_DMA_STATISTICAL a
        LEFT JOIN TF_LEAK_ANALYSE b ON a.DMA_ID = b.DMA_ID AND a.STATISTICAL_DATE = b.STATISTICAL_DATE
        LEFT JOIN TF_YWPN_DMAREGION_W c ON a.DMA_ID = c.ID
        WHERE
        1=1
        <if test="dto.dmaId != null">
            AND a.DMA_ID in
            <foreach item="item" index="index" collection="dto.dmaId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.startDate != null and dto.endDate != null">
            AND to_char(a.STATISTICAL_DATE,'yyyy-mm') between #{dto.startDate} and #{dto.endDate}
        </if>
        ORDER BY a.STATISTICAL_DATE DESC
    </select>

<!--    <select id="getLeakageRateCensus" resultType="map">-->
<!--        select  to_char(STATISTICAL_DATE,'yyyy') STATISTICAL_DATE,-->
<!--                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( LEAKAGE_RATE ) / COUNT(*),2) ELSE 0 END LEAKAGE_RATE-->
<!--        from TF_DMA_STATISTICAL-->
<!--        WHERE-->
<!--        1=1-->
<!--        <if test="dmaId != null">-->
<!--            AND DMA_ID in-->
<!--            <foreach item="item" index="index" collection="dmaId" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="startDate != null and endDate != null">-->
<!--            AND to_char(STATISTICAL_DATE,'yyyy') between #{startDate} and #{endDate}-->
<!--        </if>-->
<!--        GROUP BY to_char(STATISTICAL_DATE,'yyyy')-->
<!--        ORDER BY STATISTICAL_DATE DESC-->
<!--    </select>-->
    <select id="getLeakageRateCensus" resultType="map">
        select  to_char(STATISTICAL_DATE,'yyyy') STATISTICAL_DATE,
        case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( LEAKAGE_RATE ) / COUNT(*),2) ELSE 0 END LEAKAGE_RATE
        from TF_TOTAL_STATISTICAL
        WHERE
        1=1
        <if test="startDate != null and endDate != null">
            AND to_char(STATISTICAL_DATE,'yyyy') between #{startDate} and #{endDate}
        </if>
        GROUP BY to_char(STATISTICAL_DATE,'yyyy')
        ORDER BY STATISTICAL_DATE DESC
    </select>

    <select id="getLeakRateStatus" resultType="map">
        select STATUS,
               COUNT ( * ) AS statusCount
        from TF_LEAK_ANALYSE
        WHERE
        1=1
        <if test="dmaId != null">
            AND DMA_ID in
            <foreach item="item" index="index" collection="dmaId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="startDate != null and endDate != null">
            AND to_char(STATISTICAL_DATE,'yyyy-mm') between #{startDate} and #{endDate}
        </if>
        GROUP BY STATUS
    </select>

    <select id="getNrw" resultType="map">
        select  a.ID,
                a.POOR_PRODUCTION_RATE,
                a.WATER_SUPPLY,
                a.USER_WATER BILLING_WATER_VOLUME,
                to_char(a.STATISTICAL_DATE,'yyyy-mm') STATISTICAL_DATE,
                a.FREE_WATER_VOLUME,
                a.DMA_ID,
                c.DMA_NAME,
                c.PARTITION_LEVEL DMA_LEVEL,
                decode(c.PARTITION_LEVEL,'1','一级分区','2','二级分区','3','三级分区') DMA_LEVEL_NAME,
                b.STATUS,
                decode(b.STATUS,'0','异常','1','正常') STATUS_NAME,
                b.NRW_UP,
                b.NRW_DOWN
        from TF_DMA_STATISTICAL a
        LEFT JOIN TF_NRW_ANALYSE b ON a.DMA_ID = b.DMA_ID AND a.STATISTICAL_DATE = b.STATISTICAL_DATE
        LEFT JOIN TF_YWPN_DMAREGION_W c ON a.DMA_ID = c.ID
        WHERE
        1=1
        <if test="dto.dmaId != null">
            AND a.DMA_ID in
            <foreach item="item" index="index" collection="dto.dmaId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.startDate != null and dto.endDate != null">
            AND to_char(a.STATISTICAL_DATE,'yyyy-mm') between #{dto.startDate} and #{dto.endDate}
        </if>
        ORDER BY a.STATISTICAL_DATE DESC
    </select>

    <select id="getNrwStatus" resultType="map">
        select STATUS,
               COUNT ( * ) AS statusCount
        from TF_NRW_ANALYSE
        WHERE
        1=1
        <if test="dmaId != null">
            AND DMA_ID in
            <foreach item="item" index="index" collection="dmaId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="startDate != null and endDate != null">
            AND to_char(STATISTICAL_DATE,'yyyy-mm') between #{startDate} and #{endDate}
        </if>
        GROUP BY STATUS
    </select>

    <select id="getWaterBalanceM" resultType="map">
        select  to_char(a.STATISTICAL_DATE,'yyyy-mm') STATISTICAL_DATE,
                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.MEASURE_VOLUME) MEASURE_VOLUME,
                SUM( a.NOT_MEASURE_VOLUME) NOT_MEASURE_VOLUME,
                SUM( a.FREE_MEASURE_VOLUME) FREE_MEASURE_VOLUME,
                SUM( a.NOT_FREE_MEASURE_VOLUME) NOT_FREE_MEASURE_VOLUME,
                SUM( a.OBVIOUS_OUTFLOW_VOLUME) OBVIOUS_OUTFLOW_VOLUME,
                SUM( a.DARK_OUTFLOW_VOLUME) DARK_OUTFLOW_VOLUME,
                SUM( a.BACKGROUND_OUTFLOW_VOLUME) BACKGROUND_OUTFLOW_VOLUME,
                SUM( a.OTHER_OUTFLOW_VOLUME) OTHER_OUTFLOW_VOLUME,
                SUM( a.USER_LOSS_VOLUME) USER_LOSS_VOLUME,
                SUM( a.NOT_USER_LOSS_VOLUME) NOT_USER_LOSS_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,
                SUM( a.BILLING_WATER_VOLUME + a.USER_WATER ) CHARGE_LEGAL_WATER,
                SUM( a.LEAKAGE_OVER_VAL ) LEAKAGE_OVER_VAL,
                SUM( a.LEAKAGE_VAL ) LEAKAGE_VAL,
                SUM( a.DN_LENGTH_VAL ) DN_LENGTH_VAL,
                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( a.YEAR_PRESSURE_VAL ) / COUNT(*),2) ELSE 0 END YEAR_PRESSURE_VAL,
                SUM( a.LOSS_WATER_VOLUME + a.OTHER_WATER_VOLUME ) APPARENT_LEAKAGE_VAL,
                SUM( a.OTHER_WATER_VOLUME + a.LOSS_WATER_VOLUME + a.OUTFLOW_WATER_VOLUME ) LEAKAGE_SUM_VOLUME,
                SUM( a.USER_WATER + a.FREE_WATER_VOLUME ) LEGAL_WATER_VOLUME,
                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="dto.dmaId != null">
            AND a.DMA_ID in
            <foreach item="item" index="index" collection="dto.dmaId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.startDate != null and dto.endDate != null">
            AND to_char(a.STATISTICAL_DATE,'yyyy-mm') between #{dto.startDate} and #{dto.endDate}
        </if>
        GROUP BY to_char(a.STATISTICAL_DATE,'yyyy-mm'),b.DMA_NAME,b.PARTITION_LEVEL
        ORDER BY to_char(a.STATISTICAL_DATE,'yyyy-mm') DESC
    </select>

    <select id="getWaterBalanceY" resultType="map">
        select  to_char(a.STATISTICAL_DATE,'yyyy') STATISTICAL_DATE,
                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.MEASURE_VOLUME) MEASURE_VOLUME,
                SUM( a.NOT_MEASURE_VOLUME) NOT_MEASURE_VOLUME,
                SUM( a.FREE_MEASURE_VOLUME) FREE_MEASURE_VOLUME,
                SUM( a.NOT_FREE_MEASURE_VOLUME) NOT_FREE_MEASURE_VOLUME,
                SUM( a.OBVIOUS_OUTFLOW_VOLUME) OBVIOUS_OUTFLOW_VOLUME,
                SUM( a.DARK_OUTFLOW_VOLUME) DARK_OUTFLOW_VOLUME,
                SUM( a.BACKGROUND_OUTFLOW_VOLUME) BACKGROUND_OUTFLOW_VOLUME,
                SUM( a.OTHER_OUTFLOW_VOLUME) OTHER_OUTFLOW_VOLUME,
                SUM( a.USER_LOSS_VOLUME) USER_LOSS_VOLUME,
                SUM( a.NOT_USER_LOSS_VOLUME) NOT_USER_LOSS_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,
                SUM( a.BILLING_WATER_VOLUME + a.USER_WATER ) CHARGE_LEGAL_WATER,
                SUM( a.LEAKAGE_OVER_VAL ) LEAKAGE_OVER_VAL,
                SUM( a.LEAKAGE_VAL ) LEAKAGE_VAL,
                SUM( a.DN_LENGTH_VAL ) DN_LENGTH_VAL,
                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( a.YEAR_PRESSURE_VAL ) / COUNT(*),2) ELSE 0 END YEAR_PRESSURE_VAL,
                SUM( a.LOSS_WATER_VOLUME + a.OTHER_WATER_VOLUME ) APPARENT_LEAKAGE_VAL,
                SUM( a.OTHER_WATER_VOLUME + a.LOSS_WATER_VOLUME + a.OUTFLOW_WATER_VOLUME ) LEAKAGE_SUM_VOLUME,
                SUM( a.USER_WATER + a.FREE_WATER_VOLUME ) LEGAL_WATER_VOLUME,
                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="dto.dmaId != null">
            AND a.DMA_ID in
            <foreach item="item" index="index" collection="dto.dmaId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.startDate != null and dto.endDate != null">
            AND to_char(a.STATISTICAL_DATE,'yyyy') between #{dto.startDate} and #{dto.endDate}
        </if>
        GROUP BY to_char(a.STATISTICAL_DATE,'yyyy'),b.DMA_NAME,b.PARTITION_LEVEL
        ORDER BY to_char(a.STATISTICAL_DATE,'yyyy') DESC
    </select>

    <select id="getObserveFlowM" resultType="map">
        select (a.max-a.min) fold,
               to_char(a.START_TIME,'yyyy-mm') START_TIME,
               to_char(a.END_TIME,'yyyy-mm') END_TIME,
               c.NAME,
               decode(c.STATUS , '0','故障','1','运行中', '2','空闲','3','检修中', '4','离线') STATUS,
               c.DESCRIBE
        from STATISTICS_SCADA a
        LEFT JOIN TF_INDEX_ALLOCATION b ON a.CODE = b.VARIABLE_CODE
        LEFT JOIN TF_DEVICE_ARCHIVE_MANAGE c ON c.ID = b.DEVICE_ID
        WHERE
        1=1
          AND a.DATA_TYPE = '1'
        <if test="dto.deviceId != null">
            AND c.ID in
            <foreach item="item" index="index" collection="dto.deviceId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.statisticsType != null">
            AND a.STATISTICS_TYPE = #{dto.statisticsType}
        </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>
        ORDER BY to_char(a.START_TIME,'yyyy-mm') DESC
    </select>

    <select id="getObserveFlowD" resultType="map">
        select (a.max-a.min) fold,
               to_char(a.START_TIME,'yyyy-mm-dd') START_TIME,
               to_char(a.END_TIME,'yyyy-mm-dd') END_TIME,
               c.NAME,
               decode(c.STATUS , '0','故障','1','运行中', '2','空闲','3','检修中', '4','离线') STATUS,
               c.DESCRIBE
        from STATISTICS_SCADA a
        LEFT JOIN TF_INDEX_ALLOCATION b ON a.CODE = b.VARIABLE_CODE
        LEFT JOIN TF_DEVICE_ARCHIVE_MANAGE c ON c.ID = b.DEVICE_ID
        WHERE
            1=1
            AND a.DATA_TYPE = '1'
        <if test="dto.deviceId != null">
            AND c.ID in
            <foreach item="item" index="index" collection="dto.deviceId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.statisticsType != null">
            AND a.STATISTICS_TYPE = #{dto.statisticsType}
        </if>
        <if test="dto.startDate != null and dto.endDate != null">
            AND to_char(a.START_TIME,'yyyy-mm-dd') between #{dto.startDate} and #{dto.endDate}
            AND to_char(a.END_TIME,'yyyy-mm-dd') between #{dto.startDate} and #{dto.endDate}
        </if>
        ORDER BY to_char(a.START_TIME,'yyyy-mm-dd') DESC
    </select>

    <select id="getObserveFlowH" resultType="map">
        select (a.max-a.min) fold,
               to_char(a.START_TIME,'yyyy-mm-dd hh24') START_TIME,
               to_char(a.END_TIME,'yyyy-mm-dd hh24') END_TIME,
               c.NAME,
               decode(c.STATUS , '0','故障','1','运行中', '2','空闲','3','检修中', '4','离线') STATUS,
               c.DESCRIBE
        from STATISTICS_SCADA a
        LEFT JOIN TF_INDEX_ALLOCATION b ON a.CODE = b.VARIABLE_CODE
        LEFT JOIN TF_DEVICE_ARCHIVE_MANAGE c ON c.ID = b.DEVICE_ID
        WHERE
            1=1
            AND a.DATA_TYPE = '1'
        <if test="dto.deviceId != null">
            AND c.ID in
            <foreach item="item" index="index" collection="dto.deviceId" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.statisticsType != null">
            AND a.STATISTICS_TYPE = #{dto.statisticsType}
        </if>
        <if test="dto.startDate != null and dto.endDate != null">
            AND to_char(a.START_TIME,'yyyy-mm-dd hh24') between #{dto.startDate} and #{dto.endDate}
            AND to_char(a.END_TIME,'yyyy-mm-dd hh24') between #{dto.startDate} and #{dto.endDate}
        </if>
        ORDER BY to_char(a.START_TIME,'yyyy-mm-dd hh24') DESC
    </select>

<!--    <select id="getLeakOverview" resultType="map">-->
<!--        select to_char(STATISTICAL_DATE,'yyyy-mm') STATISTICAL_DATE,-->
<!--               SUM( USER_WATER ) BILLING_WATER_VOLUME,-->
<!--               case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( LEAKAGE_RATE ) / COUNT(*),2) ELSE 0 END LEAKAGE_RATE,-->
<!--               case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( POOR_PRODUCTION_RATE ) / COUNT(*),2) ELSE 0 END POOR_PRODUCTION_RATE,-->
<!--               SUM( WATER_SUPPLY ) WATER_SUPPLY,-->
<!--               SUM( LEAKAGE_OVER_VAL ) LEAKAGE_OVER_VAL,-->
<!--               SUM( LEAKAGE_VAL ) LEAKAGE_VA-->
<!--        from TF_DMA_STATISTICAL-->
<!--        WHERE-->
<!--            TO_CHAR(STATISTICAL_DATE,'YYYY-MM')=TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM')-->
<!--        GROUP BY to_char(STATISTICAL_DATE,'yyyy-mm')-->
<!--    </select>-->
    <select id="getLeakOverview" resultType="map">
        select to_char(STATISTICAL_DATE,'yyyy-mm') STATISTICAL_DATE,
               USER_WATER BILLING_WATER_VOLUME,
               LEAKAGE_RATE LEAKAGE_RATE,
               POOR_PRODUCTION_RATE POOR_PRODUCTION_RATE,
               WATER_SUPPLY WATER_SUPPLY,
               LEAKAGE_OVER_VAL LEAKAGE_OVER_VAL,
               LEAKAGE_VAL LEAKAGE_VA
        from TF_TOTAL_STATISTICAL
        WHERE
            TO_CHAR(STATISTICAL_DATE,'YYYY-MM')=TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM')
    </select>

<!--    <select id="getSupplyWaterYear" resultType="map">-->
<!--        select  to_char(STATISTICAL_DATE,'yyyy-mm') STATISTICAL_DATE,-->
<!--                SUM( WATER_SUPPLY ) WATER_SUPPLY,-->
<!--                SUM( USER_WATER ) BILLING_WATER_VOLUME,-->
<!--                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( LEAKAGE_RATE ) / COUNT(*),2) ELSE 0 END LEAKAGE_RATE,-->
<!--                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( POOR_PRODUCTION_RATE ) / COUNT(*),2) ELSE 0 END POOR_PRODUCTION_RATE-->
<!--        from TF_DMA_STATISTICAL-->
<!--        WHERE-->
<!--            1=1-->
<!--        <if test="startDate != null and endDate != null">-->
<!--            AND to_char(STATISTICAL_DATE,'yyyy-mm') between #{startDate} and #{endDate}-->
<!--        </if>-->
<!--        GROUP BY to_char(STATISTICAL_DATE,'yyyy-mm')-->
<!--        ORDER BY STATISTICAL_DATE DESC-->
<!--    </select>-->
    <select id="getSupplyWaterYear" resultType="map">
        select  to_char(STATISTICAL_DATE,'yyyy-mm') STATISTICAL_DATE,
                WATER_SUPPLY WATER_SUPPLY,
                USER_WATER BILLING_WATER_VOLUME,
                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 STATISTICAL_DATE DESC
    </select>

    <select id="getMonitorCount" resultType="int">
        select COUNT( * )
        from TF_DMA_DEVICE_ASSOCIATION
    </select>

<!--    <select id="getDmaStatisticalMonth" resultType="map">-->
<!--        select  to_char(STATISTICAL_DATE,'yyyy-mm') STATISTICAL_DATE,-->
<!--                round( SUM( WATER_SUPPLY ), 2 ) WATER_SUPPLY,-->
<!--                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( LEAKAGE_RATE ) / COUNT(*),2) ELSE 0 END LEAKAGE_RATE,-->
<!--                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( POOR_PRODUCTION_RATE ) / COUNT(*),2) ELSE 0 END POOR_PRODUCTION_RATE-->
<!--        from TF_DMA_STATISTICAL-->
<!--        WHERE-->
<!--            1=1-->
<!--        <if test="censusMonth != null and censusMonth.trim() != ''">-->
<!--            AND TO_CHAR(STATISTICAL_DATE,'yyyy-mm') = #{censusMonth}-->
<!--        </if>-->
<!--        <if test="startYear != null and endYear != null">-->
<!--            AND to_char(STATISTICAL_DATE,'yyyy') between #{startYear} and #{endYear}-->
<!--        </if>-->
<!--        <if test="startMonth != null and endMonth != null">-->
<!--            AND to_char(STATISTICAL_DATE,'yyyy-mm') between #{startMonth} and #{endMonth}-->
<!--        </if>-->
<!--        GROUP BY to_char(STATISTICAL_DATE,'yyyy-mm')-->
<!--        ORDER BY STATISTICAL_DATE DESC-->
<!--    </select>-->
    <select id="getDmaStatisticalMonth" resultType="map">
        select  to_char(STATISTICAL_DATE,'yyyy-mm') STATISTICAL_DATE,
                WATER_SUPPLY WATER_SUPPLY,
                USER_WATER USER_WATER,
                LEAKAGE_RATE LEAKAGE_RATE,
                POOR_PRODUCTION_RATE POOR_PRODUCTION_RATE
        from TF_TOTAL_STATISTICAL
        WHERE
        1=1
        <if test="censusMonth != null and censusMonth.trim() != ''">
            AND TO_CHAR(STATISTICAL_DATE,'yyyy-mm') = #{censusMonth}
        </if>
        <if test="startYear != null and endYear != null">
            AND to_char(STATISTICAL_DATE,'yyyy') between #{startYear} and #{endYear}
        </if>
        <if test="startMonth != null and endMonth != null">
            AND to_char(STATISTICAL_DATE,'yyyy-mm') between #{startMonth} and #{endMonth}
        </if>
        ORDER BY STATISTICAL_DATE DESC
    </select>

    <select id="getDmaStatisticalMonthOne" resultType="map">
        select  to_char(STATISTICAL_DATE,'yyyy-mm') STATISTICAL_DATE,
        WATER_SUPPLY WATER_SUPPLY,
        LEAKAGE_RATE LEAKAGE_RATE,
        POOR_PRODUCTION_RATE POOR_PRODUCTION_RATE
        from TF_TOTAL_STATISTICAL
        WHERE
        1=1
        <if test="censusMonth != null and censusMonth.trim() != ''">
            AND TO_CHAR(STATISTICAL_DATE,'yyyy-mm') = #{censusMonth}
        </if>
        ORDER BY STATISTICAL_DATE DESC
    </select>

    <select id="getLevelDmaLeak" resultType="map">
        select TO_CHAR(STATISTICAL_DATE,'yyyy-mm') TIME,
               LEAKAGE_RATE VALUE
        from TF_DMA_STATISTICAL
        WHERE
            1=1
        <if test="dmaIdOne != null">
            AND DMA_ID = #{dmaIdOne}
        </if>
        <if test="censusMonth != null and censusMonth.trim() != ''">
            AND TO_CHAR(STATISTICAL_DATE,'yyyy-mm') = #{censusMonth}
        </if>
        <if test="censusYear != null and censusYear.trim() != ''">
            AND TO_CHAR(STATISTICAL_DATE,'yyyy') = #{censusYear}
        </if>
        <if test="startMonth != null and endMonth != null">
            AND to_char(STATISTICAL_DATE,'yyyy-mm') between #{startMonth} and #{endMonth}
        </if>
        ORDER BY time DESC
    </select>

    <select id="getLevelDmaLeakAvg" resultType="Float">
        select case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( LEAKAGE_RATE ) / COUNT(*),2) ELSE 0 END VALUE
        from TF_DMA_STATISTICAL
        WHERE
            1=1
        <if test="dmaIdOne != null">
            AND DMA_ID = #{dmaIdOne}
        </if>
        <if test="startMonth != null and endMonth != null">
            AND to_char(STATISTICAL_DATE,'yyyy-mm') between #{startMonth} and #{endMonth}
        </if>
    </select>

    <select id="getDmaCount" resultType="int">
        select COUNT( * )
        from TF_YWPN_DMAREGION_W
    </select>

    <select id="getLeakageCount" resultType="Integer">
        select SUM( LEAKAGE_VAL )
        from TF_DMA_STATISTICAL
        WHERE
            TO_CHAR(STATISTICAL_DATE,'yyyy-mm')=TO_CHAR(SYSDATE-1,'yyyy-mm')
    </select>

    <select id="viewDmaCensusParam" resultType="map">
        select a.*,
               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="dmaId != null and dmaId != ''">
            AND b.ID = #{dmaId}
        </if>
        <if test="censusDate != null and censusDate.trim() != ''">
            AND to_char(a.STATISTICAL_DATE,'yyyy-mm') = #{censusDate}
        </if>
    </select>

    <select id="getPipeDevice" resultType="int">
        select count( * )
        from TF_DEVICE_ARCHIVE_MANAGE
        WHERE
        1=1
        <if test="type != null and type.trim() != ''">
            AND TYPE = #{type}
        </if>
        <if test="deviceType != null and deviceType.trim() != ''">
            AND DEVICE_TYPE = #{deviceType}
        </if>
        <if test="status != null and status.trim() != ''">
            AND STATUS = #{status}
        </if>
    </select>

    <select id="getWaterAmount" resultType="int">
        select count( * )
        from TF_WATER_INFO
    </select>

    <select id="getCameraAmount" resultType="int">
        select count( * )
        from TF_CAMERA_MANAGE
    </select>

    <select id="getPipeTableAmount" resultType="int">
        select count( * )
        from TF_YWPN_WATERMETER_W
        WHERE ISSUM = 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
        <if test="name != null and name.trim() != ''">
            AND NAME like '%'||#{name}||'%'
        </if>
    </select>

    <select id="getNoiseCheckAmount" resultType="int">
        select count( * )
        from TF_DEVICE_ARCHIVE_MANAGE
        where DEVICE_TYPE = '4'
    </select>

    <select id="getYesterdaySupplyWater" resultType="BigDecimal">
--         select case WHEN(NVL(SUM ( a.MAX ), 0)) != 0 AND (NVL(SUM ( a.MIN ), 0)) != 0 THEN round( SUM ( a.MAX ) - SUM ( a.MIN ), 2 ) ELSE 0 END yesterdaySupplyWater
--         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
--         WHERE
--             1=1
--           AND c.TYPE = '1'
--           AND a.STATISTICS_TYPE = 1
--           AND b.TYPE = '19'
--           AND TO_CHAR(a.START_TIME,'yyyy-MM-dd') = TO_CHAR(SYSDATE-1,'yyyy-MM-dd')
--           AND TO_CHAR(a.END_TIME,'yyyy-MM-dd') = TO_CHAR(SYSDATE-1,'yyyy-MM-dd')
        SELECT
            NVL( SUM( t.yesterdaySupplyWater ), 0 ) yesterdaySupplyWater
        FROM
            (
                SELECT
                    a.CODE,
                    CASE
                        WHEN ( NVL( SUM( a.MAX ), 0 ) ) != 0
                        AND ( NVL( SUM( a.MIN ), 0 ) ) != 0 THEN
                        round( SUM( a.MAX ) - SUM( a.MIN ), 2 ) ELSE 0
                    END yesterdaySupplyWater
                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
                WHERE
                    1 = 1
                  AND c.TYPE = '1'
                  AND a.STATISTICS_TYPE = 1
                  AND TO_CHAR( a.START_TIME, 'yyyy-MM-dd' ) = TO_CHAR( SYSDATE - 1, 'yyyy-MM-dd' )
                  AND TO_CHAR( a.END_TIME, 'yyyy-MM-dd' ) = TO_CHAR( SYSDATE - 1, 'yyyy-MM-dd' )
                GROUP BY
                    a.CODE
            ) t
        WHERE
            t.CODE LIKE '%' || 'total_FT_1141'
           OR t.CODE LIKE '%' || 'total_FT_1142'
           OR t.CODE LIKE '%' || 'total_FT_1145'
           OR t.CODE LIKE '%' || 'total_FT_1143'
           OR t.CODE LIKE '%' || 'total_FT_1144'
           OR t.CODE LIKE '%' || 'total_FTA5'
           OR t.CODE LIKE '%' || 'total_FTA_4'
    </select>

    <select id="getYesterdayUserWater" resultType="BigDecimal">
        select case WHEN(NVL(SUM ( a.MAX ), 0)) != 0 AND (NVL(SUM ( a.MIN ), 0)) != 0 THEN round( SUM ( a.MAX ) - SUM ( a.MIN ), 2 ) ELSE 0 END yesterdayUserWater
        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
        WHERE
            1=1
          AND c.TYPE = '1'
          AND a.STATISTICS_TYPE = 1
          AND b.TYPE = '19'
          AND TO_CHAR(a.START_TIME,'yyyy-MM-dd') = TO_CHAR(SYSDATE-1,'yyyy-MM-dd')
          AND TO_CHAR(a.END_TIME,'yyyy-MM-dd') = TO_CHAR(SYSDATE-1,'yyyy-MM-dd')
    </select>

    <select id="getWaterInfo" resultType="com.tofly.xrtygis.entity.TfWaterInfo">
        select *
        from TF_WATER_INFO
        ORDER BY BLOW_IN_TIME
    </select>

<!--    <select id="getNearYearStatistical" resultType="map">-->
<!--        select  case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( LEAKAGE_RATE ) / COUNT(*),2) ELSE 0 END LEAKAGE_RATE,-->
<!--                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( POOR_PRODUCTION_RATE ) / COUNT(*),2) ELSE 0 END POOR_PRODUCTION_RATE-->
<!--        from TF_DMA_STATISTICAL-->
<!--        WHERE 1=1-->
<!--        <if test="startDate != null and endDate != null">-->
<!--            AND to_char(STATISTICAL_DATE,'yyyy-mm') between #{startDate} and #{endDate}-->
<!--        </if>-->
<!--        GROUP BY to_char(STATISTICAL_DATE,'yyyy-mm')-->
<!--        ORDER BY to_char(STATISTICAL_DATE,'yyyy-mm') DESC-->
<!--    </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="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
        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
        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.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>
        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,
                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
        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.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>
        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,
                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
        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.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>
        ORDER BY TIME DESC
    </select>

    <select id="currencyViewIndexH" resultType="map">
        select  a.CODE,
                case WHEN trim(translate(a.VALUE,'0123456789.-',' ')) is NULL THEN ROUND(to_number(a.VALUE),nvl(b.accuracy,0)) ELSE 0 END VALUE,
                a.STATISTICS_TYPE,
                a.START_TIME,
                a.END_TIME,
                case WHEN trim(translate(a.MAX,'0123456789.-',' ')) is NULL THEN ROUND(to_number(a.MAX),nvl(b.accuracy,0)) ELSE 0 END MAX,
                case WHEN trim(translate(a.MIN,'0123456789.-',' ')) is NULL THEN ROUND(to_number(a.MIN),nvl(b.accuracy,0)) ELSE 0 END MIN,
                case WHEN trim(translate(a.AVE,'0123456789.-',' ')) is NULL THEN ROUND(to_number(a.AVE),nvl(b.accuracy,0)) ELSE 0 END AVE,
                case WHEN trim(translate(a.FOLD,'0123456789.-',' ')) is NULL THEN ROUND(to_number(a.FOLD),nvl(b.accuracy,0)) ELSE 0 END FOLD,
                a.DATA_TYPE,
                a.PASS,
                a.ERROR_COUNT,
                a.ERROR_TIME_TOTAL,
                a.TIME_TOTAL,
                b.*,
                c.*
        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_DMA_DEVICE_ASSOCIATION d ON d.DEVICE_ID = c.ID
        WHERE
            1=1
        <if test="statisticsType != null and statisticsType != ''">
            AND a.STATISTICS_TYPE = #{statisticsType}
        </if>
        <if test="dataType != null and dataType.trim() != ''">
            AND a.DATA_TYPE = #{dataType}
        </if>
        <if test="startHour != null and endHour != null">
            AND to_char(a.START_TIME,'yyyy-mm-dd hh24') between #{startHour} and #{endHour}
            AND to_char(a.END_TIME,'yyyy-mm-dd hh24') between #{startHour} and #{endHour}
        </if>
        <if test="censusDay != null and censusDay.trim() != ''">
            AND to_char(a.START_TIME,'yyyy-mm-dd') = #{censusDay}
            AND to_char(a.END_TIME,'yyyy-mm-dd') = #{censusDay}
        </if>
        <if test="censusHour != null and censusHour.trim() != ''">
            AND to_char(a.START_TIME,'yyyy-mm-dd hh24') = #{censusHour}
            AND to_char(a.END_TIME,'yyyy-mm-dd hh24') = #{censusHour}
        </if>
        <if test="model != null and model.trim() != ''">
            AND b.MODEL = #{model}
        </if>
        <if test="indexCodes != null">
            AND b.VARIABLE_CODE in
            <foreach item="item" index="index" collection="indexCodes" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="deviceIds != null">
            AND c.ID in
            <foreach item="item" index="index" collection="deviceIds" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="type != null and type.trim() != ''">
            AND c.TYPE = #{type}
        </if>
        <if test="deviceType != null and deviceType.trim() != ''">
            AND c.DEVICE_TYPE = #{deviceType}
        </if>
        <if test="deviceCodes != null">
            AND c.CODE in
            <foreach item="item" index="index" collection="deviceCodes" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dmaId != null and dmaId != ''">
            AND d.DMA_ID = #{dmaId}
        </if>
        ORDER BY a.END_TIME DESC
    </select>

    <select id="currencyViewIndexAvgH" resultType="map">
        select  to_char(a.END_TIME,'yyyy-mm-dd hh24') TIME,
                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( a.AVE ) / COUNT(*),2) ELSE 0 END AVG
        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_DMA_DEVICE_ASSOCIATION d ON d.DEVICE_ID = c.ID
        WHERE
            1=1
            AND a.STATISTICS_TYPE = 0
        <if test="dataType != null and dataType.trim() != ''">
            AND a.DATA_TYPE = #{dataType}
        </if>
        <if test="startHour != null and endHour != null">
            AND to_char(a.START_TIME,'yyyy-mm-dd hh24') between #{startHour} and #{endHour}
            AND to_char(a.END_TIME,'yyyy-mm-dd hh24') between #{startHour} and #{endHour}
        </if>
        <if test="censusDay != null and censusDay.trim() != ''">
            AND to_char(a.START_TIME,'yyyy-mm-dd') = #{censusDay}
            AND to_char(a.END_TIME,'yyyy-mm-dd') = #{censusDay}
        </if>
        <if test="censusHour != null and censusHour.trim() != ''">
            AND to_char(a.START_TIME,'yyyy-mm-dd hh24') = #{censusHour}
            AND to_char(a.END_TIME,'yyyy-mm-dd hh24') = #{censusHour}
        </if>
        <if test="model != null and model.trim() != ''">
            AND b.MODEL = #{model}
        </if>
        <if test="indexCodes != null">
            AND b.VARIABLE_CODE in
            <foreach item="item" index="index" collection="indexCodes" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="deviceIds != null">
            AND c.ID in
            <foreach item="item" index="index" collection="deviceIds" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="type != null and type.trim() != ''">
            AND c.TYPE = #{type}
        </if>
        <if test="deviceType != null and deviceType.trim() != ''">
            AND c.DEVICE_TYPE = #{deviceType}
        </if>
        <if test="deviceCodes != null">
            AND c.CODE in
            <foreach item="item" index="index" collection="deviceCodes" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dmaId != null and dmaId != ''">
            AND d.DMA_ID = #{dmaId}
        </if>
        GROUP BY to_char(a.END_TIME,'yyyy-mm-dd hh24')
        ORDER BY TIME DESC
    </select>

    <select id="censusDeviceStaCount" resultType="map">
        select decode(STATUS, '0', '故障', '1', '在线', '2', '空闲', '3', '检修中', '4', '离线') name,
               COUNT ( * ) value
        from TF_DEVICE_ARCHIVE_MANAGE
        GROUP BY STATUS
    </select>

    <select id="censusIndexStaCount" resultType="map">
        select decode(IS_ALARM, '0', '正常', '1', '报警') name,
               COUNT ( * ) value
        from TF_INDEX_ALLOCATION
        GROUP BY IS_ALARM
    </select>

    <select id="getAllDeviceType" resultType="String">
        SELECT distinct DEVICE_TYPE
        FROM TF_DEVICE_ARCHIVE_MANAGE
        WHERE
        1=1
        <if test="name != null and name.trim() != ''">
            AND NAME like '%'||#{name}||'%'
        </if>
        <if test="type != null and type.trim() != ''">
            AND TYPE = #{type}
        </if>
        GROUP BY DEVICE_TYPE
    </select>

    <select id="getDeviceTypeName" resultType="string">
        SELECT CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE PCID = 53400
          AND CCODE = #{deviceType}
    </select>

    <select id="getWaterQualityDevice" resultType="Integer">
        SELECT COUNT ( * )
        FROM TF_INDEX_ALLOCATION a
        LEFT JOIN TF_DEVICE_ARCHIVE_MANAGE b ON a.DEVICE_ID = b.ID
        WHERE
            1=1
            AND b.DEVICE_TYPE = '6'
        <if test="isAlarm != null and isAlarm.trim() != ''">
            AND IS_ALARM = #{isAlarm}
        </if>
    </select>

<!--    <select id="getStatisticalGroupYear" resultType="map">-->
<!--        select  case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( LOSS_WATER_VOLUME ) / COUNT(*),2) ELSE 0 END LOSS_WATER_VOLUME,-->
<!--                round( SUM( WATER_SUPPLY ), 2 ) WATER_SUPPLY,-->
<!--                round( SUM( OUTFLOW_WATER_VOLUME ), 2 ) OUTFLOW_WATER_VOLUME,-->
<!--                round( SUM( LOSS_WATER_VOLUME ), 2 ) LOSS_WATER_VOLUME,-->
<!--                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( OUTFLOW_WATER_VOLUME ) / COUNT(*),2) ELSE 0 END OUTFLOW_WATER_VOLUME-->
<!--        from TF_DMA_STATISTICAL-->
<!--        WHERE-->
<!--            1=1-->
<!--        <if test="censusMonth != null and censusMonth.trim() != ''">-->
<!--            AND TO_CHAR(STATISTICAL_DATE,'yyyy-mm') = #{censusMonth}-->
<!--        </if>-->
<!--        <if test="startMonth != null and endMonth != null">-->
<!--            AND to_char(STATISTICAL_DATE,'yyyy-mm') between #{startMonth} and #{endMonth}-->
<!--        </if>-->
<!--    </select>-->
    <select id="getStatisticalGroupYear" resultType="map">
        select  case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( LOSS_WATER_VOLUME ) / COUNT(*),2) ELSE 0 END LOSS_WATER_VOLUME,
                round( SUM( WATER_SUPPLY ), 2 ) WATER_SUPPLY,
                round( SUM( USER_WATER ), 2 ) USER_WATER,
                round( SUM( OUTFLOW_WATER_VOLUME ), 2 ) OUTFLOW_WATER_VOLUME,
                round( SUM( LOSS_WATER_VOLUME ), 2 ) LOSS_WATER_VOLUME,
                case WHEN(NVL(COUNT(*), 0)) != 0 THEN round(SUM( OUTFLOW_WATER_VOLUME ) / COUNT(*),2) ELSE 0 END OUTFLOW_WATER_VOLUME
        from TF_TOTAL_STATISTICAL
        WHERE
        1=1
        <if test="censusMonth != null and censusMonth.trim() != ''">
            AND TO_CHAR(STATISTICAL_DATE,'yyyy-mm') = #{censusMonth}
        </if>
        <if test="startMonth != null and endMonth != null">
            AND to_char(STATISTICAL_DATE,'yyyy-mm') between #{startMonth} and #{endMonth}
        </if>
    </select>

    <select id="viewLossCensus" resultType="map">
        select  to_char(FILLING_DATE,'yyyy-mm') FILLING_DATE,
                round( SUM( EXPEND_AMOUNT ) , 2 ) EXPEND_AMOUNT
        from TF_LOSS_CENSUS
        WHERE
        1=1
        <if test="type != null and type.trim() != ''">
            AND TYPE = #{type}
        </if>
        <if test="startYear != null and endYear != null">
            AND to_char(FILLING_DATE,'yyyy') between #{startYear} and #{endYear}
        </if>
        <if test="startMonth != null and endMonth != null">
            AND to_char(FILLING_DATE,'yyyy-mm') between #{startMonth} and #{endMonth}
        </if>
        <if test="censusYear != null and censusYear.trim() != ''">
            AND to_char(FILLING_DATE,'yyyy') = #{censusYear}
        </if>
        <if test="censusMonth != null and censusMonth.trim() != ''">
            AND to_char(FILLING_DATE,'yyyy-mm') = #{censusMonth}
        </if>
        <if test="censusMonths != null">
            AND to_char(FILLING_DATE,'yyyy-mm') in
            <foreach item="item" index="index" collection="censusMonths" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="fillingType != null and fillingType.trim() != ''">
            AND FILLING_TYPE = #{fillingType}
        </if>
        GROUP BY to_char(FILLING_DATE,'yyyy-mm')
        ORDER BY FILLING_DATE DESC
    </select>

    <select id="viewLossCensusOne" resultType="map">
        select  round( SUM( EXPEND_AMOUNT ) , 2 ) EXPEND_AMOUNT
        from TF_LOSS_CENSUS
        WHERE
        1=1
        <if test="type != null and type.trim() != ''">
            AND TYPE = #{type}
        </if>
        <if test="censusMonth != null and censusMonth.trim() != ''">
            AND to_char(FILLING_DATE,'yyyy-mm') = #{censusMonth}
        </if>
        <if test="censusYear != null and censusYear.trim() != ''">
            AND to_char(FILLING_DATE,'yyyy') = #{censusYear}
        </if>
    </select>

<!--    <select id="viewInspectCensus" resultType="map">-->
<!--        select  SUM ( PLAN_NUM ) INSPECT_NUM,-->
<!--                SUM( PLAN_TOTAL_DISTANCE ) PLAN_TOTAL_DISTANCE,-->
<!--                SUM( REPAIR_ORDER_NUM ) ORDER_NUM,-->
<!--                SUM( FIND_TROUBLE_NUM ) FIND_TROUBLE_NUM,-->
<!--                SUM( REPAIR_ORDER_NUM ) - SUM( COMPLETE_ORDER_NUM ) HANDLE_ORDER_NUM,-->
<!--                SUM( COMPLETE_ORDER_NUM ) COMPLETE_ORDER_NUM-->
<!--        from TF_YWPN_GPSCALCULATE_W-->
<!--        WHERE-->
<!--            1=1-->
<!--        <if test="censusMonth != null and censusMonth.trim() != ''">-->
<!--            AND to_char(GPS_DATE,'yyyy-mm') = #{censusMonth}-->
<!--        </if>-->
<!--        <if test="startMonth != null and endMonth != null">-->
<!--            AND to_char(GPS_DATE,'yyyy-mm') between #{startMonth} and #{endMonth}-->
<!--        </if>-->
<!--        <if test="censusYear != null and censusYear.trim() != ''">-->
<!--            AND to_char(GPS_DATE,'yyyy') = #{censusYear}-->
<!--        </if>-->
<!--    </select>-->

<!--    <select id="viewGpsCalculateByMonth" resultType="map">-->
<!--        select  to_char(GPS_DATE,'yyyy-mm') GPS_DATE,-->
<!--                SUM ( PLAN_NUM ) INSPECT_NUM,-->
<!--                SUM( PLAN_TOTAL_DISTANCE ) PLAN_TOTAL_DISTANCE,-->
<!--                SUM( REPAIR_ORDER_NUM ) ORDER_NUM,-->
<!--                SUM( FIND_TROUBLE_NUM ) FIND_TROUBLE_NUM,-->
<!--                SUM( REPAIR_ORDER_NUM ) - SUM( COMPLETE_ORDER_NUM ) HANDLE_ORDER_NUM,-->
<!--                SUM( COMPLETE_ORDER_NUM ) COMPLETE_ORDER_NUM-->
<!--        from TF_YWPN_GPSCALCULATE_W-->
<!--        WHERE-->
<!--            1=1-->
<!--        <if test="startMonth != null and endMonth != null">-->
<!--            AND to_char(GPS_DATE,'yyyy-mm') between #{startMonth} and #{endMonth}-->
<!--        </if>-->
<!--        GROUP BY to_char(GPS_DATE,'yyyy-mm')-->
<!--        ORDER BY GPS_DATE DESC-->
<!--    </select>-->

    <select id="getInspectPersonNum" resultType="integer">
        select COUNT ( distinct USER_ID )
        from TF_YWPN_PLAN_INSPECT_USER_W
    </select>

    <select id="getInspectPersonList" resultType="Long">
        select distinct USER_ID
        from TF_YWPN_PLAN_INSPECT_USER_W
    </select>

    <select id="viewOrderCensus" resultType="Long">
        select COUNT ( * ) NUM
        from TF_YWPN_GDINFO_W
        WHERE
            1=1
        <if test="censusMonth != null and censusMonth.trim() != ''">
            AND to_char(DJSJ,'yyyy-mm') = #{censusMonth}
        </if>
        <if test="processNode != null">
            AND LCJD = #{processNode}
        </if>
        <if test="startMonth != null and endMonth != null">
            AND to_char(DJSJ,'yyyy-mm') between #{startMonth} and #{endMonth}
        </if>
        <if test="censusYear != null and censusYear.trim() != ''">
            AND to_char(DJSJ,'yyyy') = #{censusYear}
        </if>
    </select>

    <select id="viewOrderByMonth" resultType="map">
        select to_char(DJSJ,'yyyy-mm') DJSJ,
               COUNT ( * ) NUM
        from TF_YWPN_GDINFO_W
        WHERE
            1=1
        <if test="startMonth != null and endMonth != null">
            AND to_char(DJSJ,'yyyy-mm') between #{startMonth} and #{endMonth}
        </if>
        GROUP BY to_char(DJSJ,'yyyy-mm')
        ORDER BY DJSJ DESC
    </select>

    <select id="viewInspectPlanCensus" resultType="Long">
        select COUNT ( * ) NUM
        from TF_YWPN_PLAN_W
        WHERE
        1=1
        <if test="censusMonth != null and censusMonth.trim() != ''">
            AND to_char(PLAN_BEGINDATE,'yyyy-mm') = #{censusMonth}
        </if>
        <if test="startMonth != null and endMonth != null">
            AND to_char(PLAN_BEGINDATE,'yyyy-mm') between #{startMonth} and #{endMonth}
        </if>
        <if test="censusYear != null and censusYear.trim() != ''">
            AND to_char(PLAN_BEGINDATE,'yyyy') = #{censusYear}
        </if>
    </select>

    <select id="viewInspectPlanByMonth" resultType="map">
        select to_char(PLAN_BEGINDATE,'yyyy-mm') INSPECT_DATE,
               COUNT ( * ) NUM
        from TF_YWPN_PLAN_W
        WHERE
            1=1
        <if test="startMonth != null and endMonth != null">
            AND to_char(PLAN_BEGINDATE,'yyyy-mm') between #{startMonth} and #{endMonth}
        </if>
        GROUP BY to_char(PLAN_BEGINDATE,'yyyy-mm')
        ORDER BY INSPECT_DATE DESC
    </select>

    <select id="viewTroubleCensus" resultType="Long">
        select COUNT ( * ) NUM
        from TF_YWPN_TROUBLE_W
        WHERE
        1=1
        <if test="censusMonth != null and censusMonth.trim() != ''">
            AND to_char(CREATE_TIME,'yyyy-mm') = #{censusMonth}
        </if>
        <if test="troubleState != null and troubleState.trim() != ''">
            AND STATE = #{troubleState}
        </if>
        <if test="startMonth != null and endMonth != null">
            AND to_char(CREATE_TIME,'yyyy-mm') between #{startMonth} and #{endMonth}
        </if>
        <if test="censusYear != null and censusYear.trim() != ''">
            AND to_char(CREATE_TIME,'yyyy') = #{censusYear}
        </if>
    </select>

    <select id="viewTroubleByMonth" resultType="map">
        select to_char(CREATE_TIME,'yyyy-mm') CREATE_TIME,
               COUNT ( * ) NUM
        from TF_YWPN_TROUBLE_W
        WHERE
        1=1
        <if test="startMonth != null and endMonth != null">
            AND to_char(CREATE_TIME,'yyyy-mm') between #{startMonth} and #{endMonth}
        </if>
        GROUP BY to_char(CREATE_TIME,'yyyy-mm')
        ORDER BY DJSJ DESC
    </select>

    <select id="getUserByDmaId" resultType="Long">
        select COUNT ( distinct a.KHBH ) NUM
        from TF_YWPN_TABLELINKUSER_W a
        left join TF_DMA_WATER_W b on a.TABLE_ID = b.WATER_METER_ID
        WHERE
            1=1
        <if test="id != null">
            AND b.DMA_ID = #{id}
        </if>
    </select>

    <select id="getScadaReportById" resultType="Map">
        select *
        from TF_SCADA_REPORT
        WHERE
            1=1
        <if test="reportIdList != null">
            AND ID in
            <foreach item="item" index="index" collection="reportIdList" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
    </select>

    <select id="getSomeDayWater" resultType="map">
        SELECT
            NVL(SUM(a.MAX - a.MIN), 0) diff,
            c.ID device_id
        FROM STATISTICS_SCADA a
                 LEFT JOIN TF_INDEX_ALLOCATION b on b.VARIABLE_CODE = a.CODE
                 LEFT JOIN TF_DEVICE_ARCHIVE_MANAGE c on c.ID = b.DEVICE_ID
        WHERE
            a.STATISTICS_TYPE = 1
          AND a.DATA_TYPE = '19'
          AND TO_CHAR(a.START_TIME,'yyyy-MM') = #{day}
        GROUP BY
            c.ID
    </select>
</mapper>