浏览代码

Merge remote-tracking branch 'origin/master'

zx 1 天之前
父节点
当前提交
3437051278

+ 1 - 1
fs-qw-task/src/main/java/com/fs/app/task/UserCourseWatchCountTask.java

@@ -29,7 +29,7 @@ public class UserCourseWatchCountTask {
     /**
      * 每20分钟执行一次
      */
-    @Scheduled(cron = "0 */20 * * * ?")  // 每20分钟执行一次
+    @Scheduled(cron = "0 */15 * * * ?")  // 每15分钟执行一次
     public void userCourseCountTask() {
         try {
             log.info("==============会员看课统计任务执行===============开始");

+ 3 - 0
fs-service-system/src/main/java/com/fs/course/mapper/FsCourseRedPacketLogMapper.java

@@ -157,4 +157,7 @@ public interface FsCourseRedPacketLogMapper
      */
     @Select("select ifnull(sum(fcrpl.amount), 0) from fs_course_red_packet_log fcrpl where fcrpl.company_user_id = #{companyUserId}")
     BigDecimal getSumByCompanyUserIdId(@Param("companyUserId") Long companyUserId);
+
+    @Select("select * from fs_course_red_packet_log where video_id = #{videoId} and user_id = #{userId} and period_id = #{periodId} limit 1")
+    FsCourseRedPacketLog selectUserFsCourseRedPacketLog(@Param("videoId") Long videoId, @Param("userId")Long userId, @Param("periodId")Long periodId);
 }

+ 13 - 6
fs-service-system/src/main/java/com/fs/course/service/impl/FsCourseQuestionBankServiceImpl.java

@@ -11,10 +11,7 @@ import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
 import com.fs.course.cache.FsUserCourseCategoryCacheService;
 import com.fs.course.config.CourseConfig;
-import com.fs.course.domain.FsCourseAnswerLogs;
-import com.fs.course.domain.FsCourseQuestionBank;
-import com.fs.course.domain.FsCourseWatchLog;
-import com.fs.course.domain.FsUserCourseCategory;
+import com.fs.course.domain.*;
 import com.fs.course.dto.FsCourseQuestionBankImportDTO;
 import com.fs.course.mapper.*;
 import com.fs.course.param.FsCourseQuestionAnswerUParam;
@@ -171,7 +168,11 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
         if (param.getLinkType()!=null&&param.getLinkType()==1){
             rightLog = courseAnswerLogsMapper.selectRightLogByCourseVideo(param.getVideoId(), param.getUserId(),null);
             if (rightLog!=null){
-                return R.error("该课程已答题完成,不可重复答题");
+                // 增加判断,去查询红包记录是否已发送成功,如果成功,则返回当前提示,否则返回答题成功(让其可以继续答题,直到红包领取完成)
+                FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectUserFsCourseRedPacketLog(param.getVideoId(), param.getUserId(),param.getPeriodId());
+                if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 1){
+                    return R.error("该课程已答题完成,不可重复答题");
+                }
             }
             errorCount = courseAnswerLogsMapper.selectErrorCountByCourseVideo(param.getVideoId(), param.getUserId(),null);
 
@@ -193,7 +194,13 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
             rightLog = courseAnswerLogsMapper.selectRightLogByCourseVideo(param.getVideoId(), param.getUserId(), param.getQwUserId());
             if (rightLog != null) {
                 if (log.getRewardType() != null) {
-                    return R.error("该课程已答题完成,不可重复答题");
+                    // 增加判断,去查询红包记录是否已发送成功,如果成功,则返回当前提示,否则返回答题成功(让其可以继续答题,直到红包领取完成)
+                    FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectUserFsCourseRedPacketLog(param.getVideoId(), param.getUserId(),param.getPeriodId());
+                    if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 1) {
+                        return R.error("该课程已答题完成,不可重复答题");
+                    } else {
+                        return R.ok("答题成功");
+                    }
                 } else {
                     return R.ok("答题成功");
                 }

+ 12 - 1
fs-service-system/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -737,7 +737,18 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
             return R.error("无记录");
         }
         if (log.getRewardType() != null) {
-            return R.error("奖励已发放");
+            FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectUserFsCourseRedPacketLog(param.getVideoId(), param.getUserId(),param.getPeriodId());
+            if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 1) {
+                return R.error("奖励已发放");
+            }
+            if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 0) {
+                if(StringUtils.isNotEmpty(fsCourseRedPacketLog.getResult())){
+                    R r = JSON.parseObject(fsCourseRedPacketLog.getResult(), R.class);
+                    return r;
+                } else {
+                    return R.error();
+                }
+            }
         }
 
 

