<?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="lingtao.net.dao.QuestionMapper">

	<select id="questions" parameterType="Question"
		resultType="Question">
		SELECT
		*
		FROM
		tbl_question
		<where>
			<if test="question != null and question != ''">
				question like '%${question}%'
			</if>
			<if test="type != null and type != ''">
				type = #{type}
			</if>
		</where>
		order by createDate desc
	</select>
	<!-- 获取单选题 -->
	<select id="getSingleQuestions" resultType="Question">
		SELECT
		*
		FROM
		tbl_question
		where type = 0
		ORDER BY id ASC
	</select>
	<!-- 获取多选题 -->
	<select id="getMultipleQuestions" resultType="Question">
		SELECT
		*
		FROM
		tbl_question
		where type = 1
		ORDER BY id ASC
	</select>
	<!-- 获取填空题 -->
	<select id="getFillQuestions" resultType="Question">
		SELECT
		*
		FROM
		tbl_question
		where type = 2
		ORDER BY id ASC
	</select>

	<insert id="addQuestion" parameterType="Question">
		insert into tbl_question
		(question,answer1,answer2,answer3,answer4,answer,type,ansCount,createBy,createDate)
		values
		(#{question},#{answer1},#{answer2},#{answer3},#{answer4},#{answer},#{type},#{ansCount},#{createBy},now())
	</insert>

	<update id="updateQuestionById" parameterType="Question">
		update tbl_question
		<set>
			<if test="question != null">
				question = #{question,jdbcType=VARCHAR},
			</if>
			<if test="answer1 != null">
				answer1 = #{answer1,jdbcType=VARCHAR},
			</if>
			<if test="answer2 != null">
				answer2 = #{answer2,jdbcType=VARCHAR},
			</if>
			<if test="answer3 != null">
				answer3 = #{answer3,jdbcType=VARCHAR},
			</if>
			<if test="answer4 != null">
				answer4 = #{answer4,jdbcType=VARCHAR},
			</if>
			<if test="answer != null">
				answer = #{answer,jdbcType=VARCHAR},
			</if>
			<if test="type != null">
				type = #{type,jdbcType=VARCHAR},
			</if>
			<if test="ansCount != null">
				ansCount = #{ansCount,jdbcType=INTEGER},
			</if>
			<if test="updateBy != null">
				updateBy = #{updateBy,jdbcType=VARCHAR},
			</if>
			<if test="updateDate != null">
				updateDate = now(),
			</if>
		</set>
		where id = #{id,jdbcType=INTEGER}
	</update>

	<delete id="deleteQuestionById">
		delete from tbl_question where id = #{id}
	</delete>
</mapper>