Procházet zdrojové kódy

1、限制观看奖励发放

yys před 1 dnem
rodič
revize
f919826e12

+ 16 - 3
fs-live-app/src/main/java/com/fs/live/task/Task.java

@@ -508,15 +508,28 @@ public class Task {
                         LOG_PREFIX, openRewardLive.getLiveId(), config.getParticipateCondition());
                 continue;
             }
+            if (openRewardLive.getStartTime() != null
+                    && openRewardLive.getStartTime().isAfter(LocalDateTime.now())) {
+                log.info("{} autoUpdateWatchReward 直播未开始,跳过: liveId={}, startTime={}",
+                        LOG_PREFIX, openRewardLive.getLiveId(), openRewardLive.getStartTime());
+                continue;
+            }
 
             List<LiveWatchUser> liveWatchUsers = liveWatchUserService.checkOnlineNoRewardUser(openRewardLive.getLiveId(), now);
             if (liveWatchUsers == null || liveWatchUsers.isEmpty()) {
                 log.info("{} autoUpdateWatchReward 无待发放用户: liveId={}", LOG_PREFIX, openRewardLive.getLiveId());
                 continue;
             }
-            // 3.检查当前直播间的在线用户(可以传入一个时间,然后查出来当天没领取奖励的用户)
-            List<LiveWatchUser> onlineUser = liveWatchUsers
-                    .stream().filter(user -> (now.getTime() - user.getUpdateTime().getTime() + (user.getOnlineSeconds() == null ? 0L : user.getOnlineSeconds())) > config.getWatchDuration() * 60 * 1000)
+            long requiredWatchSeconds = config.getWatchDuration() * 60;
+            List<LiveWatchUser> onlineUser = liveWatchUsers.stream()
+                    .filter(user -> {
+                        if (user.getUserId() == null) {
+                            return false;
+                        }
+                        Long watchSeconds = liveWatchUserService.getUserWatchDuration(
+                                openRewardLive.getLiveId(), user.getUserId());
+                        return watchSeconds != null && watchSeconds >= requiredWatchSeconds;
+                    })
                     .collect(Collectors.toList());
             if (onlineUser.isEmpty()) {
                 log.info("{} autoUpdateWatchReward 无达到观看时长用户: liveId={}", LOG_PREFIX, openRewardLive.getLiveId());

+ 6 - 2
fs-service/src/main/java/com/fs/live/service/impl/LiveCompletionCouponServiceImpl.java

@@ -474,12 +474,16 @@ public class LiveCompletionCouponServiceImpl implements ILiveCompletionCouponSer
         if (live == null) {
             return false;
         }
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime startTime = live.getStartTime();
+        if (startTime != null && startTime.isAfter(now)) {
+            return false;
+        }
         Integer status = live.getStatus();
         if (status != null && (status == 2 || status == 3 || status == 4)) {
             return true;
         }
-        LocalDateTime startTime = live.getStartTime();
-        return startTime != null && !startTime.isAfter(LocalDateTime.now());
+        return startTime != null && !startTime.isAfter(now);
     }
 
     private CompletionCouponConfig resolveConfig(Long liveId) {

+ 6 - 2
fs-service/src/main/java/com/fs/live/service/impl/LiveWatchUserServiceImpl.java

@@ -1371,12 +1371,16 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
         if (live == null) {
             return false;
         }
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime startTime = live.getStartTime();
+        if (startTime != null && startTime.isAfter(now)) {
+            return false;
+        }
         Integer status = live.getStatus();
         if (status != null && (status == 2 || status == 3 || status == 4)) {
             return true;
         }
-        LocalDateTime startTime = live.getStartTime();
-        return startTime != null && !startTime.isAfter(LocalDateTime.now());
+        return startTime != null && !startTime.isAfter(now);
     }
 
     private long resolveLiveStartMillis(Live live) {