<?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.MarkPaperPackageMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.teachcloud.mark.entity.MarkPaperPackage">
        <id column="exam_id" property="examId" />
        <id column="course_paper_id" property="coursePaperId" />
        <id column="paper_type" property="paperType" />
        <id column="package_code" property="packageCode" />
        <result column="course_code" property="courseCode" />
        <result column="course_name" property="courseName" />
        <result column="paper_number" property="paperNumber" />
    </resultMap>

    <select id="getPackageCountByExamId" resultType="java.lang.Integer">
        select count(1)
        FROM mark_paper_package t
        where t.exam_id=#{examId}
        <if test="courseCode != null and courseCode != ''">
            and t.course_code = #{courseCode}
        </if>
        <if test="coursePaperId != null and coursePaperId != ''">
            and t.course_paper_id= #{coursePaperId}
        </if>
        <if test="dpr != null or status != null">
            and exists (select 1 from (select * from mark_paper where status = #{status}) mp left join sys_user su on mp.user_id = su.id
            where t.exam_id = mp.exam_id
            and t.course_paper_id = mp.course_paper_id
            and t.paper_type = mp.paper_type
            <if test="dpr != null">
                <if test="dpr.requestUserId != null">
                    AND mp.user_id = #{dpr.requestUserId}
                </if>
                <if test="dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
                    AND su.org_id IN
                    <foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            </if>
            )
        </if>
    </select>
</mapper>