|
|
@@ -993,5 +993,148 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
o.company_id,
|
|
|
o.send_type
|
|
|
</select>
|
|
|
+ <select id="selectFsCourseReportVO" resultType="com.fs.his.vo.FsCourseReportVO">
|
|
|
+ SELECT
|
|
|
+ c.company_id AS companyId,
|
|
|
+ c.company_name AS companyName,
|
|
|
+
|
|
|
+ <!-- 看课统计数据 -->
|
|
|
+ COALESCE(watch.pending_count, 0) AS pendingCount,
|
|
|
+ COALESCE(watch.watching_count, 0) AS watchingCount,
|
|
|
+ COALESCE(watch.finished_count, 0) AS finishedCount,
|
|
|
+ COALESCE(watch.interrupted_count, 0) AS interruptedCount,
|
|
|
+ COALESCE(watch.today_access_count, 0) AS accessCount,
|
|
|
+
|
|
|
+ <!-- 计算比率(避免除零) -->
|
|
|
+ CASE
|
|
|
+ WHEN COALESCE(watch.today_access_count, 0) > 0
|
|
|
+ THEN ROUND(
|
|
|
+ (COALESCE(watch.watching_count, 0) + COALESCE(watch.finished_count, 0)) * 100.0 /
|
|
|
+ watch.today_access_count,
|
|
|
+ 2
|
|
|
+ )
|
|
|
+ ELSE 0
|
|
|
+ END AS watchRate,
|
|
|
+
|
|
|
+ CASE
|
|
|
+ WHEN COALESCE(watch.today_access_count, 0) > 0
|
|
|
+ THEN ROUND(
|
|
|
+ COALESCE(watch.finished_count, 0) * 100.0 /
|
|
|
+ watch.today_access_count,
|
|
|
+ 2
|
|
|
+ )
|
|
|
+ ELSE 0
|
|
|
+ END AS finishRate,
|
|
|
+
|
|
|
+ <!-- 答题人数 -->
|
|
|
+ COALESCE(answer.answer_user_count, 0) AS answerUserCount,
|
|
|
+
|
|
|
+ <!-- 红包统计 -->
|
|
|
+ COALESCE(packet.packet_user_count, 0) AS packetUserCount,
|
|
|
+ COALESCE(packet.packet_amount, 0) AS packetAmount
|
|
|
+
|
|
|
+ <!-- 动态判断是否查询营期信息 -->
|
|
|
+ <if test="trainingCampId != null">
|
|
|
+ ,(SELECT training_camp_name FROM fs_user_course_training_camp
|
|
|
+ WHERE training_camp_id = (SELECT training_camp_id FROM fs_user_course_period WHERE period_id = watch.sample_period_id LIMIT 1)
|
|
|
+ ) AS trainingCampName
|
|
|
+ </if>
|
|
|
+ <if test="periodId != null">
|
|
|
+ , (SELECT period_name FROM fs_user_course_period WHERE period_id = watch.sample_period_id LIMIT 1) AS periodName
|
|
|
+ </if>
|
|
|
+
|
|
|
+ FROM company c
|
|
|
+
|
|
|
+ <!-- 看课统计(一次性预聚合) -->
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ company_id,
|
|
|
+ MAX(period_id) AS sample_period_id,
|
|
|
+ COUNT(DISTINCT CASE WHEN log_type = 3 THEN user_id END) AS pending_count,
|
|
|
+ COUNT(DISTINCT CASE WHEN log_type = 1 THEN user_id END) AS watching_count,
|
|
|
+ COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS finished_count,
|
|
|
+ COUNT(DISTINCT CASE WHEN log_type = 4 THEN user_id END) AS interrupted_count,
|
|
|
+ COUNT(DISTINCT CASE WHEN DATE(create_time) = CURDATE() THEN user_id END) AS today_access_count
|
|
|
+ FROM fs_course_watch_log
|
|
|
+ <where>
|
|
|
+ <if test="sTime != null and eTime != null">
|
|
|
+ AND create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
+ </if>
|
|
|
+ <if test="trainingCampId != null">
|
|
|
+ AND period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
|
|
|
+ </if>
|
|
|
+ <if test="periodId !=null">
|
|
|
+ AND period_id =#{periodId}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ GROUP BY company_id
|
|
|
+ ) AS watch ON c.company_id = watch.company_id
|
|
|
+
|
|
|
+ <!-- 答题统计(预聚合) -->
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ w.company_id,
|
|
|
+ COUNT(DISTINCT a.user_id) AS answer_user_count
|
|
|
+ FROM fs_course_answer_logs a
|
|
|
+ INNER JOIN fs_course_watch_log w ON a.watch_log_id = w.log_id
|
|
|
+ <where>
|
|
|
+ <if test="sTime != null and eTime != null">
|
|
|
+ AND w.create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
+ </if>
|
|
|
+ <if test="trainingCampId != null">
|
|
|
+ AND w.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
|
|
|
+ </if>
|
|
|
+ <if test="periodId!=null">
|
|
|
+ AND w.period_id = #{periodId}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ GROUP BY w.company_id
|
|
|
+ ) AS answer ON c.company_id = answer.company_id
|
|
|
+
|
|
|
+ <!-- 红包统计(预聚合) -->
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ company_id,
|
|
|
+ COUNT(DISTINCT user_id) AS packet_user_count,
|
|
|
+ COALESCE(SUM(amount), 0) AS packet_amount
|
|
|
+ FROM red_packet_log
|
|
|
+ <where>
|
|
|
+ <if test="sTime != null and eTime != null">
|
|
|
+ AND create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ GROUP BY company_id
|
|
|
+ ) AS packet ON c.company_id = packet.company_id
|
|
|
+
|
|
|
+ <!-- 只显示有数据的公司 -->
|
|
|
+ WHERE watch.company_id IS NOT NULL
|
|
|
+
|
|
|
+ <!-- 公司筛选条件 -->
|
|
|
+
|
|
|
+ <if test="companyId != null and companyId != ''">
|
|
|
+ AND c.company_id =#{companyId}
|
|
|
+ </if>
|
|
|
+
|
|
|
+ <!-- 训练营筛选条件 -->
|
|
|
+ <if test="trainingCampId != null">
|
|
|
+ AND EXISTS (
|
|
|
+ SELECT 1 FROM fs_course_watch_log w2
|
|
|
+ INNER JOIN fs_user_course_period p ON w2.period_id = p.period_id
|
|
|
+ WHERE w2.company_id = c.company_id
|
|
|
+ AND p.training_camp_id = #{trainingCampId}
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+
|
|
|
+ <if test="periodId != null">
|
|
|
+ AND EXISTS (
|
|
|
+ SELECT 1 FROM fs_course_watch_log w2
|
|
|
+ WHERE w2.company_id = c.company_id
|
|
|
+ AND w2.period_id = #{periodId}
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+
|
|
|
+ ORDER BY COALESCE(watch.today_access_count, 0) DESC
|
|
|
+
|
|
|
+ </select>
|
|
|
|
|
|
</mapper>
|