<?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.LearnKnowledgeQuestionMapper">
    
    <resultMap type="LearnKnowledgeQuestion" id="LearnKnowledgeQuestionResult">
        <result property="id"    column="id"    />
        <result property="knowledgeId"    column="knowledge_id"    />
        <result property="type"    column="type"    />
        <result property="questionId"    column="question_id"    />
        <result property="seq"    column="seq"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectLearnKnowledgeQuestionVo">
        select id, knowledge_id, type, question_id, seq, create_time from learn_knowledge_question
    </sql>

    <select id="selectLearnKnowledgeQuestionList" parameterType="LearnKnowledgeQuestion" resultMap="LearnKnowledgeQuestionResult">
        <include refid="selectLearnKnowledgeQuestionVo"/>
        <where>  
            <if test="knowledgeId != null "> and knowledge_id = #{knowledgeId}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="questionId != null "> and question_id = #{questionId}</if>
            <if test="seq != null "> and seq = #{seq}</if>
        </where>
    </select>
    
    <select id="selectLearnKnowledgeQuestionById" parameterType="Long" resultMap="LearnKnowledgeQuestionResult">
        <include refid="selectLearnKnowledgeQuestionVo"/>
        where id = #{id}
    </select>

    <insert id="insertLearnKnowledgeQuestion" parameterType="LearnKnowledgeQuestion" useGeneratedKeys="true" keyProperty="id">
        insert into learn_knowledge_question
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="knowledgeId != null">knowledge_id,</if>
            <if test="type != null">type,</if>
            <if test="questionId != null">question_id,</if>
            <if test="seq != null">seq,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="knowledgeId != null">#{knowledgeId},</if>
            <if test="type != null">#{type},</if>
            <if test="questionId != null">#{questionId},</if>
            <if test="seq != null">#{seq},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateLearnKnowledgeQuestion" parameterType="LearnKnowledgeQuestion">
        update learn_knowledge_question
        <trim prefix="SET" suffixOverrides=",">
            <if test="knowledgeId != null">knowledge_id = #{knowledgeId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="questionId != null">question_id = #{questionId},</if>
            <if test="seq != null">seq = #{seq},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLearnKnowledgeQuestionById" parameterType="Long">
        delete from learn_knowledge_question where id = #{id}
    </delete>

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