<?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.sexam.mapper.paperstudent.EScanerrorMapper">
    <!--试卷扫描出错列表-->
    <select id="listByBatchIds" resultType="com.xhkjedu.sexam.model.paperstudent.EScanerror">
        select serrorid, batchid, errortype, pagenum, stupic, errorstate, createtime
        from e_scanerror where batchid in (${batchids})
    </select>
    <!--批量标记待处理的扫描异常为已处理缺考异常-->
    <update id="batchHandleQkError">
        update e_scanerror
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="errorstate = case" suffix="end,">
                <foreach collection="list" item="q">
                    when serrorid=#{q.serrorid} then #{q.errorstate}
                </foreach>
            </trim>
            <trim prefix="qkjg = case" suffix="end,">
                <foreach collection="list" item="q">
                    when serrorid=#{q.serrorid} then #{q.qkjg}
                </foreach>
            </trim>
        </trim>
        <where>
            <foreach collection="list" item="q" separator="or">
                serrorid=#{q.serrorid}
            </foreach>
        </where>
    </update>
    <!--更新状态-->
    <update id="updateErrorState">
        update e_scanerror set errorstate=#{errorstate} where serrorid=#{serrorid}
    </update>
    <!--获取考号重复扫描出错记录id-->
    <select id="listIdByExamNo" resultType="java.lang.Integer">
        SELECT e.serrorid FROM e_scanerror e left join e_scanbatch b on b.batchid=e.batchid
        WHERE b.epid=#{epid} and e.errortype=3 and e.errorjson->'$.examno'=#{examno}
    </select>

    <!--获取扫描操作各类型未处理数量-->
    <select id="listBatchErrorNum" resultType="java.util.Map">
        select r.errortype,count(*) num from e_scanerror r
        left join e_scanbatch b on r.batchid=b.batchid
        where b.epid=#{epid} and r.errorstate=0 group by r.errortype order by r.errortype
    </select>
    <!--根据试卷id和错误类型获取扫描错误信息-->
    <select id="listErrorsByErrortype" resultType="com.xhkjedu.sexam.model.paperstudent.EScanerror">
        select r.serrorid,r.batchid,b.batchname,b.epid,r.errortype,r.pagenum,r.stupic,r.errorstate,r.examno,
               r.createtime,r.qkjg
        from e_scanerror r left join e_scanbatch b on r.batchid=b.batchid
        where b.epid=#{epid} and r.errortype=#{errortype} order by b.batchid desc,r.serrorid asc
    </select>
    <!--根据批次名称获取扫描出错数量-->
    <select id="getErrNumByBatchName" resultType="java.lang.Integer">
        select count(es.serrorid) from e_scanbatch b left join e_scanerror es on b.batchid = es.batchid
        where b.batchname=#{batchname}
    </select>

    <!--获取考试试卷对应出错准考证号-->
    <select id="getErrorNumByExamno" resultType="java.lang.Integer">
        select count(es.serrorid) from e_scanbatch b left join e_scanerror es on b.batchid = es.batchid
        where b.epid=#{epid} and es.examno=#{examno} and es.errorstate=0
    </select>

    <!--修改stupic地址-->
    <update id="updateErrorStupic">
        update e_scanerror set stupic=#{stupic} where serrorid=#{serrorid}
    </update>

    <!--根据serrorid获取errorjson数据-->
    <select id="getErrorJsonById" resultType="com.xhkjedu.sexam.model.paperstudent.EScanerror">
        select  serrorid, batchid, errortype, pagenum, stupic, errorstate,errorjson from e_scanerror where serrorid=#{serrorid}
    </select>

    <!--获取errorjson内容-->
    <select id="listErrorObjByIds" resultType="com.xhkjedu.sexam.model.paperstudent.EScanerror">
        select serrorid,errorjson from e_scanerror where serrorid in
        <foreach collection="serrorids" index="index" item="id" separator="," close=")" open="(">
            #{id}
        </foreach>
    </select>
    <!--修改扫描出错状态和考号-->
    <update id="updateErrorStateExamno">
        update e_scanerror set errorstate=#{errorstate},examno=#{examno} where serrorid=#{serrorid}
    </update>
</mapper>
