mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-10 19:36:50 +08:00
处理study接口,添加接口访问限制次数
This commit is contained in:
@@ -12,7 +12,7 @@ import com.xboe.api.vo.*;
|
|||||||
import com.xboe.module.course.vo.TeacherVo;
|
import com.xboe.module.course.vo.TeacherVo;
|
||||||
import com.xboe.module.usergroup.entity.UserGroupItem;
|
import com.xboe.module.usergroup.entity.UserGroupItem;
|
||||||
import com.xboe.module.usergroup.service.IUserGroupService;
|
import com.xboe.module.usergroup.service.IUserGroupService;
|
||||||
import com.xboe.school.aspect.LimitRequest;
|
import com.xboe.school.study.dao.StudyCourseDao;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
@@ -68,7 +68,10 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value="/xboe/school/study/course")
|
@RequestMapping(value="/xboe/school/study/course")
|
||||||
public class StudyCourseApi extends ApiBaseController{
|
public class StudyCourseApi extends ApiBaseController{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
StudyCourseDao scDao;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
IStudyCourseService service;
|
IStudyCourseService service;
|
||||||
|
|
||||||
@@ -98,12 +101,7 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
StringRedisTemplate redisTemplate;
|
StringRedisTemplate redisTemplate;
|
||||||
private static final RateLimiter rateLimiter = RateLimiter.create(1.0);
|
|
||||||
public void someApi() {
|
|
||||||
rateLimiter.acquire(); // 请求之前获取许可
|
|
||||||
// 你的业务逻辑
|
|
||||||
log.info("Request processed at " + System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* 用于查询课程的学习记录
|
* 用于查询课程的学习记录
|
||||||
* @param pager
|
* @param pager
|
||||||
@@ -300,7 +298,6 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
* @param
|
* @param
|
||||||
* @return 返回学习条目的id
|
* @return 返回学习条目的id
|
||||||
*/
|
*/
|
||||||
@LimitRequest(count=5)
|
|
||||||
@PostMapping("/study")
|
@PostMapping("/study")
|
||||||
public JsonResponse<String> study(@RequestBody StudyContentDto sci, HttpServletRequest request){
|
public JsonResponse<String> study(@RequestBody StudyContentDto sci, HttpServletRequest request){
|
||||||
|
|
||||||
@@ -330,11 +327,7 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
if (StringUtils.isEmpty(token)) {
|
if (StringUtils.isEmpty(token)) {
|
||||||
token = request.getHeader("token");
|
token = request.getHeader("token");
|
||||||
}
|
}
|
||||||
StudyCourseApi example = new StudyCourseApi();
|
//检查是否已存在
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
new Thread(() -> example.someApi()).start();
|
|
||||||
//检查是否已存在
|
|
||||||
}
|
|
||||||
StudyCourseItem item = studyService.checkHas(sci.getStudyId(),sci.getContentId());
|
StudyCourseItem item = studyService.checkHas(sci.getStudyId(),sci.getContentId());
|
||||||
if(item!=null) {
|
if(item!=null) {
|
||||||
//如果记录存在,但是进度不100无成情况,就更新进度,一期不会有这种情况
|
//如果记录存在,但是进度不100无成情况,就更新进度,一期不会有这种情况
|
||||||
@@ -347,7 +340,7 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
log.info("在线课学习记录"+allUserList);
|
log.info("在线课学习记录"+allUserList);
|
||||||
return success(item.getId());
|
return success(item.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isBlank(sci.getCourseId())){
|
if(StringUtils.isBlank(sci.getCourseId())){
|
||||||
return error("无课程信息");
|
return error("无课程信息");
|
||||||
}
|
}
|
||||||
@@ -553,7 +546,7 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
//检查是否已存在
|
//检查是否已存在
|
||||||
try {
|
try {
|
||||||
studyService.updateLastTime(itemId,videoTime, getCurrent().getAccountId());
|
studyService.updateLastTime(itemId,videoTime, getCurrent().getAccountId());
|
||||||
if (contentId != null && courseId != null){
|
if (contentId != null && courseId != null && progressVideo != null){
|
||||||
contentService.updateProcessVideo(contentId, courseId, progressVideo);
|
contentService.updateProcessVideo(contentId, courseId, progressVideo);
|
||||||
}
|
}
|
||||||
return success(true);
|
return success(true);
|
||||||
@@ -708,18 +701,23 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value="/study-course-content",method = {RequestMethod.GET,RequestMethod.POST})
|
@RequestMapping(value="/study-course-content",method = {RequestMethod.GET,RequestMethod.POST})
|
||||||
public JsonResponse<StudyCourseItem> findStudyCourseItem(String studyId,String contentId){
|
public JsonResponse<StudyCourseItem> findStudyCourseItem(String studyId,String contentId,Integer contentTotal, HttpServletRequest request){
|
||||||
if(StringUtils.isBlank(studyId)){
|
if(StringUtils.isBlank(studyId)){
|
||||||
return error("无学习信息");
|
return error("无学习信息");
|
||||||
}
|
}
|
||||||
if(StringUtils.isBlank(contentId)){
|
if(StringUtils.isBlank(contentId)){
|
||||||
return error("无课程内容信息");
|
return error("无课程内容信息");
|
||||||
}
|
}
|
||||||
|
String token = request.getHeader("Xboe-Access-Token");
|
||||||
|
if (StringUtils.isEmpty(token)) {
|
||||||
|
token = request.getHeader("token");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
StudyCourseItem rs=studyService.checkHas(studyId, contentId);
|
StudyCourseItem rs=studyService.checkHas(studyId, contentId);
|
||||||
if(rs==null) {
|
if(rs==null) {
|
||||||
return notfound();
|
return notfound();
|
||||||
}
|
}
|
||||||
|
scDao.finishCheck(studyId,contentId,contentTotal,token);
|
||||||
return success(rs);
|
return success(rs);
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
log.error("查询课程学习记录错误",e.getMessage());
|
log.error("查询课程学习记录错误",e.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user