<?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.ruoyi.sy.mapper.SyTestPaperMapper">
    
    <resultMap type="SyTestPaper" id="SyTestPaperResult">
        <result property="paperId"    column="paper_id"    />
        <result property="category"    column="category"    />
        <result property="name"    column="name"    />
        <result property="creatorId"    column="creator_id"    />
        <result property="createdTime"    column="created_time"    />
    </resultMap>

    <sql id="selectSyTestPaperVo">
        select paper_id, category, name, creator_id, created_time from sy_test_paper
    </sql>

    <select id="selectSyTestPaperList" parameterType="SyTestPaper" resultMap="SyTestPaperResult">
        <include refid="selectSyTestPaperVo"/>
        <where>  
            <if test="category != null "> and category = #{category}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="creatorId != null "> and creator_id = #{creatorId}</if>
            <if test="createdTime != null "> and created_time = #{createdTime}</if>
        </where>
    </select>
    
    <select id="selectSyTestPaperById" parameterType="Long" resultMap="SyTestPaperResult">
        <include refid="selectSyTestPaperVo"/>
        where paper_id = #{paperId}
    </select>
        
    <insert id="insertSyTestPaper" parameterType="SyTestPaper" useGeneratedKeys="true" keyProperty="paperId">
        insert into sy_test_paper
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="category != null">category,</if>
            <if test="name != null">name,</if>
            <if test="creatorId != null">creator_id,</if>
            <if test="createdTime != null">created_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="category != null">#{category},</if>
            <if test="name != null">#{name},</if>
            <if test="creatorId != null">#{creatorId},</if>
            <if test="createdTime != null">#{createdTime},</if>
         </trim>
    </insert>

    <update id="updateSyTestPaper" parameterType="SyTestPaper">
        update sy_test_paper
        <trim prefix="SET" suffixOverrides=",">
            <if test="category != null">category = #{category},</if>
            <if test="name != null">name = #{name},</if>
            <if test="creatorId != null">creator_id = #{creatorId},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
        </trim>
        where paper_id = #{paperId}
    </update>

    <delete id="deleteSyTestPaperById" parameterType="Long">
        delete from sy_test_paper where paper_id = #{paperId}
    </delete>

    <delete id="deleteSyTestPaperByIds" parameterType="String">
        delete from sy_test_paper where paper_id in 
        <foreach item="paperId" collection="array" open="(" separator="," close=")">
            #{paperId}
        </foreach>
    </delete>
</mapper>