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

    <resultMap id="dmanightflowMap" type="com.tofly.xrtygis.entity.Dmanightflow">
        <id property="id" column="ID"/>
        <result property="tableId" column="TABLE_ID"/>
        <result property="tableName" column="TABLE_NAME"/>
        <result property="minval" column="MINVAL"/>
        <result property="mintime" column="MINTIME"/>
        <result property="minpval" column="MINPVAL"/>
        <result property="tval" column="TVAL"/>
        <result property="uday" column="UDAY"/>
        <result property="umonth" column="UMONTH"/>
        <result property="utime" column="UTIME"/>
        <result property="usfl" column="USFL"/>
        <result property="notes" column="NOTES"/>
    </resultMap>
    <select id="getMinFlowCollet" resultType="java.util.Map">
        SELECT to_char(UDAY , 'yyyy-MM') UDAY,
               sum(case when USFL = '0' then 1 else 0 end) NORMAL,
               sum(case when USFL = '1' then 1 else 0 end) ABNORMAL
        FROM TF_YWPN_DMANIGHTFLOW_W
        WHERE TABLE_ID IN (${ids})
        and UDAY <![CDATA[ <= ]]> #{end}
        and UDAY <![CDATA[ >= ]]> #{start}
        GROUP BY to_char(UDAY , 'yyyy-MM')
        ORDER BY UDAY ASC
    </select>
    <select id="getMinFlowDetail" resultType="java.util.Map">
        SELECT TABLE_ID , to_char(UDAY , 'yyyy-MM') UDAY, decode(USFL , '0','正常','1','超限异常') USFL,
               TABLE_NAME , MINVAL , MINTIME , MINPVAL
        FROM TF_YWPN_DMANIGHTFLOW_W
        WHERE TABLE_ID IN (${ids})
          and USFL in ('0','1')
          and UDAY <![CDATA[ <= ]]> #{end}
          and UDAY <![CDATA[ >= ]]> #{start}
        ORDER BY UDAY ASC
    </select>
    <select id="getMinFlowDetailPage" resultType="java.util.Map">
        SELECT a.TABLE_ID , to_char(a.UDAY , 'yyyy-MM-dd') UDAY , decode(a.USFL , '0','正常','1','超限异常') USFL ,
               a.TABLE_NAME , a.MINVAL , a.MINTIME , a.MINPVAL , a.TVAL , b.MIN_FLOW
        FROM TF_YWPN_DMANIGHTFLOW_W a LEFT JOIN TF_YWPN_DMATABLE_W b ON a.TABLE_ID = b.ID
        WHERE a.TABLE_ID IN (${ids})
          and a.USFL in ('0','1')
          and a.UDAY <![CDATA[ <= ]]> #{end}
          and a.UDAY <![CDATA[ >= ]]> #{start}
        ORDER BY a.UDAY ASC
    </select>
    <select id="getFlowList" resultType="com.tofly.xrtygis.entity.Dmanightflow">
        SELECT t1.NAME tableName,t4.id tableId,nvl(t4.MIN_FLOW,0) tval,nvl(t3.min,0) minval,t3.START_TIME mintime,
               (CASE WHEN nvl(t3.min,0) > nvl(t4.MIN_FLOW,0) THEN 1 else 0 END) usfl
        FROM TF_DEVICE_ARCHIVE_MANAGE t1 LEFT JOIN TF_INDEX_ALLOCATION t2
                                                   ON t1.id = t2.DEVICE_ID
                                         LEFT JOIN STATISTICS_SCADA t3
                                                   on t2.VARIABLE_CODE = t3.CODE
                                         LEFT JOIN TF_YWPN_DMATABLE_W t4
                                                   on t1.id = t4.DEVICE_ID
        WHERE
            t3.STATISTICS_TYPE = '0'
        and t2.TYPE = '13'
        and t3.START_TIME >= #{startTime}
        and t3.START_TIME &lt;= #{endTime}
        ORDER BY t3.START_TIME DESC
    </select>

    <select id="getPressureList" resultType="com.tofly.xrtygis.entity.Dmanightflow">
        SELECT t1.NAME tableName,t4.id tableId,nvl(t3.value,0) minpval,t3.START_TIME mintime
        FROM TF_DEVICE_ARCHIVE_MANAGE t1 LEFT JOIN TF_INDEX_ALLOCATION t2
                                                   ON t1.PRESSURE_DEVICE_ID = t2.DEVICE_ID
                                         LEFT JOIN STATISTICS_SCADA t3
                                                   on t2.VARIABLE_CODE = t3.CODE
                                         LEFT JOIN TF_YWPN_DMATABLE_W t4
                                                   on t1.id = t4.DEVICE_ID
        WHERE
              t3.STATISTICS_TYPE = '0'
          and t3.DATA_TYPE = '0'
          and t3.START_TIME >= #{startTime}
          and t3.START_TIME &lt;= #{endTime}
        ORDER BY t3.START_TIME DESC
    </select>

</mapper>
