<?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.goldenwater.slgc.mapper.AttResBaseMapper">

    <resultMap type="AttResBase" id="AttResBaseResult">
        <result property="resCode" column="RES_CODE"/>
        <result property="collDate" column="COLL_DATE"/>
        <result property="resName" column="RES_NAME"/>
        <result property="lowLeftLong" column="LOW_LEFT_LONG"/>
        <result property="lowLeftLat" column="LOW_LEFT_LAT"/>
        <result property="upRightLong" column="UP_RIGHT_LONG"/>
        <result property="upRightLat" column="UP_RIGHT_LAT"/>
        <result property="resLoc" column="RES_LOC"/>
        <result property="resType" column="RES_TYPE"/>
        <result property="engGrad" column="ENG_GRAD"/>
        <result property="engScal" column="ENG_SCAL"/>
        <result property="watShedArea" column="WAT_SHED_AREA"/>
        <result property="daadMulAverRuof" column="DAAD_MUL_AVER_RUOF"/>
        <result property="uppLevFlco" column="UPP_LEV_FLCO"/>
        <result property="normWatLev" column="NORM_WAT_LEV"/>
        <result property="normPoolStagArea" column="NORM_POOL_STAG_AREA"/>
        <result property="normPoolStagCap" column="NORM_POOL_STAG_CAP"/>
        <result property="flLowLimLev" column="FL_LOW_LIM_LEV"/>
        <result property="flLowLimLevCap" column="FL_LOW_LIM_LEV_CAP"/>
        <result property="deadLev" column="DEAD_LEV"/>
        <result property="totCap" column="TOT_CAP"/>
        <result property="storFlCap" column="STOR_FL_CAP"/>
        <result property="flcoCap" column="FLCO_CAP"/>
        <result property="benResCap" column="BEN_RES_CAP"/>
        <result property="deadCap" column="DEAD_CAP"/>
        <result property="engStat" column="ENG_STAT"/>
        <result property="runStat" column="RUN_STAT"/>
        <result property="startDate" column="START_DATE"/>
        <result property="compDate" column="COMP_DATE"/>
        <result property="admDep" column="ADM_DEP"/>
        <result property="note" column="NOTE"/>
        <result property="updDate" column="UPD_DATE"/>
        <result property="type" column="TYPE"/>
    </resultMap>

    <sql id="selectAttResBaseVo">
        select RES_CODE, COLL_DATE, RES_NAME, LOW_LEFT_LONG, LOW_LEFT_LAT, UP_RIGHT_LONG, UP_RIGHT_LAT,
               RES_LOC, RES_TYPE, ENG_GRAD, ENG_SCAL, WAT_SHED_AREA, DAAD_MUL_AVER_RUOF, UPP_LEV_FLCO,
               NORM_WAT_LEV, NORM_POOL_STAG_AREA, NORM_POOL_STAG_CAP, FL_LOW_LIM_LEV, FL_LOW_LIM_LEV_CAP,
               DEAD_LEV, TOT_CAP, STOR_FL_CAP, FLCO_CAP, BEN_RES_CAP, DEAD_CAP,
               ENG_STAT, RUN_STAT, START_DATE, COMP_DATE, ADM_DEP, NOTE, UPD_DATE, TYPE
        from ATT_RES_BASE
    </sql>

    <select id="selectAttResBaseList" parameterType="AttResBase" resultMap="AttResBaseResult">
        <include refid="selectAttResBaseVo"/>
        <where>
            <if test="resName != null and resName != ''">
                and RES_NAME like concat('%', #{resName}, '%')
            </if>
            <if test="resType != null and resType != ''">
                and RES_TYPE = #{resType}
            </if>
            <if test="engGrad != null and engGrad != ''">
                and ENG_GRAD = #{engGrad}
            </if>
            <if test="engStat != null and engStat != ''">
                and ENG_STAT = #{engStat}
            </if>
            <if test="runStat != null and runStat != ''">
                and RUN_STAT = #{runStat}
            </if>
            <if test="admDep != null and admDep != ''">
                and ADM_DEP = #{admDep}
            </if>
        </where>
        order by RES_CODE
    </select>

    <select id="selectAttResBaseById" parameterType="String" resultMap="AttResBaseResult">
        <include refid="selectAttResBaseVo"/>
        where RES_CODE = #{resCode}
    </select>

    <delete id="deleteAttResBaseById" parameterType="String">
        delete from ATT_RES_BASE where RES_CODE = #{resCode}
    </delete>

    <delete id="deleteAttResBaseByIds" parameterType="String">
        delete from ATT_RES_BASE where RES_CODE in
        <foreach item="resCode" collection="array" open="(" separator="," close=")">
            #{resCode}
        </foreach>
    </delete>

    <insert id="insertAttResBase" parameterType="AttResBase">
        insert into ATT_RES_BASE
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="resCode != null">RES_CODE,</if>
            <if test="collDate != null">COLL_DATE,</if>
            <if test="resName != null">RES_NAME,</if>
            <if test="lowLeftLong != null">LOW_LEFT_LONG,</if>
            <if test="lowLeftLat != null">LOW_LEFT_LAT,</if>
            <if test="upRightLong != null">UP_RIGHT_LONG,</if>
            <if test="upRightLat != null">UP_RIGHT_LAT,</if>
            <if test="resLoc != null">RES_LOC,</if>
            <if test="resType != null">RES_TYPE,</if>
            <if test="engGrad != null">ENG_GRAD,</if>
            <if test="engScal != null">ENG_SCAL,</if>
            <if test="watShedArea != null">WAT_SHED_AREA,</if>
            <if test="daadMulAverRuof != null">DAAD_MUL_AVER_RUOF,</if>
            <if test="uppLevFlco != null">UPP_LEV_FLCO,</if>
            <if test="normWatLev != null">NORM_WAT_LEV,</if>
            <if test="normPoolStagArea != null">NORM_POOL_STAG_AREA,</if>
            <if test="normPoolStagCap != null">NORM_POOL_STAG_CAP,</if>
            <if test="flLowLimLev != null">FL_LOW_LIM_LEV,</if>
            <if test="flLowLimLevCap != null">FL_LOW_LIM_LEV_CAP,</if>
            <if test="deadLev != null">DEAD_LEV,</if>
            <if test="totCap != null">TOT_CAP,</if>
            <if test="storFlCap != null">STOR_FL_CAP,</if>
            <if test="flcoCap != null">FLCO_CAP,</if>
            <if test="benResCap != null">BEN_RES_CAP,</if>
            <if test="deadCap != null">DEAD_CAP,</if>
            <if test="engStat != null">ENG_STAT,</if>
            <if test="runStat != null">RUN_STAT,</if>
            <if test="startDate != null">START_DATE,</if>
            <if test="compDate != null">COMP_DATE,</if>
            <if test="admDep != null">ADM_DEP,</if>
            <if test="note != null">NOTE,</if>
            <if test="updDate != null">UPD_DATE,</if>
            <if test="type != null">TYPE,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="resCode != null">#{resCode},</if>
            <if test="collDate != null">#{collDate},</if>
            <if test="resName != null">#{resName},</if>
            <if test="lowLeftLong != null">#{lowLeftLong},</if>
            <if test="lowLeftLat != null">#{lowLeftLat},</if>
            <if test="upRightLong != null">#{upRightLong},</if>
            <if test="upRightLat != null">#{upRightLat},</if>
            <if test="resLoc != null">#{resLoc},</if>
            <if test="resType != null">#{resType},</if>
            <if test="engGrad != null">#{engGrad},</if>
            <if test="engScal != null">#{engScal},</if>
            <if test="watShedArea != null">#{watShedArea},</if>
            <if test="daadMulAverRuof != null">#{daadMulAverRuof},</if>
            <if test="uppLevFlco != null">#{uppLevFlco},</if>
            <if test="normWatLev != null">#{normWatLev},</if>
            <if test="normPoolStagArea != null">#{normPoolStagArea},</if>
            <if test="normPoolStagCap != null">#{normPoolStagCap},</if>
            <if test="flLowLimLev != null">#{flLowLimLev},</if>
            <if test="flLowLimLevCap != null">#{flLowLimLevCap},</if>
            <if test="deadLev != null">#{deadLev},</if>
            <if test="totCap != null">#{totCap},</if>
            <if test="storFlCap != null">#{storFlCap},</if>
            <if test="flcoCap != null">#{flcoCap},</if>
            <if test="benResCap != null">#{benResCap},</if>
            <if test="deadCap != null">#{deadCap},</if>
            <if test="engStat != null">#{engStat},</if>
            <if test="runStat != null">#{runStat},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="compDate != null">#{compDate},</if>
            <if test="admDep != null">#{admDep},</if>
            <if test="note != null">#{note},</if>
            <if test="updDate != null">#{updDate},</if>
            <if test="type != null">#{type},</if>
        </trim>
    </insert>

    <update id="updateAttResBase" parameterType="AttResBase">
        update ATT_RES_BASE
        <trim prefix="SET" suffixOverrides=",">
            <if test="collDate != null">COLL_DATE = #{collDate},</if>
            <if test="resName != null">RES_NAME = #{resName},</if>
            <if test="lowLeftLong != null">LOW_LEFT_LONG = #{lowLeftLong},</if>
            <if test="lowLeftLat != null">LOW_LEFT_LAT = #{lowLeftLat},</if>
            <if test="upRightLong != null">UP_RIGHT_LONG = #{upRightLong},</if>
            <if test="upRightLat != null">UP_RIGHT_LAT = #{upRightLat},</if>
            <if test="resLoc != null">RES_LOC = #{resLoc},</if>
            <if test="resType != null">RES_TYPE = #{resType},</if>
            <if test="engGrad != null">ENG_GRAD = #{engGrad},</if>
            <if test="engScal != null">ENG_SCAL = #{engScal},</if>
            <if test="watShedArea != null">WAT_SHED_AREA = #{watShedArea},</if>
            <if test="daadMulAverRuof != null">DAAD_MUL_AVER_RUOF = #{daadMulAverRuof},</if>
            <if test="uppLevFlco != null">UPP_LEV_FLCO = #{uppLevFlco},</if>
            <if test="normWatLev != null">NORM_WAT_LEV = #{normWatLev},</if>
            <if test="normPoolStagArea != null">NORM_POOL_STAG_AREA = #{normPoolStagArea},</if>
            <if test="normPoolStagCap != null">NORM_POOL_STAG_CAP = #{normPoolStagCap},</if>
            <if test="flLowLimLev != null">FL_LOW_LIM_LEV = #{flLowLimLev},</if>
            <if test="flLowLimLevCap != null">FL_LOW_LIM_LEV_CAP = #{flLowLimLevCap},</if>
            <if test="deadLev != null">DEAD_LEV = #{deadLev},</if>
            <if test="totCap != null">TOT_CAP = #{totCap},</if>
            <if test="storFlCap != null">STOR_FL_CAP = #{storFlCap},</if>
            <if test="flcoCap != null">FLCO_CAP = #{flcoCap},</if>
            <if test="benResCap != null">BEN_RES_CAP = #{benResCap},</if>
            <if test="deadCap != null">DEAD_CAP = #{deadCap},</if>
            <if test="engStat != null">ENG_STAT = #{engStat},</if>
            <if test="runStat != null">RUN_STAT = #{runStat},</if>
            <if test="startDate != null">START_DATE = #{startDate},</if>
            <if test="compDate != null">COMP_DATE = #{compDate},</if>
            <if test="admDep != null">ADM_DEP = #{admDep},</if>
            <if test="note != null">NOTE = #{note},</if>
            <if test="updDate != null">UPD_DATE = #{updDate},</if>
            <if test="type != null">TYPE = #{type},</if>
        </trim>
        where RES_CODE = #{resCode}
    </update>

    <select id="countType" resultType="java.util.Map">
        select TYPE as name, count(*) as value
        from ATT_RES_BASE
        where TYPE is not null
        group by TYPE
    </select>

</mapper>
