<?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="cn.iocoder.yudao.module.knowledge.mapper.TTestPaperInfoMapper">

    <resultMap type="cn.iocoder.yudao.module.knowledge.entity.TTestPaperInfo" id="tTestPaperInfoMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="testNum" column="test_num"/>
        <result property="startDate" column="start_date"/>
        <result property="duration" column="duration"/>
        <result property="peopleCount" column="people_count"/>
        <result property="questionBankName" column="question_bank_name"/>
        <result property="questionBankId" column="question_bank_id"/>
        <result property="type" column="type"/>
        <result property="allScore" column="all_score"/>
        <result property="passScore" column="pass_score"/>
        <result property="makeUp" column="make_up"/>
        <result property="errorCorrection" column="error_correction"/>
        <result property="allQuestionSum" column="all_question_sum"/>
        <result property="trainId" column="train_id"/>
        <result property="setting" column="setting"
                typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result property="teachCode" column="teach_code"/>
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="columns">
        id
        ,`name`,test_num,start_date,duration,people_count,train_id, question_bank_name,question_bank_id,`type`,all_score,pass_score,make_up,error_correction,all_question_sum,teach_code,setting
    </sql>
    <sql id="columns2">
        id
        ,`name`,test_num,start_date,duration,people_count,train_id,pass_score
    </sql>
    <select id="findList" resultMap="tTestPaperInfoMap">
        select
        *
        from t_test_paper_info
        <where>
            <if test="params.name != null and params.name != ''">
                name like concat('%',#{params.name},'%')
            </if>
            <if test="params.startDate != null">
                and start_date = #{params.startDate}
            </if>
            <if test="params.trainIdList != null and params.trainIdList.size > 0">
                and train_id in
                <foreach collection="params.trainIdList" item="trainId" open="(" separator="," close=")">
                    #{trainId}
                </foreach>
            </if>
            and deleted = 0
        </where>
        order by create_time desc
    </select>

    <select id="findListAll" resultMap="tTestPaperInfoMap">
        select *
        from t_test_paper_info
        <where>
            deleted = 0
            <if test="params.name != null and params.name != ''">
                and name like concat('%',#{params.name},'%')
            </if>
            <if test="params.startDate != null">
                and start_date = #{params.startDate}
            </if>
            <if test="params.type != null">
                and type = #{params.type}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="getOneByTrainId" resultMap="tTestPaperInfoMap">
        select *
        from t_test_paper_info
        where train_id = #{id} and deleted = 0
        order by create_time desc
        limit 1
    </select>
    <select id="queryByIds"
            resultType="cn.iocoder.yudao.module.knowledge.entity.TTestPaperInfo">
        select id, pass_score,name from t_test_paper_info
        <where>
            deleted = 0
            and id in
            <foreach collection="ids" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </where>
    </select>


    <update id="deleteByTrainId" parameterType="java.lang.Long">
        update t_test_paper_info
        set deleted = 1
        where train_id = #{id}
    </update>


</mapper>
