状态校验修改
This commit is contained in:
parent
02969a2c75
commit
d6dcb8eeee
|
|
@ -1,6 +1,7 @@
|
|||
package com.sqx.common.aspect;
|
||||
|
||||
import com.sqx.common.annotation.Debounce;
|
||||
import com.sqx.common.exception.SqxException;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.common.utils.SpelUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -26,8 +27,8 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||
public class DebounceAspect {
|
||||
|
||||
@Pointcut("@annotation(com.sqx.common.annotation.Debounce)")
|
||||
public void logPointCut() {
|
||||
|
||||
public void logPointCut() {
|
||||
|
||||
}
|
||||
|
||||
// 用于存储基于方法和入参情况的上次执行时间,结构为:方法签名 -> (入参值 -> 上次执行时间)
|
||||
|
|
@ -87,7 +88,16 @@ public class DebounceAspect {
|
|||
if (lastTime == null || currentTime - timeUnit.toMillis(interval) >= lastTime) {
|
||||
// 满足防抖间隔,更新上次执行时间,并执行目标方法
|
||||
methodExecutionTimeMap.put(targetValue, currentTime);
|
||||
return joinPoint.proceed();
|
||||
try {
|
||||
return joinPoint.proceed();
|
||||
}catch (Exception e) {
|
||||
if (e instanceof SqxException && ((SqxException) e).getCode() == 403) {
|
||||
methodExecutionTimeMap.remove(targetValue);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// 在防抖间隔内,不执行目标方法,直接返回
|
||||
return Result.error("请求频繁,请重试");
|
||||
|
|
|
|||
|
|
@ -39,16 +39,15 @@ public class AppOrdersController extends AbstractController {
|
|||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
private boolean checkWxBind(Long userId) {
|
||||
private void checkWxBind(Long userId) {
|
||||
CommonInfo commonInfo = commonInfoService.findOne(938);
|
||||
if (commonInfo == null || !"1".equals(commonInfo.getValue())) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
UserEntity userEntity = userService.queryByUserId(userId);
|
||||
if (StrUtil.isBlank(userEntity.getWxOpenId())) {
|
||||
return false;
|
||||
throw new SqxException("请先绑定微信", 407);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -64,9 +63,7 @@ public class AppOrdersController extends AbstractController {
|
|||
@ApiOperation("生成商品订单")
|
||||
@Debounce(interval = 20000, value = "#userId")
|
||||
public Result insertCourseOrders(Long courseId,Long courseDetailsId, @RequestAttribute("userId") Long userId) {
|
||||
if (!checkWxBind(userId)) {
|
||||
return Result.error(407, "请先绑定微信");
|
||||
}
|
||||
checkWxBind(userId);
|
||||
return ordersService.insertCourseOrders(courseId, courseDetailsId,userId);
|
||||
}
|
||||
|
||||
|
|
@ -81,9 +78,7 @@ public class AppOrdersController extends AbstractController {
|
|||
@GetMapping("/insertCourseOrders/limit10")
|
||||
@ApiOperation("生成商品订单")
|
||||
public Result insertCourseOrdersLimit10(Long courseId, @RequestAttribute("userId") Long userId) {
|
||||
if (!checkWxBind(userId)) {
|
||||
return Result.error(407, "请先绑定微信");
|
||||
}
|
||||
checkWxBind(userId);
|
||||
return ordersService.insertCourseOrdersLimit10(courseId, userId);
|
||||
}
|
||||
|
||||
|
|
@ -91,9 +86,7 @@ public class AppOrdersController extends AbstractController {
|
|||
@GetMapping("/insertVipOrders")
|
||||
@ApiOperation("生成会员订单")
|
||||
public Result insertVipOrders(@ApiParam("会员详情信息") Long vipDetailsId, @RequestAttribute("userId") Long userId) {
|
||||
if (!checkWxBind(userId)) {
|
||||
return Result.error(407, "请先绑定微信");
|
||||
}
|
||||
checkWxBind(userId);
|
||||
return ordersService.insertVipOrders(vipDetailsId, userId);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue