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

    <resultMap type="AttPustBase" id="AttPustBaseResult">
        <result property="pustCode" column="PUST_CODE"/>
        <result property="collDate" column="COLL_DATE"/>
        <result property="pustName" column="PUST_NAME"/>
        <result property="pustLong" column="PUST_LONG"/>
        <result property="pustLat" column="PUST_LAT"/>
        <result property="pustLoc" column="PUST_LOC"/>
        <result property="pustType" column="PUST_TYPE"/>
        <result property="insFlow" column="INS_FLOW"/>
        <result property="insPow" column="INS_POW"/>
        <result property="pumpNum" column="PUMP_NUM"/>
        <result property="pumpSetNum" column="PUMP_SET_NUM"/>
        <result property="desTotInsCap" column="DES_TOT_INS_CAP"/>
        <result property="desHead" column="DES_HEAD"/>
        <result property="engTask" column="ENG_TASK"/>
        <result property="wasuRang" column="WASU_RANG"/>
        <result property="engGrad" column="ENG_GRAD"/>
        <result property="engScal" column="ENG_SCAL"/>
        <result property="wainWasoType" column="WAIN_WASO_TYPE"/>
        <result property="mainBuildGrad" column="MAIN_BUILD_GRAD"/>
        <result property="engStat" column="ENG_STAT"/>
        <result property="startDate" column="START_DATE"/>
        <result property="compDate" column="COMP_DATE"/>
        <result property="startRunDate" column="START_RUN_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="selectAttPustBaseVo">
        select PUST_CODE, COLL_DATE, PUST_NAME, PUST_LONG, PUST_LAT, PUST_LOC, PUST_TYPE,
               INS_FLOW, INS_POW, PUMP_NUM, PUMP_SET_NUM, DES_TOT_INS_CAP, DES_HEAD,
               ENG_TASK, WASU_RANG, ENG_GRAD, ENG_SCAL, WAIN_WASO_TYPE, MAIN_BUILD_GRAD,
               ENG_STAT, START_DATE, COMP_DATE, START_RUN_DATE, ADM_DEP, NOTE, UPD_DATE, TYPE
        from ATT_PUST_BASE
    </sql>

    <select id="selectAttPustBaseList" parameterType="AttPustBase" resultMap="AttPustBaseResult">
        <include refid="selectAttPustBaseVo"/>
        <where>
            <if test="pustName != null and pustName != ''">
                and PUST_NAME like concat('%', #{pustName}, '%')
            </if>
            <if test="pustType != null and pustType != ''">
                and PUST_TYPE = #{pustType}
            </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="admDep != null and admDep != ''">
                and ADM_DEP = #{admDep}
            </if>
        </where>
        order by PUST_CODE
    </select>

    <select id="selectAttPustBaseById" parameterType="String" resultMap="AttPustBaseResult">
        <include refid="selectAttPustBaseVo"/>
        where PUST_CODE = #{pustCode}
    </select>

    <delete id="deleteAttPustBaseById" parameterType="String">
        delete from ATT_PUST_BASE where PUST_CODE = #{pustCode}
    </delete>

    <delete id="deleteAttPustBaseByIds" parameterType="String">
        delete from ATT_PUST_BASE where PUST_CODE in
        <foreach item="pustCode" collection="array" open="(" separator="," close=")">
            #{pustCode}
        </foreach>
    </delete>

    <insert id="insertAttPustBase" parameterType="AttPustBase">
        insert into ATT_PUST_BASE
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pustCode != null">PUST_CODE,</if>
            <if test="collDate != null">COLL_DATE,</if>
            <if test="pustName != null">PUST_NAME,</if>
            <if test="pustLong != null">PUST_LONG,</if>
            <if test="pustLat != null">PUST_LAT,</if>
            <if test="pustLoc != null">PUST_LOC,</if>
            <if test="pustType != null">PUST_TYPE,</if>
            <if test="insFlow != null">INS_FLOW,</if>
            <if test="insPow != null">INS_POW,</if>
            <if test="pumpNum != null">PUMP_NUM,</if>
            <if test="pumpSetNum != null">PUMP_SET_NUM,</if>
            <if test="desTotInsCap != null">DES_TOT_INS_CAP,</if>
            <if test="desHead != null">DES_HEAD,</if>
            <if test="engTask != null">ENG_TASK,</if>
            <if test="wasuRang != null">WASU_RANG,</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="mainBuildGrad != null">MAIN_BUILD_GRAD,</if>
            <if test="engStat != null">ENG_STAT,</if>
            <if test="startDate != null">START_DATE,</if>
            <if test="compDate != null">COMP_DATE,</if>
            <if test="startRunDate != null">START_RUN_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="pustCode != null">#{pustCode},</if>
            <if test="collDate != null">#{collDate},</if>
            <if test="pustName != null">#{pustName},</if>
            <if test="pustLong != null">#{pustLong},</if>
            <if test="pustLat != null">#{pustLat},</if>
            <if test="pustLoc != null">#{pustLoc},</if>
            <if test="pustType != null">#{pustType},</if>
            <if test="insFlow != null">#{insFlow},</if>
            <if test="insPow != null">#{insPow},</if>
            <if test="pumpNum != null">#{pumpNum},</if>
            <if test="pumpSetNum != null">#{pumpSetNum},</if>
            <if test="desTotInsCap != null">#{desTotInsCap},</if>
            <if test="desHead != null">#{desHead},</if>
            <if test="engTask != null">#{engTask},</if>
            <if test="wasuRang != null">#{wasuRang},</if>
            <if test="engGrad != null">#{engGrad},</if>
            <if test="engScal != null">#{engScal},</if>
            <if test="wainWasoType != null">#{wainWasoType},</if>
            <if test="mainBuildGrad != null">#{mainBuildGrad},</if>
            <if test="engStat != null">#{engStat},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="compDate != null">#{compDate},</if>
            <if test="startRunDate != null">#{startRunDate},</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="updateAttPustBase" parameterType="AttPustBase">
        update ATT_PUST_BASE
        <trim prefix="SET" suffixOverrides=",">
            <if test="collDate != null">COLL_DATE = #{collDate},</if>
            <if test="pustName != null">PUST_NAME = #{pustName},</if>
            <if test="pustLong != null">PUST_LONG = #{pustLong},</if>
            <if test="pustLat != null">PUST_LAT = #{pustLat},</if>
            <if test="pustLoc != null">PUST_LOC = #{pustLoc},</if>
            <if test="pustType != null">PUST_TYPE = #{pustType},</if>
            <if test="insFlow != null">INS_FLOW = #{insFlow},</if>
            <if test="insPow != null">INS_POW = #{insPow},</if>
            <if test="pumpNum != null">PUMP_NUM = #{pumpNum},</if>
            <if test="pumpSetNum != null">PUMP_SET_NUM = #{pumpSetNum},</if>
            <if test="desTotInsCap != null">DES_TOT_INS_CAP = #{desTotInsCap},</if>
            <if test="desHead != null">DES_HEAD = #{desHead},</if>
            <if test="engTask != null">ENG_TASK = #{engTask},</if>
            <if test="wasuRang != null">WASU_RANG = #{wasuRang},</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="mainBuildGrad != null">MAIN_BUILD_GRAD = #{mainBuildGrad},</if>
            <if test="engStat != null">ENG_STAT = #{engStat},</if>
            <if test="startDate != null">START_DATE = #{startDate},</if>
            <if test="compDate != null">COMP_DATE = #{compDate},</if>
            <if test="startRunDate != null">START_RUN_DATE = #{startRunDate},</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 PUST_CODE = #{pustCode}
    </update>

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

</mapper>
