|
@@ -718,7 +718,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
|
speakerCache.set(roomSpeakerInfo);
|
|
|
log.info("startLive>>>> roomSpeakerInfo: {}", JSONObject.toJSONString(roomSpeakerInfo));
|
|
|
//主播开启直播,查询所有在直播间的用户并写入观看时间
|
|
|
- CompletableFuture.runAsync(() -> this.asyncOpsLiveLookTime(roomUid, 1));
|
|
|
+ CompletableFuture.runAsync(() -> this.asyncOpsLiveLookTime(roomUid, 1, now));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -769,7 +769,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
|
//写入本次直播时长
|
|
|
roomSpeakerInfo.setTotalLiveTime(getLookMinutes(roomSpeakerInfo.getStartLiveTime(), roomSpeakerInfo.getTotalLiveTime()));
|
|
|
//关闭直播后异步执行计算房间人员观看时长
|
|
|
- CompletableFuture.runAsync(() -> this.asyncOpsLiveLookTime(roomSpeakerInfo.getRoomUid(), 2));
|
|
|
+ CompletableFuture.runAsync(() -> this.asyncOpsLiveLookTime(roomSpeakerInfo.getRoomUid(), 2, now));
|
|
|
}
|
|
|
//计算完后将开始直播时间设置为空,待下次开启后再计算
|
|
|
roomSpeakerInfo.setStartLiveTime(null);
|
|
@@ -783,7 +783,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
|
* @param roomUid 房间uid
|
|
|
* @param type type 1:开始直播-开始录像 2:关闭直播关闭录像
|
|
|
*/
|
|
|
- private void asyncOpsLiveLookTime(String roomUid, Integer type) {
|
|
|
+ private void asyncOpsLiveLookTime(String roomUid, Integer type, Date now) {
|
|
|
//加锁-避免快速点击开启直播和关闭直后异步执行后直播数据错误
|
|
|
boolean b = this.runIfLockCanGet(LIVE_LOOK_LOCK.replace(ROOM_UID, roomUid), () -> {
|
|
|
//查询所有在直播间的用户并计算观看时长
|
|
@@ -800,7 +800,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
|
//开启直播后对当前在房间的用户写入观看时间
|
|
|
userInfo.setDynamicLookTime(new Date());
|
|
|
} else if (type.equals(2)) {
|
|
|
- userInfo.setTotalViewTime(getLookMinutes(userInfo.getDynamicLookTime(), userInfo.getTotalViewTime()));
|
|
|
+ userInfo.setTotalViewTime(getLookMinutes(userInfo.getDynamicLookTime(), now, userInfo.getTotalViewTime()));
|
|
|
userInfo.setDynamicLookTime(null);
|
|
|
} else {
|
|
|
return;
|
|
@@ -810,7 +810,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
|
});
|
|
|
}, 2, 1, TimeUnit.MINUTES);
|
|
|
if (!b) {
|
|
|
- this.asyncOpsLiveLookTime(roomUid, type);
|
|
|
+ this.asyncOpsLiveLookTime(roomUid, type, now);
|
|
|
}
|
|
|
}
|
|
|
|