<!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.WaterSupplyMapper">
    <select id="getSupplyMonth" resultType="map">
        select table_name,
        flow,
        umonth,
        decode(usfl,'0','正常','1','异常') usfl,
        notes
        from TF_YWPN_DMATABLEMONTH_W
        where TABLE_ID = #{id}
        <if test="start != null and end != null">
            and umonth between #{start} and #{end}
        </if>
        <if test="start == null and end == null">
            and umonth between to_char(add_months(sysdate,-36),'yyyymm') and to_char(sysdate,'yyyymm')
        </if>
        order by umonth desc
    </select>

    <select id="getSupplyDay" resultType="map">
        select table_name,
        flow,
        to_char(UDAY , 'yyyy-MM-dd') uday,
        decode(usfl,'0','正常','1','异常') usfl,
        notes
        from TF_YWPN_DMATABLEDAY_W
        where TABLE_ID = #{id}
        <if test="start != null and end != null">
            and to_char(UDAY , 'yyyyMMdd') between #{start} and #{end}
        </if>
        order by UDAY
    </select>

    <select id="getSupplyHour" resultType="java.util.Map">
        select table_name,
        flow,
        to_char(UHOUR , 'yyyy-MM-dd hh24:mi:ss') uhour,
        decode(usfl,'0','正常','1','异常') usfl,
        notes
        from TF_YWPN_DMATABLEHOUR_W
        where TABLE_ID = #{id}
        <if test="start != null and end != null">
            and to_char(UHOUR , 'yyyyMMddhh24') between #{start} and #{end}
        </if>
        order by UHOUR
    </select>

    <select id="viewSupplyMonth" resultType="map">
        select table_name,
        flow,
        umonth,
        decode(usfl,'0','正常','1','异常') usfl,
        notes
        from TF_YWPN_DMATABLEMONTH_W
        where TABLE_ID = #{id}
        <if test="start != null and end != null">
            and umonth between #{start} and #{end}
        </if>
        <if test="start == null and end == null">
            and umonth between to_char(add_months(sysdate,-36),'yyyymm') and to_char(sysdate,'yyyymm')
        </if>
        order by umonth desc
    </select>

    <select id="viewSupplyDay" resultType="java.util.Map">
        select table_name,
        flow,
        to_char(UDAY , 'yyyy-MM-dd') uday,
        decode(usfl,'0','正常','1','异常') usfl,
        notes
        from TF_YWPN_DMATABLEDAY_W
        where TABLE_ID = #{id}
        <if test="start != null and end != null">
            and to_char(UDAY , 'yyyyMMdd') between #{start} and #{end}
        </if>
        order by UDAY
    </select>
    <select id="viewSupplyHour" resultType="java.util.Map">
        select table_name,
        flow,
        to_char(UHOUR , 'yyyy-MM-dd hh24:mi:ss') uhour,
        decode(usfl,'0','正常','1','异常') usfl,
        notes
        from TF_YWPN_DMATABLEHOUR_W
        where TABLE_ID = #{id}
        <if test="start != null and end != null">
            and to_char(UHOUR , 'yyyyMMddhh24') between #{start} and #{end}
        </if>
        order by UHOUR
    </select>


</mapper>