<?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.tcm.training.admin.live.mapper.LiveCourseMapper">
|
|
<!-- 课程分页列表(动态筛选) -->
|
<select id="selectCoursePage"
|
resultType="com.tcm.training.admin.live.vo.LiveCourseListRow">
|
SELECT
|
c.id, c.title, c.level, c.expert_id AS expertId,
|
e.name AS expertName,
|
e.avatar AS expertAvatar,
|
c.cover_img AS coverImg,
|
COALESCE(ss.reserve_count, 0) AS reserveCount,
|
COALESCE(ss.watch_count, 0) AS watchCount,
|
c.quiz_points AS quizPoints,
|
ls.start_time AS startTime,
|
COALESCE(ls.live_status, 0) AS liveStatus,
|
c.status, c.created_at AS createdAt
|
FROM tcm_live_course c
|
LEFT JOIN tcm_expert e ON e.id = c.expert_id AND e.deleted = 0
|
LEFT JOIN (
|
SELECT live_course_id,
|
SUM(base_reserve_count + real_reserve_count) AS reserve_count,
|
SUM(base_watch_count + real_watch_count) AS watch_count
|
FROM tcm_live_session
|
WHERE deleted = 0
|
GROUP BY live_course_id
|
) ss ON ss.live_course_id = c.id
|
LEFT JOIN (
|
SELECT t1.live_course_id, t1.start_time, t1.video_url, t1.live_status
|
FROM tcm_live_session t1
|
JOIN (
|
SELECT live_course_id, MAX(start_time) AS max_start
|
FROM tcm_live_session
|
WHERE deleted = 0 AND start_time IS NOT NULL
|
GROUP BY live_course_id
|
) m1 ON m1.live_course_id = t1.live_course_id AND m1.max_start = t1.start_time
|
JOIN (
|
SELECT live_course_id, start_time, MAX(id) AS max_id
|
FROM tcm_live_session
|
WHERE deleted = 0 AND start_time IS NOT NULL
|
GROUP BY live_course_id, start_time
|
) m2 ON m2.live_course_id = t1.live_course_id
|
AND m2.start_time = t1.start_time
|
AND m2.max_id = t1.id
|
WHERE t1.deleted = 0
|
) ls ON ls.live_course_id = c.id
|
WHERE c.deleted = 0
|
<if test="keyword != null and keyword.trim() != ''">
|
AND c.title LIKE CONCAT('%', #{keyword}, '%')
|
</if>
|
<if test="expertId != null">
|
AND c.expert_id = #{expertId}
|
</if>
|
<if test="status != null">
|
AND c.status = #{status}
|
</if>
|
<if test="liveStatus != null">
|
AND COALESCE(ls.live_status, 0) = #{liveStatus}
|
</if>
|
ORDER BY c.id DESC
|
</select>
|
|
<!-- 课程详情 -->
|
<select id="selectCourseDetail"
|
resultType="com.tcm.training.admin.live.vo.LiveCourseDetailRow">
|
SELECT
|
c.id, c.title, c.level, c.expert_id AS expertId,
|
e.name AS expertName,
|
e.avatar AS expertAvatar,
|
c.cover_img AS coverImg, c.banner_imgs AS bannerImgs,
|
c.intro, c.target_users AS targetUsers,
|
c.quiz_delay_minutes AS quizDelayMinutes,
|
c.quiz_points AS quizPoints,
|
ls.start_time AS startTime,
|
ls.video_url AS videoUrl,
|
COALESCE(ls.live_status, 0) AS liveStatus,
|
c.status,
|
COALESCE(ss.reserve_count, 0) AS reserveCount,
|
COALESCE(ss.watch_count, 0) AS watchCount,
|
c.created_at AS createdAt, c.updated_at AS updatedAt
|
FROM tcm_live_course c
|
LEFT JOIN tcm_expert e ON e.id = c.expert_id AND e.deleted = 0
|
LEFT JOIN (
|
SELECT live_course_id,
|
SUM(base_reserve_count + real_reserve_count) AS reserve_count,
|
SUM(base_watch_count + real_watch_count) AS watch_count
|
FROM tcm_live_session
|
WHERE deleted = 0
|
GROUP BY live_course_id
|
) ss ON ss.live_course_id = c.id
|
LEFT JOIN (
|
SELECT t1.live_course_id, t1.start_time, t1.video_url, t1.live_status
|
FROM tcm_live_session t1
|
JOIN (
|
SELECT live_course_id, MAX(start_time) AS max_start
|
FROM tcm_live_session
|
WHERE deleted = 0 AND start_time IS NOT NULL
|
GROUP BY live_course_id
|
) m1 ON m1.live_course_id = t1.live_course_id AND m1.max_start = t1.start_time
|
JOIN (
|
SELECT live_course_id, start_time, MAX(id) AS max_id
|
FROM tcm_live_session
|
WHERE deleted = 0 AND start_time IS NOT NULL
|
GROUP BY live_course_id, start_time
|
) m2 ON m2.live_course_id = t1.live_course_id
|
AND m2.start_time = t1.start_time
|
AND m2.max_id = t1.id
|
WHERE t1.deleted = 0
|
) ls ON ls.live_course_id = c.id
|
WHERE c.deleted = 0 AND c.id = #{id}
|
</select>
|
|
</mapper>
|