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

    <resultMap type="AttDamBase" id="AttDamBaseResult">
        <result property="damCode" column="DAM_CODE"/>
        <result property="damName" column="DAM_NAME"/>
        <result property="startLong" column="START_LONG"/>
        <result property="startLat" column="START_LAT"/>
        <result property="endLong" column="END_LONG"/>
        <result property="endLat" column="END_LAT"/>
        <result property="damLoc" column="DAM_LOC"/>
        <result property="ifMainDam" column="IF_MAIN_DAM"/>
        <result property="damGrad" column="DAM_GRAD"/>
        <result property="damMaxHeig" column="DAM_MAX_HEIG"/>
        <result property="damTopLen" column="DAM_TOP_LEN"/>
        <result property="damTopWid" column="DAM_TOP_WID"/>
        <result property="damTypeMat" column="DAM_TYPE_MAT"/>
        <result property="damTypeStr" column="DAM_TYPE_STR"/>
        <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="note" column="NOTE"/>
        <result property="collDate" column="COLL_DATE"/>
        <result property="updDate" column="UPD_DATE"/>
    </resultMap>

    <sql id="selectAttDamBaseVo">
        select DAM_CODE, DAM_NAME, START_LONG, START_LAT, END_LONG, END_LAT, DAM_LOC, IF_MAIN_DAM, DAM_GRAD,
               DAM_MAX_HEIG, DAM_TOP_LEN, DAM_TOP_WID, DAM_TYPE_MAT, DAM_TYPE_STR, ENG_STAT, RUN_STAT,
               START_DATE, COMP_DATE, NOTE, COLL_DATE, UPD_DATE
        from ATT_DAM_BASE
    </sql>

    <select id="selectAttDamBaseList" parameterType="AttDamBase" resultMap="AttDamBaseResult">
        <include refid="selectAttDamBaseVo"/>
        <where>
            <if test="damName != null and damName != ''">
                and DAM_NAME like concat('%', #{damName}, '%')
            </if>
            <if test="damGrad != null and damGrad != ''">
                and DAM_GRAD = #{damGrad}
            </if>
            <if test="damTypeMat != null and damTypeMat != ''">
                and DAM_TYPE_MAT = #{damTypeMat}
            </if>
            <if test="damTypeStr != null and damTypeStr != ''">
                and DAM_TYPE_STR = #{damTypeStr}
            </if>
            <if test="ifMainDam != null and ifMainDam != ''">
                and IF_MAIN_DAM = #{ifMainDam}
            </if>
            <if test="engStat != null and engStat != ''">
                and ENG_STAT = #{engStat}
            </if>
            <if test="runStat != null and runStat != ''">
                and RUN_STAT = #{runStat}
            </if>
        </where>
        order by DAM_CODE
    </select>

    <select id="selectAttDamBaseById" parameterType="String" resultMap="AttDamBaseResult">
        <include refid="selectAttDamBaseVo"/>
        where DAM_CODE = #{damCode}
    </select>

    <delete id="deleteAttDamBaseById" parameterType="String">
        delete from ATT_DAM_BASE where DAM_CODE = #{damCode}
    </delete>

    <delete id="deleteAttDamBaseByIds" parameterType="String">
        delete from ATT_DAM_BASE where DAM_CODE in
        <foreach item="damCode" collection="array" open="(" separator="," close=")">
            #{damCode}
        </foreach>
    </delete>

    <insert id="insertAttDamBase" parameterType="AttDamBase">
        insert into ATT_DAM_BASE
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="damCode != null">DAM_CODE,</if>
            <if test="damName != null">DAM_NAME,</if>
            <if test="startLong != null">START_LONG,</if>
            <if test="startLat != null">START_LAT,</if>
            <if test="endLong != null">END_LONG,</if>
            <if test="endLat != null">END_LAT,</if>
            <if test="damLoc != null">DAM_LOC,</if>
            <if test="ifMainDam != null">IF_MAIN_DAM,</if>
            <if test="damGrad != null">DAM_GRAD,</if>
            <if test="damMaxHeig != null">DAM_MAX_HEIG,</if>
            <if test="damTopLen != null">DAM_TOP_LEN,</if>
            <if test="damTopWid != null">DAM_TOP_WID,</if>
            <if test="damTypeMat != null">DAM_TYPE_MAT,</if>
            <if test="damTypeStr != null">DAM_TYPE_STR,</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="note != null">NOTE,</if>
            <if test="collDate != null">COLL_DATE,</if>
            <if test="updDate != null">UPD_DATE,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="damCode != null">#{damCode},</if>
            <if test="damName != null">#{damName},</if>
            <if test="startLong != null">#{startLong},</if>
            <if test="startLat != null">#{startLat},</if>
            <if test="endLong != null">#{endLong},</if>
            <if test="endLat != null">#{endLat},</if>
            <if test="damLoc != null">#{damLoc},</if>
            <if test="ifMainDam != null">#{ifMainDam},</if>
            <if test="damGrad != null">#{damGrad},</if>
            <if test="damMaxHeig != null">#{damMaxHeig},</if>
            <if test="damTopLen != null">#{damTopLen},</if>
            <if test="damTopWid != null">#{damTopWid},</if>
            <if test="damTypeMat != null">#{damTypeMat},</if>
            <if test="damTypeStr != null">#{damTypeStr},</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="note != null">#{note},</if>
            <if test="collDate != null">#{collDate},</if>
            <if test="updDate != null">#{updDate},</if>
        </trim>
    </insert>

    <update id="updateAttDamBase" parameterType="AttDamBase">
        update ATT_DAM_BASE
        <trim prefix="SET" suffixOverrides=",">
            <if test="damName != null">DAM_NAME = #{damName},</if>
            <if test="startLong != null">START_LONG = #{startLong},</if>
            <if test="startLat != null">START_LAT = #{startLat},</if>
            <if test="endLong != null">END_LONG = #{endLong},</if>
            <if test="endLat != null">END_LAT = #{endLat},</if>
            <if test="damLoc != null">DAM_LOC = #{damLoc},</if>
            <if test="ifMainDam != null">IF_MAIN_DAM = #{ifMainDam},</if>
            <if test="damGrad != null">DAM_GRAD = #{damGrad},</if>
            <if test="damMaxHeig != null">DAM_MAX_HEIG = #{damMaxHeig},</if>
            <if test="damTopLen != null">DAM_TOP_LEN = #{damTopLen},</if>
            <if test="damTopWid != null">DAM_TOP_WID = #{damTopWid},</if>
            <if test="damTypeMat != null">DAM_TYPE_MAT = #{damTypeMat},</if>
            <if test="damTypeStr != null">DAM_TYPE_STR = #{damTypeStr},</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="note != null">NOTE = #{note},</if>
            <if test="collDate != null">COLL_DATE = #{collDate},</if>
            <if test="updDate != null">UPD_DATE = #{updDate},</if>
        </trim>
        where DAM_CODE = #{damCode}
    </update>

</mapper>
