<?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.qmth.teachcloud.mark.mapper.ScanBatchMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.teachcloud.mark.entity.ScanBatch">
        <id column="id" property="id" />
        <result column="exam_id" property="examId" />
        <result column="user_id" property="userId" />
        <result column="scan_count" property="scanCount" />
        <result column="assigned_count" property="assignedCount" />
        <result column="status" property="status" />
        <result column="creator_id" property="creatorId" />
        <result column="updater_id" property="updaterId" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="course_paper_id" property="coursePaperId" />
    </resultMap>
	<update id="updateAssignedCount">
		UPDATE scan_batch t
		SET t.assigned_count = (select count(distinct bp.student_id)
		from scan_batch_paper bp
		where bp.batch_id = #{id}
		and bp.assigned = 1)
		WHERE t.id = #{id}
	</update>
	<update id="updateScanCount">
		UPDATE scan_batch t
		SET t.scan_count =
		(select count(distinct bp.student_id) from scan_batch_paper bp where
		bp.batch_id = #{id})
		where t.id = #{id}
	</update>
	<select id="findStudentCountByBatch" resultType="int">
		SELECT count(distinct bp.student_id)
		FROM scan_batch_paper bp
		WHERE bp.batch_id = #{batchId}
	</select>
</mapper>
