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

    <resultMap type="AttWagaBase" id="AttWagaBaseResult">
        <result property="wagaCode" column="WAGA_CODE"/>
        <result property="collDate" column="COLL_DATE"/>
        <result property="wagaName" column="WAGA_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="wagaLoc" column="WAGA_LOC"/>
        <result property="wagaType" column="WAGA_TYPE"/>
        <result property="wagaUse" column="WAGA_USE"/>
        <result property="engGrad" column="ENG_GRAD"/>
        <result property="engScal" column="ENG_SCAL"/>
        <result property="wainWasoType" column="WAIN_WASO_TYPE"/>
        <result property="lockDisc" column="LOCK_DISC"/>
        <result property="gaorNum" column="GAOR_NUM"/>
        <result property="insPow" column="INS_POW"/>
        <result property="desTotInsCap" column="DES_TOT_INS_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="selectAttWagaBaseVo">
        select WAGA_CODE, COLL_DATE, WAGA_NAME, START_LONG, START_LAT, END_LONG, END_LAT,
               WAGA_LOC, WAGA_TYPE, WAGA_USE, ENG_GRAD, ENG_SCAL, WAIN_WASO_TYPE,
               LOCK_DISC, GAOR_NUM, INS_POW, DES_TOT_INS_CAP,
               ENG_STAT, RUN_STAT, START_DATE, COMP_DATE, ADM_DEP, NOTE, UPD_DATE, TYPE
        from ATT_WAGA_BASE
    </sql>

    <select id="selectAttWagaBaseList" parameterType="AttWagaBase" resultMap="AttWagaBaseResult">
        <include refid="selectAttWagaBaseVo"/>
        <where>
            <if test="wagaName != null and wagaName != ''">
                and WAGA_NAME like concat('%', #{wagaName}, '%')
            </if>
            <if test="wagaLoc != null and wagaLoc != ''">
                and WAGA_LOC like concat('%', #{wagaLoc}, '%')
            </if>
            <if test="wagaType != null and wagaType != ''">
                and WAGA_TYPE = #{wagaType}
            </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 WAGA_CODE
    </select>

    <select id="selectAttWagaBaseById" parameterType="String" resultMap="AttWagaBaseResult">
        <include refid="selectAttWagaBaseVo"/>
        where WAGA_CODE = #{wagaCode}
    </select>

    <delete id="deleteAttWagaBaseById" parameterType="String">
        delete from ATT_WAGA_BASE where WAGA_CODE = #{wagaCode}
    </delete>

    <delete id="deleteAttWagaBaseByIds" parameterType="String">
        delete from ATT_WAGA_BASE where WAGA_CODE in
        <foreach item="wagaCode" collection="array" open="(" separator="," close=")">
            #{wagaCode}
        </foreach>
    </delete>

    <insert id="insertAttWagaBase" parameterType="AttWagaBase">
        insert into ATT_WAGA_BASE
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wagaCode != null">WAGA_CODE,</if>
            <if test="collDate != null">COLL_DATE,</if>
            <if test="wagaName != null">WAGA_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="wagaLoc != null">WAGA_LOC,</if>
            <if test="wagaType != null">WAGA_TYPE,</if>
            <if test="wagaUse != null">WAGA_USE,</if>
            <if test="engGrad != null">ENG_GRAD,</if>
            <if test="engScal != null">ENG_SCAL,</if>
            <if test="wainWasoType != null">WAIN_WASO_TYPE,</if>
            <if test="lockDisc != null">LOCK_DISC,</if>
            <if test="gaorNum != null">GAOR_NUM,</if>
            <if test="insPow != null">INS_POW,</if>
            <if test="desTotInsCap != null">DES_TOT_INS_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="wagaCode != null">#{wagaCode},</if>
            <if test="collDate != null">#{collDate},</if>
            <if test="wagaName != null">#{wagaName},</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="wagaLoc != null">#{wagaLoc},</if>
            <if test="wagaType != null">#{wagaType},</if>
            <if test="wagaUse != null">#{wagaUse},</if>
            <if test="engGrad != null">#{engGrad},</if>
            <if test="engScal != null">#{engScal},</if>
            <if test="wainWasoType != null">#{wainWasoType},</if>
            <if test="lockDisc != null">#{lockDisc},</if>
            <if test="gaorNum != null">#{gaorNum},</if>
            <if test="insPow != null">#{insPow},</if>
            <if test="desTotInsCap != null">#{desTotInsCap},</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="updateAttWagaBase" parameterType="AttWagaBase">
        update ATT_WAGA_BASE
        <trim prefix="SET" suffixOverrides=",">
            <if test="collDate != null">COLL_DATE = #{collDate},</if>
            <if test="wagaName != null">WAGA_NAME = #{wagaName},</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="wagaLoc != null">WAGA_LOC = #{wagaLoc},</if>
            <if test="wagaType != null">WAGA_TYPE = #{wagaType},</if>
            <if test="wagaUse != null">WAGA_USE = #{wagaUse},</if>
            <if test="engGrad != null">ENG_GRAD = #{engGrad},</if>
            <if test="engScal != null">ENG_SCAL = #{engScal},</if>
            <if test="wainWasoType != null">WAIN_WASO_TYPE = #{wainWasoType},</if>
            <if test="lockDisc != null">LOCK_DISC = #{lockDisc},</if>
            <if test="gaorNum != null">GAOR_NUM = #{gaorNum},</if>
            <if test="insPow != null">INS_POW = #{insPow},</if>
            <if test="desTotInsCap != null">DES_TOT_INS_CAP = #{desTotInsCap},</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 WAGA_CODE = #{wagaCode}
    </update>

    <select id="countType" resultType="java.util.Map">
        select a.type as "name", count(a.type) as "value" from
        ( SELECT
            CASE
                WHEN LOCK_DISC >= 50 THEN '大型'
                WHEN LOCK_DISC > 10 THEN '中型'
                WHEN LOCK_DISC &lt;= 10 THEN '小型'
                ELSE '其他'
            END AS type
          FROM ATT_WAGA_BASE) a
        group by a.type
    </select>

</mapper>
