|
|
@@ -169,7 +169,9 @@ public class Task {
|
|
|
redisCache.expire(key+live.getLiveId(), 1, TimeUnit.DAYS);
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+ String cacheKey = String.format(LiveKeysConstant.LIVE_DATA_CACHE, live.getLiveId());
|
|
|
+ redisCache.setCacheObject(cacheKey,live,1,TimeUnit.HOURS);
|
|
|
+ liveWatchUserService.clearLiveFlagCache(live.getLiveId());
|
|
|
// 将开启的直播间信息写入Redis缓存,用于打标签定时任务
|
|
|
try {
|
|
|
// 获取视频时长
|
|
|
@@ -216,8 +218,10 @@ public class Task {
|
|
|
redisCache.redisTemplate.opsForZSet().remove(key + live.getLiveId(), JSON.toJSONString(liveAutoTask),liveAutoTask.getAbsValue().getTime());
|
|
|
});
|
|
|
}
|
|
|
+ String cacheKey = String.format(LiveKeysConstant.LIVE_DATA_CACHE, live.getLiveId());
|
|
|
+ redisCache.deleteObject(cacheKey);
|
|
|
webSocketServer.removeLikeCountCache(live.getLiveId());
|
|
|
-
|
|
|
+
|
|
|
// 删除打标签缓存
|
|
|
try {
|
|
|
String tagMarkKey = String.format(LiveKeysConstant.LIVE_TAG_MARK_CACHE, live.getLiveId());
|
|
|
@@ -679,7 +683,8 @@ public class Task {
|
|
|
queryUser.setLiveId(liveId);
|
|
|
queryUser.setLiveFlag(1);
|
|
|
queryUser.setReplayFlag(0);
|
|
|
- List<LiveWatchUser> liveUsers = liveWatchUserService.selectLiveWatchUserList(queryUser);
|
|
|
+ queryUser.setOnline(0);
|
|
|
+ List<LiveWatchUser> liveUsers = liveWatchUserService.selectAllWatchUser(queryUser);
|
|
|
|
|
|
if (liveUsers != null && !liveUsers.isEmpty()) {
|
|
|
|
|
|
@@ -725,6 +730,7 @@ public class Task {
|
|
|
// 更新直播用户的在线时长
|
|
|
liveUser.setOnlineSeconds(totalOnlineSeconds);
|
|
|
liveUser.setUpdateTime(nowDate);
|
|
|
+ liveUser.setOnline(1);
|
|
|
updateLiveUsers.add(liveUser);
|
|
|
|
|
|
// 2. 生成回放用户数据(liveFlag = 0, replayFlag = 1),在线时长从0开始
|
|
|
@@ -732,7 +738,7 @@ public class Task {
|
|
|
replayUser.setLiveId(liveUser.getLiveId());
|
|
|
replayUser.setUserId(liveUser.getUserId());
|
|
|
replayUser.setMsgStatus(liveUser.getMsgStatus());
|
|
|
- replayUser.setOnline(liveUser.getOnline());
|
|
|
+ replayUser.setOnline(0);
|
|
|
replayUser.setOnlineSeconds(0L); // 回放观看时长从0开始,重新计时
|
|
|
replayUser.setGlobalVisible(liveUser.getGlobalVisible());
|
|
|
replayUser.setSingleVisible(liveUser.getSingleVisible());
|
|
|
@@ -742,6 +748,7 @@ public class Task {
|
|
|
replayUser.setCreateTime(nowDate);
|
|
|
replayUser.setUpdateTime(nowDate);
|
|
|
replayUsers.add(replayUser);
|
|
|
+ redisCache.setCacheObject(entryTimeKey,now);
|
|
|
}
|
|
|
|
|
|
// 批量更新直播用户的在线时长
|
|
|
@@ -824,8 +831,7 @@ public class Task {
|
|
|
queryUser.setLiveId(liveId);
|
|
|
queryUser.setLiveFlag(1);
|
|
|
queryUser.setReplayFlag(0);
|
|
|
- queryUser.setOnline(0); // 在线用户
|
|
|
- List<LiveWatchUser> onlineUsers = liveWatchUserService.selectLiveWatchUserList(queryUser);
|
|
|
+ List<LiveWatchUser> onlineUsers = liveWatchUserService.selectAllWatchUser(queryUser);
|
|
|
if (onlineUsers == null || onlineUsers.isEmpty()) {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -840,6 +846,7 @@ public class Task {
|
|
|
}
|
|
|
|
|
|
// 处理每个在线用户
|
|
|
+ List<LiveWatchLog> updateLog = new ArrayList<>();
|
|
|
for (LiveWatchUser user : onlineUsers) {
|
|
|
try {
|
|
|
Long userId = user.getUserId();
|
|
|
@@ -869,13 +876,22 @@ public class Task {
|
|
|
|
|
|
// 使用 updateLiveWatchLogTypeByDuration 的逻辑更新观看记录状态
|
|
|
updateLiveWatchLogTypeByDuration(liveId, userId, qwUserId, externalContactId,
|
|
|
- onlineSeconds, totalVideoDuration);
|
|
|
+ onlineSeconds, totalVideoDuration, updateLog);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理用户观看记录状态异常: liveId={}, userId={}, error={}",
|
|
|
liveId, user.getUserId(), e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
+ // 批量插入回放用户数据
|
|
|
+ if (!updateLog.isEmpty()) {
|
|
|
+ int batchSize = 500;
|
|
|
+ for (int i = 0; i < updateLog.size(); i += batchSize) {
|
|
|
+ int end = Math.min(i + batchSize, updateLog.size());
|
|
|
+ List<LiveWatchLog> batch = updateLog.subList(i, end);
|
|
|
+ liveWatchLogService.batchUpdateLiveWatchLog(batch);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理直播间观看记录状态异常: liveId={}, error={}",
|
|
|
@@ -897,7 +913,7 @@ public class Task {
|
|
|
* @param totalVideoDuration 视频总时长(秒)
|
|
|
*/
|
|
|
private void updateLiveWatchLogTypeByDuration(Long liveId, Long userId, Long qwUserId,
|
|
|
- Long exId, Long onlineSeconds, long totalVideoDuration) {
|
|
|
+ Long exId, Long onlineSeconds, long totalVideoDuration, List<LiveWatchLog> updateLog) {
|
|
|
try {
|
|
|
// 查询 LiveWatchLog
|
|
|
LiveWatchLog queryLog = new LiveWatchLog();
|
|
|
@@ -906,7 +922,7 @@ public class Task {
|
|
|
queryLog.setQwUserId(String.valueOf(qwUserId));
|
|
|
queryLog.setExternalContactId(exId);
|
|
|
|
|
|
- List<LiveWatchLog> logs = liveWatchLogService.selectLiveWatchLogList(queryLog);
|
|
|
+ List<LiveWatchLog> logs = liveWatchLogService.selectLiveWatchLogByLogIdWithCache(queryLog);
|
|
|
if (logs == null || logs.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -940,7 +956,7 @@ public class Task {
|
|
|
// 如果 logType 已经是 2(完课),不再更新
|
|
|
if (needUpdate) {
|
|
|
log.setLogType(newLogType);
|
|
|
- liveWatchLogService.updateLiveWatchLog(log);
|
|
|
+ updateLog.add(log);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|