فهرست منبع

将限流数量改成配置的方式获取

liu 2 ماه پیش
والد
کامیت
9a24bede21
1فایلهای تغییر یافته به همراه9 افزوده شده و 2 حذف شده
  1. 9 2
      src/main/java/com/sqx/modules/common/service/impl/CommonInfoServiceImpl.java

+ 9 - 2
src/main/java/com/sqx/modules/common/service/impl/CommonInfoServiceImpl.java

@@ -11,6 +11,7 @@ import com.sqx.modules.common.service.CommonInfoService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.redisson.api.RAtomicLong;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.text.SimpleDateFormat;
@@ -30,6 +31,9 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
 
     private final RedisUtils redisUtils;
 
+    @Autowired
+    private CommonInfoService commonInfoService;
+
     @Override
     public Result update(CommonInfo commonInfo) {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -100,7 +104,10 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
             log.info("3");
             int current = currentValue == null ? 0 : Integer.parseInt(currentValue.toString());
             log.info("4");
-            if (current < limit) {
+            String count = commonInfoService.findOne(451).getValue();
+            Integer limit2 = Integer.valueOf(count);
+            log.info("当前订单数:【{}】,总订单数:【{}】",current,limit2);
+            if (current < limit2) {
                 log.info("5");
                 // 令牌桶未满,允许通过,令牌数+1
                 Long newValue = redisUtils.increment(redisKey);// 自增并返回新值
@@ -115,7 +122,7 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
                 return true;
             } else {
                 // 令牌桶已满,拒绝通过
-                log.info("接口限流,key: {}, current: {}, limit: {}", key, current, limit);
+                log.info("接口限流,key: {}, current: {}, limit: {}", key, current, limit2);
                 return false;
             }
         } catch (Exception e) {