|
|
@@ -835,13 +835,18 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
|
|
|
log.error("key中id为null:{}", key);
|
|
|
continue;
|
|
|
}
|
|
|
- String durationStr = redisCache.getCacheObject(key, String.class);
|
|
|
- if (com.fs.common.utils.StringUtils.isEmpty(durationStr)) {
|
|
|
+ Object cached = redisCache.getCacheObject(key);
|
|
|
+ if (cached == null) {
|
|
|
redisCache.deleteObject(key);
|
|
|
log.error("key中数据为null:{}", key);
|
|
|
continue; // 如果 Redis 中没有记录,跳过
|
|
|
}
|
|
|
- Long duration = Long.valueOf(durationStr);
|
|
|
+ Long duration;
|
|
|
+ if (cached instanceof Number) {
|
|
|
+ duration = ((Number) cached).longValue();
|
|
|
+ } else {
|
|
|
+ duration = Long.valueOf(cached.toString());
|
|
|
+ }
|
|
|
|
|
|
FsCourseWatchLog watchLog = new FsCourseWatchLog();
|
|
|
watchLog.setVideoId(videoId);
|
|
|
@@ -1133,20 +1138,25 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
|
|
|
public Long getVideoDuration(Long videoId){
|
|
|
//将视频时长也存到redis
|
|
|
String videoRedisKey = "h5user:video:duration:" + videoId;
|
|
|
- Long videoDuration=0L;
|
|
|
- try {
|
|
|
- videoDuration = redisCache.getCacheObject(videoRedisKey, Long.class);
|
|
|
- }catch (Exception e){
|
|
|
- String string = redisCache.getCacheObject(videoRedisKey, String.class);
|
|
|
- videoDuration=Long.parseLong(string);
|
|
|
- log.error("key中id为S:{}", videoDuration);
|
|
|
+ Long videoDuration = null;
|
|
|
+ Object cached = redisCache.getCacheObject(videoRedisKey);
|
|
|
+ if (cached instanceof Number) {
|
|
|
+ videoDuration = ((Number) cached).longValue();
|
|
|
+ } else if (cached != null) {
|
|
|
+ try {
|
|
|
+ videoDuration = Long.parseLong(cached.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("视频时长缓存格式异常 key={}, value={}", videoRedisKey, cached);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (videoDuration==null){
|
|
|
+ if (videoDuration == null) {
|
|
|
FsUserCourseVideo video = courseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
- videoDuration=video.getDuration();
|
|
|
- redisCache.setCacheObject(videoRedisKey,video.getDuration());
|
|
|
+ if (video == null || video.getDuration() == null) {
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ videoDuration = video.getDuration();
|
|
|
+ redisCache.setCacheObject(videoRedisKey, video.getDuration());
|
|
|
}
|
|
|
return videoDuration;
|
|
|
}
|
|
|
@@ -1154,11 +1164,24 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
|
|
|
public Long getVideoDurationIsOpen(Long videoId){
|
|
|
//将视频时长也存到redis
|
|
|
String videoRedisKey = "h5OpenUser:video:duration:" + videoId;
|
|
|
- Long videoDuration = redisCache.getCacheObject(videoRedisKey, Long.class);
|
|
|
- if (videoDuration==null){
|
|
|
+ Long videoDuration = null;
|
|
|
+ Object cached = redisCache.getCacheObject(videoRedisKey);
|
|
|
+ if (cached instanceof Number) {
|
|
|
+ videoDuration = ((Number) cached).longValue();
|
|
|
+ } else if (cached != null) {
|
|
|
+ try {
|
|
|
+ videoDuration = Long.parseLong(cached.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("公开课视频时长缓存格式异常 key={}, value={}", videoRedisKey, cached);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (videoDuration == null) {
|
|
|
FsUserCourseVideo video = courseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
- videoDuration=video.getDuration();
|
|
|
- redisCache.setCacheObject(videoRedisKey,video.getDuration());
|
|
|
+ if (video == null || video.getDuration() == null) {
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ videoDuration = video.getDuration();
|
|
|
+ redisCache.setCacheObject(videoRedisKey, video.getDuration());
|
|
|
}
|
|
|
return videoDuration;
|
|
|
}
|