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

    <resultMap type="com.goldenwater.slaj.ttsa.domain.BisTtsaPaper" id="BisTtsaPaperResult">
        <id property="guid" column="guid"/>
        <result property="paperCode" column="paper_code"/>
        <result property="paperGrad" column="paper_grad"/>
        <result property="paperName" column="paper_name"/>
        <result property="paperFullMark" column="paper_full_mark"/>
        <result property="paperQualScore" column="paper_qual_score"/>
        <result property="paperApply" column="paper_apply"/>
        <result property="paperStat" column="paper_stat"/>
        <result property="examCreaType" column="exam_crea_type"/>
        <result property="designGuid" column="design_guid"/>
        <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="selectBisTtsaPaperVo">
        select guid, paper_code, paper_grad, paper_name, paper_full_mark, paper_qual_score, paper_apply, paper_stat, exam_crea_type, design_guid, note, coll_time, upd_time, rec_pers
        from bis_ttsa_paper
    </sql>

    <select id="selectBisTtsaPaperAll" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaPaper" resultMap="BisTtsaPaperResult">
        <include refid="selectBisTtsaPaperVo"/>
        order by coll_time desc
    </select>

    <select id="selectBisTtsaPaperList" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaPaper" resultMap="BisTtsaPaperResult">
        <include refid="selectBisTtsaPaperVo"/>
        <where>
            <if test="paperCode != null and paperCode != ''">and paper_code = #{paperCode}</if>
            <if test="paperName != null and paperName != ''">and paper_name like '%' || #{paperName} || '%'</if>
            <if test="paperStat != null and paperStat != ''">and paper_stat = #{paperStat}</if>
            <if test="paperGrad != null and paperGrad != ''">and paper_grad = #{paperGrad}</if>
        </where>
        order by coll_time desc
    </select>

    <select id="selectBisTtsaPaperByGuid" parameterType="String" resultMap="BisTtsaPaperResult">
        <include refid="selectBisTtsaPaperVo"/>
        where guid = #{guid}
    </select>

    <insert id="insertBisTtsaPaper" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaPaper" useGeneratedKeys="true" keyProperty="guid">
        insert into bis_ttsa_paper (
            guid, paper_code, paper_grad, paper_name, paper_full_mark, paper_qual_score, paper_apply, paper_stat, exam_crea_type, design_guid, note, coll_time, upd_time, rec_pers
        ) values (
            #{guid}, #{paperCode}, #{paperGrad}, #{paperName}, #{paperFullMark}, #{paperQualScore}, #{paperApply}, #{paperStat}, #{examCreaType}, #{designGuid}, #{note}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, #{recPers}
        )
    </insert>

    <update id="updateBisTtsaPaper" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaPaper">
        update bis_ttsa_paper
        <set>
            <if test="paperCode != null">paper_code = #{paperCode},</if>
            <if test="paperGrad != null">paper_grad = #{paperGrad},</if>
            <if test="paperName != null">paper_name = #{paperName},</if>
            <if test="paperFullMark != null">paper_full_mark = #{paperFullMark},</if>
            <if test="paperQualScore != null">paper_qual_score = #{paperQualScore},</if>
            <if test="paperApply != null">paper_apply = #{paperApply},</if>
            <if test="paperStat != null">paper_stat = #{paperStat},</if>
            <if test="examCreaType != null">exam_crea_type = #{examCreaType},</if>
            <if test="designGuid != null">design_guid = #{designGuid},</if>
            <if test="note != null">note = #{note},</if>
            upd_time = CURRENT_TIMESTAMP
        </set>
        where guid = #{guid}
    </update>

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

</mapper>
