<?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.common.mapper.BasicClazzMapper">

    <select id="findBasicClazzPage"
            resultType="com.qmth.teachcloud.common.bean.result.BasicClazzResult">
        SELECT
            clz.id,
            clz.school_id AS schoolId,
            clz.clazz_code AS clazzCode,
            clz.clazz_name AS clazzName,
            clz.enable,
            clz.create_id AS createId,
            clz.create_time AS createTime,
            bm.id AS majorId,
            bm.name AS majorName
        FROM
            basic_clazz clz
                LEFT JOIN
            basic_major bm ON bm.id = clz.major_id
                AND bm.enable = TRUE
        <where>
            AND clz.enable = TRUE
            <if test="schoolId != null and schoolId != ''">
                AND clz.school_id = #{schoolId}
            </if>
            <if test="queryParams != null and queryParams != ''">
                AND (clz.clazz_name LIKE CONCAT('%',#{queryParams},'%') OR clz.clazz_code LIKE CONCAT('%',#{queryParams},'%'))
            </if>
            <if test="dpr != null">
                <if test="dpr.requestUserId != null">
                    AND clz.create_id = #{dpr.requestUserId}
                </if>
                <if test="dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
                    AND clz.org_id IN
                    <foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            </if>
        </where>
        ORDER BY clz.create_time DESC
    </select>
    <select id="findExamTaskPrintByClazzIdSet" resultType="java.util.Map">
        SELECT
            etp.id, class_id AS clazzId, class_name AS clazzName
        FROM
            exam_task_print etp
        LEFT JOIN
            exam_print_plan epp ON etp.print_plan_id = epp.id
        <where>
            AND etp.school_id = #{schoolId}
            <if test="clazzIds != null and clazzIds != '' and clazzIds.size > 0">
                AND etp.class_id IN
                <foreach collection="clazzIds" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
</mapper>
