<?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.xjrsoft.module.assessment.mapper.AssessmentPlanAnswerResultMapper">
    <select id="getResultList" parameterType="com.xjrsoft.module.assessment.dto.AssessmentQuestionResultDto" resultType="com.xjrsoft.module.assessment.vo.AssessmentQuestionResultVo">
        SELECT question_id,GROUP_CONCAT(answer_id) as answer FROM assessment_plan_answer_result
        WHERE assessment_template_plan_id = #{dto.assessmentTemplatePlanId} AND student_user_id = #{dto.userId} GROUP BY question_id
    </select>

    <select id="getClassResult" resultType="com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerClassResultVo">
        SELECT t2.name AS class_name,
        (SELECT COUNT(a1.id) FROM assessment_plan_answer_student a1
        INNER JOIN base_student_school_roll a2 ON a1.student_user_id = a2.user_id WHERE a2.class_id = t1.class_id
        AND a1.assessment_template_plan_id = t1.assessment_template_plan_id) AS student_count,
        (SELECT COUNT(a1.id) FROM assessment_plan_answer_student a1
        INNER JOIN base_student_school_roll a2 ON a1.student_user_id = a2.user_id WHERE a2.class_id = t1.class_id AND a1.submit_status = 1
        AND a1.assessment_template_plan_id = t1.assessment_template_plan_id) submitted_count,
        (SELECT COUNT(a1.id) FROM assessment_plan_answer_student a1
        INNER JOIN base_student_school_roll a2 ON a1.student_user_id = a2.user_id WHERE a2.class_id = t1.class_id
        AND a1.assessment_template_plan_id = t1.assessment_template_plan_id AND (a1.submit_status = 0 OR a1.submit_status IS NULL)) AS unsubmitted_count
        FROM assessment_plan_answer_class t1
        LEFT JOIN base_class t2 ON t1.class_id = t2.id
        WHERE t1.delete_mark = 0 AND t1.assessment_template_plan_id = #{id}
        order by t2.name
    </select>

    <select id="getQuestionResult" resultType="com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerDetailVo">
        SELECT question_id,answer_id,COUNT(*) AS choose_count FROM assessment_plan_answer_result WHERE delete_mark = 0 AND assessment_template_plan_id = #{id}
        GROUP BY question_id,answer_id
    </select>
    <select id="getScaleQuestionResult" resultType="com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerDetailVo">
        SELECT t1.question_id,t1.answer_id,COUNT(t1.id) AS choose_count FROM assessment_plan_answer_result t1
        INNER JOIN assessment_plan_question t2 ON t1.question_id = t2.id
        WHERE t1.delete_mark = 0 AND t1.assessment_template_plan_id = #{id}
        AND t2.type = 'scale_question'
        GROUP BY t1.question_id,t1.answer_id
    </select>
</mapper>