<?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.paper.library.common.mapper.BasicSemesterMapper">

    <select id="findBasicSemesterPage" resultType="com.qmth.paper.library.common.bean.result.BasicSemesterResult">
        SELECT
            id,
            name AS semesterName,
            code AS semesterCode,
            enable
        FROM
            basic_semester bs
        <where>
            AND bs.enable = true
            <if test="schoolId != null and schoolId != ''">
                AND bs.school_id = #{schoolId}
            </if>
            <if test="orgIds != null and orgIds != '' and orgIds.size > 0">
                AND bs.org_id IN
                <foreach collection="orgIds" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        ORDER BY bs.create_time DESC
    </select>
    <select id="countBasicExamBySemesterId" resultType="java.lang.Integer">
        SELECT
            COUNT(*)
        FROM
            basic_exam be
        <where>
            <if test="semesterId != null">
                AND be.semester_id = #{semesterId}
            </if>
        </where>
    </select>
</mapper>
