<?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.xhkjedu.sstudy.mapper.paper.PaperQtypeQuestionMapper">
    <!--上传试卷按题型统计(只统计母题)-->
    <select id="paperTypeAnalyze" resultType="java.util.Map">
       SELECT pt.qtypeid,pt.qtypename,COUNT(1) AS num,IFNULL(truncate(COUNT(1)/p.papernum,2),0) AS numrate,
       SUM(ptq.ptqscore) AS score,IFNULL(truncate(SUM(ptq.ptqscore)/p.paperscore,2),0) AS scorerate,
       GROUP_CONCAT(ptq.ptqorder) AS orders
       FROM t_paper_qtype_question ptq LEFT JOIN t_paper_qtype pt ON ptq.ptid = pt.ptid
       LEFT JOIN t_paper p ON ptq.paperid = p.paperid LEFT JOIN t_question q ON ptq.questionid = q.questionid
       WHERE q.qlevel = 0 AND ptq.paperid = #{paperid} GROUP BY pt.qtypeid ORDER BY ptq.ptqorder
    </select>
    <!--上传试卷按难易度统计(只统计母题)-->
    <select id="complexityRateAnalyze" resultType="java.util.Map">
        SELECT q.complexity,COUNT(1) AS complexitynum,IFNULL(truncate(COUNT(1)/p.papernum,2),0) AS complexityrate,
        GROUP_CONCAT(ptq.ptqorder) AS orders ,SUM(ptq.ptqscore) AS scoretotal
        FROM t_paper_qtype_question ptq
        LEFT JOIN t_paper p ON ptq.paperid = p.paperid LEFT JOIN t_question q ON ptq.questionid = q.questionid
        WHERE q.qlevel = 0 AND ptq.paperid = #{paperid} GROUP BY q.complexity ORDER BY ptq.ptqorder
    </select>
    <!--上传试卷按知识点统计(只统计母题)-->
    <select id="pointRateAnalyze" resultType="java.util.Map">
        SELECT qp.pointid,tp.pointname,COUNT(1) AS pointnum,SUM(ptq.ptqscore) AS pointscore,
        IFNULL(truncate(SUM(ptq.ptqscore)/p.paperscore,2),0) AS pointscorerate,GROUP_CONCAT(ptq.ptqorder) AS orders
        FROM t_paper_qtype_question ptq
        LEFT JOIN t_paper p ON ptq.paperid = p.paperid LEFT JOIN t_question q ON ptq.questionid = q.questionid
        LEFT JOIN t_question_point qp ON q.questionid = qp.questionid LEFT JOIN t_point tp ON qp.pointid = tp.pointid
        WHERE q.qlevel = 0 AND ptq.paperid = #{paperid} GROUP BY qp.pointid ORDER BY ptq.ptqorder
    </select>
    
    <!--获取试卷中主观题数量-->
    <select id="getQuestionCountCtype" resultType="java.lang.Integer">
        SELECT COUNT(DISTINCT pqq.questionid) FROM t_paper_qtype_question pqq LEFT JOIN t_question q ON pqq.questionid=q.questionid
        WHERE pqq.paperid=#{paperid} AND q.ctype in(3,13,14,15)
    </select>

    <!--据试卷id获取试卷中所有试题（试题和分值）-->
    <select id="listQuestionByPaperid" resultType="com.xhkjedu.sstudy.model.paper.TPaperQtypeQuestion">
        select ptqid,ptq.questionid,ptqscore,ptqorder,ptq.schoolid,q.ctype,ptq.questionpid,ptq.qn
        from t_paper_qtype_question ptq left join t_question q on ptq.questionid = q.questionid
        where paperid=#{paperid} order by ptqid
    </select>

    <!--根据试卷id获取试卷中所有试题及详情-->
    <select id="listQuestionsDetilByPaperid" resultType="com.xhkjedu.sstudy.model.question.TQuestion">
        select q.questionid,q.qstem,q.qoption,q.qanswer,q.ctype,ptq.ptqscore as score
        from t_paper_qtype_question ptq left join t_question q on ptq.questionid=q.questionid
        where ptq.paperid=#{paperid} order by ptq.ptqid
    </select>

    <!--作业关联试题及处理题型-->
    <select id="listPaperQuesitonsByPaperid" resultType="com.xhkjedu.sstudy.vo.paperreport.PaperRQuestionVo">
        select tq.ptqid,tq.ctype,tq.questionid,tq.questionpid,tq.qn,tq.ptqorder qorder,
        tq.ptqscore qscore,q.qtypename,q.ctype pctype
        from t_paper_qtype_question tq left join t_question q on tq.questionpid=q.questionid
        where tq.paperid=#{paperid} ORDER BY tq.ptqorder,tq.ptqid
    </select>

</mapper>
