学员真实学习时长记录

This commit is contained in:
none
2023-03-22 14:46:49 +08:00
parent 79297f7264
commit 39f46d5ace
16 changed files with 381 additions and 36 deletions

View File

@@ -25,12 +25,13 @@ public class UserCanSeeCourseCache {
public boolean check(User user, Course course, boolean isThrow) throws ServiceException {
boolean result;
if (RedisUtil.exists(key(user, course))) {
result = "1".equals(RedisUtil.get(key(user, course)));
String cacheResult = (String) RedisUtil.get(key(user, course));
result = "1".equals(cacheResult);
} else {
result = userBus.canSeeCourse(user, course);
put(user, course, result);
}
if (isThrow) {
if (!result && isThrow) {
throw new ServiceException("无权限观看");
}
return result;

View File

@@ -0,0 +1,24 @@
package xyz.playedu.api.caches;
import org.springframework.stereotype.Component;
import xyz.playedu.api.util.RedisUtil;
/**
* @Author 杭州白书科技有限公司
* @create 2023/3/22 13:57
*/
@Component
public class UserLastLearnTimeCache {
private final static String groupName = "user-learn-last-timestamp";
private final static int expire = 9500;//9.5s
public Long get(Integer userId) {
return (Long) RedisUtil.hGet(groupName, userId + "");
}
public void put(Integer userId, Long timestamp) {
RedisUtil.hSet(groupName, userId + "", timestamp);
}
}