mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-07 01:46:47 +08:00
处理study接口,添加接口访问限制次数
This commit is contained in:
@@ -84,7 +84,11 @@
|
||||
<artifactId>xboe-module-es</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.jodah</groupId>
|
||||
<artifactId>expiringmap</artifactId>
|
||||
<version>0.5.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>it.sauronsoftware</groupId>
|
||||
<artifactId>jave</artifactId>
|
||||
|
||||
@@ -24,4 +24,7 @@ public class Result {
|
||||
private int totalPage;
|
||||
private List<AuditList> list;
|
||||
|
||||
public static Object error(String s) {
|
||||
return "500 服务异常";
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,16 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.common.util.concurrent.RateLimiter;
|
||||
import com.xboe.api.ThirdApi;
|
||||
import com.xboe.api.vo.*;
|
||||
import com.xboe.module.course.vo.TeacherVo;
|
||||
import com.xboe.module.usergroup.entity.UserGroupItem;
|
||||
import com.xboe.module.usergroup.service.IUserGroupService;
|
||||
import com.xboe.school.aspect.LimitRequest;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -95,7 +98,12 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
|
||||
@Autowired
|
||||
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
|
||||
@@ -292,6 +300,7 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
* @param
|
||||
* @return 返回学习条目的id
|
||||
*/
|
||||
@LimitRequest(count=5)
|
||||
@PostMapping("/study")
|
||||
public JsonResponse<String> study(@RequestBody StudyContentDto sci, HttpServletRequest request){
|
||||
|
||||
@@ -321,7 +330,11 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
if (StringUtils.isEmpty(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());
|
||||
if(item!=null) {
|
||||
//如果记录存在,但是进度不100无成情况,就更新进度,一期不会有这种情况
|
||||
@@ -334,7 +347,7 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
log.info("在线课学习记录"+allUserList);
|
||||
return success(item.getId());
|
||||
}
|
||||
|
||||
|
||||
if(StringUtils.isBlank(sci.getCourseId())){
|
||||
return error("无课程信息");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user