<?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.questionsubjectoption.QuestionSubjectOptionMapper">

    <resultMap type="QuestionSubjectOption" id="QuestionSubjectOptionResult">
        <result property="id" column="id"/>
        <result property="questionnaireSubjectId" column="questionnaire_subject_id"/>
        <result property="questionName" column="question_name"/>
        <result property="optionName" column="option_name"/>
        <result property="optionAnswer" column="option_answer"/>
        <result property="optionScore" column="option_score"/>
        <result property="optionSort" column="option_sort"/>
        <result property="optionRemark" column="option_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"/>
	    <result property="speechContextText" column="speech_context_text"/>
	    <result property="intent" column="intent"/>
        <result property="contentedFlag" column="contented_flag"/>
        <result property="remarkableFlag" column="remarkable_flag"/>
	    <result property="additionalQuestion" column="additional_question"/>
	    <result property="additionalQuestionIntent" column="additional_question_intent"/>
    </resultMap>

    <sql id="selectQuestionSubjectOptionVo">
        select id,
               questionnaire_subject_id,
               question_name,
               option_name,
               option_answer,
               option_score,
               option_sort,
               option_remark,
               create_by,
               create_time,
               update_by,
               update_time,
               speech_context_text,
               intent,
               contented_flag,
               remarkable_flag,
               additional_question,
	    	   additional_question_intent
        from question_subject_option
    </sql>

    <select id="selectQuestionSubjectOptionList" parameterType="QuestionSubjectOption"
            resultMap="QuestionSubjectOptionResult">
        <include refid="selectQuestionSubjectOptionVo"/>
        <where>
            <if test="questionnaireSubjectId != null ">
                and questionnaire_subject_id = #{questionnaireSubjectId}
            </if>
            <if test="questionName != null  and questionName != ''">
                and question_name like concat('%', #{questionName}, '%')
            </if>
            <if test="optionName != null  and optionName != ''">
                and option_name like concat('%', #{optionName}, '%')
            </if>
            <if test="optionAnswer != null  and optionAnswer != ''">
                and option_answer = #{optionAnswer}
            </if>
            <if test="optionScore != null ">
                and option_score = #{optionScore}
            </if>
            <if test="optionSort != null ">
                and option_sort = #{optionSort}
            </if>
            <if test="optionRemark != null  and optionRemark != ''">
                and option_remark = #{optionRemark}
            </if>
            <if test="contentedFlag != null  and contentedFlag != ''">
                and contented_flag = #{contentedFlag}
            </if>
            <if test="remarkableFlag != null  and remarkableFlag != ''">
                and remarkable_flag = #{remarkableFlag}
            </if>
        </where>
    </select>

    <select id="selectQuestionSubjectOptionById" parameterType="Long"
            resultMap="QuestionSubjectOptionResult">
        <include refid="selectQuestionSubjectOptionVo"/>
        where id = #{id}
    </select>

    <insert id="insertQuestionSubjectOption" parameterType="QuestionSubjectOption" useGeneratedKeys="true"
            keyProperty="id">
        insert into question_subject_option
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="questionnaireSubjectId != null">questionnaire_subject_id,
            </if>
            <if test="questionName != null">question_name,
            </if>
            <if test="optionName != null">option_name,
            </if>
            <if test="optionAnswer != null">option_answer,
            </if>
            <if test="optionScore != null">option_score,
            </if>
            <if test="optionSort != null">option_sort,
            </if>
            <if test="optionRemark != null">option_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>
	        <if test="speechContextText != null">speech_context_text,
	        </if>
	        <if test="intent != null">intent,
	        </if>
            <if test="contentedFlag != null">contented_flag,
            </if>
            <if test="remarkableFlag != null">remarkable_flag,
            </if>
	        <if test="additionalQuestion != null">additional_question,
	        </if>
	        <if test="additionalQuestionIntent != null">additional_question_intent,
	        </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="questionnaireSubjectId != null">#{questionnaireSubjectId},
            </if>
            <if test="questionName != null">#{questionName},
            </if>
            <if test="optionName != null">#{optionName},
            </if>
            <if test="optionAnswer != null">#{optionAnswer},
            </if>
            <if test="optionScore != null">#{optionScore},
            </if>
            <if test="optionSort != null">#{optionSort},
            </if>
            <if test="optionRemark != null">#{optionRemark},
            </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>
	        <if test="speechContextText != null">#{speechContextText},
	        </if>
	        <if test="intent != null">#{intent},
	        </if>
            <if test="contentedFlag != null">#{contentedFlag},
            </if>
            <if test="remarkableFlag != null">#{remarkableFlag},
            </if>
	        <if test="additionalQuestion != null">#{additionalQuestion},
	        </if>
	        <if test="additionalQuestionIntent != null">#{additionalQuestionIntent},
	        </if>
        </trim>
    </insert>

    <update id="updateQuestionSubjectOption" parameterType="QuestionSubjectOption">
        update question_subject_option
        <trim prefix="SET" suffixOverrides=",">
            <if test="questionnaireSubjectId != null">questionnaire_subject_id =
                #{questionnaireSubjectId},
            </if>
            <if test="questionName != null">question_name =
                #{questionName},
            </if>
            <if test="optionName != null">option_name =
                #{optionName},
            </if>
            <if test="optionAnswer != null">option_answer =
                #{optionAnswer},
            </if>
            <if test="optionScore != null">option_score =
                #{optionScore},
            </if>
            <if test="optionSort != null">option_sort =
                #{optionSort},
            </if>
            <if test="optionRemark != null">option_remark =
                #{optionRemark},
            </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>
	        <if test="speechContextText != null">speech_context_text =
		        #{speechContextText},
	        </if>
	        <if test="intent != null">intent =
		        #{intent},
	        </if>
            <if test="contentedFlag != null">contented_flag =
                #{contentedFlag},
            </if>
            <if test="remarkableFlag != null">remarkable_flag =
                #{remarkableFlag},
            </if>
	        <if test="additionalQuestion != null">additional_question =
		        #{additionalQuestion},
	        </if>
	        <if test="additionalQuestionIntent != null">additional_question_intent =
		        #{additionalQuestionIntent},
	        </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQuestionSubjectOptionById" parameterType="Long">
        delete
        from question_subject_option
        where id = #{id}
    </delete>

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

    <insert id="insertQuestionSubjectOptionList">
        insert into question_subject_option(
        questionnaire_subject_id,
        question_name,
        option_name,
        option_answer,
        option_score,
        option_sort,
        option_remark,
        create_by,
        create_time,
	    speech_context_text,
	    intent,
        contented_flag,
        remarkable_flag,
	    additional_question,
	    additional_question_intent
	    ) values
        <foreach item="QuestionSubjectOption" index="index" collection="list" separator=",">
            (
            #{QuestionSubjectOption.questionnaireSubjectId},
            #{QuestionSubjectOption.questionName},
            #{QuestionSubjectOption.optionName},
            #{QuestionSubjectOption.optionAnswer},
            #{QuestionSubjectOption.optionScore},
            #{QuestionSubjectOption.optionSort},
            #{QuestionSubjectOption.optionRemark},
            #{QuestionSubjectOption.createBy},
            #{QuestionSubjectOption.createTime},
	        #{QuestionSubjectOption.speechContextText},
	        #{QuestionSubjectOption.intent},
            #{QuestionSubjectOption.contentedFlag},
            #{QuestionSubjectOption.remarkableFlag},
	        #{QuestionSubjectOption.additionalQuestion},
	        #{QuestionSubjectOption.additionalQuestionIntent}
	        )
        </foreach>
    </insert>

    <select id="selectQuestionSubjectOptions"
            resultType="com.xinelu.manage.vo.questionsubjectoption.QuestionSubjectOptionVO">
        select id,
        questionnaire_subject_id,
        question_name,
        option_name,
        option_answer,
        option_score,
        option_sort,
        option_remark,
        create_by,
        create_time,
        update_by,
        update_time,
	    speech_context_text,
	    intent,
        contented_flag,
        remarkable_flag,
	    additional_question,
	    additional_question_intent
        from question_subject_option
        <where>
            <if test="questionSubjectIds != null and questionSubjectIds.size() > 0">
                questionnaire_subject_id in
                <foreach item="questionSubjectIds" collection="questionSubjectIds" open="(" separator="," close=")">
                    #{questionSubjectIds}
                </foreach>
            </if>
        </where>
    </select>

    <delete id="deleteOptionByQuestionSubjectIds">
        delete from question_subject_option
        <where>
            <if test="questionSubjectIds != null and questionSubjectIds.size() > 0">
                questionnaire_subject_id in
                <foreach item="questionSubjectIds" collection="questionSubjectIds" open="(" separator="," close=")">
                    #{questionSubjectIds}
                </foreach>
            </if>
        </where>
    </delete>
</mapper>