+ 12 - 0
fs-service-system/src/main/java/com/fs/store/domain/FsUserCourseCount.java

@@ -79,6 +79,10 @@ public class FsUserCourseCount extends BaseEntity
     @Excel(name = "创建日期,为了创建唯一索引", width = 30, dateFormat = "yyyy-MM-dd")
     private Date createDate;
 
+    //最大的看课日期,用于查询唯一数据
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date lastDate;
+
     public void setId(Long id)
     {
         this.id = id;
@@ -214,6 +218,14 @@ public class FsUserCourseCount extends BaseEntity
         this.createDate = createDate;
     }
 
+    public Date getLastDate() {
+        return lastDate;
+    }
+
+    public void setLastDate(Date lastDate) {
+        this.lastDate = lastDate;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

+ 6 - 0
fs-service-system/src/main/java/com/fs/store/mapper/FsUserCourseCountMapper.java

@@ -68,6 +68,12 @@ public interface FsUserCourseCountMapper
      */
     List<FsUserCourseCount> getCountResult();
 
+    /**
+     * 获取最近七天每天最大心跳时间的看课记录数据
+     * @return
+     */
+    List<FsUserCourseCount> getUserStatusAndLastWatchDate();
+
     /**
      * 往看课统计表中插入数据
      */

+ 18 - 0
fs-service-system/src/main/java/com/fs/store/service/impl/FsUserCourseCountServiceImpl.java

@@ -1,6 +1,9 @@
 package com.fs.store.service.impl;
 
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
 import com.fs.common.utils.DateUtils;
 import com.fs.course.mapper.FsCourseWatchLogMapper;
 import com.google.common.collect.Lists;
@@ -115,6 +118,21 @@ public class FsUserCourseCountServiceImpl implements IFsUserCourseCountService
         // 1、获取统计结果
         List<FsUserCourseCount> countResult = fsUserCourseCountMapper.getCountResult();
 
+        // 查询用户-每天的最新的看课状态,和最后的心跳时间
+        List<FsUserCourseCount> userStatusAndLastWatchDate = fsUserCourseCountMapper.getUserStatusAndLastWatchDate();
+        Map<String, FsUserCourseCount> map = userStatusAndLastWatchDate.stream()
+                .collect(Collectors.toMap(k -> String.format("%s-%s", k.getUserId(), k.getLastDate()), v -> v));
+
+        for (FsUserCourseCount data : countResult) {
+            String key = String.format("%s-%s",data.getUserId(), data.getLastDate());
+            FsUserCourseCount fsUserCourseCount = map.get(key);
+            if(fsUserCourseCount != null){
+                data.setLastWatchDate(fsUserCourseCount.getLastWatchDate());
+                data.setStatus(fsUserCourseCount.getStatus());
+                data.setStopWatchDays(fsUserCourseCount.getStopWatchDays());
+            }
+        }
+
         // 2、分批插入数据
         this.batchInsert(countResult);
 

+ 2 - 2
fs-service-system/src/main/resources/mapper/course/FsUserWatchCourseStatisticsMapper.xml

@@ -46,9 +46,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="companyId != null "> and company_id = #{companyId}</if>
             <if test="companyName != null  and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if>
             <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
-            <if test="courseStartDateTime != null "> and course_start_date_time = #{courseStartDateTime}</if>
+            <if test="courseStartDateTime != null "> and course_start_date_time like concat(DATE(#{courseStartDateTime}),'%')</if>
             <if test="companyUserName != null  and companyUserName != ''"> and company_user_name like concat('%', #{companyUserName}, '%')</if>
-            <if test="periodStartingTime != null "> and period_starting_time = #{periodStartingTime}</if>
+            <if test="periodStartingTime != null "> and period_starting_time like concat(DATE(#{periodStartingTime}), '%')</if>
             <if test="newUserNum != null "> and new_user_num = #{newUserNum}</if>
             <if test="userNum != null "> and user_num = #{userNum}</if>
             <if test="watchNum != null "> and watch_num = #{watchNum}</if>

+ 32 - 16
fs-service-system/src/main/resources/mapper/store/FsUserCourseCountMapper.xml

@@ -149,32 +149,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             ( count( DISTINCT CASE WHEN fwl.log_type = 3 THEN fwl.video_id END ) > 0, 1, 2 ) AS missCourseStatus,
             GROUP_CONCAT( DISTINCT fwl.period_id ) AS courseIds,
             count(DISTINCT fwl.period_id ) AS partCourseCount,
-            a.last_heartbeat_time AS lastWatchDate,
-            CASE
-                WHEN a.log_type = 1
-                    OR a.log_type = 2 THEN
-                    1
-                WHEN a.log_type = 4 THEN
-                    2
-                WHEN a.log_type = 3 THEN
-                    3
-                END AS STATUS,
-            DATEDIFF(DATE_FORMAT(NOW(),'%Y-%m-%d'),DATE_FORMAT(a.last_heartbeat_time,'%Y-%m-%d')) as stop_watch_days,
             max( CASE WHEN fwl.log_type = 2 THEN fwl.last_heartbeat_time END ) AS completeWatchDate,
             count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS completeWatchCount,
             count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS watch_times,
             DATE_FORMAT(fwl.create_time,'%Y-%m-%d 00:00:00') AS createTime,
             NOW() AS updateTime,
-            DATE_FORMAT(fwl.create_time,'%Y-%m-%d') AS create_date
+            DATE_FORMAT(fwl.create_time,'%Y-%m-%d') AS create_date,
+            DATE (fwl.create_time ) AS lastDate
         FROM
-            ( SELECT fs_course_watch_log.user_id, Max( fs_course_watch_log.last_heartbeat_time ) AS last_heartbeat_time, log_type
-              FROM fs_course_watch_log where fs_course_watch_log.create_time &gt;= DATE_SUB(CURDATE(), INTERVAL 1 DAY) AND fs_course_watch_log.create_time &lt; CURDATE() GROUP BY fs_course_watch_log.user_id ) a
-                INNER JOIN fs_course_watch_log fwl ON fwl.user_id = a.user_id AND fwl.send_type = 1
-            where fwl.create_time &gt;= DATE_SUB(CURDATE(), INTERVAL 1 DAY) AND fwl.create_time &lt; CURDATE()
+            fs_course_watch_log fwl
+            where fwl.send_type = 1 and fwl.create_time &gt;= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
         GROUP BY
             fwl.user_id
     </select>
 
+    <select id="getUserStatusAndLastWatchDate" resultType="FsUserCourseCount">
+        SELECT
+            fs_course_watch_log.user_id,
+            Max( fs_course_watch_log.last_heartbeat_time ) AS lastWatchDate,
+            Max( DATE ( fs_course_watch_log.create_time ) ) AS lastDate,
+            CASE
+
+                WHEN fs_course_watch_log.log_type = 1
+                    OR fs_course_watch_log.log_type = 2 THEN
+                    1
+                WHEN fs_course_watch_log.log_type = 4 THEN
+                    2
+                WHEN fs_course_watch_log.log_type = 3 THEN
+                    3
+                END AS STATUS,
+            DATEDIFF(
+                    DATE_FORMAT( NOW(), '%Y-%m-%d' ),
+                    DATE_FORMAT( fs_course_watch_log.last_heartbeat_time, '%Y-%m-%d' )) AS stop_watch_days
+        FROM
+            fs_course_watch_log
+        WHERE
+            fs_course_watch_log.send_type = 1
+          AND fs_course_watch_log.create_time >= DATE_SUB( CURDATE(), INTERVAL 7 DAY )
+        GROUP BY
+            fs_course_watch_log.user_id, date(fs_course_watch_log.create_time)
+    </select>
+
+
     <insert id="insertFsUserCourseCountTask" parameterType="FsUserCourseCount" useGeneratedKeys="true" keyProperty="id">
         insert into fs_user_course_count
         <trim prefix="(" suffix=")" suffixOverrides=",">

+ 12 - 0
fs-service-system/src/main/resources/mapper/store/FsUserMapper.xml

@@ -998,6 +998,9 @@
             LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
             WHERE 1=1
             AND FIND_IN_SET(#{companyId}, fpd.company_id)
+            <if test="userId != null and userId != ''">
+                AND fs_user.company_user_id = #{userId}
+            </if>
             <if test="periodId != null and periodId != ''">
                 AND fcpd.period_id =  #{periodId}
             </if>
@@ -1014,6 +1017,9 @@
             LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
             WHERE 1=1
             AND FIND_IN_SET(#{companyId}, fpd.company_id)
+            <if test="userId != null and userId != ''">
+                AND fs_user.company_user_id = #{userId}
+            </if>
             <if test="periodId != null and periodId != ''">
                 AND fcpd.period_id =  #{periodId}
             </if>
@@ -1039,6 +1045,11 @@
         <if test="companyUserId != null and companyUserId != ''">
             AND fs_user.company_user_id = #{companyUserId}
         </if>
+        <where>
+            <if test="userId != null and userId != ''">
+                AND fs_user.company_user_id = #{userId}
+            </if>
+        </where>
          ) as courseUserNum
     </select>
 
@@ -1458,6 +1469,7 @@
         WHERE
             fs_user.is_del = 0
           AND fs_user.`status` = 1
+          AND company_user.user_id is not null
     </select>