<?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">
<!-- 命名，每一个映射对象不一样
	namespace:必须与对应的接口全类名一致
 -->
 <mapper namespace="com.iamberry.wechat.service.mapper.QuestionOptionMapper">
	<sql id="questionOptionMapper">
		Q.OPTION_ID optionId,
		Q.OPTION_QUESION_ID optionQuesionId,
		Q.OPTION_NAME optionName,
		Q.OPTION_SCORE optionScore,
		Q.OPTION_ORDER optionOrder,
		Q.OPTION_CREATE_DATE optionCreateDate,
		Q.OPTION_UPDATE_DATE optionUpdateDate,
		Q.OPTION_STATUS optionStatus,
		Q.OPTION_NUMBER optionNumber,
		Q.OPTION_IS_CHEKCBOX optionIsChekcbox
	</sql>
	<!-- 根据题目id获取选项 -->
	<select id="selectOptionById" parameterType="Integer" resultType="QuestionnaireOption">
		select * from tb_iamberry_questionnaire_option
		where 
		option_quesion_id = #{optionQuesionId}
		and
		option_status = 1
		ORDER BY OPTION_ORDER
	</select>
	
		<!-- 根据选项id修改选项内容 -->
	<update id="updateOptionById" parameterType="QuestionnaireOption">
		UPDATE 
			TB_IAMBERRY_QUESTIONNAIRE_OPTION
		SET  
			OPTION_NAME = #{optionName},
			OPTION_SCORE = #{optionScore},
			OPTION_IS_CHEKCBOX = #{optionIsChekcbox}
		WHERE
			option_id = #{optionId}
	</update>
	
		<!-- 根据选项id进行排序 -->
	<update id="optionSortingById" parameterType="QuestionnaireOption">
		UPDATE 
			TB_IAMBERRY_QUESTIONNAIRE_OPTION
		SET  
			OPTION_ORDER = #{optionOrder}
		WHERE
			option_id = #{optionId}
	</update>
		<!-- 插入问题选项数据 -->
	<insert id="insertOption" parameterType="QuestionnaireOption" useGeneratedKeys="true" keyProperty="questionId">
		 INSERT INTO 
		 	TB_IAMBERRY_QUESTIONNAIRE_OPTION
		 		(
			 		option_quesion_id,option_name,option_score,option_order,option_create_date,option_status,option_number,option_is_chekcbox
				)
		 VALUES 
		  	( 
			  #{optionQuesionId},
			  #{optionName},
			  #{optionScore},
			  #{optionOrder},
			  #{optionCreateDate},
			  #{optionStatus},
			  #{optionNumber},
			  #{optionIsChekcbox}
		  	)
	</insert>
</mapper>