<?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.learn.mapper.LearnTestMapper">
    
    <resultMap type="LearnTest" id="LearnTestResult">
        <result property="batchId"    column="batch_id"    />
        <result property="name"    column="name"    />
        <result property="year"    column="year"    />
        <result property="creatorId"    column="creator_id"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectLearnTestVo">
        select batch_id, name, year, creator_id, create_time from learn_test
    </sql>

    <select id="selectLearnTestList" parameterType="LearnTest" resultMap="LearnTestResult">
        <include refid="selectLearnTestVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="creatorId != null "> and creator_id = #{creatorId}</if>
        </where>
        order by batch_id desc
    </select>
    
    <select id="selectLearnTestByBatchId" parameterType="String" resultMap="LearnTestResult">
        <include refid="selectLearnTestVo"/>
        where batch_id = #{batchId}
    </select>

    <insert id="insertLearnTest" parameterType="LearnTest" useGeneratedKeys="true" keyProperty="batchId">
        insert into learn_test
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="year != null">year,</if>
            <if test="creatorId != null">creator_id,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="year != null">#{year},</if>
            <if test="creatorId != null">#{creatorId},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateLearnTest" parameterType="LearnTest">
        update learn_test
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="creatorId != null">creator_id = #{creatorId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where batch_id = #{batchId}
    </update>

    <delete id="deleteLearnTestByBatchId" parameterType="String">
        delete from learn_test where batch_id = #{batchId}
    </delete>

    <delete id="deleteLearnTestByBatchIds" parameterType="String">
        delete from learn_test where batch_id in 
        <foreach item="batchId" collection="array" open="(" separator="," close=")">
            #{batchId}
        </foreach>
    </delete>
</mapper>