|
@@ -168,14 +168,16 @@
|
|
|
</select>
|
|
</select>
|
|
|
<select id="watchEndPlayTrend" resultType="com.fs.statis.dto.WatchEndPlayTrendDTO">
|
|
<select id="watchEndPlayTrend" resultType="com.fs.statis.dto.WatchEndPlayTrendDTO">
|
|
|
SELECT
|
|
SELECT
|
|
|
--- 今日/昨日 小时
|
|
|
|
|
- <if test="type == 0 or type == 1">
|
|
|
|
|
|
|
+ <choose>
|
|
|
|
|
+ <!-- 按小时分组 -->
|
|
|
|
|
+ <when test="type == 0 or type == 1">
|
|
|
DATE_FORMAT(create_time, '%H') AS start_date,
|
|
DATE_FORMAT(create_time, '%H') AS start_date,
|
|
|
- </if>
|
|
|
|
|
--- 本周/本月/上月 天
|
|
|
|
|
- <if test="type == 2 or type == 3 or type == 4">
|
|
|
|
|
|
|
+ </when>
|
|
|
|
|
+ <!-- 按天分组 -->
|
|
|
|
|
+ <when test="type == 2 or type == 3 or type == 4">
|
|
|
DATE_FORMAT(create_time, '%Y-%m-%d') AS start_date,
|
|
DATE_FORMAT(create_time, '%Y-%m-%d') AS start_date,
|
|
|
- </if>
|
|
|
|
|
|
|
+ </when>
|
|
|
|
|
+ </choose>
|
|
|
COUNT(DISTINCT user_id) AS watch_user_count,
|
|
COUNT(DISTINCT user_id) AS watch_user_count,
|
|
|
COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS completed_user_count
|
|
COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS completed_user_count
|
|
|
FROM
|
|
FROM
|
|
@@ -192,7 +194,10 @@
|
|
|
</if>
|
|
</if>
|
|
|
</where>
|
|
</where>
|
|
|
GROUP BY
|
|
GROUP BY
|
|
|
- start_date
|
|
|
|
|
|
|
+ <choose>
|
|
|
|
|
+ <when test="type == 0 or type == 1">DATE_FORMAT(create_time, '%H')</when>
|
|
|
|
|
+ <when test="type == 2 or type == 3 or type == 4">DATE_FORMAT(create_time, '%Y-%m-%d')</when>
|
|
|
|
|
+ </choose>
|
|
|
ORDER BY
|
|
ORDER BY
|
|
|
start_date
|
|
start_date
|
|
|
</select>
|
|
</select>
|
|
@@ -224,50 +229,177 @@
|
|
|
GROUP BY company_id
|
|
GROUP BY company_id
|
|
|
limit 10
|
|
limit 10
|
|
|
</select>
|
|
</select>
|
|
|
- <select id="watchCourseTopTen" resultType="com.fs.statis.dto.CourseStatsDTO">
|
|
|
|
|
|
|
+<!-- <select id="watchCourseTopTen" resultType="com.fs.statis.dto.CourseStatsDTO">-->
|
|
|
|
|
+<!-- SELECT-->
|
|
|
|
|
+<!-- w.course_id AS course_id,-->
|
|
|
|
|
+<!-- COUNT(DISTINCT w.user_id) AS watch_user_count,-->
|
|
|
|
|
+<!-- COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,-->
|
|
|
|
|
+<!-- COUNT(DISTINCT a.user_id) AS answer_user_count,-->
|
|
|
|
|
+<!-- COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count-->
|
|
|
|
|
+<!-- FROM-->
|
|
|
|
|
+<!-- fs_course_watch_log w-->
|
|
|
|
|
+<!-- LEFT JOIN-->
|
|
|
|
|
+<!-- fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id-->
|
|
|
|
|
+<!-- <where>-->
|
|
|
|
|
+<!-- <if test="startTime != null">-->
|
|
|
|
|
+<!-- w.create_time <![CDATA[>=]]> #{startTime}-->
|
|
|
|
|
+<!-- </if>-->
|
|
|
|
|
+<!-- <if test="endTime != null">-->
|
|
|
|
|
+<!-- AND w.create_time <![CDATA[<]]> #{endTime}-->
|
|
|
|
|
+<!-- </if>-->
|
|
|
|
|
+<!-- <if test="userType != null">-->
|
|
|
|
|
+<!-- AND send_type = ${userType}-->
|
|
|
|
|
+<!-- </if>-->
|
|
|
|
|
+<!-- <if test="companyId != null">-->
|
|
|
|
|
+<!-- AND w.company_id = ${companyId}-->
|
|
|
|
|
+<!-- </if>-->
|
|
|
|
|
+<!-- </where>-->
|
|
|
|
|
+<!-- GROUP BY-->
|
|
|
|
|
+<!-- w.course_id-->
|
|
|
|
|
+<!-- ORDER BY-->
|
|
|
|
|
+<!-- -- 观看人数-->
|
|
|
|
|
+<!-- <if test="statisticalType == 0">-->
|
|
|
|
|
+<!-- COUNT(DISTINCT w.user_id)-->
|
|
|
|
|
+<!-- </if>-->
|
|
|
|
|
+<!-- <if test="statisticalType == 1">-->
|
|
|
|
|
+<!-- COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END)-->
|
|
|
|
|
+<!-- </if>-->
|
|
|
|
|
+<!-- <if test="statisticalType == 2">-->
|
|
|
|
|
+<!-- COUNT(DISTINCT a.user_id)-->
|
|
|
|
|
+<!-- </if>-->
|
|
|
|
|
+<!-- <if test="statisticalType == 3">-->
|
|
|
|
|
+<!-- COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END)-->
|
|
|
|
|
+<!-- </if>-->
|
|
|
|
|
+<!-- ${sort}-->
|
|
|
|
|
+<!-- LIMIT 10-->
|
|
|
|
|
+<!-- </select>-->
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 1. 按观看人数排序 -->
|
|
|
|
|
+ <select id="watchCourseTopTenByWatch" resultType="com.fs.statis.dto.CourseStatsDTO">
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ course_id AS courseId,
|
|
|
|
|
+ COUNT(DISTINCT user_id) AS watch_user_count,
|
|
|
|
|
+ COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS completed_user_count,
|
|
|
|
|
+ 0 AS answer_user_count,
|
|
|
|
|
+ 0 AS correct_user_count
|
|
|
|
|
+ FROM fs_course_watch_log
|
|
|
|
|
+ <where>
|
|
|
|
|
+ <if test="startTime != null">create_time <![CDATA[>=]]> #{startTime}</if>
|
|
|
|
|
+ <if test="endTime != null">AND create_time <![CDATA[<]]> #{endTime}</if>
|
|
|
|
|
+ <if test="userType != null">AND send_type = #{userType}</if>
|
|
|
|
|
+ <if test="companyId != null">AND company_id = #{companyId}</if>
|
|
|
|
|
+ </where>
|
|
|
|
|
+ GROUP BY course_id
|
|
|
|
|
+ ORDER BY watch_user_count
|
|
|
|
|
+ <choose>
|
|
|
|
|
+ <when test="sort != null and sort == 'DESC'">DESC</when>
|
|
|
|
|
+ <otherwise>ASC</otherwise>
|
|
|
|
|
+ </choose>
|
|
|
|
|
+ LIMIT 10
|
|
|
|
|
+ </select>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 2. 按完成人数排序 -->
|
|
|
|
|
+ <select id="watchCourseTopTenByComplete" resultType="com.fs.statis.dto.CourseStatsDTO">
|
|
|
SELECT
|
|
SELECT
|
|
|
- w.course_id AS course_id,
|
|
|
|
|
|
|
+ course_id AS courseId,
|
|
|
|
|
+ COUNT(DISTINCT user_id) AS watch_user_count,
|
|
|
|
|
+ COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS completed_user_count,
|
|
|
|
|
+ 0 AS answer_user_count,
|
|
|
|
|
+ 0 AS correct_user_count
|
|
|
|
|
+ FROM fs_course_watch_log
|
|
|
|
|
+ <where>
|
|
|
|
|
+ <if test="startTime != null">create_time <![CDATA[>=]]> #{startTime}</if>
|
|
|
|
|
+ <if test="endTime != null">AND create_time <![CDATA[<]]> #{endTime}</if>
|
|
|
|
|
+ <if test="userType != null">AND send_type = #{userType}</if>
|
|
|
|
|
+ <if test="companyId != null">AND company_id = #{companyId}</if>
|
|
|
|
|
+ </where>
|
|
|
|
|
+ GROUP BY course_id
|
|
|
|
|
+ ORDER BY completed_user_count
|
|
|
|
|
+ <choose>
|
|
|
|
|
+ <when test="sort != null and sort == 'DESC'">DESC</when>
|
|
|
|
|
+ <otherwise>ASC</otherwise>
|
|
|
|
|
+ </choose>
|
|
|
|
|
+ LIMIT 10
|
|
|
|
|
+ </select>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 3. 按答题人数排序 -->
|
|
|
|
|
+ <select id="watchCourseTopTenByAnswer" resultType="com.fs.statis.dto.CourseStatsDTO">
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ w.course_id AS courseId,
|
|
|
COUNT(DISTINCT w.user_id) AS watch_user_count,
|
|
COUNT(DISTINCT w.user_id) AS watch_user_count,
|
|
|
COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,
|
|
COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,
|
|
|
COUNT(DISTINCT a.user_id) AS answer_user_count,
|
|
COUNT(DISTINCT a.user_id) AS answer_user_count,
|
|
|
COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
|
|
COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
|
|
|
- FROM
|
|
|
|
|
- fs_course_watch_log w
|
|
|
|
|
- LEFT JOIN
|
|
|
|
|
- fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id
|
|
|
|
|
|
|
+ FROM fs_course_watch_log w
|
|
|
|
|
+ LEFT JOIN fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id
|
|
|
<where>
|
|
<where>
|
|
|
- <if test="startTime != null">
|
|
|
|
|
- w.create_time <![CDATA[>=]]> #{startTime}
|
|
|
|
|
- </if>
|
|
|
|
|
- <if test="endTime != null">
|
|
|
|
|
- AND w.create_time <![CDATA[<]]> #{endTime}
|
|
|
|
|
- </if>
|
|
|
|
|
- <if test="userType != null">
|
|
|
|
|
- AND send_type = ${userType}
|
|
|
|
|
- </if>
|
|
|
|
|
- <if test="companyId != null">
|
|
|
|
|
- AND w.company_id = ${companyId}
|
|
|
|
|
- </if>
|
|
|
|
|
|
|
+ <if test="startTime != null">w.create_time <![CDATA[>=]]> #{startTime}</if>
|
|
|
|
|
+ <if test="endTime != null">AND w.create_time <![CDATA[<]]> #{endTime}</if>
|
|
|
|
|
+ <if test="userType != null">AND w.send_type = #{userType}</if>
|
|
|
|
|
+ <if test="companyId != null">AND w.company_id = #{companyId}</if>
|
|
|
|
|
+<!-- <if test="startTime != null">AND a.create_time <![CDATA[>=]]> #{startTime}</if> -->
|
|
|
|
|
+<!-- <if test="endTime != null">AND a.create_time <![CDATA[<]]> #{endTime}</if> -->
|
|
|
</where>
|
|
</where>
|
|
|
- GROUP BY
|
|
|
|
|
- w.course_id
|
|
|
|
|
- ORDER BY
|
|
|
|
|
- -- 观看人数
|
|
|
|
|
- <if test="statisticalType == 0">
|
|
|
|
|
- COUNT(DISTINCT w.user_id)
|
|
|
|
|
- </if>
|
|
|
|
|
- <if test="statisticalType == 1">
|
|
|
|
|
- COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END)
|
|
|
|
|
- </if>
|
|
|
|
|
- <if test="statisticalType == 2">
|
|
|
|
|
- COUNT(DISTINCT a.user_id)
|
|
|
|
|
- </if>
|
|
|
|
|
- <if test="statisticalType == 3">
|
|
|
|
|
- COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END)
|
|
|
|
|
- </if>
|
|
|
|
|
- ${sort}
|
|
|
|
|
|
|
+ GROUP BY w.course_id
|
|
|
|
|
+ ORDER BY answer_user_count
|
|
|
|
|
+ <choose>
|
|
|
|
|
+ <when test="sort != null and sort == 'DESC'">DESC</when>
|
|
|
|
|
+ <otherwise>ASC</otherwise>
|
|
|
|
|
+ </choose>
|
|
|
|
|
+ LIMIT 10
|
|
|
|
|
+ </select>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 4. 按正确人数排序 -->
|
|
|
|
|
+ <select id="watchCourseTopTenByCorrect" resultType="com.fs.statis.dto.CourseStatsDTO">
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ w.course_id AS courseId,
|
|
|
|
|
+ COUNT(DISTINCT w.user_id) AS watch_user_count,
|
|
|
|
|
+ COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,
|
|
|
|
|
+ COUNT(DISTINCT a.user_id) AS answer_user_count,
|
|
|
|
|
+ COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
|
|
|
|
|
+ FROM fs_course_watch_log w
|
|
|
|
|
+ LEFT JOIN fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id
|
|
|
|
|
+ <where>
|
|
|
|
|
+ <if test="startTime != null">w.create_time <![CDATA[>=]]> #{startTime}</if>
|
|
|
|
|
+ <if test="endTime != null">AND w.create_time <![CDATA[<]]> #{endTime}</if>
|
|
|
|
|
+ <if test="userType != null">AND w.send_type = #{userType}</if>
|
|
|
|
|
+ <if test="companyId != null">AND w.company_id = #{companyId}</if>
|
|
|
|
|
+ <if test="startTime != null">AND a.create_time <![CDATA[>=]]> #{startTime}</if>
|
|
|
|
|
+ <if test="endTime != null">AND a.create_time <![CDATA[<]]> #{endTime}</if>
|
|
|
|
|
+ </where>
|
|
|
|
|
+ GROUP BY w.course_id
|
|
|
|
|
+ ORDER BY correct_user_count
|
|
|
|
|
+ <choose>
|
|
|
|
|
+ <when test="sort != null and sort == 'DESC'">DESC</when>
|
|
|
|
|
+ <otherwise>ASC</otherwise>
|
|
|
|
|
+ </choose>
|
|
|
LIMIT 10
|
|
LIMIT 10
|
|
|
</select>
|
|
</select>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 5. 批量补充答题数据 -->
|
|
|
|
|
+ <select id="getAnswerStatsByCourseIds" resultType="com.fs.statis.dto.CourseStatsDTO">
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ w.course_id AS courseId,
|
|
|
|
|
+ COUNT(DISTINCT a.user_id) AS answer_user_count,
|
|
|
|
|
+ COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
|
|
|
|
|
+ FROM fs_course_answer_logs a
|
|
|
|
|
+ INNER JOIN fs_course_watch_log w ON a.video_id = w.video_id AND a.user_id = w.user_id
|
|
|
|
|
+ <where>
|
|
|
|
|
+ w.course_id IN
|
|
|
|
|
+ <foreach collection="courseIds" item="courseId" open="(" close=")" separator=",">
|
|
|
|
|
+ #{courseId}
|
|
|
|
|
+ </foreach>
|
|
|
|
|
+ <if test="param.startTime != null">AND w.create_time <![CDATA[>=]]> #{param.startTime}</if>
|
|
|
|
|
+ <if test="param.endTime != null">AND w.create_time <![CDATA[<]]> #{param.endTime}</if>
|
|
|
|
|
+ <if test="param.userType != null">AND w.send_type = #{param.userType}</if>
|
|
|
|
|
+ <if test="param.companyId != null">AND w.company_id = #{param.companyId}</if>
|
|
|
|
|
+ <if test="param.startTime != null">AND a.create_time <![CDATA[>=]]> #{param.startTime}</if>
|
|
|
|
|
+ <if test="param.endTime != null">AND a.create_time <![CDATA[<]]> #{param.endTime}</if>
|
|
|
|
|
+ </where>
|
|
|
|
|
+ GROUP BY w.course_id
|
|
|
|
|
+ </select>
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
<select id="rewardMoneyTopTen" resultType="com.fs.statis.dto.RewardMoneyTopTenDTO">
|
|
<select id="rewardMoneyTopTen" resultType="com.fs.statis.dto.RewardMoneyTopTenDTO">
|
|
|
SELECT
|
|
SELECT
|
|
|
-- 按公司
|
|
-- 按公司
|