<?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>
|