自定义 过分请求异常
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
package com.sqx.modules.callback;
|
||||
import com.sqx.common.exception.CzgException;
|
||||
import com.sqx.modules.callback.service.UniAdCallbackRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -31,4 +32,9 @@ public class UniCallBackController {
|
||||
log.info("接收到uni-ad广告完播回调,回调信息: {}", dto);
|
||||
return ResponseEntity.ok(uniCallBackService.adCallBack(dto));
|
||||
}
|
||||
|
||||
@GetMapping("/testException")
|
||||
public String testException() throws CzgException {
|
||||
throw new CzgException("测试异常");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sqx.common.annotation.Debounce;
|
||||
import com.sqx.common.exception.CzgException;
|
||||
import com.sqx.common.utils.*;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
@@ -165,7 +166,7 @@ public class DiscSpinningController {
|
||||
})
|
||||
@ApiOperation("抽取大转盘")
|
||||
@Debounce(interval = 3000, value = "#userId")
|
||||
public Result draw(@ApiIgnore @RequestAttribute("userId") Long userId, @RequestParam(required = false, defaultValue = "1") Integer source) {
|
||||
public Result draw(@ApiIgnore @RequestAttribute("userId") Long userId, @RequestParam(required = false, defaultValue = "1") Integer source) throws CzgException {
|
||||
double amount = 0;
|
||||
Long sourceId = null;
|
||||
Integer i = recordService.countDraw(userId);
|
||||
@@ -174,11 +175,11 @@ public class DiscSpinningController {
|
||||
//订单抽奖
|
||||
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
|
||||
if (i != null && i >= drawCount) {
|
||||
return Result.error("当日可抽奖次数已超限");
|
||||
throw new CzgException("当日可抽奖次数已超限");
|
||||
}
|
||||
Orders orders = ordersService.selectOrdersByDay(userId);
|
||||
if (orders == null) {
|
||||
return Result.error("无可抽奖机会");
|
||||
throw new CzgException("无可抽奖机会");
|
||||
}
|
||||
amount = orders.getPayMoney().doubleValue();
|
||||
sourceId = orders.getOrdersId();
|
||||
@@ -218,14 +219,14 @@ public class DiscSpinningController {
|
||||
redisUtils.set(redisKey, week, DateUtils.todayAfterSecond());
|
||||
}
|
||||
if (source == 1 && sourceId == null) {
|
||||
throw new RuntimeException("异常请求");
|
||||
throw new CzgException("异常请求");
|
||||
}
|
||||
if (DataLimitUtil.isAllowed(RedisKeys.getDateKey("spinning:draw:") + sourceId, 120)) {
|
||||
DiscSpinningRecord draws = discSpinningService.draws(i == null ? 1 : i + 1, amount, sourceId, userId, source);
|
||||
executor.schedule(() -> discSpinningService.receive1(draws), 4, TimeUnit.SECONDS);
|
||||
return new Result().put("data", draws);
|
||||
} else {
|
||||
throw new RuntimeException("异常请求");
|
||||
throw new CzgException("异常请求");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user