zjk
2026-09-29 54dcf0a82e7490fa58b1c056d5c0b9cb739c2931
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?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.statistics.mapper.ContentStatisticsMapper">
 
    <select id="selectDailyStatistics" resultType="com.tcm.training.admin.statistics.row.ContentStatisticsDailyRow">
        SELECT
            t.statDate,
            SUM(t.videoPlayCount) AS videoPlayCount,
            SUM(t.courseFavoriteCount) AS courseFavoriteCount,
            SUM(t.consultClickCount) AS consultClickCount,
            SUM(t.pointsEarnedCount) AS pointsEarnedCount
        FROM (
            SELECT
                DATE(w.watch_start) AS statDate,
                COUNT(1) AS videoPlayCount,
                0 AS courseFavoriteCount,
                0 AS consultClickCount,
                0 AS pointsEarnedCount
            FROM tcm_live_watch_record w
            WHERE w.watch_start <![CDATA[>=]]> #{startTime}
              AND w.watch_start <![CDATA[<=]]> #{endTime}
            GROUP BY DATE(w.watch_start)
 
            UNION ALL
 
            SELECT
                DATE(p.play_start) AS statDate,
                COUNT(1) AS videoPlayCount,
                0 AS courseFavoriteCount,
                0 AS consultClickCount,
                0 AS pointsEarnedCount
            FROM tcm_health_course_play_record p
            WHERE p.play_start <![CDATA[>=]]> #{startTime}
              AND p.play_start <![CDATA[<=]]> #{endTime}
            GROUP BY DATE(p.play_start)
 
            UNION ALL
 
            SELECT
                DATE(f.action_time) AS statDate,
                0 AS videoPlayCount,
                COUNT(1) AS courseFavoriteCount,
                0 AS consultClickCount,
                0 AS pointsEarnedCount
            FROM tcm_health_course_favorite_record f
            WHERE f.action_type = 'FAVORITE'
              AND f.action_time <![CDATA[>=]]> #{startTime}
              AND f.action_time <![CDATA[<=]]> #{endTime}
            GROUP BY DATE(f.action_time)
 
            UNION ALL
 
            SELECT
                DATE(c.clicked_at) AS statDate,
                0 AS videoPlayCount,
                0 AS courseFavoriteCount,
                COUNT(1) AS consultClickCount,
                0 AS pointsEarnedCount
            FROM tcm_content_consult_click_record c
            WHERE c.clicked_at <![CDATA[>=]]> #{startTime}
              AND c.clicked_at <![CDATA[<=]]> #{endTime}
            GROUP BY DATE(c.clicked_at)
 
            UNION ALL
 
            SELECT
                DATE(q.answered_at) AS statDate,
                0 AS videoPlayCount,
                0 AS courseFavoriteCount,
                0 AS consultClickCount,
                COALESCE(SUM(q.points_earned), 0) AS pointsEarnedCount
            FROM tcm_live_session_quiz_record q
            WHERE q.answered_at <![CDATA[>=]]> #{startTime}
              AND q.answered_at <![CDATA[<=]]> #{endTime}
            GROUP BY DATE(q.answered_at)
        ) t
        GROUP BY t.statDate
        ORDER BY t.statDate ASC
    </select>
 
</mapper>