Ver Fonte

不需要防重

xw há 3 dias atrás
pai
commit
1208ea953d

+ 24 - 37
fs-live-app/src/main/java/com/fs/live/task/LiveCompletionPointsTask.java

@@ -76,9 +76,10 @@ public class LiveCompletionPointsTask {
                     for (Map.Entry<Object, Object> entry : userDurations.entrySet()) {
                         try {
                             Long userId = Long.parseLong(entry.getKey().toString());
+                            Long duration = Long.parseLong(entry.getValue().toString());  // 从 Redis 直接获取观看时长
                             
-                            // 4. 检查并创建完课记录(传null,自动累计直播+回放时长
-                            completionPointsRecordService.checkAndCreateCompletionRecord(liveId, userId, null);
+                            // 4. 检查并创建完课记录(传入Redis中的观看时长,不要传null)
+                            completionPointsRecordService.checkAndCreateCompletionRecord(liveId, userId, duration);
 
                             // 5. 检查是否有新的完课记录待领取,推送弹窗消息(防重复)
                             sendCompletionNotificationOnce(liveId, userId);
@@ -98,43 +99,29 @@ public class LiveCompletionPointsTask {
         }
     }
 
-    /**
-     * 发送完课通知(通过WebSocket推送弹窗) - 防重复版本
-     */
-    private void sendCompletionNotificationOnce(Long liveId, Long userId) {
-        try {
-            // 1. 检查 Redis 是否已推送过(防止每分钟都推送)
-            String notifyKey = "live:completion:notified:" + liveId + ":" + userId;
-            Boolean hasNotified = redisCache.hasKey(notifyKey);
-            
-            if (Boolean.TRUE.equals(hasNotified)) {
-                return;  // 已经推送过,不再重复推送
-            }
-            
-            // 2. 查询未领取的完课记录
-            List<LiveCompletionPointsRecord> unreceivedRecords = 
-                completionPointsRecordService.getUserUnreceivedRecords(liveId, userId);
-            
-            if (unreceivedRecords != null && !unreceivedRecords.isEmpty()) {
-                // 3. 构造弹窗消息
-                SendMsgVo sendMsgVo = new SendMsgVo();
-                sendMsgVo.setLiveId(liveId);
-                sendMsgVo.setUserId(userId);
-                sendMsgVo.setCmd("completionPoints");
-                sendMsgVo.setMsg("完成任务!");
-                sendMsgVo.setData(JSONObject.toJSONString(unreceivedRecords.get(0)));
+   private void sendCompletionNotificationOnce(Long liveId, Long userId) {
+    try {
+        // 查询未领取的完课记录
+        List<LiveCompletionPointsRecord> unreceivedRecords = 
+            completionPointsRecordService.getUserUnreceivedRecords(liveId, userId);
+        
+        if (unreceivedRecords == null || unreceivedRecords.isEmpty()) {
+            return;
+        }
 
-                // 4. 通过WebSocket发送给特定用户
-                webSocketServer.sendCompletionPointsMessage(liveId, userId, sendMsgVo);
-                
-                // 5. 记录已推送,24小时后过期(第二天可以再次推送)
-                redisCache.setCacheObject(notifyKey, "1", 24, TimeUnit.HOURS);
-                
-                log.info("发送完课积分弹窗通知成功, liveId={}, userId={}, points={}", 
-                        liveId, userId, unreceivedRecords.get(0).getPointsAwarded());
-            }
+        SendMsgVo sendMsgVo = new SendMsgVo();
+        sendMsgVo.setLiveId(liveId);
+        sendMsgVo.setUserId(userId);
+        sendMsgVo.setCmd("completionPoints");
+        sendMsgVo.setMsg("完成任务!");
+        sendMsgVo.setData(JSONObject.toJSONString(unreceivedRecords.get(0)));
+        
+        webSocketServer.sendCompletionPointsMessage(liveId, userId, sendMsgVo);
+        
+        log.info("发送完课积分弹窗通知, liveId={}, userId={}, points={}", 
+                liveId, userId, unreceivedRecords.get(0).getPointsAwarded());
         } catch (Exception e) {
-            log.error("发送完课通知失败, liveId={}, userId={}", liveId, userId, e);
+        log.error("发送完课通知失败", e);
         }
     }
 }

+ 3 - 0
fs-service/src/main/java/com/fs/live/vo/LiveVo.java

@@ -33,6 +33,9 @@ public class LiveVo {
     private String liveImgUrl;
 
     private String liveConfig;
+    
+    /** 直播配置 */
+    private String configJson;
 
     private String videoUrl;
     private Long videoId;