From 50c5a4c1920b55265507920cbb62cb84a1a0ac63 Mon Sep 17 00:00:00 2001 From: caiyuchao Date: Wed, 25 Jun 2025 12:24:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20billRule=E4=B8=8D=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/wfc/user/service/impl/UAccountServiceImpl.java | 6 ++++-- .../org/wfc/user/service/impl/UCdrServiceImpl.java | 10 +++++++++- .../org/wfc/user/service/impl/UOrderServiceImpl.java | 4 +++- .../src/main/java/org/wfc/user/util/AccountUtil.java | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UAccountServiceImpl.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UAccountServiceImpl.java index 3c08b52..ea830ab 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UAccountServiceImpl.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UAccountServiceImpl.java @@ -205,7 +205,7 @@ public class UAccountServiceImpl extends ServiceImpl i wifiApi.cancelAuthClient(site.getSiteId(), client.getMac()); continue; } - if (!AccountUtil.isValid(account, current)) { + if (!AccountUtil.isValid(account, current, enabledBalance)) { wifiApi.cancelAuthClient(site.getSiteId(), client.getMac()); continue; } @@ -233,7 +233,9 @@ public class UAccountServiceImpl extends ServiceImpl i return; } Date current = new Date(); - if (AccountUtil.isValid(account, current)) { + List billRules = billRuleMapper.selectList(Wrappers.lambdaQuery().eq(UBillRule::getEnable, true)); + Optional billRuleOptional = billRules.stream().findFirst(); + if (AccountUtil.isValid(account, current, billRuleOptional.isPresent())) { if (account.getClientNumEnable()) { int onlineClientNum = uClientService.getCurrentClients(client.getUserId()).size(); diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UCdrServiceImpl.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UCdrServiceImpl.java index aa1afcd..c9daaf6 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UCdrServiceImpl.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UCdrServiceImpl.java @@ -26,6 +26,7 @@ import org.wfc.omada.api.organization.model.OperationResponseGridVoSiteSummaryIn import org.wfc.omada.api.organization.model.SiteSummaryInfo; import org.wfc.user.api.IWifiApi; import org.wfc.user.domain.UAccount; +import org.wfc.user.domain.UBillRule; import org.wfc.user.domain.UCdr; import org.wfc.user.domain.UCdrHistory; import org.wfc.user.domain.UClient; @@ -36,6 +37,7 @@ import org.wfc.user.domain.constant.UserTypeEnum; import org.wfc.user.domain.vo.UCdrClientVo; import org.wfc.user.domain.vo.UCdrHistoryUserVo; import org.wfc.user.domain.vo.UCdrUserVo; +import org.wfc.user.mapper.UBillRuleMapper; import org.wfc.user.mapper.UCdrMapper; import org.wfc.user.service.IUAccountService; import org.wfc.user.service.IUCdrHistoryService; @@ -48,6 +50,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -91,6 +94,9 @@ public class UCdrServiceImpl extends ServiceImpl implements IU @Autowired private IUClientService uClientService; + @Autowired + private UBillRuleMapper billRuleMapper; + @Override public UCdrUserVo getByUser() { @@ -184,11 +190,13 @@ public class UCdrServiceImpl extends ServiceImpl implements IU if (CollUtil.isEmpty(userIds)) { return macs; } + List billRules = billRuleMapper.selectList(Wrappers.lambdaQuery().eq(UBillRule::getEnable, true)); + Optional billRuleOptional = billRules.stream().findFirst(); List accounts = accountService.list(Wrappers.lambdaQuery().in(UAccount::getUserId, userIds)); for (UClient unAuthClient : unAuthClients) { for (UAccount account : accounts) { if (Objects.equals(unAuthClient.getUserId(), account.getUserId())) { - if (AccountUtil.isValid(account, new Date())) { + if (AccountUtil.isValid(account, new Date(), billRuleOptional.isPresent())) { if (account.getClientNumEnable()) { int onlineClientNum = uClientService.getCurrentClients(account.getUserId()).size(); if (onlineClientNum >= account.getClientNum()) { diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java index e71b193..08f719c 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java @@ -129,7 +129,9 @@ public class UOrderServiceImpl extends ServiceImpl impleme } else { accountId = account.getId(); oldBalance = account.getBalance(); - isValid = AccountUtil.isValid(account, new Date()); + List billRules = billRuleMapper.selectList(Wrappers.lambdaQuery().eq(UBillRule::getEnable, true)); + Optional billRuleOptional = billRules.stream().findFirst(); + isValid = AccountUtil.isValid(account, new Date(), billRuleOptional.isPresent()); } if (OrderTypeEnum.PACKAGE.getCode().equals(order.getType())) { // 套餐 diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/util/AccountUtil.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/util/AccountUtil.java index 868d576..800ab33 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/util/AccountUtil.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/util/AccountUtil.java @@ -21,12 +21,12 @@ public class AccountUtil { * @param current 当前时间 * @return boolean */ - public static boolean isValid(UAccount account, Date current) { + public static boolean isValid(UAccount account, Date current, boolean enableBalance) { // 过期/流量已用完/时长已用完应取消授权 return ((DateUtil.compare(account.getStartTime(), current) <= 0 && DateUtil.compare(account.getEndTime(), current) > 0) && (!account.getTrafficEnable() || account.getTrafficUsed() <= account.getTraffic()) && (!account.getDurationEnable() || account.getDurationUsed() <= account.getDuration())) - || (ObjectUtil.isNotNull(account.getBalance()) && account.getBalance().compareTo(BigDecimal.ZERO) > 0 + || (enableBalance && ObjectUtil.isNotNull(account.getBalance()) && account.getBalance().compareTo(BigDecimal.ZERO) > 0 && (ObjectUtil.isNull(account.getBalanceUsed()) || account.getBalanceUsed().compareTo(BigDecimal.ZERO) == 0 || (ObjectUtil.isNotNull(account.getBalanceUsed()) && account.getBalance().compareTo(BigDecimal.ZERO) > 0 && account.getBalance().subtract(account.getBalanceUsed()).compareTo(BigDecimal.ZERO) > 0)));