<?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="cn.com.countrygarden.bi.main.dao.review.ReviewQuestionnaireMapper">
	<!-- 通用查询映射结果 -->
	<resultMap id="BaseResultMap"
		type="cn.com.countrygarden.bi.main.model.review.ReviewQuestionnaire">

		<id column="id" property="id" />
		<result column="name" property="name" />
		<result column="investigationmanagement_id"
			property="investigationmanagementId" />
		<result column="described" property="described" />
		<result column="flag" property="flag" />
		<result column="create_by" property="createBy" />
		<result column="create_time" property="createTime" />
		<result column="update_by" property="updateBy" />
		<result column="update_time" property="updateTime" />
	</resultMap>



	<select id="getfalag" resultType="java.lang.Integer"
		parameterType="java.lang.Integer">


		select count(ri.id) from review_investigated ri
		where
		ri.id=#{id} and ri.flag=1
	</select>

	<select id="getisrepeat" resultType="java.lang.Integer"
		parameterType="java.lang.Integer">


		select count(rs.id) from review_score rs,review_judge
		rj,review_investigated
		ri
		where rs.judge_id=rj.id and
		rj.investigated_id=ri.id and ri.id=#{id} and
		rs.judge_id=#{judgeId}
		and
		ri.questionnaire_id=#{questionnaireId} and rj.is_submission=1 and
		ri.is_repeat=0
	</select>



	<resultMap id="answer"
		type="cn.com.countrygarden.bi.main.model.review.ReviewQuestionnaire">
		<id column="id" property="id" />
		<result column="name" property="name" />
		<result column="described" property="described" />
		<collection property="reviewquestionnaireproblemlist"
			javaType="ArrayList"
			ofType="cn.com.countrygarden.bi.main.model.review.ReviewQuestionnaireProblem">
			<id column="id" property="id" />
			<result column="questionnaire_id" property="questionnaireId" />
			<result column="questionnaire_problem_classification_id"
				property="questionnaireProblemClassificationId" />
			<result column="question_type_id" property="questionTypeId" />
			<result column="score" property="score" />
			<result column="title_description" property="titleDescription" />
			<result column="answer_description"
				property="answerDescription" />
		</collection>
	</resultMap>
	
  <select id="ReviewQuestionnairelistVo"
		resultType="cn.com.countrygarden.bi.main.dto.ReviewQuestionnairelistVo">
	select q.id id,q.name name ,q.flag flag ,(select count(i.id) from
		review_investigated i where
		i.questionnaire_id=q.id) total,(select count(distinct(j.investigated_id)) from review_judge j,review_investigated i
		where j.questionnaire_id=q.id and j.is_submission=0 and i.id=j.investigated_id  and i.flag=0) underWay from
		review_questionnaire q
		where q.flag=1 
		<if test="name!=null and name!=''">
			and q.name like concat('%',#{name},'%')
		</if>
		<if test="name!=null">
			and q.investigationmanagement_id =#{investigationmanagementId}
		</if>
		<if test="hasRole==false">
			and q.create_by=#{userCode}
		</if>
		order by q.create_time desc
	</select>




</mapper>