<?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.slaj.ttsa.mapper.BisTtsaTrainMapper">
    <resultMap type="com.goldenwater.slaj.ttsa.domain.BisTtsaTrain" id="BisTtsaTrainResult">
        <result property="guid" column="guid"/>
        <result property="citNum" column="cit_num"/>
        <result property="orgGuid" column="org_guid"/>
        <result property="trainOrgName" column="train_org_name"/>
        <result property="trainType" column="train_type"/>
        <result property="trainStartTime" column="train_start_time"/>
        <result property="trainCompTime" column="train_comp_time"/>
        <result property="trainTeat" column="train_teat"/>
        <result property="trainAddr" column="train_addr"/>
        <result property="trainOrgGuid" column="train_org_guid"/>
        <result property="trainPersTot" column="train_pers_tot"/>
        <result property="trainHour" column="train_hour"/>
        <result property="veriStat" column="veri_stat"/>
        <result property="note" column="note"/>
        <result property="collTime" column="coll_time"/>
        <result property="updTime" column="upd_time"/>
        <result property="recPers" column="rec_pers"/>
    </resultMap>

    <sql id="selectBisTtsaTrainVo">
        select guid, cit_num, org_guid, train_org_name, train_type,
               train_start_time, train_comp_time, train_teat, train_addr, train_org_guid,
               train_pers_tot, train_hour, veri_stat, note, coll_time,
               upd_time, rec_pers
        from bis_ttsa_train
    </sql>

    <select id="selectBisTtsaTrainByGuid" parameterType="String" resultMap="BisTtsaTrainResult">
        <include refid="selectBisTtsaTrainVo"/> where guid = #{guid}
    </select>

    <select id="selectBisTtsaTrainList" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaTrain" resultMap="BisTtsaTrainResult">
        <include refid="selectBisTtsaTrainVo"/>
        <where>
            <if test="orgGuid != null and orgGuid != ''">and org_guid = #{orgGuid}</if>
            <if test="trainType != null and trainType != ''">and train_type = #{trainType}</if>
            <if test="veriStat != null and veriStat != ''">and veri_stat = #{veriStat}</if>
            <if test="trainOrgName != null and trainOrgName != ''">and train_org_name like concat('%', #{trainOrgName}, '%')</if>
        </where>
    </select>

    <insert id="insertBisTtsaTrain" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaTrain">
        insert into bis_ttsa_train (
            guid, cit_num, org_guid, train_org_name, train_type,
            train_start_time, train_comp_time, train_teat, train_addr, train_org_guid,
            train_pers_tot, train_hour, veri_stat, note, coll_time,
            upd_time, rec_pers
        ) values (
            #{guid}, #{citNum}, #{orgGuid}, #{trainOrgName}, #{trainType},
            #{trainStartTime}, #{trainCompTime}, #{trainTeat}, #{trainAddr}, #{trainOrgGuid},
            #{trainPersTot}, #{trainHour}, #{veriStat}, #{note}, #{collTime},
            #{updTime}, #{recPers}
        )
    </insert>

    <update id="updateBisTtsaTrain" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaTrain">
        update bis_ttsa_train
        <set>
            <if test="citNum != null">cit_num = #{citNum},</if>
            <if test="orgGuid != null">org_guid = #{orgGuid},</if>
            <if test="trainOrgName != null">train_org_name = #{trainOrgName},</if>
            <if test="trainType != null">train_type = #{trainType},</if>
            <if test="trainStartTime != null">train_start_time = #{trainStartTime},</if>
            <if test="trainCompTime != null">train_comp_time = #{trainCompTime},</if>
            <if test="trainTeat != null">train_teat = #{trainTeat},</if>
            <if test="trainAddr != null">train_addr = #{trainAddr},</if>
            <if test="trainOrgGuid != null">train_org_guid = #{trainOrgGuid},</if>
            <if test="trainPersTot != null">train_pers_tot = #{trainPersTot},</if>
            <if test="trainHour != null">train_hour = #{trainHour},</if>
            <if test="veriStat != null">veri_stat = #{veriStat},</if>
            <if test="note != null">note = #{note},</if>
            <if test="updTime != null">upd_time = #{updTime},</if>
            <if test="recPers != null">rec_pers = #{recPers},</if>
        </set>
        where guid = #{guid}
    </update>

    <delete id="deleteBisTtsaTrainByGuid" parameterType="String">
        delete from bis_ttsa_train where guid = #{guid}
    </delete>

    <delete id="deleteBisTtsaTrainByGuids" parameterType="String">
        delete from bis_ttsa_train where guid in
        <foreach item="guid" collection="array" open="(" separator="," close=")">
            #{guid}
        </foreach>
    </delete>
</mapper>
