he2802 пре 3 година
родитељ
комит
db26335eee

+ 72 - 85
zhongzheng-system/src/main/resources/mapper/modules/course/CourseMenuMapper.xml

@@ -57,96 +57,83 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <select id="getList" parameterType="com.zhongzheng.modules.course.bo.CourseMenuQueryBo"  resultMap="CourseMenuResultVo">
+        SELECT * from (SELECT
+        m.*,
+        cm.module_name AS menu_name,
+        cm.publish_status AS publish_status,
+        cm.code AS code,
+        0 AS duration_time,
+        NULL AS section_type,
+        NULL AS live_start_time,
+        NULL AS live_end_time,
+        NULL AS live_url,
+        NULL AS recording_url,
+        cm.exam_type AS exam_type,
+        cm.free_exam_id AS free_exam_id,
+        (
+        CASE
+        cm.exam_type
+        WHEN 1 THEN
+        ( SELECT module_name FROM question_module WHERE module_exam_id = cm.free_exam_id )
+        WHEN 2 THEN
+        ( SELECT `name` FROM question_chapter WHERE chapter_exam_id = cm.free_exam_id )
+        WHEN 3 THEN
+        ( SELECT exam_name FROM exam WHERE exam_id = cm.free_exam_id ) ELSE ( NULL )
+        END
+        ) free_exam_name
+        FROM
+        course_menu m
+        LEFT JOIN course_module cm ON m.menu_id = cm.module_id
+        WHERE
+        m.course_id = #{courseId}
+        AND m.type = 1 and cm.`status`!=-1
+        UNION
         SELECT
-            m.*,
-            CASE
-                WHEN m.type = 1 THEN
-                    cm.module_name
-                WHEN m.type = 2 THEN
-                    cc.`name`
-                WHEN m.type = 3 THEN
-                    cs.`name`
-                END menu_name,
-            CASE
-                WHEN m.type = 1 THEN
-                cm.publish_status
-                WHEN m.type = 2 THEN
-                cc.publish_status
-                WHEN m.type = 3 THEN
-                cs.publish_status
-                END publish_status,
-            CASE
-                WHEN m.type = 1 THEN
-                cm.code
-                WHEN m.type = 2 THEN
-                cc.code
-                WHEN m.type = 3 THEN
-                cs.code
-                END code,
-            CASE
-
-                WHEN m.type = 1 THEN
-                    0
-                WHEN m.type = 2 THEN
-                    0
-                WHEN m.type = 3 THEN
-                    cs.duration_time
-                END duration_time,
-            cs.section_type,
-            cs.live_start_time,
-            cs.live_end_time,
-            cs.live_url,
-            CASE
-                WHEN m.type = 1 THEN
-                    ''
-                WHEN m.type = 2 THEN
-                    ''
-                WHEN m.type = 3 THEN
-                    cs.recording_url
-                END recording_url,
-            CASE
-            WHEN m.type = 1 THEN
-            cm.exam_type
-            WHEN m.type = 2 THEN
-            NULL
-            WHEN m.type = 3 THEN
-                NULL
-            END exam_type,
-            CASE
-            WHEN m.type = 1 THEN
-            cm.free_exam_id
-            WHEN m.type = 2 THEN
-            NULL
-            WHEN m.type = 3 THEN
-            NULL
-            END free_exam_id,
-            CASE
-            WHEN m.type = 1 THEN
-            ( CASE cm.exam_type
-        WHEN 1 THEN (SELECT module_name FROM question_module WHERE module_exam_id = cm.free_exam_id)
-        WHEN 2 THEN (SELECT `name` FROM question_chapter WHERE chapter_exam_id = cm.free_exam_id)
-        WHEN 3 THEN (SELECT exam_name FROM exam WHERE exam_id = cm.free_exam_id)
-        ELSE (NULL) END)
-            WHEN m.type = 2 THEN
-            NULL
-            WHEN m.type = 3 THEN
-            NULL
-            END free_exam_name
-
+        m.*,
+        cc.`name` AS menu_name,
+        cc.publish_status AS publish_status,
+        cc.code AS code,
+        0 AS duration_time,
+        NULL AS section_type,
+        NULL AS live_start_time,
+        NULL AS live_end_time,
+        NULL AS live_url,
+        NULL AS recording_url,
+        NULL AS exam_type,
+        NULL AS free_exam_id,
+        NULL as  free_exam_name
         FROM
-            course_menu m
-                LEFT JOIN course_module cm ON m.menu_id = cm.module_id
-                AND m.type = 1 AND cm.`status` !=-1
-                LEFT JOIN course_chapter cc ON m.menu_id = cc.chapter_id
-                AND m.type = 2 AND cc.`status` !=-1
-                LEFT JOIN course_section cs ON m.menu_id = cs.section_id
-                AND m.type = 3 AND cs.`status` !=-1
+        course_menu m
+        LEFT JOIN course_chapter cc ON m.menu_id = cc.chapter_id
         WHERE
-            m.course_id = #{courseId}
+        m.course_id = #{courseId}
+        AND m.type = 2 and cc.`status`!=-1
+        UNION
+        SELECT
+        m.*,
+        cs.`name` AS menu_name,
+        cs.publish_status AS publish_status,
+        cs.code AS code,
+        cs.duration_time AS duration_time,
+        cs.section_type AS section_type,
+        cs.live_start_time AS live_start_time,
+        cs.live_end_time AS live_end_time,
+        cs.live_url AS live_url,
+        cs.recording_url AS recording_url,
+        NULL AS exam_type,
+        NULL AS free_exam_id,
+        NULL as  free_exam_name
+        FROM
+        course_menu m
+        LEFT JOIN course_section cs ON m.menu_id = cs.section_id
+        WHERE
+        m.course_id = #{courseId}
+        AND m.type = 3 and cs.`status`!=-1 )un
+        WHERE 1=1
         <if test="type != null and type != ''">
-            AND m.type = #{type}
+            AND un.type = #{type}
         </if>
-        ORDER BY m.sort asc
+        ORDER BY un.sort asc
     </select>
 
     <select id="menuList" parameterType="com.zhongzheng.modules.course.bo.CourseMenuQueryBo"  resultMap="CourseUserMenuVo">