|
|
@@ -2,21 +2,27 @@ package com.sqx.modules.order.controller.app;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.google.common.util.concurrent.RateLimiter;
|
|
|
import com.sqx.common.exception.SqxException;
|
|
|
import com.sqx.common.utils.PageUtils;
|
|
|
import com.sqx.common.utils.Result;
|
|
|
import com.sqx.modules.app.annotation.Login;
|
|
|
+import com.sqx.modules.common.service.CommonInfoService;
|
|
|
+import com.sqx.modules.common.service.impl.CommonInfoServiceImpl;
|
|
|
import com.sqx.modules.order.controller.query.GoodsSkuQuery;
|
|
|
import com.sqx.modules.order.entity.Evaluate;
|
|
|
import com.sqx.modules.order.entity.TbOrder;
|
|
|
import com.sqx.modules.order.service.AppOrderService;
|
|
|
import com.sqx.modules.order.service.EvaluateService;
|
|
|
+import com.sqx.modules.order.service.impl.AppAppOrderServiceImpl;
|
|
|
import com.sqx.modules.pay.dto.PayOrderDTO;
|
|
|
import com.sqx.modules.pay.vo.PayTransactionsVO;
|
|
|
+import com.sqx.modules.utils.RateLimiters;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
@@ -37,6 +43,9 @@ public class AppOrderController {
|
|
|
private final AppOrderService appOrderService;
|
|
|
private final EvaluateService evaluateService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ CommonInfoService commonInfoService;
|
|
|
+
|
|
|
@Login
|
|
|
@ApiOperation("生成订单(未结算状态)")
|
|
|
@PostMapping(value = "/insertOrder")
|
|
|
@@ -62,7 +71,11 @@ public class AppOrderController {
|
|
|
@ApiOperation("直接购买单个商品")
|
|
|
@PostMapping(value = "buyGoods")
|
|
|
public Result buyGoods(@RequestAttribute Long userId, Long shopId, Long goodsId, Integer num, Long skuId, String skuMessage, Integer orderType){
|
|
|
-
|
|
|
+ boolean allow = commonInfoService.limit("buyGoods",100,1);
|
|
|
+ if (!allow) {
|
|
|
+ log.info("用餐高峰期,请刷新重试!");
|
|
|
+ return Result.error("用餐高峰期,请刷新重试!");
|
|
|
+ }
|
|
|
return appOrderService.buyGoods(userId, shopId, goodsId, num, skuId, skuMessage, orderType);
|
|
|
}
|
|
|
|
|
|
@@ -279,9 +292,14 @@ public class AppOrderController {
|
|
|
}
|
|
|
|
|
|
@Login
|
|
|
- @ApiOperation("获取支付参数")
|
|
|
+ @ApiOperation("获取支付参数,新支付")
|
|
|
@GetMapping(value = "get-pay-param")
|
|
|
public Result getPayParam(@RequestAttribute("userId") Long userId, @Valid PayOrderDTO payOrderDTO){
|
|
|
+ boolean allow = commonInfoService.limit("getPayParam",100,1);
|
|
|
+ if (!allow) {
|
|
|
+ log.info("用餐高峰期,请刷新重试!");
|
|
|
+ return Result.error("用餐高峰期,请刷新重试!");
|
|
|
+ }
|
|
|
PayTransactionsVO payParamVO = appOrderService.getTransactionsParam(userId, payOrderDTO);
|
|
|
return Result.success(BeanUtil.beanToMap(payParamVO, false, true));
|
|
|
}
|
|
|
@@ -298,4 +316,21 @@ public class AppOrderController {
|
|
|
public void exportGoodsSkuSalesCount(@Valid GoodsSkuQuery query){
|
|
|
appOrderService.exportGoodsSkuSalesCount(query);
|
|
|
}
|
|
|
+
|
|
|
+ Integer i=0;
|
|
|
+
|
|
|
+ @GetMapping(value = "testlimit")
|
|
|
+ @ApiOperation("导出商品sku销售数量")
|
|
|
+ public Result exportGoodsSkuSalesCount(){
|
|
|
+ i++;
|
|
|
+
|
|
|
+ // 限流:每秒最多100个请求
|
|
|
+ boolean allow = commonInfoService.limit("testlimit", 100, 1);
|
|
|
+ if (!allow) {
|
|
|
+ log.info("高峰期,请稍后重试" + i);
|
|
|
+ return Result.error("高峰期,请稍后重试!");
|
|
|
+ }
|
|
|
+ log.info("正常操作" + i);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
}
|