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

    <select id="findTeachCoursePage"
            resultType="com.qmth.distributed.print.business.bean.result.TeachCourseResult">
        SELECT
            tc.id,
            bc.code AS courseCode,
            bc.name AS courseName,
            tc.create_id AS createId,
            tc.create_time AS createTime,
            tc.user_id AS userId,
            su.login_name as userLoginName,
            su.real_name AS userName
        FROM
            teach_course tc
                INNER JOIN
            basic_course bc ON tc.school_id = bc.school_id AND tc.course_code = bc.code AND bc.enable = TRUE
                LEFT JOIN
            sys_user su ON tc.user_id = su.id
        <where>
            <if test="schoolId != null">
                AND tc.school_id = #{schoolId}
            </if>
            <if test="examId != null">
                AND tc.exam_id = #{examId}
            </if>
            <if test="courseName != null and courseName != ''">
                AND bc.name LIKE CONCAT('%',#{courseName},'%')
            </if>
            AND tc.enable = true
            <if test="dpr != null">
                <if test="dpr.requestUserId != null">
                    AND tc.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>
        </where>
        ORDER BY tc.create_time DESC
    </select>
    <select id="findTeacherTeamPage" resultType="com.qmth.teachcloud.common.bean.result.TeacherTeamResult">
        SELECT
            tc.id,
            tc.user_id as userId,
            su.real_name as userName,
            su.code as userCode,
            so.name as orgName
        FROM
            teach_course tc
                LEFT JOIN
            sys_user su ON tc.user_id = su.id
                LEFT JOIN
            sys_org so ON su.org_id = so.id
        <where>
            AND su.enable = true
            <if test="courseCode != null and courseCode != ''">
                AND tc.course_code = #{courseCode}
            </if>
            <if test="leaderId != null">
                AND tc.create_id = #{leaderId}
            </if>
            <if test="userInfo != null and userInfo != ''">
                AND (su.real_name LIKE CONCAT('%',#{userInfo},'%') OR su.code LIKE CONCAT('%',#{userInfo},'%'))
            </if>
        </where>
    </select>
    <select id="findTeacherByOrgIds" resultType="com.qmth.teachcloud.common.bean.result.TeacherSelectResult">
        SELECT
            su.id, su.code, su.real_name AS realName, so.name AS orgName
        FROM
            sys_user su
                LEFT JOIN
            sys_org so ON su.org_id = so.id
        <where>
            su.enable = true
            <if test="orgIdList != null and orgIdList != '' and orgIdList.size() > 0">
                AND su.org_id IN
                <foreach collection="orgIdList" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        ORDER BY so.id
    </select>
</mapper>


