<?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.BigScreenMapper">


    <select id="getHourWater" resultType="map">
        select (
        <choose>
            <when test="scid == 784">
                (
                <include refid="getWaterYieldHour">
                    <property name="scid" value="786"/>
                    <property name="flag" value="0"/>
                </include>
                ) - (
                <include refid="getWaterYieldHour">
                    <property name="scid" value="785"/>
                    <property name="flag" value="0"/>
                </include>
                )
            </when>
            <otherwise>
                <include refid="getWaterYieldHour">
                    <property name="scid" value="#{scid}"/>
                    <property name="flag" value="0"/>
                </include>
            </otherwise>
        </choose>
        ) qsl,
        (
        <include refid="getWaterYieldHour">
            <property name="scid" value="#{scid}"/>
            <property name="flag" value="1"/>
        </include>
        ) gsl
        from DUAL
    </select>

    <sql id="getWaterYieldHour">
        select sum(FLOW) val
        from TF_YWPN_HOURWATERYIELD_W
        where ITCD in (select ITEM
                       from TF_YWPN_WATERYIELDCONFIG_W
                       where FACTORY = ${scid}
                         and flag = ${flag})
          and time = to_char(sysdate - 1 / 24, 'yyyy-mm-dd hh24')
    </sql>

    <select id="waterVolume" resultType="map">
        select
        <choose>
            <when test="code == 0">
                round(sum(GSL_TOTAL),4) GSL_TOTAL,
            </when>
            <when test="code == 1">
                round(sum(SSL_TOTAL),4) SSL_TOTAL,
            </when>
        </choose>
        to_char(UP_DATE,'yyyy') up_date
        from TF_YWPN_COSTRLWATER_W
        where MARK = 1
        <if test="start != null and end != null">
            and to_char(UP_DATE,'yyyy') between #{start} and #{end}
        </if>
        <if test="start == null and end == null">
            and to_char(up_date,'yyyy') between to_char(add_months(sysdate,-36),'yyyy') and
            to_char(sysdate,'yyyy')
        </if>
        group by to_char(UP_DATE,'yyyy')
    </select>

    <select id="hourGslHistory" resultType="map">
        select TIME uhour, sum(FLOW) gsl
        from TF_YWPN_HOURWATERYIELD_W
        where ITCD in (
            select ITEM
            from TF_YWPN_WATERYIELDCONFIG_W
            where FACTORY = #{scid}
              and flag = 1
        )
          and time between substr(#{start}, 1, 13) and substr(#{end}, 1, 13)
        group by TIME
        order by TIME desc
    </select>

    <select id="hourQslHistory" resultType="map">
        select
        <choose>
            <when test="scid == 784">
                ((select sum(FLOW) qsl
                from TF_YWPN_HOURWATERYIELD_W
                where ITCD in (
                select ITEM
                from TF_YWPN_WATERYIELDCONFIG_W
                where FACTORY = 786
                and flag = 0)
                and time = h.time)-(select sum(FLOW) qsl
                from TF_YWPN_HOURWATERYIELD_W
                where ITCD in (
                select ITEM
                from TF_YWPN_WATERYIELDCONFIG_W
                where FACTORY = 785
                and flag = 0)
                and time = h.time)) qsl,
            </when>
            <otherwise>
                sum(FLOW) qsl,
            </otherwise>
        </choose>
        TIME uhour
        from TF_YWPN_HOURWATERYIELD_W h
        where time between substr(#{start},1,13) and substr(#{end},1,13)
        <if test="scid != 784">
            and ITCD in (
            select ITEM
            from TF_YWPN_WATERYIELDCONFIG_W
            where FACTORY = #{scid}
            and flag = 0
            )
        </if>
        group by TIME
        order by TIME desc
    </select>

    <select id="dayGslHistory" resultType="map">
        select TIME uday, sum(FLOW) gsl
        from TF_YWPN_DAYWATERYIELD_W
        where ITCD in (
            select ITEM
            from TF_YWPN_WATERYIELDCONFIG_W
            where FACTORY = #{scid}
              and flag = 1
        )
          and time between substr(#{start}, 1, 10) and substr(#{end}, 1, 10)
        group by TIME
        order by TIME desc
    </select>

    <select id="dayQslHistory" resultType="map">
        select
        <choose>
            <when test="scid == 784">
                ((select sum(FLOW) qsl
                from TF_YWPN_DAYWATERYIELD_W
                where ITCD in (
                select ITEM
                from TF_YWPN_WATERYIELDCONFIG_W
                where FACTORY = 786
                and flag = 0)
                and time = h.time)-(select sum(FLOW) qsl
                from TF_YWPN_DAYWATERYIELD_W
                where ITCD in (
                select ITEM
                from TF_YWPN_WATERYIELDCONFIG_W
                where FACTORY = 785
                and flag = 0)
                and time = h.time)) qsl,
            </when>
            <otherwise>
                sum(FLOW) qsl,
            </otherwise>
        </choose>
        TIME uday
        from TF_YWPN_DAYWATERYIELD_W h
        where time between substr(#{start},1,10) and substr(#{end},1,10)
        <if test="scid != 784">
            and ITCD in (
            select ITEM
            from TF_YWPN_WATERYIELDCONFIG_W
            where FACTORY = #{scid}
            and flag = 0
            )
        </if>
        group by TIME
        order by TIME desc
    </select>

    <select id="getwaterVolume" resultType="map">
        select (
        <choose>
            <when test="scid == 784">
                (
                <include refid="getWaterYieldDay">
                    <property name="scid" value="786"/>
                    <property name="flag" value="0"/>
                </include>
                ) - (
                <include refid="getWaterYieldDay">
                    <property name="scid" value="785"/>
                    <property name="flag" value="0"/>
                </include>
                )
            </when>
            <otherwise>
                <include refid="getWaterYieldDay">
                    <property name="scid" value="#{scid}"/>
                    <property name="flag" value="0"/>
                </include>
            </otherwise>
        </choose>
        ) qsl,
        (
        <include refid="getWaterYieldDay">
            <property name="scid" value="#{scid}"/>
            <property name="flag" value="1"/>
        </include>
        ) gsl
        from DUAL
    </select>

    <sql id="getWaterYieldDay">
        select sum(FLOW) val
        from TF_YWPN_DAYWATERYIELD_W
        where ITCD in (select ITEM
                       from TF_YWPN_WATERYIELDCONFIG_W
                       where FACTORY = ${scid}
                         and flag = ${flag})
          and time = to_char(sysdate - 1, 'yyyy-mm-dd')
    </sql>

    <select id="getStationHistory" resultType="map">
        select round(sum(SJDL) / nullif(sum(GSL), 0) / 10,4) DWHD,
        UP_DATE
        from TF_YWPN_COSTPRESTATION_W s
        where mark = '1'
        <if test="start != null and end != null">
            and to_char(UP_DATE,'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        </if>
        <if test="start == null and end == null">
            and up_date between add_months(sysdate,-12) and sysdate
        </if>
        group by up_date
        order by up_date desc
    </select>

    <select id="getWaterValHistory" resultType="map">
        select to_char(UDAY,'yyyy-mm-dd') uday,sum(${param}) ${param}
        from TF_YWPN_WATERTREND_W
        where SCID = #{scid}
        <if test="start != null and end != null">
            and to_char(uday,'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        </if>
        <if test="start == null and end == null">
            and uday between add_months(sysdate,-3) and sysdate
        </if>
        group by to_char(UDAY,'yyyy-mm-dd')
        order by uday desc
    </select>

    <select id="getConsumeHistory" resultType="map">
        select
        <choose>
            <when test="'zsl_one'.equals(param.toLowerCase())">
                ZSL_ONE + ZSL_HQSK ZSL_ONE,
            </when>
            <otherwise>
                ${param},
            </otherwise>
        </choose>
        UP_DATE
        from TF_YWPN_COSTRLWATER_W
        where MARK = 0
        <if test="start != null and end != null ">
            and to_char(UP_DATE,'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        </if>
        <if test="start == null and end == null">
            and UP_DATE between add_months(sysdate,-3) and sysdate
        </if>
        order by UP_DATE
    </select>

    <select id="getIndexHistory" resultType="map">
        select ITNUM_VAL ITVAL, SCADA_TIME
        from TF_YWPN_SCADAHISTORY_R_VIEW
        where ITCD = #{param}
        <if test="start != null and end != null ">
            and to_char(SCADA_TIME,'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        </if>
        <if test="start == null and end == null">
            and SCADA_TIME between add_months(sysdate,-3) and sysdate
        </if>
    </select>

    <select id="getPowerHistory" resultType="map">
        select UP_DATE, ${param}
        from TF_YWPN_COSTRLWATER_W
        where MARK = '0'
        <if test="start != null and end != null">
            and to_char(up_date,'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        </if>
        <if test="start == null and end == null">
            and up_date between add_months(sysdate,-3) and sysdate
        </if>
        order by UP_DATE desc
    </select>

    <select id="getStationPower" resultType="long">
        select round(sum(SJDL) / nullif(sum(GSL), 0) / 10, 4) dh
        from TF_YWPN_COSTPRESTATION_W
        where to_char(UP_DATE, 'yyyy-mm') = to_char(add_months(sysdate, -1), 'yyyy-mm')
          and MARK = '1'
    </select>

    <select id="getValue" resultType="map">
        select PAC_ONE                                      pacone,
               PAC_TWO                                      pactwo,
               SY_ONE                                       syone,
               YL_TWO                                       yltwo,
               round(DLDL_ONE / nullif(ZSL_ONE * 10, 0), 4) dhone,
               round(DLDL_TWO / nullif(ZSL_TWO * 10, 0), 4) dhtwo,
               ZSL_ONE + ZSL_HQSK                           ZSL_ONE,
               ZSL_TWO,
               CN,
               CN_TWO
        from TF_YWPN_COSTRLWATER_W
        where MARK = '0'
          and to_char(UP_DATE, 'yyyy-mm-dd') = to_char(sysdate - 1, 'yyyy-mm-dd')

    </select>

    <select id="getRealVal" resultType="map">
        select ITCD,ITNUM_VAL ITVAL,SCADA_TIME
        from TF_YWPN_SCADAREALTIME_R
        where ITCD in
        <foreach collection="list" item="itcd" open="(" separator="," close=")">
            #{itcd}
        </foreach>
    </select>

    <select id="monthNrw" resultType="map">
        select round(((nvl(GSL_TOTAL, 0) +
                       nvl(GSL_QBJ, 0) -
                       nvl(SSL_TOTAL, 0)) /
                      nullif(nvl(GSL_TOTAL, 0) + nvl(GSL_QBJ, 0), 0) * 100),
                     2)                    nrw,
               extract(month from UP_DATE) month
        from TF_YWPN_COSTRLWATER_W
        where extract(year from UP_DATE) = extract(year from sysdate)
          and MARK = '1'
        order by month
    </select>

    <select id="yearNrwPlan" resultType="double">
        select round(((nvl(sum(GSL_TOTAL), 0) +
                       nvl(sum(GSL_QBJ), 0) -
                       nvl(sum(SSL_TOTAL), 0)) /
                      nullif(nvl(sum(GSL_TOTAL), 0) + nvl(sum(GSL_QBJ), 0), 0) * 100), 2) nrw
        from TF_YWPN_COSTBGWATER_W tbg
        where extract(year from sysdate) =
              (select YEAR from TF_YWPN_COSTBGWATERYEAR_W tbgYear where tbg.YEAR_ID = tbgYear.ID)
        group by YEAR_ID
    </select>

    <select id="yearNrw" resultType="double">
        select round(((nvl(sum(GSL_TOTAL), 0) +
                       nvl(sum(GSL_QBJ), 0) -
                       nvl(sum(SSL_TOTAL), 0)) /
                      nullif(nvl(sum(GSL_TOTAL), 0) + nvl(sum(GSL_QBJ), 0), 0) * 100), 2) nrw
        from TF_YWPN_COSTRLWATER_W
        where extract(year from UP_DATE
                  ) = extract(year from sysdate)
          and MARK = '1'
        group by extract(year from UP_DATE
                     )
    </select>

    <select id="monthLeakage" resultType="map">
        select trunc(((nvl(GSL_TOTAL, 0) + nvl(GSL_QBJ, 0) - nvl(SSL_TOTAL, 0) -
                       nvl(WSPSL, 0)) / nullif(nvl(GSL_TOTAL, 0) + nvl(GSL_QBJ, 0), 0) * 100), 4) leakage,
               extract(month from UP_DATE)                                                        month
        from TF_YWPN_COSTRLWATER_W
        where extract(year from UP_DATE) = extract(year from sysdate)
          and MARK = '1'
        order by month
    </select>

    <select id="yearLeakage" resultType="double">
        select trunc(((nvl(sum(GSL_TOTAL), 0) + nvl(sum(GSL_QBJ), 0) -
                       nvl(sum(SSL_TOTAL), 0) - nvl(sum(WSPSL), 0)) /
                      nullif(nvl(sum(GSL_TOTAL), 0) + nvl(sum(GSL_QBJ), 0), 0) * 100), 4) leakage
        from TF_YWPN_COSTRLWATER_W
        where extract(year from UP_DATE
                  ) = extract(year from sysdate)
          and MARK = '1'
        group by extract(year from UP_DATE
                     )
    </select>

    <select id="yearLeakagePlan" resultType="double">
        select trunc(((nvl(sum(GSL_TOTAL), 0) + nvl(sum(GSL_QBJ), 0) -
                       nvl(sum(SSL_TOTAL), 0) - nvl(sum(WSPSL), 0)) /
                      nullif(nvl(sum(GSL_TOTAL), 0) + nvl(sum(GSL_QBJ), 0), 0) * 100), 4) leakage
        from TF_YWPN_COSTBGWATER_W tbg
        where extract(year from sysdate) =
              (select YEAR from TF_YWPN_COSTBGWATERYEAR_W tbgYear where tbg.YEAR_ID = tbgYear.ID)
        group by YEAR_ID
    </select>

       <select id="monSupSellWater" resultType="map">
        select round(GSL_TOTAL, 4) gsl,
               round(SSL_TOTAL, 4) ssl,
               extract(month from UP_DATE
                   )               month
        from TF_YWPN_COSTRLWATER_W
        where MARK = '1'
          and extract(year from sysdate) = extract(year from UP_DATE)
        order by month
    </select>

    <select id="monSupSellWaterPlan" resultType="map">
        select round(GSL_TOTAL, 4) gsl, round(SSL_TOTAL, 4) ssl, MONTH
        from TF_YWPN_COSTBGWATER_W tbg
        where extract(year from sysdate) = (select year from TF_YWPN_COSTBGWATERYEAR_W year where tbg.YEAR_ID = year.ID)
    </select>

    <select id="yearSupSellWater" resultType="map">
        select round(sum(GSL_TOTAL), 4) gsl,
               round(sum(SSL_TOTAL), 4) ssl
        from TF_YWPN_COSTRLWATER_W
        where MARK = '1'
          and extract(year from sysdate) = extract(year from UP_DATE)
        group by extract(year from UP_DATE)
    </select>

    <select id="yearSupSellWaterPlan" resultType="map">
        select round(sum(GSL_TOTAL), 4) gsl, round(sum(SSL_TOTAL), 4) ssl
        from TF_YWPN_COSTBGWATER_W tbg
        where extract(year from sysdate) = (select year from TF_YWPN_COSTBGWATERYEAR_W year where tbg.YEAR_ID = year.ID)
        group by YEAR_ID
    </select>

    <select id="monthFixed" resultType="map">
        select to_char(fixed.UP_DATE, 'yyyy-mm') month,
               DWCB_TOTAL                        cost
        from TF_YWPN_COSTRLFIXED_W fixed
        where fixed.MARK = '1'
          and to_char(fixed.UP_DATE, 'yyyy') = extract(year from sysdate)
        order by month
    </select>

    <select id="yearFixed" resultType="double">
        select round((sum(ZFY) / nullif(sum(GSL_TOTAL), 0)) * 1000, 4) cost
        from TF_YWPN_COSTRLFIXED_W fixed
                 full join TF_YWPN_COSTRLWATER_W TYCW
                           on to_char(fixed.UP_DATE, 'yyyy-MM-dd') = to_char(TYCW.UP_DATE, 'yyyy-MM-dd')
                               and fixed.MARK = TYCW.MARK
        where fixed.MARK = '1'
          and extract(year from fixed.UP_DATE) = extract(year from sysdate)
    </select>

    <select id="yearFixedPlan" resultType="double">
        select round((sum(ZFY) / nullif(sum(GSL_TOTAL), 0)) * 1000, 4) cost
        from TF_YWPN_COSTBGFIXED_W fixed
                 full join TF_YWPN_COSTBGWATER_W tycw
                           on fixed.MOUTH = tycw.MONTH
        where substr(fixed.MOUTH, 1, 4) = extract(year from sysdate)
    </select>

    <select id="getTodayWater" resultType="double">
        select ITNUM_VAL itval
        from TF_YWPN_SCADAHISTORY_R_VIEW
        where SCADA_TIME >= to_date(concat(to_char(sysdate, 'yyyy-mm-dd'), ' 08:00:00'), 'yyyy-mm-dd HH24:mi:ss')
          and itcd = #{itcd}
          and rownum = 1
    </select>

    <select id="getYesterday" resultType="double">
        select ITNUM_VAL itval
        from TF_YWPN_SCADAHISTORY_R_VIEW
        where SCADA_TIME >= to_date(concat(to_char(sysdate - 1, 'yyyy-mm-dd'), ' 08:00:00'), 'yyyy-mm-dd HH24:mi:ss')
          and itcd = #{itcd}
          and rownum = 1
    </select>

    <select id="medicine" resultType="map">
        select (decode(PAC_ONE, null, 0, PAC_ONE) + decode(SY_ONE, null, 0, SY_ONE)) ychl,
               (decode(PAC_TWO, null, 0, PAC_TWO) + decode(YL_TWO, null, 0, YL_TWO)) echl
        from TF_YWPN_COSTRLWATER_W
        where rownum = 1
          and MARK = '0'
          and UP_DATE &lt;= to_date(concat(to_char(sysdate, 'yyyy-mm-dd'), ' 00:00:00'), 'yyyy-mm-dd hh24:mi:ss')
    </select>

    <select id="power" resultType="map">
        select DH_ONE ycdh, DH_TWO ecdh
        from TF_YWPN_COSTRLUNIT_W
        where rownum = 1
          and MARK = '0'
          and UP_DATE
            &lt;= to_date(concat(to_char(sysdate, 'yyyy-mm-dd'), ' 00:00:00'), 'yyyy-mm-dd hh24:mi:ss')
    </select>

    <select id="nrwByMonth" resultType="map">
        select round(CXC,2) nrw,
        to_char(UP_DATE
        ,'yyyy-mm') month
        from TF_YWPN_COSTRLWATER_W
        where MARK = 1
        <if test="year != null and code == 0">
            and extract(year from UP_DATE
            ) = #{year}
        </if>
        <if test="code == 2">
            and extract(year from UP_DATE
            ) between extract(year from sysdate) - 3 and extract(year from sysdate)
        </if>
        order by month
    </select>

    <select id="nrwByCodePlan" resultType="map">
        select
        round(CXC,2) nrw,
        month
        from TF_YWPN_COSTBGWATER_W
        <where>
            <if test="year != null and code == 0">
                substr(MONTH,1,4) = #{year}
            </if>
            <if test="code == 2">
                substr(MONTH,1,4) between extract(year from sysdate) - 3 and extract(year from sysdate)
            </if>
            order by month
        </where>

    </select>

    <select id="nrwByQuarterly" resultType="map">
        select round(((sum(GSL_TOTAL) + sum(GSL_QBJ) - sum(SSL_TOTAL)) /
                      nullif(sum(GSL_TOTAL) + sum(GSL_QBJ), 0) * 100), 2) nrw,
               to_char(UP_DATE, 'Q')                                      que,
               extract(year from UP_DATE)                                 year
        from TF_YWPN_COSTRLWATER_W
        where MARK = 1
          and to_char(UP_DATE, 'yyyy') = #{year}
        group by to_char(UP_DATE, 'Q'), extract(year from UP_DATE)
        order by year, que
    </select>

    <select id="nrwByQuarterlyPlan" resultType="map">
        select round(((sum(GSL_TOTAL) - sum(SSL_TOTAL) + sum(GSL_QBJ)) /
                      nullif(sum(GSL_TOTAL) + sum(GSL_QBJ), 0) * 100), 2) nrw,
               to_char(to_date(MONTH, 'yyyy-mm'), 'Q')                    que,
               substr(MONTH, 1, 4)                                        year
        from TF_YWPN_COSTBGWATER_W
        where substr(MONTH, 1, 4) = #{year}
        group by to_char(to_date(MONTH, 'yyyy-mm'), 'Q'), substr(MONTH, 1, 4)
        order by year, que
    </select>

    <select id="leakageByMonth" resultType="map">
        select round(LSL,4) leakage,
        to_char(UP_DATE
        ,'yyyy-mm') month
        from TF_YWPN_COSTRLWATER_W
        where MARK = '1'
        <if test="year != null and code == 0">
            and to_char(UP_DATE,'yyyy') = #{year}
        </if>
        <if test="code == 2">
            and to_char(UP_DATE,'yyyy') between extract(year from sysdate) - 3 and extract(year from sysdate)
        </if>
        order by month
    </select>

    <select id="leakageByCodePlan" resultType="map">
        select round(LSL,4) leakage,
        month
        from TF_YWPN_COSTBGWATER_W
        <where>
            <if test="year != null and code == 0">
                substr(MONTH,1,4) = #{year}
            </if>
            <if test="code == 2">
                substr(MONTH,1,4) between extract(year from sysdate) - 3 and extract(year from sysdate)
            </if>
            order by month
        </where>
    </select>

    <select id="leakageByQuarterly" resultType="map">
        select round(((sum(GSL_TOTAL) -
                       sum(SSL_TOTAL) +
                       sum(GSL_QBJ) -
                       sum(WSPSL)) / nullif(sum(GSL_TOTAL) + sum(GSL_QBJ), 0) *
                      100), 2)            leakage,
               to_char(UP_DATE, 'Q')      que,
               extract(year from UP_DATE) year
        from TF_YWPN_COSTRLWATER_W
        where MARK = '1'
          and to_char(UP_DATE, 'yyyy') = #{year}
        group by to_char(UP_DATE, 'Q'), extract(year from UP_DATE)
        order by year, que
    </select>

    <select id="leakageByQuarterlyPlan" resultType="map">
        select round(((sum(GSL_TOTAL) -
                       sum(SSL_TOTAL) -
                       sum(WSPSL) +
                       sum(GSL_QBJ)) /
                      nullif(sum(GSL_TOTAL) + sum(GSL_QBJ), 0) * 100),
                     2)                                leakage,
               to_char(to_date(MONTH, 'yyyy-mm'), 'Q') que,
               substr(MONTH, 1, 4)                     year
        from TF_YWPN_COSTBGWATER_W
        where substr(MONTH, 1, 4) = #{year}
        group by to_char(to_date(MONTH, 'yyyy-mm'), 'Q'), substr(MONTH, 1, 4)
        order by year, que
    </select>

    <select id="supSellMore" resultType="map">
        select round(GSL_TOTAL, 4) gsl,
        round(SSL_TOTAL, 4) ssl,
        to_char(UP_DATE,'yyyy-mm') month
        from TF_YWPN_COSTRLWATER_W
        where MARK = '1'
        <if test="code == 0">
            and to_char(UP_DATE,'yyyy') = #{year}
        </if>
        <if test="code == 2">
            and to_char(UP_DATE,'yyyy') between extract(year from sysdate) - 3 and extract(year from sysdate)
        </if>
        order by month
    </select>

    <select id="supSellMoreQuarterly" resultType="map">
        select round(sum(GSL_TOTAL), 4)   gsl,
               round(sum(SSL_TOTAL), 4)   ssl,
               to_char(UP_DATE, 'Q')      que,
               extract(year from UP_DATE) year
        from TF_YWPN_COSTRLWATER_W
        where MARK = '1'
          and extract(year from UP_DATE) = #{year}
        group by to_char(UP_DATE, 'Q'), extract(year from UP_DATE)
        order by year, que
    </select>

    <select id="supSellMorePlan" resultType="map">
        select round(GSL_TOTAL, 4) gsl,
        round(SSL_TOTAL, 4) ssl,
        MONTH
        from TF_YWPN_COSTBGWATER_W
        <where>
            <if test="code == 0">
                substr(MONTH,1,4) = #{year}
            </if>
            <if test="code == 2">
                substr(MONTH,1,4) between extract(year from sysdate) - 3 and extract(year from sysdate)
            </if>
            order by month
        </where>
    </select>

    <select id="supSellMoreQuarterlyPlan" resultType="map">
        select round(sum(GSL_TOTAL), 4)                gsl,
               round(sum(SSL_TOTAL), 4)                ssl,
               to_char(to_date(MONTH, 'yyyy-mm'), 'Q') que,
               substr(MONTH, 1, 4)                     year
        from TF_YWPN_COSTBGWATER_W
        where substr(MONTH, 1, 4) = #{year}
        group by to_char(to_date(MONTH, 'yyyy-mm'), 'Q'), substr(MONTH, 1, 4)
        order by year, que
    </select>

    <select id="firstPlantFixed" resultType="map">
        select round(DWCB_ONE,4) fixed,
        to_char(fixed.UP_DATE,'yyyy-mm') mon
        from TF_YWPN_COSTRLFIXED_W fixed
        where fixed.MARK = 1
        <if test="code == 0">
            and extract(year from fixed.UP_DATE) = #{year}
        </if>
        <if test="code == 2">
            and to_char(fixed.UP_DATE,'yyyy')
            between to_char(add_months(to_date(#{year},'yyyy'),-36),'yyyy') and #{year}
        </if>
        order by mon
    </select>

    <select id="firstPlantFixedYear" resultType="map">
        select round((sum(ZFY_ONE) / nullif(sum(tycw.GSL_ONE), 0)) * 1000, 4) info,
               extract(year from fixed.UP_DATE)                               year
        from TF_YWPN_COSTRLFIXED_W fixed
                 full join TF_YWPN_COSTRLWATER_W tycw
                           on to_char(tycw.UP_DATE, 'yyyy-mm') = to_char(fixed.UP_DATE, 'yyyy-mm')
                               and tycw.MARK = fixed.MARK
        where tycw.MARK = 1
          and extract(year from fixed.UP_DATE) = #{year}
        group by extract(year from fixed.UP_DATE)
    </select>

    <select id="secondPlantFixed" resultType="map">
        select round(DWCB_TWO,4) fixed,
        to_char(fixed.UP_DATE,'yyyy-mm') mon
        from TF_YWPN_COSTRLFIXED_W fixed
        where fixed.MARK = 1
        <if test="code == 0">
            and extract(year from fixed.UP_DATE) = #{year}
        </if>
        <if test="code == 2">
            and to_char(fixed.UP_DATE,'yyyy')
            between to_char(add_months(to_date(#{year},'yyyy'),-36),'yyyy') and #{year}
        </if>
        order by mon
    </select>


    <select id="secondPlantFixedYear" resultType="map">
        select round((sum(ZFY_TWO), 0 /
                                    nullif(sum(GSL_TWO), 0)) * 1000, 4) fixed,
               extract(year from fixed.UP_DATE)                         year
        FROM TF_YWPN_COSTRLFIXED_W fixed
                 left join TF_YWPN_COSTRLWATER_W w
                           on to_char(fixed.UP_DATE, 'yyyy-mm') = to_char(w.UP_DATE, 'yyyy-mm') and fixed.MARK = w.MARK
        where fixed.MARK = 1
          and extract(year from fixed.UP_DATE) = #{year}
        group by extract(year from fixed.UP_DATE)
    </select>

    <select id="firstPlantFixedPlan" resultType="map">
        select
        round(DWCB_ONE,4) fixed,
        fixed.MOUTH
        from TF_YWPN_COSTBGFIXED_W fixed
        <where>
            <if test="code == 0">
                substr(fixed.mouth,1,4) = #{year}
            </if>
            <if test="code == 2">
                substr(fixed.mouth,1,4) between to_char(add_months(to_date(#{year},'yyyy'),-36),'yyyy') and #{year}
            </if>
        </where>
        order by fixed.MOUTH
    </select>

    <select id="firstPlantFixedPlanYear" resultType="map">
        select round(sum(ZFY_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 3) info,
               substr(MOUTH, 1, 4)                                     year
        from TF_YWPN_COSTBGFIXED_W fixed
                 full join TF_YWPN_COSTBGWATER_W tycw
                           on tycw.MONTH = fixed.MOUTH
        where substr(MOUTH, 1, 4) = #{year}
        group by substr(MOUTH, 1, 4)
    </select>

    <select id="secondPlantFixedPlan" resultType="map">
        select round(DWCB_TWO,4) fixed,MOUTH
        from TF_YWPN_COSTBGFIXED_W fixed
        <where>
            <if test="code == 0">
                substr(fixed.mouth,1,4) = #{year}
            </if>
            <if test="code == 2">
                substr(fixed.mouth,1,4) between to_char(add_months(to_date(#{year},'yyyy'),-36),'yyyy') and #{year}
            </if>
        </where>
        order by fixed.MOUTH
    </select>

    <select id="secondPlantFixedPlanYear" resultType="map">
        select round(sum(ZFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4) fixed,
               substr(MOUTH, 1, 4)                                     year
        from TF_YWPN_COSTBGFIXED_W fixed
                 full join TF_YWPN_COSTBGWATER_W tycw
                           on tycw.MONTH = fixed.MOUTH
        where substr(MOUTH, 1, 4) = #{year}
        group by substr(MOUTH, 1, 4)
    </select>

    <select id="firstPlantQue" resultType="map">
        select round(sum(fixed.ZFY_ONE) / nullif(sum(tycw.GSL_ONE), 0) * 1000, 4) fixed,
               to_char(fixed.UP_DATE, 'Q')                                        que,
               extract(year from fixed.UP_DATE)                                   year
        from TF_YWPN_COSTRLFIXED_W fixed
                 full join TF_YWPN_COSTRLWATER_W tycw
                           on to_char(tycw.UP_DATE
                                  , 'yyyy-mm') = to_char(fixed.UP_DATE
                                  , 'yyyy-mm')
        where extract(year from fixed.UP_DATE) = #{year}
        group by to_char(fixed.UP_DATE, 'Q'), extract(year from fixed.UP_DATE)
        order by year, que
    </select>

    <select id="secondPlantQue" resultType="map">
        select round(sum(fixed.ZFY_TWO) /
                     nullif(sum(tycw.GSL_TWO), 0) * 1000, 4) fixed,
               to_char(fixed.UP_DATE, 'Q')                   que,
               extract(year from fixed.UP_DATE)              year
        from TF_YWPN_COSTRLFIXED_W fixed
                 full join TF_YWPN_COSTRLWATER_W tycw
                           on to_char(tycw.UP_DATE, 'yyyy-mm') = to_char(fixed.UP_DATE, 'yyyy-mm')
        where extract(year from fixed.UP_DATE) = #{year}
        group by to_char(fixed.UP_DATE, 'Q'), extract(year from fixed.UP_DATE)
        order by year, que
    </select>

    <select id="firstPlantQuePlan" resultType="map">
        select round(sum(fixed.ZFY_ONE) /
                     nullif(sum(tycw.GSL_ONE), 0) * 1000, 4) fixed,
               to_char(to_date(fixed.MOUTH, 'yyyy-mm'), 'Q') que,
               substr(fixed.mouth, 1, 4)                     year
        from TF_YWPN_COSTBGFIXED_W fixed
                 full join TF_YWPN_COSTBGWATER_W tycw
                           on tycw.MONTH = fixed.MOUTH
        where substr(fixed.mouth, 1, 4) = #{year}
        group by to_char(to_date(fixed.MOUTH, 'yyyy-mm'), 'Q'), substr(fixed.mouth, 1, 4)
        order by que
    </select>

    <select id="secondPlantQuePlan" resultType="map">
        select round(sum(fixed.ZFY_TWO) /
                     nullif(sum(tycw.GSL_TWO), 0) * 1000, 4) fixed,
               to_char(to_date(fixed.MOUTH, 'yyyy-mm'), 'Q') que,
               substr(fixed.mouth, 1, 4)                     year
        from TF_YWPN_COSTBGFIXED_W fixed
                 full join TF_YWPN_COSTBGWATER_W tycw
                           on tycw.MONTH = fixed.MOUTH
        where substr(fixed.mouth, 1, 4) = #{year}
        group by to_char(to_date(fixed.MOUTH, 'yyyy-mm'), 'Q'), substr(fixed.mouth, 1, 4)
        order by que
    </select>

    <select id="getWarn" resultType="map">
        select warn_type,
               id,
               (select RANGEID
                from TF_YWPN_SCADASTATION_B
                where ID = (select STATION_ID
                            from TF_YWPN_SCADASTAITEM_W
                            where TF_YWPN_SCADASTAITEM_W.ITCD = TF_YWPN_WARN_W.ITCD)) RANGE,
               notes,
               ITCD,
               address,
               num,
               isconfirm,
               isclear,
               scada_time
        from TF_YWPN_WARN_W
        order by SCADA_TIME desc
    </select>


    <select id="getWarHistory" resultType="map">
        select v.id,
        v.itcd,
        (select ITNUM_VAL from TF_YWPN_SCADAREALTIME_R where ITCD = v.ITCD and ROWNUM = 1) real_val,
        warn_type,
        (select CNAME from TF_YWPN_SYSCHILDCODE_D where CCODE = warn_type and PCID = 845) type_name,
        STNM station_name,
        v.notes,
        address,
        v.num,
        isconfirm,
        isclear,
        scada_time,
        round((sysdate - SCADA_TIME) * 24 * 60, 2) interval_time
        from TF_YWPN_WARNHISTORY_W_VIEW v
        left join TF_YWPN_SCADASTAITEM_W s on s.ITCD = v.ITCD
        left join TF_YWPN_SCADASTATION_B sta on sta.ID = s.STATION_ID
        where (IS_WARN = 1 or WARN_TYPE = 2)
        <if test="type != null">
            and WARN_TYPE = #{type}
        </if>
        <if test="start != null and end != null">
            and to_char(scada_time,'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        </if>
        <if test="isclear != null">
            and isclear = #{isclear}
        </if>
        <if test="isconfirm != null">
            and isconfirm = #{isconfirm}
        </if>
    </select>

    <select id="countWarnType" resultType="map">
        select (select CNAME from TF_YWPN_SYSCHILDCODE_D where PCID = 845 and CCODE = WARN_TYPE) typeName,
               count(WARN_TYPE)                                                                  sum
        from TF_YWPN_WARN_W a
                 left join TF_YWPN_SCADASTAITEM_W b on a.ITCD = b.ITCD
                 left join TF_YWPN_SCADASTATION_B c on b.STATION_ID = c.ID
        where (c.IS_WARN = 1
            or WARN_TYPE = 2)
          and WARN_TYPE is not null
        group by WARN_TYPE
    </select>

    <select id="getRealIndexInfo" resultType="com.tofly.xrtygis.custom.entity.vo.IndexInfoVo">
        select ID,ITCD,ITNUM_VAL ITVAL
        from TF_YWPN_SCADAREALTIME_R
        where ITCD in
        <foreach collection="list" item="itcd" open="(" close=")" separator=",">
            #{itcd}
        </foreach>
    </select>

    <select id="existWarn" resultType="map">
        select WARN_TYPE
        from TF_YWPN_WARN_W
        where ITCD = #{itcd,jdbcType = VARCHAR}
    </select>

    <select id="getWarnType" resultType="map">
        select distinct (select CNAME from TF_YWPN_SYSCHILDCODE_D where PCID = 845 and CCODE = WARN_TYPE) type_name,
                        WARN_TYPE
        from TF_YWPN_WARNHISTORY_W_VIEW
    </select>

    <select id="getEveryCostOne" resultType="map">
        select round(sum(YSF) / nullif(sum(GSL_TOTAL), 0) * 1000, 4)                      YSFCB,
               round(sum(SZYSF_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4)                  SZYSFCB_ONE,
               round((sum(JBDF_ONE) + sum(DLDF_ONE)) / nullif(sum(GSL_ONE), 0) * 1000, 4) DFCB_ONE,
               round(sum(ZZSCLFY_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4)                ZSCLCB_ONE,
               round(sum(GSL_ONE), 4)                                                     GSL_ONE
        from TF_YWPN_COSTRLFIXED_W f,
             TF_YWPN_COSTRLWATER_W w
        where to_char(f.UP_DATE, 'yyyy') = to_char(w.UP_DATE, 'yyyy')
          and f.MARK = w.MARK
          and f.MARK = 1
          and to_char(f.UP_DATE, 'yyyy') = #{year}
    </select>

    <select id="getEveryCostOneMonth" resultType="map">
        select round(YSF, 4)                 YSFCB,
               round(SZYSF_ONE, 4)           SZYSFCB_ONE,
               round(DLDL_ONE + JBDF_ONE, 4) DFCB_ONE,
               round(ZZSCLFY_ONE, 4)         ZSCLCB_ONE,
               round(GSL_ONE, 4)             GSL_ONE,
               to_char(f.UP_DATE, 'yyyy-mm') month
        from TF_YWPN_COSTRLFIXED_W f,
             TF_YWPN_COSTRLWATER_W w
        where to_char(f.UP_DATE, 'yyyy-mm') = to_char(w.UP_DATE, 'yyyy-mm')
          and f.MARK = w.MARK
          and f.MARK = 1
          and to_char(f.UP_DATE, 'yyyy') = #{year}
        order by month
    </select>

    <select id="getEveryCostOneQue" resultType="map">
        select round(sum(YSF), 4)                      YSFCB,
               round(sum(SZYSF_ONE), 4)                SZYSFCB_ONE,
               round(sum(DLDF_ONE) + sum(JBDF_ONE), 4) DFCB_ONE,
               round(sum(ZZSCLFY_ONE), 4)              ZSCLCB_ONE,
               round(sum(GSL_ONE), 4)                  GSL_ONE,
               to_char(f.UP_DATE, 'Q')                 que
        from TF_YWPN_COSTRLFIXED_W f,
             TF_YWPN_COSTRLWATER_W w
        where to_char(f.UP_DATE, 'yyyy-mm') = to_char(w.UP_DATE, 'yyyy-mm')
          and f.MARK = w.MARK
          and f.MARK = 1
          and to_char(f.UP_DATE, 'yyyy') = #{year}
        group by to_char(f.UP_DATE, 'Q')
        order by que
    </select>

    <select id="getEveryCostTwo" resultType="map">
        select round(sum(SZYSF_TWO), 4)                SZYSFCB_TWO,
               round(sum(DLDF_TWO) + sum(JBDF_TWO), 4) DFCB_TWO,
               round(sum(ZZSCLFY_TWO), 4)              ZSCLCB_TWO,
               round(sum(GSL_TWO), 4)                  GSL_TWO
        from TF_YWPN_COSTRLFIXED_W f,
             TF_YWPN_COSTRLWATER_W w
        where to_char(f.UP_DATE, 'yyyy') = to_char(w.UP_DATE, 'yyyy')
          and f.MARK = w.MARK
          and f.MARK = 1
          and to_char(f.UP_DATE, 'yyyy') = #{year}
    </select>

    <select id="getEveryCostTwoMonth" resultType="map">
        select round(SZYSF_TWO, 4)           SZYSFCB_TWO,
               round(JBDF_TWO + DLDL_TWO, 4) DFCB_TWO,
               round(ZZSCLFY_TWO, 4)         ZSCLCB_TWO,
               round(GSL_TWO, 4)             GSL_TWO,
               to_char(f.UP_DATE, 'yyyy-mm') month
        from TF_YWPN_COSTRLFIXED_W f,
             TF_YWPN_COSTRLWATER_W w
        where to_char(f.UP_DATE, 'yyyy-mm') = to_char(w.UP_DATE, 'yyyy-mm')
          and f.MARK = w.MARK
          and f.MARK = 1
          and to_char(f.UP_DATE, 'yyyy') = #{year}
        order by month
    </select>

    <select id="getEveryCostTwoQue" resultType="map">
        select round(sum(SZYSF_TWO), 4)                SZYSFCB_TWO,
               round(sum(DLDF_TWO) + sum(JBDF_TWO), 4) DFCB_TWO,
               round(sum(ZZSCLFY_TWO), 4)              ZSCLCB_TWO,
               round(sum(GSL_TWO), 4)                  GSL_TWO,
               to_char(f.UP_DATE, 'Q')                 que
        from TF_YWPN_COSTRLFIXED_W f,
             TF_YWPN_COSTRLWATER_W w
        where to_char(f.UP_DATE, 'yyyy-mm') = to_char(w.UP_DATE, 'yyyy-mm')
          and f.MARK = w.MARK
          and f.MARK = 1
          and to_char(f.UP_DATE, 'yyyy') = #{year}
        group by to_char(f.UP_DATE, 'Q')
        order by que
    </select>

    <select id="getEveryCostAll" resultType="map">
        select round(sum(YSF) / nullif(sum(GSL_TOTAL), 0) * 1000, 4)                              YSFCB,
               round(sum(SZYSF_TOTAL) / nullif(sum(GSL_TOTAL), 0) * 1000, 4)                      SZYSFCB_TOTAL,
               round((sum(JBDF_TOTAL) + sum(DLDF_TOTAL)) / nullif(sum(GSL_TOTAL), 0) * 1000, 4)   DFCB_TOTAL,
               round((sum(ZZSCLFY_TWO) + sum(ZZSCLFY_ONE)) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) ZSCLCB_TOTAL,
               round(sum(GSL_TOTAL), 4)                                                           GSL_TOTAL
        from TF_YWPN_COSTRLFIXED_W f,
             TF_YWPN_COSTRLWATER_W w
        where to_char(f.UP_DATE, 'yyyy') = to_char(w.UP_DATE, 'yyyy')
          and f.MARK = w.MARK
          and f.MARK = 1
          and to_char(f.UP_DATE, 'yyyy') = #{year}
    </select>

    <select id="viewWarnInfo" resultType="com.tofly.xrtygis.entity.Warnhistory">
        select id,
               itcd,
               warn_type,
               isloc,
               notes,
               address,
               duration,
               num,
               isconfirm,
               isclear,
               confirm_time,
               confirm_user,
               scada_time,
               create_time
        from TF_YWPN_WARNHISTORY_W_VIEW
        where ID = #{id}
    </select>

    <select id="getEveryCostAllMonth" resultType="map">
        select round(YSF, 4)                       YSFCB,
               round(SZYSF_TOTAL, 4)               SZYSFCB_TOTAL,
               round(DLDF_TOTAL, 4)                DFCB_TOTAL,
               round(ZZSCLFY_ONE + ZZSCLFY_TWO, 4) ZSCLCB_TOTAL,
               round(GSL_TOTAL, 4)                 GSL_TOTAL,
               to_char(f.UP_DATE, 'yyyy-mm')       month
        from TF_YWPN_COSTRLFIXED_W f,
             TF_YWPN_COSTRLWATER_W w
        where to_char(f.UP_DATE, 'yyyy-mm') = to_char(w.UP_DATE, 'yyyy-mm')
          and f.MARK = w.MARK
          and f.MARK = 1
          and to_char(f.UP_DATE, 'yyyy') = #{year}
        order by month
    </select>

    <select id="getEveryCostAllQue" resultType="map">
        select round(sum(YSF), 4)                              YSFCB,
               round(sum(SZYSF_TOTAL), 4)                      SZYSFCB_TOTAL,
               round(sum(JBDF_TOTAL) + sum(DLDF_TOTAL), 4)     DFCB_TOTAL,
               round((sum(ZZSCLFY_TWO) + sum(ZZSCLFY_ONE)), 4) ZSCLCB_TOTAL,
               sum(GSL_TOTAL)                                  GSL_TOTAL,
               to_char(f.UP_DATE, 'Q')                         que
        from TF_YWPN_COSTRLFIXED_W f,
             TF_YWPN_COSTRLWATER_W w
        where to_char(f.UP_DATE, 'yyyy-mm') = to_char(w.UP_DATE, 'yyyy-mm')
          and f.MARK = w.MARK
          and f.MARK = 1
          and to_char(f.UP_DATE, 'yyyy') = #{year}
        group by to_char(f.UP_DATE, 'Q')
        order by que
    </select>

    <select id="allFixed" resultType="map">
        select round(DWCB_TOTAL,4) fixed,
        to_char(f.UP_DATE,'yyyy-mm') month
        from TF_YWPN_COSTRLFIXED_W f
        where f.MARK = 1
        <if test="code == 0">
            and to_char(f.UP_DATE, 'yyyy') = #{year}
        </if>
        <if test="code == 2">
            and to_char(f.UP_DATE, 'yyyy') between to_char(add_months(to_date(#{year},'yyyy'),-36),'yyyy') and #{year}
        </if>
        order by month
    </select>

    <select id="allFixedYear" resultType="map">
        select round((sum(ZFY) / nullif(sum(GSL_TOTAL), 0)) * 1000, 4) info,
               to_char(f.UP_DATE, 'yyyy')                              year
        FROM TF_YWPN_COSTRLFIXED_W f
                 left join TF_YWPN_COSTRLWATER_W w
                           on to_char(f.UP_DATE, 'yyyy-mm') = to_char(w.UP_DATE, 'yyyy-mm') and f.MARK = w.MARK
        where f.MARK = 1
          and extract(year from f.UP_DATE) = #{year}
        group by to_char(f.UP_DATE, 'yyyy')
    </select>

    <select id="allFixedPlan" resultType="map">
        select round(DWCB_TOTAL,4) fixed,
        f.MOUTH month
        from TF_YWPN_COSTBGFIXED_W f,
        TF_YWPN_COSTBGWATER_W w
        where f.MOUTH = w.MONTH
        <if test="code == 0">
            and substr(f.MOUTH,1,4) = #{year}
        </if>
        <if test="code == 2">
            and substr(f.MOUTH,1,4) between to_char(add_months(to_date(#{year},'yyyy'),-36),'yyyy') and #{year}
        </if>
        order by month
    </select>

    <select id="allFixedPlanYear" resultType="map">
        select round(sum(ZFY) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) info,
               substr(MOUTH, 1, 4)                                   year
        from TF_YWPN_COSTBGFIXED_W f,
             TF_YWPN_COSTBGWATER_W w
        where f.MOUTH = w.MONTH
          and substr(f.MOUTH, 1, 4) = #{year}
        group by substr(MOUTH, 1, 4)
    </select>

    <select id="allFixedQue" resultType="map">
        select round(sum(ZFY) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) fixed,
               to_char(f.UP_DATE, 'Q')                               que
        from TF_YWPN_COSTRLFIXED_W f,
             TF_YWPN_COSTRLWATER_W w
        where to_char(f.UP_DATE, 'yyyy') = to_char(f.UP_DATE, 'yyyy')
          and f.MARK = w.MARK
          and f.MARK = 1
          and to_char(f.UP_DATE, 'yyyy') = #{year}
        group by to_char(f.UP_DATE, 'Q')
        order by que
    </select>

    <select id="allFixedQuePlan" resultType="map">
        select round(sum(ZFY) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) fixed,
               to_char(to_date(f.MOUTH, 'yyyy-mm'), 'Q')             que
        from TF_YWPN_COSTBGFIXED_W f,
             TF_YWPN_COSTBGWATER_W w
        where f.MOUTH = w.MONTH
          and substr(f.MOUTH, 1, 4) = #{year}
        group by to_char(to_date(f.MOUTH, 'yyyy-mm'), 'Q')
        order by que
    </select>

    <update id="changeHistory">
        update ${table}
        <set>
            ISCONFIRM = 1,
            CONFIRM_USER = #{userId},
            <if test="close != null">
                ISCLEAR = 1
            </if>
        </set>
        where id = #{id}

    </update>

    <select id="viewWarnHistory" resultType="date">
        select SCADA_TIME
        from TF_YWPN_WARNHISTORY_W_VIEW
        where ID = #{id}
    </select>

    <select id="getSumIndexInfo" resultType="double">
        select sum(ITVAL) itval
        from TF_YWPN_SCADAREALTIME_R
        where ITCD in
        <foreach collection="list" item="index" open="(" close=")" separator=",">
            #{index}
        </foreach>

    </select>

    <select id="getNrwByYear" resultType="map">
        select round(((nvl(sum(GSL_TOTAL), 0) +
                       nvl(sum(GSL_QBJ), 0) -
                       nvl(sum(SSL_TOTAL), 0)) /
                      nullif(sum(GSL_TOTAL) + sum(GSL_QBJ), 0) * 100),
                     2)                   info,
               extract(year from UP_DATE) year
        from TF_YWPN_COSTRLWATER_W
        where extract(year from UP_DATE) = #{year}
          and MARK = '1'
        group by extract(year from UP_DATE)
    </select>

    <select id="getNrwPlanByYear" resultType="map">
        select round(((nvl(sum(GSL_TOTAL), 0) +
                       nvl(sum(GSL_QBJ), 0) -
                       nvl(sum(SSL_TOTAL), 0)) /
                      nullif(nvl(sum(GSL_TOTAL), 0) + nvl(sum(GSL_QBJ), 0), 0) * 100),
                     2)            info,
               substr(MONTH, 1, 4) year
        from TF_YWPN_COSTBGWATER_W
        where substr(MONTH, 1, 4) = #{year}
        group by substr(MONTH, 1, 4)
    </select>

    <select id="getLeakageByYear" resultType="map">
        select round(((nvl(sum(GSL_TOTAL), 0) + nvl(sum(GSL_QBJ), 0) - nvl(sum(SSL_TOTAL), 0) -
                       nvl(sum(WSPSL), 0)) / nullif(nvl(sum(GSL_TOTAL), 0) + nvl(sum(GSL_QBJ), 0), 0) * 100),
                     2)                   info,
               extract(year from UP_DATE) year
        from TF_YWPN_COSTRLWATER_W
        where extract(year from UP_DATE) = #{year}
          and MARK = '1'
        group by extract(year from UP_DATE)
    </select>

    <select id="getLeakagePlanByYear" resultType="map">
        select round(((nvl(sum(GSL_TOTAL), 0) + nvl(sum(GSL_QBJ), 0) - nvl(sum(SSL_TOTAL), 0) -
                       nvl(sum(WSPSL), 0)) / nullif(nvl(sum(GSL_TOTAL), 0) + nvl(sum(GSL_QBJ), 0), 0) * 100),
                     2)            info,
               substr(MONTH, 1, 4) year
        from TF_YWPN_COSTBGWATER_W
        where substr(MONTH, 1, 4) = #{year}
        group by substr(MONTH, 1, 4)
    </select>

    <select id="getSupSellByYear" resultType="map">
        select round(sum(GSL_TOTAL), 4)   gsl,
               round(sum(SSL_TOTAL), 4)   ssl,
               extract(year from UP_DATE) year
        from TF_YWPN_COSTRLWATER_W
        where MARK = '1'
          and extract(year from UP_DATE) = #{year}
        group by extract(year from UP_DATE)
    </select>

    <select id="getSupSellPlanByYear" resultType="map">
        select round(sum(GSL_TOTAL), 4) gsl,
               round(sum(SSL_TOTAL), 4) ssl,
               substr(MONTH, 1, 4)      year
        from TF_YWPN_COSTBGWATER_W
        where substr(MONTH, 1, 4) = #{year}
        group by substr(MONTH, 1, 4)
    </select>

    <select id="getWarnInfo" resultType="map">
        select (select cname from TF_YWPN_SYSCHILDCODE_D where PCID = 845 and CCODE = WARN_TYPE) type_name,
        ADDRESS,
        itcd,
        WARN_TYPE,
        case
        when WARN_TYPE = 2
        then null
        else (select itval from TF_YWPN_SCADAREALTIME_R where w.ITCD = itcd)
        end new_val,
        round((sysdate - SCADA_TIME) * 24 * 60, 2) interval_time,
        case
        when WARN_TYPE = 2
        then null
        else (select stnm
        from TF_YWPN_SCADASTATION_B
        where id = (select STATION_ID from TF_YWPN_SCADASTAITEM_W where itcd = w.ITCD))
        end station_name,
        SCADA_TIME
        from TF_YWPN_WARN_W w
        where to_char(SCADA_TIME,'yyyy-mm-dd') between #{start} and #{end}
        <if test="type != null">
            and WARN_TYPE = #{type}
        </if>

    </select>

    <select id="getItcdValeHistory" resultType="map">
        select ID, SCADA_TIME, ITVAL
        from TF_YWPN_SCADAHISTORY_R_VIEW
        where ITCD = #{itcd}
          and to_char(scada_time, 'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
    </select>
</mapper>