<?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.paperreport.PaperStudentReportMapper" >
    <!--作业概况-学生概况-->
    <select id="getPaperStu" resultType="java.util.Map">
        select ps.userscore,ps.paperscore,ps.costtime,truncate(ps.userscore*100/ps.paperscore,2)scorerate
        ,prc.classnum,prc.classavgscore,prc.classmaxscore
        ,(select count(*)+1 from t_paper_student ps1
        where ps1.paperid=ps.paperid and ps1.classid=ps.classid and ps1.userscore>ps.userscore)'rank'
        from t_paper_rclass prc left join t_paper_student ps on ps.paperid=prc.paperid
        and ps.classid = prc.classid and ps.studentid=#{studentid}
        where prc.paperid=#{paperid} and prc.classid=#{classid}
    </select>
    <!--作业概况-试题错误率-->
    <select id="listPaperClassQuestionRate" resultType="java.util.Map">
        select q.qorder,q.qn,q.classscorerate,q.classlostrate,q.lostrate,q.scorerate,q.ctype
        from t_paper_rstudent_question q
        where paperid=#{paperid} and q.classid=#{classid} and q.studentid=#{studentid}
        order by qorder
    </select>
    <!--作业概况-知识点错误率-->
    <select id="listPaperClassPointRate" resultType="java.util.Map">
        select pointname,scorerate,lostrate
        from t_paper_rstudent_point where paperid=#{paperid} and classid=#{classid} and studentid=#{studentid}
    </select>
    <!--作业分析-->
    <select id="getPaperAnalyze" resultType="java.util.Map">
        select p.paperid,p.papertype,p.papername,p.hasreport,pa.pointjson,ifnull(ps.showanswer,0) as showanswer,ps.psid
        ,(select pc.showtype from t_paper_class pc where pc.paperid=ps.paperid and pc.classid=ps.classid)showtype
        from t_paper p left join t_paper_analyze pa on p.paperid = pa.paperid
        left join t_paper_student ps on p.paperid = ps.paperid
        where p.paperid=#{paperid} and ps.classid=#{classid} and ps.studentid=#{studentid}
    </select>
    <resultMap id="typeResult" type="java.util.Map">
        <result property="ptid" column="ptid"/>
        <result property="ptorder" column="ptorder"/>
        <result property="qtypename" column="qtypename"/>
        <collection property="questions" ofType="java.util.Map" javaType="java.util.List">
            <result property="ptqid" column="ptqid"/>
            <result property="qn" column="qn"/>
            <result property="qorder" column="qorder"/>
            <result property="qscore" column="qscore"/>
            <result property="answerjson" column="answerjson"/>
            <result property="ctype" column="ctype"/>
            <result property="questionid" column="questionid"/>
            <result property="classavgscore" column="classavgscore"/>
            <result property="classscorerate" column="classscorerate"/>
            <result property="stuscore" column="stuscore"/>
            <result property="scorerate" column="scorerate"/>
            <result property="answertype" column="answertype"/>
            <result property="useranswer" column="useranswer"/>
            <result property="converted" column="converted"/>
            <result property="useranswertxt" column="useranswertxt"/>
            <result property="good" column="good"/>
            <result property="qstem" column="qstem"/>
            <result property="qoption" column="qoption"/>
            <result property="qanswer" column="qanswer"/>
            <result property="qanalyze" column="qanalyze"/>
            <result property="hashear" column="hashear"/>
            <result property="hearfile" column="hearfile"/>
            <result property="qlevel" column="qlevel"/>
            <result property="optionnum" column="optionnum"/>
            <result property="ptqid" column="ptqid"/>
            <result property="checkcomm" column="checkcomm"/>
            <result property="answered" column="answered"/>
        </collection>
    </resultMap>
    <!--题库作业试题-->
    <select id="listTkSt" resultMap="typeResult">
        select pq.qtypename,pq.ptid,pq.ptorder,psq.qorder,sum(psq.qscore) as qscore,tq.ctype,
        (if(tq.qlevel=1, pqq.qn, pqq.ptqorder)) as qn,
        pqq.questionpid as questionid,tq.qtypename qqtypename
        <if test="showanswer==1 or hasreport==1">
            ,q.classavgscore,q.classscorerate,truncate(sum(psq.stuscore)*100/sum(psq.qscore),2) as scorerate
            ,sum(psq.stuscore) as stuscore,psq.good
            ,(if(tq.qlevel=1, psq.checkcomm, '')) as checkcomm
        </if>
        <if test="showanswer==1">
            ,tq.qanswer,tq.qanalyze
        </if>
        ,psq.answered,psq.answertype,psq.useranswer,psq.converted,psq.useranswertxt
        ,tq.qstem,tq.qoption,tq.hashear,tq.hearfile,tq.qlevel
        from t_paper_qtype_question pqq left join t_paper_qtype pq on pqq.ptid=pq.ptid
        right join t_paper_student_question psq on pqq.paperid=psq.paperid
        and psq.classid=#{classid} and psq.studentid=#{studentid} and pqq.questionid=psq.questionid
        left join t_question tq on pqq.questionpid=tq.questionid
        left join t_paper_rclass_question q
        on pqq.paperid=q.paperid and pqq.questionpid=q.questionid and q.classid=#{classid}
        where pqq.paperid=#{paperid} group by pqq.questionpid  order by pqq.ptqorder
    </select>
    <!--附件作业试题-->
    <select id="listFjSt" resultMap="typeResult">
        select pq.qtypename,pq.psqtypeid as ptid,pq.pstorder as ptorder,ps.qn,ps.psorder as qorder
        ,ps.psscore as qscore,ps.ctype,ps.optionnum,ps.pscaid as ptqid,ps.qtypename as qqtypename
        <if test="showanswer==1 or hasreport==1">
            ,q.classavgscore,q.classscorerate,truncate(pss.stuscore*100/pss.qscore,2)scorerate
            ,pss.stuscore,pss.good,pss.checkcomm
        </if>
        <if test="showanswer==1">
            ,ps.psanswer qanswer
        </if>
        ,pss.answered,pss.answertype,pss.useranswer,pss.converted,pss.useranswertxt
        from t_paper_scantron ps left join t_paper_student_scantron pss on ps.pscaid=pss.pscaid
        left join t_paper_scantron_qtype pq on ps.psqtypeid=pq.psqtypeid
        left join t_paper_rclass_question q
        on ps.paperid=q.paperid and q.ptqid = ps.pscaid and q.classid=#{classid}
        where ps.paperid=#{paperid} and pss.classid=#{classid} and pss.studentid=#{studentid}
        order by ps.psorder
    </select>
    <!--题库作业子题-->
    <select id="listZtQuestion" resultType="java.util.Map">
        select q.questionid,q.questionpid,q.qscore,q.qn
        ,q.answered,q.answertype,q.useranswer,q.converted,q.useranswertxt
        <if test="showanswer==1 or hasreport==1">
            ,q.stuscore,q.good,ifnull(q.checkcomm,'') as checkcomm
        </if>
        <if test="showanswer==1">
            ,tq.qanswer,tq.qanalyze
        </if>
        ,tq.sorder,tq.qstem,tq.qoption,tq.ctype,tq.qtypename
        from t_question tq right join t_paper_student_question q on tq.questionid=q.questionid
        where q.psid=#{psid} and tq.questionpid in
        <foreach collection="questionids" item="questionid" open="(" separator="," close=")">#{questionid}</foreach>
        order by tq.sorder
    </select>
    <!--优秀作答-->
    <resultMap id="answerResult" type="java.util.Map">
        <result property="ptid" column="ptid"/>
        <result property="qorder" column="qorder"/>
        <result property="qn" column="mqn"/>
        <collection property="students" ofType="java.util.Map" javaType="java.util.List">
            <result property="studentid" column="studentid"/>
            <result property="username" column="username"/>
            <result property="headpic" column="headpic"/>
            <result property="qorder" column="qorder"/>
            <result property="psid" column="psid"/>
            <collection property="questions" ofType="java.util.Map" javaType="java.util.List">
                <result property="studentid" column="studentid"/>
                <result property="qn" column="qn"/>
                <result property="qorder" column="qorder"/>
                <result property="psqid" column="psqid"/>
                <result property="questionpid" column="questionpid"/>
                <result property="stuscore" column="stuscore"/>
                <result property="qscore" column="qscore"/>
                <result property="answertype" column="answertype"/>
                <result property="useranswer" column="useranswer"/>
                <result property="converted" column="converted"/>
                <result property="useranswertxt" column="useranswertxt"/>
                <result property="checkcomm" column="checkcomm"/>
                <result property="checkid" column="checkid"/>
            </collection>
        </collection>
    </resultMap>
    <select id="listGoodAnswer" resultMap="answerResult">
        select q.qorder,q.qn,q.stuscore,q.qscore,q.answertype,q.useranswer,q.converted,q.useranswertxt,q.checkcomm,q.checkid
        ,q.studentid,q.psid,u.username,u.headpic
        <if test="papertype!=2">,q.qorder mqn,q.psqid,q.questionpid from t_paper_student_question q</if>
        <if test="papertype==2">,q.qn mqn,q.pssid psqid from t_paper_student_scantron q</if>
        left join t_user u on q.studentid=u.userid
        where q.paperid=#{paperid} and q.classid=#{classid} and good=1
        order by q.qorder,q.qn,convert(u.username using gbk)
    </select>
    <!--作业基本信息-->
    <select id="getPaper" resultType="java.util.Map">
        select p.papername,p.papertype,p.paperclass,p.createtime,p.hasfile,p.hearfile,p.committype,p.timetype
        ,pg.starttime,pg.stoptime,pg.showtype,ps.papernum,ps.paperscore,ps.showanswer
        ,(if(ps.showanswer=1, ps.userscore, 0)) as userscore
        from t_paper p left join t_paper_class pg on p.paperid = pg.paperid
        left join t_paper_student ps on ps.paperid=pg.paperid and ps.classid=pg.classid
        where p.paperid=#{paperid} and pg.classid=#{classid} and ps.studentid=#{studentid}
    </select>
</mapper>