增加周播放量
This commit is contained in:
parent
732ee1df4b
commit
5e4aaf78ce
|
|
@ -1,6 +1,7 @@
|
||||||
package com.sqx.common.utils;
|
package com.sqx.common.utils;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
@ -114,8 +115,13 @@ public class ApiAccessLimitUtil {
|
||||||
String redisKey = generateRedisKey(key, id);
|
String redisKey = generateRedisKey(key, id);
|
||||||
Object countObj = redisUtils.get(redisKey);
|
Object countObj = redisUtils.get(redisKey);
|
||||||
if (countObj == null) {
|
if (countObj == null) {
|
||||||
// 根据不同时间周期设置过期时间并初始化访问次数为1
|
long expireAt;
|
||||||
long expireAt = calculateExpireAt(timeFormat);
|
if (StrUtil.isBlank(timeFormat)) {
|
||||||
|
expireAt = count;
|
||||||
|
}else {
|
||||||
|
// 根据不同时间周期设置过期时间并初始化访问次数为1
|
||||||
|
expireAt = calculateExpireAt(timeFormat);
|
||||||
|
}
|
||||||
redisUtils.set(redisKey, 1, expireAt);
|
redisUtils.set(redisKey, 1, expireAt);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,6 @@ public class AppCourseController extends AbstractController {
|
||||||
if (week != null) {
|
if (week != null) {
|
||||||
return Result.success().put("data", week);
|
return Result.success().put("data", week);
|
||||||
}
|
}
|
||||||
// courseService.asyncIncrView(courseDetailsId);
|
|
||||||
Result result = courseDetailsService.selectCourseDetailsById(id, token, courseDetailsId);
|
Result result = courseDetailsService.selectCourseDetailsById(id, token, courseDetailsId);
|
||||||
if (result.get("code").equals(0)) {
|
if (result.get("code").equals(0)) {
|
||||||
redisUtils.set(redisKey, result.get("data"), 3);
|
redisUtils.set(redisKey, result.get("data"), 3);
|
||||||
|
|
|
||||||
|
|
@ -332,6 +332,7 @@ public class Course implements Serializable {
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private Integer isCollect;
|
private Integer isCollect;
|
||||||
|
private Integer weekView;
|
||||||
|
|
||||||
public Course() {}
|
public Course() {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.sqx.common.exception.SqxException;
|
import com.sqx.common.exception.SqxException;
|
||||||
|
import com.sqx.common.utils.ApiAccessLimitUtil;
|
||||||
import com.sqx.common.utils.DateUtils;
|
import com.sqx.common.utils.DateUtils;
|
||||||
import com.sqx.common.utils.PageUtils;
|
import com.sqx.common.utils.PageUtils;
|
||||||
import com.sqx.common.utils.Result;
|
import com.sqx.common.utils.Result;
|
||||||
|
|
@ -130,6 +131,14 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setCourseView(Course course) {
|
||||||
|
if (ApiAccessLimitUtil.isAccessAllowed("setCourseView:" + course.getCourseId(), "updateAuthCertInfo", 1, 600)) {
|
||||||
|
int courseViewCount = redisServiceImpl.getCourseWeekViewCount(course.getCourseId());
|
||||||
|
course.setWeekView(courseViewCount);
|
||||||
|
courseDao.updateById(course);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result selectCourseDetailsById(Long id, String token, String courseDetailsId) {
|
public Result selectCourseDetailsById(Long id, String token, String courseDetailsId) {
|
||||||
Course bean = courseDao.selectById(id);
|
Course bean = courseDao.selectById(id);
|
||||||
|
|
@ -139,6 +148,9 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
||||||
bean.setViewCounts(bean.getViewCounts() + 1);
|
bean.setViewCounts(bean.getViewCounts() + 1);
|
||||||
}
|
}
|
||||||
courseDao.updateById(bean);
|
courseDao.updateById(bean);
|
||||||
|
|
||||||
|
setCourseView(bean);
|
||||||
|
|
||||||
Long userId = null;
|
Long userId = null;
|
||||||
if (StringUtils.isNotEmpty(token)) {
|
if (StringUtils.isNotEmpty(token)) {
|
||||||
Claims claims = jwtUtils.getClaimByToken(token);
|
Claims claims = jwtUtils.getClaimByToken(token);
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,6 @@ public interface RedisService {
|
||||||
boolean isRecordUserOnLineTime(long userId);
|
boolean isRecordUserOnLineTime(long userId);
|
||||||
|
|
||||||
boolean isSetUserState(long userId);
|
boolean isSetUserState(long userId);
|
||||||
|
|
||||||
|
int getCourseWeekViewCount(long courseId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -291,4 +291,23 @@ public class RedisServiceImpl implements RedisService {
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue