增加周播放量

This commit is contained in:
张松
2025-01-02 18:04:23 +08:00
parent 732ee1df4b
commit 5e4aaf78ce
6 changed files with 42 additions and 3 deletions

View File

@@ -21,4 +21,6 @@ public interface RedisService {
boolean isRecordUserOnLineTime(long userId);
boolean isSetUserState(long userId);
int getCourseWeekViewCount(long courseId);
}

View File

@@ -291,4 +291,23 @@ public class RedisServiceImpl implements RedisService {
return false;
}
}
@Override
public int getCourseWeekViewCount(long courseId) {
String key = "course:viewCount:" + courseId;
String info = redisUtils.get(key);
if (StrUtil.isBlank(info)) {
// 获取当前时间
DateTime now = DateUtil.date();
// 获取下周一的日期
DateTime nextMonday = DateUtil.nextWeek();
// 计算距离下周一还有多少秒
long seconds = nextMonday.getTime() - now.getTime();
redisUtils.set(key, 1, seconds);
return 1;
}
int i = Integer.parseInt(info) + 1;
redisUtils.set(key, i, -1);
return i;
}
}