<?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.project.training.spec.mapper.TStQuestionBankMapper">
    
    <resultMap type="TStQuestionBank" id="TStQuestionBankResult">
        <result property="id"    column="id"    />
        <result property="question"    column="question"    />
        <result property="questionType"    column="question_type"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTStQuestionBankVo">
        select d.id, d.question, d.question_type ,s.dept_name from t_st_question_bank d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTStQuestionBankList" parameterType="TStQuestionBank" resultMap="TStQuestionBankResult">
        <include refid="selectTStQuestionBankVo"/>
        <where>  
            <if test="question != null  and question != ''"> and question = #{question}</if>
            <if test="questionType != null "> and question_type = #{questionType}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTStQuestionBankById" parameterType="Long" resultMap="TStQuestionBankResult">
        <include refid="selectTStQuestionBankVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTStQuestionBank" parameterType="TStQuestionBank">
        insert into t_st_question_bank
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="question != null">question,</if>
            <if test="questionType != null">question_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="question != null">#{question},</if>
            <if test="questionType != null">#{questionType},</if>
         </trim>
    </insert>

    <update id="updateTStQuestionBank" parameterType="TStQuestionBank">
        update t_st_question_bank
        <trim prefix="SET" suffixOverrides=",">
            <if test="question != null">question = #{question},</if>
            <if test="questionType != null">question_type = #{questionType},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTStQuestionBankById" parameterType="Long">
        update t_st_question_bank set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTStQuestionBankByIds" parameterType="String">
        update t_st_question_bank set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>