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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.distributed.print.business.entity.TPCourse">
        <id column="id" property="id" />
        <result column="professional_id" property="professionalId" />
        <result column="course_code" property="courseCode" />
        <result column="course_name" property="courseName" />
        <result column="sort_num" property="sortNum" />
        <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="queryList"
            resultType="com.qmth.distributed.print.business.bean.result.ProfessionalCourseSelectResult">
        SELECT
            bc.code courseCode,
            bc.name courseName,
            bc.teaching_room_id orgId,
            so.name orgName,
            CASE
                WHEN tpc.id IS NULL THEN TRUE
                ELSE FALSE
                END canSelect
        FROM
            (SELECT
                 *
             FROM
                 basic_course
             WHERE
                 teaching_room_id IN
             <foreach collection="orgIdSet" item="orgId" separator="," open="(" close=")">
                 #{orgId}
             </foreach>
             ) bc
                LEFT JOIN
            (SELECT
                 *
             FROM
                 t_p_course
             WHERE
                 professional_id = #{professionalId}) tpc ON bc.code = tpc.course_code
                LEFT JOIN
            sys_org so ON bc.teaching_room_id = so.id
    </select>

</mapper>
