<?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.xinelu.manage.mapper.questionsubject.QuestionSubjectMapper">

    <resultMap type="QuestionSubject" id="QuestionSubjectResult">
        <result property="id" column="id"/>
        <result property="questionInfoId" column="question_info_id"/>
        <result property="questionNumber" column="question_number"/>
        <result property="questionType" column="question_type"/>
        <result property="questionName" column="question_name"/>
        <result property="questionNameAlias" column="question_name_alias"/>
        <result property="questionDescription" column="question_description"/>
        <result property="writeDescription" column="write_description"/>
        <result property="fillBlanksAnswer" column="fill_blanks_answer"/>
        <result property="optionCount" column="option_count"/>
        <result property="whetherScore" column="whether_score"/>
        <result property="scoringMethod" column="scoring_method"/>
        <result property="scoringDescription" column="scoring_description"/>
        <result property="questionScore" column="question_score"/>
        <result property="customTriggerCondition" column="custom_trigger_condition"/>
        <result property="propagandaInfoId" column="propaganda_info_id"/>
        <result property="propagandaTitle" column="propaganda_title"/>
        <result property="questionSort" column="question_sort"/>
        <result property="questionRemark" column="question_remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectQuestionSubjectVo">
        select id,
               question_info_id,
               question_number,
               question_type,
               question_name,
               question_name_alias,
               question_description,
               write_description,
               fill_blanks_answer,
               option_count,
               whether_score,
               scoring_method,
               scoring_description,
               question_score,
               custom_trigger_condition,
               propaganda_info_id,
               propaganda_title,
               question_sort,
               question_remark,
               create_by,
               create_time,
               update_by,
               update_time
        from question_subject
    </sql>

    <select id="selectQuestionSubjectList" parameterType="QuestionSubject" resultMap="QuestionSubjectResult">
        <include refid="selectQuestionSubjectVo"/>
        <where>
            <if test="questionInfoId != null ">
                and question_info_id = #{questionInfoId}
            </if>
            <if test="questionNumber != null ">
                and question_number = #{questionNumber}
            </if>
            <if test="questionType != null  and questionType != ''">
                and question_type = #{questionType}
            </if>
            <if test="questionName != null  and questionName != ''">
                and question_name like concat('%', #{questionName}, '%')
            </if>
            <if test="questionNameAlias != null  and questionNameAlias != ''">
                and question_name_alias like concat('%', #{questionNameAlias}, '%')
            </if>
            <if test="questionDescription != null  and questionDescription != ''">
                and question_description = #{questionDescription}
            </if>
            <if test="writeDescription != null  and writeDescription != ''">
                and write_description = #{writeDescription}
            </if>
            <if test="fillBlanksAnswer != null  and fillBlanksAnswer != ''">
                and fill_blanks_answer = #{fillBlanksAnswer}
            </if>
            <if test="optionCount != null ">
                and option_count = #{optionCount}
            </if>
            <if test="whetherScore != null ">
                and whether_score = #{whetherScore}
            </if>
            <if test="scoringMethod != null  and scoringMethod != ''">
                and scoring_method = #{scoringMethod}
            </if>
            <if test="scoringDescription != null  and scoringDescription != ''">
                and scoring_description = #{scoringDescription}
            </if>
            <if test="questionScore != null ">
                and question_score = #{questionScore}
            </if>
            <if test="customTriggerCondition != null  and customTriggerCondition != ''">
                and custom_trigger_condition = #{customTriggerCondition}
            </if>
            <if test="propagandaInfoId != null ">
                and propaganda_info_id = #{propagandaInfoId}
            </if>
            <if test="propagandaTitle != null  and propagandaTitle != ''">
                and propaganda_title = #{propagandaTitle}
            </if>
            <if test="questionSort != null ">
                and question_sort = #{questionSort}
            </if>
            <if test="questionRemark != null  and questionRemark != ''">
                and question_remark = #{questionRemark}
            </if>
        </where>
    </select>

    <select id="selectQuestionSubjectById" parameterType="Long"
            resultMap="QuestionSubjectResult">
        <include refid="selectQuestionSubjectVo"/>
        where id = #{id}
    </select>

    <insert id="insertQuestionSubject" parameterType="QuestionSubject" useGeneratedKeys="true"
            keyProperty="id">
        insert into question_subject
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="questionInfoId != null">question_info_id,
            </if>
            <if test="questionNumber != null">question_number,
            </if>
            <if test="questionType != null">question_type,
            </if>
            <if test="questionName != null">question_name,
            </if>
            <if test="questionNameAlias != null">question_name_alias,
            </if>
            <if test="questionDescription != null">question_description,
            </if>
            <if test="writeDescription != null">write_description,
            </if>
            <if test="fillBlanksAnswer != null">fill_blanks_answer,
            </if>
            <if test="optionCount != null">option_count,
            </if>
            <if test="whetherScore != null">whether_score,
            </if>
            <if test="scoringMethod != null">scoring_method,
            </if>
            <if test="scoringDescription != null">scoring_description,
            </if>
            <if test="questionScore != null">question_score,
            </if>
            <if test="customTriggerCondition != null">custom_trigger_condition,
            </if>
            <if test="propagandaInfoId != null">propaganda_info_id,
            </if>
            <if test="propagandaTitle != null">propaganda_title,
            </if>
            <if test="questionSort != null">question_sort,
            </if>
            <if test="questionRemark != null">question_remark,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="questionInfoId != null">#{questionInfoId},
            </if>
            <if test="questionNumber != null">#{questionNumber},
            </if>
            <if test="questionType != null">#{questionType},
            </if>
            <if test="questionName != null">#{questionName},
            </if>
            <if test="questionNameAlias != null">#{questionNameAlias},
            </if>
            <if test="questionDescription != null">#{questionDescription},
            </if>
            <if test="writeDescription != null">#{writeDescription},
            </if>
            <if test="fillBlanksAnswer != null">#{fillBlanksAnswer},
            </if>
            <if test="optionCount != null">#{optionCount},
            </if>
            <if test="whetherScore != null">#{whetherScore},
            </if>
            <if test="scoringMethod != null">#{scoringMethod},
            </if>
            <if test="scoringDescription != null">#{scoringDescription},
            </if>
            <if test="questionScore != null">#{questionScore},
            </if>
            <if test="customTriggerCondition != null">#{customTriggerCondition},
            </if>
            <if test="propagandaInfoId != null">#{propagandaInfoId},
            </if>
            <if test="propagandaTitle != null">#{propagandaTitle},
            </if>
            <if test="questionSort != null">#{questionSort},
            </if>
            <if test="questionRemark != null">#{questionRemark},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
        </trim>
    </insert>

    <update id="updateQuestionSubject" parameterType="QuestionSubject">
        update question_subject
        <trim prefix="SET" suffixOverrides=",">
            <if test="questionInfoId != null">question_info_id =
                #{questionInfoId},
            </if>
            <if test="questionNumber != null">question_number =
                #{questionNumber},
            </if>
            <if test="questionType != null">question_type =
                #{questionType},
            </if>
            <if test="questionName != null">question_name =
                #{questionName},
            </if>
            <if test="questionNameAlias != null">question_name_alias =
                #{questionNameAlias},
            </if>
            <if test="questionDescription != null">question_description =
                #{questionDescription},
            </if>
            <if test="writeDescription != null">write_description =
                #{writeDescription},
            </if>
            <if test="fillBlanksAnswer != null">fill_blanks_answer =
                #{fillBlanksAnswer},
            </if>
            <if test="optionCount != null">option_count =
                #{optionCount},
            </if>
            <if test="whetherScore != null">whether_score =
                #{whetherScore},
            </if>
            <if test="scoringMethod != null">scoring_method =
                #{scoringMethod},
            </if>
            <if test="scoringDescription != null">scoring_description =
                #{scoringDescription},
            </if>
            <if test="questionScore != null">question_score =
                #{questionScore},
            </if>
            <if test="customTriggerCondition != null">custom_trigger_condition =
                #{customTriggerCondition},
            </if>
            <if test="propagandaInfoId != null">propaganda_info_id =
                #{propagandaInfoId},
            </if>
            <if test="propagandaTitle != null">propaganda_title =
                #{propagandaTitle},
            </if>
            <if test="questionSort != null">question_sort =
                #{questionSort},
            </if>
            <if test="questionRemark != null">question_remark =
                #{questionRemark},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQuestionSubjectById" parameterType="Long">
        delete
        from question_subject
        where id = #{id}
    </delete>

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

    <insert id="insertQuestionSubjectList" useGeneratedKeys="true" keyProperty="id">
        insert into question_subject(
        question_info_id,
        question_number,
        question_type,
        question_name,
        question_name_alias,
        question_description,
        write_description,
        fill_blanks_answer,
        option_count,
        whether_score,
        scoring_method,
        scoring_description,
        question_score,
        custom_trigger_condition,
        propaganda_info_id,
        propaganda_title,
        question_sort,
        question_remark,
        create_by,
        create_time
        ) values
        <foreach item="QuestionSubject" index="index" collection="list" separator=",">
            (
            #{QuestionSubject.questionInfoId},
            #{QuestionSubject.questionNumber},
            #{QuestionSubject.questionType},
            #{QuestionSubject.questionName},
            #{QuestionSubject.questionNameAlias},
            #{QuestionSubject.questionDescription},
            #{QuestionSubject.writeDescription},
            #{QuestionSubject.fillBlanksAnswer},
            #{QuestionSubject.optionCount},
            #{QuestionSubject.whetherScore},
            #{QuestionSubject.scoringMethod},
            #{QuestionSubject.scoringDescription},
            #{QuestionSubject.questionScore},
            #{QuestionSubject.customTriggerCondition},
            #{QuestionSubject.propagandaInfoId},
            #{QuestionSubject.propagandaTitle},
            #{QuestionSubject.questionSort},
            #{QuestionSubject.questionRemark},
            #{QuestionSubject.createBy},
            #{QuestionSubject.createTime}
            )
        </foreach>
    </insert>

    <select id="selectQuestionSubjectBy" resultType="com.xinelu.manage.vo.questionsubject.QuestionSubjectVO">
        <include refid="selectQuestionSubjectVo"/>
        <where>
            <if test="questionInfoId != null ">
                question_info_id = #{id}
            </if>
        </where>
    </select>

    <delete id="deleteSubjectByQuestionInfoId">
        delete
        from question_subject
        where question_info_id = #{questionInfoId}
    </delete>
</mapper>
