<?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.distributed.print.business.mapper.BasicExamMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.teachcloud.common.entity.BasicExam">
        <result column="id" property="id" />
        <result column="school_id" property="schoolId" />
        <result column="semester_id" property="semesterId" />
        <result column="name" property="name" />
        <result column="category" property="category" />
        <result column="exam_model" property="examModel" />
        <result column="enable" property="enable" />
        <result column="create_id" property="createId" />
        <result column="create_time" property="createTime" />
        <result column="update_id" property="updateId" />
        <result column="update_time" property="updateTime" />
    </resultMap>


    <select id="findBasicExamPage" resultType="com.qmth.teachcloud.common.entity.BasicExam">
        SELECT
            a.id,
            a.school_id schoolId,
            a.semester_id semesterId,
            b.name semesterName,
            a.name,
            a.category,
            a.exam_model examModel,
            a.enable,
            a.create_id createId,
            a.create_time createTime,
            a.update_id updateId,
            a.update_time updateTime
        FROM
            basic_exam a
        LEFT JOIN basic_semester b ON a.semester_id = b.id
        <where>
            a.school_id = #{schoolId} and b.enable = true
            <if test="semesterId != null and semesterId != ''">
                and a.semester_id = #{semesterId}
            </if>
            <if test="enable != null and enable != '' or enable == 0">
                and a.enable = #{enable}
            </if>
            <if test="dpr != null">
                <if test="dpr.requestUserId != null">
                    AND a.create_id = #{dpr.requestUserId}
                </if>
                <if test="dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
                    AND a.org_id IN
                    <foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            </if>
        </where>
        order by a.create_time desc
    </select>
</mapper>