<?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.PaperScantronMapper">

    <!-- 答题卡试卷 题型 -->
    <select id="listQtypeAnalyze" resultType="java.util.Map">
        SELECT psq.qtypeid,psq.qtypename,COUNT(1) AS num,IFNULL(truncate(COUNT(1)/p.papernum,2),0) AS numrate,
        psq.pstscore AS score,IFNULL(truncate(SUM(psq.pstscore)/p.paperscore,2),0) AS scorerate,
        GROUP_CONCAT(ps.psorder) AS orders
        FROM t_paper_scantron_qtype psq LEFT JOIN t_paper_scantron ps ON psq.psqtypeid=ps.psqtypeid
        LEFT JOIN t_paper p ON  psq.paperid=p.paperid
        WHERE p.papertype=2 AND psq.paperid=#{paperid} GROUP BY psq.qtypename ORDER BY psq.pstorder
    </select>
    <!--获取答题卡详情-->
    <select id="findById" resultType="com.xhkjedu.sstudy.model.paper.TPaperScantron">
        select ps.psanswer,ps.ctype from t_paper_scantron ps
        where ps.pscaid=#{pscaid} limit 1
    </select>

    <!--获取试卷中主观题数量-->
    <select id="getQuestionCountCtype" resultType="java.lang.Integer">
       SELECT COUNT(*) FROM t_paper_scantron WHERE paperid=#{paperid} AND ctype in(3,13,14,15)
    </select>

    <!--作业中所有试题-->
    <select id="listPaperScansByPaperid" resultType="com.xhkjedu.sstudy.model.paper.TPaperScantron">
        select pscaid,ctype,psorder,psscore,psanswer,qn from t_paper_scantron where paperid=#{paperid} order by psorder
    </select>
</mapper>
