<?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.mapper.DmamonthflowMapper">

    <resultMap id="dmamonthflowMap" type="com.tofly.xrtygis.entity.Dmamonthflow">
        <id property="lid" column="LID"/>
        <result property="dmaId" column="DMA_ID"/>
        <result property="dmaName" column="DMA_NAME"/>
        <result property="inflow" column="INFLOW"/>
        <result property="outflow" column="OUTFLOW"/>
        <result property="supplyFlow" column="SUPPLY_FLOW"/>
        <result property="saleFlow" column="SALE_FLOW"/>
        <result property="cxc" column="CXC"/>
        <result property="cxcl" column="CXCL"/>
        <result property="minDiff" column="MIN_DIFF"/>
        <result property="maxDiff" column="MAX_DIFF"/>
        <result property="umonth" column="UMONTH"/>
        <result property="usfl" column="USFL"/>
        <result property="notes" column="NOTES"/>
        <result property="utime" column="UTIME"/>
    </resultMap>
    <select id="getNorAndAbnor" resultType="java.util.Map">
        SELECT UMONTH,
               sum(case when USFL = '0' then 1 else 0 end)         NORMAL,
               sum(case when USFL IN ('1', '2') then 1 else 0 end) ABNORMAL
        FROM TF_YWPN_DMAMONTHFLOW_W
        WHERE DMA_ID in (${ids})
          and UMONTH <![CDATA[ <= ]]> #{end}
          and UMONTH <![CDATA[ >= ]]> #{start}
        GROUP BY UMONTH
        ORDER BY UMONTH ASC
    </select>

    <select id="getAllChildByDmaId" resultType="java.lang.Long">
        select ID
        from Tf_Ywpn_Dmaregion_w start with id in (${dmaId})
        connect by prior id=pid
        order by pid
    </select>
    <select id="getwaterDiffDetail" resultType="java.util.Map">
        SELECT UMONTH, DMA_NAME , SUPPLY_FLOW , SALE_FLOW , CXC , CXCL , MIN_DIFF , MAX_DIFF ,
               decode(USFL , '0','正常','1','超高异常','2','超低异常') USFL, NOTES
        FROM TF_YWPN_DMAMONTHFLOW_W
        WHERE DMA_ID in (${ids})
          and USFL in ('0','1','2')
          and UMONTH <![CDATA[ <= ]]> #{end}
          and UMONTH <![CDATA[ >= ]]> #{start}
        ORDER BY UMONTH ASC
    </select>
    <select id="getClloctByDma" resultType="java.util.Map">
        SELECT UMONTH , SUM(SUPPLY_FLOW) SUPPLY_FLOW , SUM(SALE_FLOW) SALE_FLOW , SUM(CXC) CXC
        FROM TF_YWPN_DMAMONTHFLOW_W
        WHERE DMA_ID in (${ids})
          and USFL in ('0','1','2')
          and UMONTH <![CDATA[ <= ]]> #{end}
          and UMONTH <![CDATA[ >= ]]> #{start}
        GROUP BY UMONTH
        ORDER BY UMONTH ASC
    </select>


</mapper>
