Browse Source

api次数逻辑优化

dsx 2 years ago
parent
commit
c0aec8bfad

+ 5 - 1
src/main/java/com/fdkankan/openApi/service/system/impl/AccountServiceImpl.java

@@ -183,13 +183,16 @@ public class AccountServiceImpl extends ServiceImpl<IAccountMapper, Account> imp
 
         UserAuthInfo userAuthInfo = userAuthService.findByAccountId(account.getId());
         if(Objects.nonNull(param.getCountType())){
-            boolean initCallCount = false;
             boolean dbIsInfinite = false;//原数据中是否无限制
             Integer totalCount = userAuthInfo.getTotalCount();
             if(totalCount < 0){
                 totalCount = 0;
                 dbIsInfinite = true;
             }
+            //无限制次数不能减少次数
+            if(dbIsInfinite && CountType.REDUCE.code() == param.getCountType()){
+                throw new BusinessException(ErrorCode.PARAM_ERROR);
+            }
             boolean currentIsInfinite = false;//当前修改数据中是否无限制
             Integer count = param.getCount();
             if(CountType.NO_LIMIT.code() == param.getCountType()){
@@ -198,6 +201,7 @@ public class AccountServiceImpl extends ServiceImpl<IAccountMapper, Account> imp
             }else if(CountType.REDUCE.code() == param.getCountType()){
                 totalCount  -= count;
                 totalCount = totalCount < 0 ? 0 : totalCount;
+                count = -count;
             }else{
                 totalCount += count;
             }