Explorar el Código

Merge remote-tracking branch 'origin/ScrmStores' into ScrmStores

yjwang hace 1 mes
padre
commit
a398596aec

+ 5 - 12
fs-service/src/main/java/com/fs/statis/service/impl/StatisticsCompanyServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fs.statis.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fs.common.core.domain.R;
@@ -450,7 +451,10 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
         dto.setCompanyId(companyId);
         List<CourseStatsDTO> courseStatsDTOS = watchCourseTopTen(dto);
 
-        redisCache.setCacheObject( String.format("%s:%d:%d:%d:%s:%d", CHARTS_WATCH_TOP_TEN, type,statisticalType,userType,sort,companyId), courseStatsDTOS);
+        if(ObjectUtil.isNotEmpty(courseStatsDTOS)){
+            redisCache.setCacheObject( String.format("%s:%d:%d:%d:%s:%d", CHARTS_WATCH_TOP_TEN, type,statisticalType,userType,sort,companyId), courseStatsDTOS);
+        }
+
 
     }
 
@@ -462,7 +466,6 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
             if (companyId == null) {
                 continue;
             }
-
             watchCourseTopTenTask(0,0,1,"DESC",companyId);
             watchCourseTopTenTask(0,0,1,"ASC",companyId);
             watchCourseTopTenTask(0,1,1,"DESC",companyId);
@@ -471,16 +474,6 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
             watchCourseTopTenTask(0,2,1,"ASC",companyId);
             watchCourseTopTenTask(0,3,1,"DESC",companyId);
             watchCourseTopTenTask(0,3,1,"ASC",companyId);
-
-            watchCourseTopTenTask(0,0,1,"DESC",companyId);
-            watchCourseTopTenTask(0,0,1,"ASC",companyId);
-            watchCourseTopTenTask(0,1,1,"DESC",companyId);
-            watchCourseTopTenTask(0,1,1,"ASC",companyId);
-            watchCourseTopTenTask(0,2,1,"DESC",companyId);
-            watchCourseTopTenTask(0,2,1,"ASC",companyId);
-            watchCourseTopTenTask(0,3,1,"DESC",companyId);
-            watchCourseTopTenTask(0,3,1,"ASC",companyId);
-
         }
 
     }

+ 109 - 30
fs-service/src/main/resources/mapper/statis/ConsumptionBalanceMapper.xml

@@ -224,50 +224,129 @@
         GROUP BY company_id
         limit 10
     </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-->
+<!--        &#45;&#45; 观看人数-->
+<!--        <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>-->
+    <select id="watchCourseTopTen"
+            resultType="com.fs.statis.dto.CourseStatsDTO">
+
+        SELECT
+        t.courseId,
+        t.watchUserCount,
+        t.completedUserCount,
+        t.answerUserCount,
+        t.correctUserCount
+        FROM (
         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
+        w.course_id           AS courseId,
+        COUNT(w.user_id)      AS watchUserCount,
+        SUM(w.completed_flag) AS completedUserCount,
+        COUNT(a.user_id)      AS answerUserCount,
+        SUM(a.correct_flag)   AS correctUserCount
         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
+        (
+        /* 看课用户去重 + 是否完课 */
+        SELECT
+        course_id,
+        user_id,
+        MAX(CASE WHEN log_type = 2 THEN 1 ELSE 0 END) AS completed_flag
+        FROM fs_course_watch_log
         <where>
-            <if test="startTime != null">
-                w.create_time <![CDATA[>=]]> #{startTime}
+            <if test="startTime != null and startTime != ''">
+                AND create_time <![CDATA[>=]]> #{startTime}
             </if>
-            <if test="endTime != null">
-                AND w.create_time <![CDATA[<]]> #{endTime}
+            <if test="endTime != null and endTime != ''">
+                AND create_time <![CDATA[<]]> #{endTime}
             </if>
             <if test="userType != null">
-                AND send_type = ${userType}
+                AND send_type = #{userType}
             </if>
             <if test="companyId != null">
-                AND w.company_id = ${companyId}
+                AND 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)
+        GROUP BY course_id, user_id
+        ) w
+        LEFT JOIN
+        (
+        /* 答题用户去重 + 是否答对 */
+        SELECT
+        course_id,
+        user_id,
+        MAX(CASE WHEN is_right = 1 THEN 1 ELSE 0 END) AS correct_flag
+        FROM fs_course_answer_logs
+        <where>
+            <if test="startTime != null and startTime != ''">
+                AND create_time <![CDATA[>=]]> #{startTime}
             </if>
-            <if test="statisticalType == 3">
-                COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END)
+            <if test="endTime != null and endTime != ''">
+                AND create_time <![CDATA[<]]> #{endTime}
             </if>
-        ${sort}
+        </where>
+        GROUP BY course_id, user_id
+        ) a
+        ON w.course_id = a.course_id
+        AND w.user_id = a.user_id
+        GROUP BY w.course_id
+        ) t
+        ORDER BY
+        <choose>
+            <when test="statisticalType == 0">t.watchUserCount</when>
+            <when test="statisticalType == 1">t.completedUserCount</when>
+            <when test="statisticalType == 2">t.answerUserCount</when>
+            <when test="statisticalType == 3">t.correctUserCount</when>
+            <otherwise>t.watchUserCount</otherwise>
+        </choose>
+        <choose>
+            <when test="sort == 'ASC'">ASC</when>
+            <otherwise>DESC</otherwise>
+        </choose>
         LIMIT 10
+
     </select>
+
+
     <select id="rewardMoneyTopTen" resultType="com.fs.statis.dto.RewardMoneyTopTenDTO">
         SELECT
             -- 按公司