<?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.tamguo.admin.dao.QuestionMapper">

	<resultMap id="BaseResultMap" type="com.tamguo.admin.model.QuestionEntity" >
	    <id column="user_id" property="userId" jdbcType="BIGINT" />
	    <result column="analysis" property="analysis" jdbcType="VARCHAR" />
	    <result column="paper_id" property="paperId" jdbcType="BIGINT" />
	    <result column="answer" property="answer" jdbcType="VARCHAR" />
	    <result column="chapter_id" property="chapterId" jdbcType="BIGINT" />
	    <result column="chapter_name" property="chapterName" jdbcType="VARCHAR" />
	    <result column="question_type" property="questionType" jdbcType="VARCHAR" />
	    <result column="course_id" property="courseId" jdbcType="VARCHAR" />
	    <result column="course_name" property="courseName" jdbcType="VARCHAR" />
	    <result column="review_point" property="reviewPoint" jdbcType="VARCHAR" />
	    <result column="year" property="year" jdbcType="VARCHAR" />
	    <result column="score" property="score" jdbcType="BIGINT" />
	    <result column="subject_name" property="subjectName" jdbcType="VARCHAR"/>
	    <result column="subject_id" property="subjectId" jdbcType="VARCHAR"/>
	    <result column="audit_status" property="auditStatus" jdbcType="VARCHAR"/>
	</resultMap>

	<select id="findByChapterId" resultType="QuestionEntity">
		SELECT
			q.uid,
			q.analysis,
			q.answer,
			q.chapter_id,
			q.content,
			q.question_type,
			q.course_id,
			q.review_point,
			q.year,
			q.score,
			q.subject_id,
			q.audit_status
		FROM
			tiku_question q
		WHERE
			q.chapter_id = #{chapterId}
	</select>
	
	<select id="findByPaperId" resultType="QuestionEntity">
		SELECT
			q.analysis,
			q.answer,
			q.chapter_id,
			q.content,
			q.paper_id,
			q.question_type,
			q.review_point,
			q.score,
			q.course_id,
			q.uid,
			q.`year`,
			q.subject_id,
			q.audit_status
		FROM
			tiku_question q
		WHERE
			q.paper_id = #{paperId}
	</select>
	
	<select id="queryPageByName" resultType="QuestionEntity">
		SELECT
			q.analysis,
			q.answer,
			q.chapter_id,
			(select c.name from tiku_chapter c where c.uid = q.chapter_id) as chapter_name,
			q.content,
			q.paper_id,
			q.question_type,
			q.review_point,
			q.score,
			q.course_id,
			(select c.name from tiku_course c where c.uid = q.course_id) as course_name,
			q.uid,
			q.`year`,
			q.subject_id,
			(select s.name from tiku_subject s where s.uid = q.subject_id) as subject_name,
			q.audit_status
		FROM
			tiku_question q
		<where>
			<if test="name != null and name != ''">
				q.name like #{name}
			</if>
		</where>		
	</select>
	
	<select id="queryQuestionList" resultType="QuestionEntity">
		SELECT
			q.analysis,
			q.answer,
			q.chapter_id,
			q.content,
			q.paper_id,
			q.question_type,
			q.review_point,
			q.score,
			q.course_id,
			q.uid,
			q.`year`,
			q.subject_id,
			q.audit_status
		FROM
			tiku_question q
		<where>
			<if test="uid != null and uid != ''">
				q.uid = #{uid}
			</if>
			<if test="reviewPoint != null and reviewPoint != ''">
				q.review_point like #{reviewPoint}
			</if>
			<if test="questionType != null and questionType != ''">
				q.question_type = #{questionType}
			</if>
		</where>
	</select>
	
	<select id="selectByUid" resultType="QuestionEntity">
		SELECT
			q.uid,
			q.analysis,
			q.answer,
			q.chapter_id,
			(select c.name from tiku_chapter c where c.uid = q.chapter_id) as chapter_name,
			q.content,
			q.question_type,
			q.course_id,
			q.review_point,
			q.year,
			q.score,
			q.subject_id,
			q.audit_status
		FROM
			tiku_question q
		WHERE
			q.uid = #{uid}
	</select>
	
	<select id="findNormalQuestion" resultType="QuestionEntity">
		SELECT
			q.uid,
			q.analysis,
			q.answer,
			q.chapter_id,
			(select c.name from tiku_chapter c where c.uid = q.chapter_id) as chapter_name,
			q.content,
			q.question_type,
			q.course_id,
			q.review_point,
			q.year,
			q.score,
			q.subject_id,
			q.audit_status
		FROM
			tiku_question q
		WHERE
			q.uid = #{uid} and q.audit_status = '1'
	</select>
</mapper>