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

    <resultMap type="AttDikeBase" id="AttDikeBaseResult">
        <result property="dikeCode" column="DIKE_CODE"/>
        <result property="collDate" column="COLL_DATE"/>
        <result property="dikeName" column="DIKE_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="startLoc" column="START_LOC"/>
        <result property="endLoc" column="END_LOC"/>
        <result property="dikeGrad" column="DIKE_GRAD"/>
        <result property="dikeType" column="DIKE_TYPE"/>
        <result property="dikePatt" column="DIKE_PATT"/>
        <result property="dikeLen" column="DIKE_LEN"/>
        <result property="dikeStartNum" column="DIKE_START_NUM"/>
        <result property="dikeEndNum" column="DIKE_END_NUM"/>
        <result property="startDikeTopEl" column="START_DIKE_TOP_EL"/>
        <result property="endDikeTopEl" column="END_DIKE_TOP_EL"/>
        <result property="dikeHeigMin" column="DIKE_HEIG_MIN"/>
        <result property="dikeHeigMax" column="DIKE_HEIG_MAX"/>
        <result property="dikeTopWidMin" column="DIKE_TOP_WID_MIN"/>
        <result property="dikeTopWidMax" column="DIKE_TOP_WID_MAX"/>
        <result property="engStat" column="ENG_STAT"/>
        <result property="runStat" column="RUN_STAT"/>
        <result property="engTask" column="ENG_TASK"/>
        <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"/>
    </resultMap>

    <sql id="selectAttDikeBaseVo">
        select DIKE_CODE, COLL_DATE, DIKE_NAME, START_LONG, START_LAT, END_LONG, END_LAT, START_LOC, END_LOC,
               DIKE_GRAD, DIKE_TYPE, DIKE_PATT, DIKE_LEN, DIKE_START_NUM, DIKE_END_NUM, START_DIKE_TOP_EL,
               END_DIKE_TOP_EL, DIKE_HEIG_MIN, DIKE_HEIG_MAX, DIKE_TOP_WID_MIN, DIKE_TOP_WID_MAX,
               ENG_STAT, RUN_STAT, ENG_TASK, START_DATE, COMP_DATE, ADM_DEP, NOTE, UPD_DATE
        from ATT_DIKE_BASE
    </sql>

    <select id="selectAttDikeBaseList" parameterType="AttDikeBase" resultMap="AttDikeBaseResult">
        <include refid="selectAttDikeBaseVo"/>
        <where>
            <if test="dikeName != null and dikeName != ''">
                and DIKE_NAME like concat('%', #{dikeName}, '%')
            </if>
            <if test="startLoc != null and startLoc != ''">
                and START_LOC like concat('%', #{startLoc}, '%')
            </if>
            <if test="dikeGrad != null and dikeGrad != ''">
                and DIKE_GRAD = #{dikeGrad}
            </if>
            <if test="dikeType != null and dikeType != ''">
                and DIKE_TYPE = #{dikeType}
            </if>
            <if test="dikePatt != null and dikePatt != ''">
                and DIKE_PATT = #{dikePatt}
            </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 DIKE_CODE
    </select>

    <select id="selectAttDikeBaseById" parameterType="String" resultMap="AttDikeBaseResult">
        <include refid="selectAttDikeBaseVo"/>
        where DIKE_CODE = #{dikeCode}
    </select>

    <delete id="deleteAttDikeBaseById" parameterType="String">
        delete from ATT_DIKE_BASE where DIKE_CODE = #{dikeCode}
    </delete>

    <delete id="deleteAttDikeBaseByIds" parameterType="String">
        delete from ATT_DIKE_BASE where DIKE_CODE in
        <foreach item="dikeCode" collection="array" open="(" separator="," close=")">
            #{dikeCode}
        </foreach>
    </delete>

    <insert id="insertAttDikeBase" parameterType="AttDikeBase">
        insert into ATT_DIKE_BASE
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dikeCode != null">DIKE_CODE,</if>
            <if test="collDate != null">COLL_DATE,</if>
            <if test="dikeName != null">DIKE_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="startLoc != null">START_LOC,</if>
            <if test="endLoc != null">END_LOC,</if>
            <if test="dikeGrad != null">DIKE_GRAD,</if>
            <if test="dikeType != null">DIKE_TYPE,</if>
            <if test="dikePatt != null">DIKE_PATT,</if>
            <if test="dikeLen != null">DIKE_LEN,</if>
            <if test="dikeStartNum != null">DIKE_START_NUM,</if>
            <if test="dikeEndNum != null">DIKE_END_NUM,</if>
            <if test="startDikeTopEl != null">START_DIKE_TOP_EL,</if>
            <if test="endDikeTopEl != null">END_DIKE_TOP_EL,</if>
            <if test="dikeHeigMin != null">DIKE_HEIG_MIN,</if>
            <if test="dikeHeigMax != null">DIKE_HEIG_MAX,</if>
            <if test="dikeTopWidMin != null">DIKE_TOP_WID_MIN,</if>
            <if test="dikeTopWidMax != null">DIKE_TOP_WID_MAX,</if>
            <if test="engStat != null">ENG_STAT,</if>
            <if test="runStat != null">RUN_STAT,</if>
            <if test="engTask != null">ENG_TASK,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dikeCode != null">#{dikeCode},</if>
            <if test="collDate != null">#{collDate},</if>
            <if test="dikeName != null">#{dikeName},</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="startLoc != null">#{startLoc},</if>
            <if test="endLoc != null">#{endLoc},</if>
            <if test="dikeGrad != null">#{dikeGrad},</if>
            <if test="dikeType != null">#{dikeType},</if>
            <if test="dikePatt != null">#{dikePatt},</if>
            <if test="dikeLen != null">#{dikeLen},</if>
            <if test="dikeStartNum != null">#{dikeStartNum},</if>
            <if test="dikeEndNum != null">#{dikeEndNum},</if>
            <if test="startDikeTopEl != null">#{startDikeTopEl},</if>
            <if test="endDikeTopEl != null">#{endDikeTopEl},</if>
            <if test="dikeHeigMin != null">#{dikeHeigMin},</if>
            <if test="dikeHeigMax != null">#{dikeHeigMax},</if>
            <if test="dikeTopWidMin != null">#{dikeTopWidMin},</if>
            <if test="dikeTopWidMax != null">#{dikeTopWidMax},</if>
            <if test="engStat != null">#{engStat},</if>
            <if test="runStat != null">#{runStat},</if>
            <if test="engTask != null">#{engTask},</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>
        </trim>
    </insert>

    <update id="updateAttDikeBase" parameterType="AttDikeBase">
        update ATT_DIKE_BASE
        <trim prefix="SET" suffixOverrides=",">
            <if test="collDate != null">COLL_DATE = #{collDate},</if>
            <if test="dikeName != null">DIKE_NAME = #{dikeName},</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="startLoc != null">START_LOC = #{startLoc},</if>
            <if test="endLoc != null">END_LOC = #{endLoc},</if>
            <if test="dikeGrad != null">DIKE_GRAD = #{dikeGrad},</if>
            <if test="dikeType != null">DIKE_TYPE = #{dikeType},</if>
            <if test="dikePatt != null">DIKE_PATT = #{dikePatt},</if>
            <if test="dikeLen != null">DIKE_LEN = #{dikeLen},</if>
            <if test="dikeStartNum != null">DIKE_START_NUM = #{dikeStartNum},</if>
            <if test="dikeEndNum != null">DIKE_END_NUM = #{dikeEndNum},</if>
            <if test="startDikeTopEl != null">START_DIKE_TOP_EL = #{startDikeTopEl},</if>
            <if test="endDikeTopEl != null">END_DIKE_TOP_EL = #{endDikeTopEl},</if>
            <if test="dikeHeigMin != null">DIKE_HEIG_MIN = #{dikeHeigMin},</if>
            <if test="dikeHeigMax != null">DIKE_HEIG_MAX = #{dikeHeigMax},</if>
            <if test="dikeTopWidMin != null">DIKE_TOP_WID_MIN = #{dikeTopWidMin},</if>
            <if test="dikeTopWidMax != null">DIKE_TOP_WID_MAX = #{dikeTopWidMax},</if>
            <if test="engStat != null">ENG_STAT = #{engStat},</if>
            <if test="runStat != null">RUN_STAT = #{runStat},</if>
            <if test="engTask != null">ENG_TASK = #{engTask},</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>
        </trim>
        where DIKE_CODE = #{dikeCode}
    </update>

    <select id="countType" resultType="java.util.Map">
        select CASE DIKE_GRAD
                 WHEN '1' THEN '一级'
                 WHEN '2' THEN '二级'
                 WHEN '3' THEN '三级'
                 WHEN '4' THEN '四级'
                 WHEN '5' THEN '五级'
                 ELSE '其他'
               END as "name",
               count(*) as "value"
        from ATT_DIKE_BASE
        group by DIKE_GRAD
    </select>

</mapper>
