|
|
@@ -4,6 +4,7 @@ package com.fs.live.websocket.service;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fs.common.constant.LiveKeysConstant;
|
|
|
+import com.fs.common.core.redis.RedisCacheT;
|
|
|
import com.fs.common.exception.base.BaseException;
|
|
|
import com.fs.common.utils.date.DateUtil;
|
|
|
import com.fs.his.domain.FsUser;
|
|
|
@@ -329,21 +330,28 @@ public class WebSocketServer {
|
|
|
String hashKey = "live:watch:duration:hash:" + liveId;
|
|
|
String userIdField = String.valueOf(watchUserId);
|
|
|
|
|
|
+ log.info("[心跳-观看时长] 开始处理, liveId={}, userId={}, hashKey={}, userIdField={}, currentDuration={}",
|
|
|
+ liveId, watchUserId, hashKey, userIdField, currentDuration);
|
|
|
+
|
|
|
// 获取现有时长
|
|
|
- Object existingDuration = redisCache.redisTemplate.opsForHash().get(hashKey, userIdField);
|
|
|
+ Object existingDuration = redisCache.hashGet(hashKey, userIdField);
|
|
|
|
|
|
- // 只有当新的时长更大时才更新(避免时间倒退)
|
|
|
+ // 只有当新的时长更大时才更新
|
|
|
if (existingDuration == null || currentDuration > Long.parseLong(existingDuration.toString())) {
|
|
|
// 更新Hash中的用户时长
|
|
|
- redisCache.redisTemplate.opsForHash().put(hashKey, userIdField, currentDuration.toString());
|
|
|
+ redisCache.hashPut(hashKey, userIdField, currentDuration.toString());
|
|
|
// 设置过期时间(2小时)
|
|
|
- redisCache.redisTemplate.expire(hashKey, 2, TimeUnit.HOURS);
|
|
|
+ redisCache.expire(hashKey, 2, TimeUnit.HOURS);
|
|
|
+
|
|
|
+ log.info("[心跳-观看时长] 更新成功, liveId={}, userId={}, duration={}, hashKey={}",
|
|
|
+ liveId, watchUserId, currentDuration, hashKey);
|
|
|
|
|
|
// 实时更新用户看课状态(仅在直播期间)
|
|
|
updateWatchLogTypeInRealTime(liveId, watchUserId, currentDuration);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- log.error("心跳更新观看时长失败, liveId={}, userId={}", liveId, watchUserId, e);
|
|
|
+ log.error("[心跳-观看时长] 更新失败, liveId={}, userId={}, data={}",
|
|
|
+ liveId, watchUserId, msg.getData(), e);
|
|
|
}
|
|
|
}
|
|
|
|