<?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.BasicMajorMapper">

    <select id="findBasicMajorPage"
            resultType="com.qmth.teachcloud.common.bean.result.BasicMajorResult">
        SELECT
            bm.id,
            bm.name AS majorName,
            bm.code AS majorCode,
            bm.create_id AS createId,
            bm.create_time AS createTime,
            bc.id AS collegeId,
            bc.name AS collegeName
        FROM
            basic_major bm
                LEFT JOIN
            sys_org bc ON bm.belong_org_id = bc.id
        <where>
            AND bm.enable = true
            <if test="schoolId != null and schoolId != ''">
                AND bm.school_id = #{schoolId}
            </if>
            <if test="majorName != null and majorName != ''">
                AND bm.name LIKE CONCAT('%',#{majorName},'%')
            </if>
            <if test="dpr != null">
                <if test="dpr.requestUserId != null">
                    AND bm.create_id = #{dpr.requestUserId}
                </if>
                <if test="dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
                    AND bm.org_id IN
                    <foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            </if>
        </where>
        ORDER BY bm.create_time DESC
    </select>
</mapper>
