<?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="vip.xiaonuo.disk.mapper.CourseInfoMapper">

    <select id="queryList" resultType="java.util.Map">
        select
            t1.COURSE_ID as courseId,
            t1.COURSE_NAME as courseName,
            t1.COURSE_TYPE as courseType,
            IFNULL(( SELECT dd1.DICT_LABEL FROM (SELECT d1.DICT_LABEL,d1.DICT_VALUE  FROM  DEV_DICT d1 WHERE PARENT_ID = (SELECT d2.ID  FROM  DEV_DICT d2 WHERE d2.DICT_VALUE='COURSE_TYPE') )dd1 WHERE dd1.DICT_VALUE = TRIM(t1.COURSE_TYPE) ),'') AS isCreaterName,
            t1.COURSE_DESC as courseDesc,
            t1.TEACHER_ID as teacherId,
            t7.NAME AS teacherIdName,
            t1.COLLEGE_ID AS collegeId,
            t2.NAME AS collegeIdName,
            t1.MAJOR_ID AS majorId,
            t3.major_name AS majorIdName,
            t1.PUBLISH_TIME as publishTime,
            t1.TIME_LIMIT_TYPE as timeLimitType,
            t1.START_TIME as startTime,
            t1.END_TIME as endTime
        FROM COURSE_INFO t1
        LEFT JOIN college t2 ON t1.COLLEGE_ID=t2.ID AND t2.DELETE_FLAG ='NOT_DELETE'
        LEFT JOIN major t3 ON t1.MAJOR_ID=t3.id AND t3.DELETE_FLAG ='NOT_DELETE'
        LEFT JOIN SYS_USER t7 ON t7.ID=t1.TEACHER_ID AND t7.DELETE_FLAG ='NOT_DELETE'
        WHERE t1.DELETE_FLAG ='NOT_DELETE'
        <if test="param.collegeId !=null and param.collegeId != ''">
            and t1.COLLEGE_ID=#{param.courseId}
        </if>
        <if test="param.majorId !=null and param.majorId != ''">
            and t1.MAJOR_ID=#{param.majorId}
        </if>
        <if test="param.courseType !=null and param.courseType != ''">
            and t1.COURSE_TYPE=#{param.courseType}
        </if>
        <if test="param.courseName !=null and param.courseName != ''">
            and t1.COURSE_NAME=#{param.courseName}
        </if>
        <if test="param.sortflag !=null and param.sortflag != ''">
            <if test=" param.sortflag == 0">
                order by t1.PUBLISH_TIME desc
            </if>
            <if test=" param.sortflag == 1">
                order by t1.VIEW_COUNT desc
            </if>
        </if>
        order by t1.COLLEGE_ID desc
    </select>

    <select id="queryInfo" parameterType="java.util.Map" resultType="java.util.Map">
        select
            t1.COURSE_ID as courseId,
            t1.COURSE_NAME as courseName,
            t1.COURSE_TYPE as courseType,
            IFNULL(( SELECT dd1.DICT_LABEL FROM (SELECT d1.DICT_LABEL,d1.DICT_VALUE  FROM  DEV_DICT d1 WHERE PARENT_ID = (SELECT d2.ID  FROM  DEV_DICT d2 WHERE d2.DICT_VALUE='COURSE_TYPE') )dd1 WHERE dd1.DICT_VALUE = TRIM(t1.COURSE_TYPE) ),'') AS isCreaterName,
            t1.COURSE_DESC as courseDesc,
            t1.TEACHER_ID as teacherId,
            t7.NAME AS teacherIdName,
            t1.COLLEGE_ID AS collegeId,
            t2.NAME AS collegeIdName,
            t1.MAJOR_ID AS majorId,
            t3.major_name AS majorIdName,
            t1.PUBLISH_TIME as publishTime,
            t1.TIME_LIMIT_TYPE as timeLimitType,
            t1.START_TIME as startTime,
            t1.END_TIME as endTime
        FROM COURSE_INFO t1
        LEFT JOIN college t2 ON t1.COLLEGE_ID=t2.ID AND t2.DELETE_FLAG ='NOT_DELETE'
        LEFT JOIN major t3 ON t1.MAJOR_ID=t3.id AND t3.DELETE_FLAG ='NOT_DELETE'
        LEFT JOIN SYS_USER t7 ON t7.ID=t1.TEACHER_ID AND t7.DELETE_FLAG ='NOT_DELETE'
        <if test="courseId !=null and courseId != ''">
            and t1.COURSE_ID=#{courseId}
        </if>
    </select>
</mapper>
