<?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.sclass.mapper.classroom.ClassroomPaperStudentMapper">
    <!--获取考试学生信息-->
    <select id="findById" resultType="com.xhkjedu.sclass.model.classroom.TClassroomPaperStudent">
        select s.*,p.subjectid,p.papername from t_classroom_paper_student s
        left join t_classroom_paper p on p.paperid=s.paperid
        where s.psid=#{psid} limit 1
    </select>
    <!--更新用户得分-->
    <update id="updateScantronStuScore">
        UPDATE t_classroom_paper_student s SET pschecked=1
        ,s.stuscore = (SELECT SUM(IFNULL(q.stuscore,0)) FROM t_classroom_paper_student_scantron q WHERE q.psid=s.psid)
        WHERE s.psid = #{psid}
    </update>
    <!--判断该作业该班级是否存在未批改学生-->
    <select id="getNotCorrect" resultType="java.lang.Integer">
        select count(*) from t_classroom_paper_student
        where paperid=#{paperid} and classid=#{classid} and pschecked!=1
    </select>
    <!--根据考试学生id获取考试是否完成批阅-->
    <select id="getCheckedByPsId" resultType="java.lang.Integer">
        select p.checked from t_classroom_paper_student ps
        left join t_classroom_paper p on ps.paperid=p.paperid
        where ps.psid=#{psid}
    </select>
    <!--考试按人统计-->
    <select id="listEStudent" resultType="java.util.Map">
        select u.username,ps.stuscore,ps.costtime,ps.stoptime
        from t_classroom_paper_student ps left join t_user u on ps.studentid=u.userid
        where ps.paperid=#{paperid}
        order by ps.stuscore desc
    </select>
    <!--修改学生得分和批改状态-->
    <update id="updateScantronStuScoreAndChecked">
        update t_classroom_paper_student set stuscore=#{stuscore},pschecked=#{pschecked} where psid=#{psid}
    </update>
    <!--批量修改学生得分和批改状态-->
    <update id="batchUpdateScantronStuScoreAndChecked">
        <foreach collection="students" item="s" separator=";">
            update t_classroom_paper_student set stuscore=${s.stuscore},pschecked=${s.pschecked} where psid=${s.psid}
        </foreach>
    </update>
</mapper>
