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

    <select id="findObeCourseOutlinePage"
            resultType="com.qmth.distributed.print.business.bean.result.ObeCourseOutlineResult">
        SELECT
            oco.id,
            oco.name AS outlineName,
            bc.id AS courseId,
            bc.name AS courseName,
            bc.code AS courseCode,
            oco.evaluation_mode AS evaluationMode,
            oco.course_type AS courseType,
            bs.id AS semesterId,
            bs.name AS semesterName,
            ocp.id AS cultureProgramId,
            ocp.name AS cultureProgramName,
            su.id AS userId,
            su.real_name AS userName,
            bp.id AS professionalId,
            bp.name AS professionalName
        FROM
            obe_course_outline oco
                LEFT JOIN
            basic_course bc ON oco.course_id = bc.id
                LEFT JOIN
            basic_semester bs ON oco.semester_id = bs.id
                LEFT JOIN
            sys_user su ON oco.user_id = su.id
                LEFT JOIN
            obe_culture_program ocp ON ocp.id = oco.culture_program_id
                LEFT JOIN
            basic_professional bp ON ocp.professional_id = bp.id
        <where>
            <if test="professionalId != null">
                AND ocp.professional_id = #{professionalId}
            </if>
            <if test="cultureProgramId != null">
                AND ocp.id = #{cultureProgramId}
            </if>
            <if test="courseId != null">
                AND bc.id = #{courseId}
            </if>
            <if test="courseOutlineName != null and courseOutlineName != ''">
                AND oco.name LIKE CONCAT('%', #{courseOutlineName}, '%')
            </if>
            <if test="dpr != null">
                <if test="dpr.requestUserId != null">
                    AND oco.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 oco.create_time DESC
    </select>
    <select id="findCourseBasicInfo"
            resultType="com.qmth.distributed.print.business.bean.result.ObeCourseBasicInfoResult">
        SELECT
            bp.name AS professionalName, ocp.name AS cultureProgramName
        FROM
            obe_course_outline oco
                LEFT JOIN
            obe_culture_program ocp ON oco.culture_program_id = ocp.id
                LEFT JOIN
            basic_professional bp ON ocp.professional_id = bp.id
        <where>
            <if test="obeCourseOutlineId != null">
                AND oco.id = #{obeCourseOutlineId}
            </if>
        </where>
    </select>
    <select id="findCanChooseCultureProgram"
            resultType="com.qmth.distributed.print.business.bean.result.DictionaryResult">
        SELECT
            ocp.id AS id, ocp.name AS name
        FROM
            obe_culture_program ocp
                LEFT JOIN
            sys_user su ON ocp.create_id = su.id
        <where>
            <if test="dpr != null">
                <if test="dpr.requestUserId != null">
                    AND ocp.create_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>
    </select>
    <select id="findCanChooseCourse"
            resultType="com.qmth.distributed.print.business.bean.result.DictionaryResult">
        SELECT
            bc.id AS id, bc.name AS name, bc.code AS code
        FROM
            obe_culture_program_course ocpc
                LEFT JOIN
            basic_course bc ON ocpc.course_id = bc.id
        <where>
            <if test="obeCultureProgramId != null">
                AND ocpc.culture_program_id = #{obeCultureProgramId}
            </if>
        </where>
    </select>
</mapper>
