2
0

fix: 修复取消授权问题

This commit is contained in:
caiyuchao
2025-02-24 10:31:49 +08:00
parent 03c2876e0e
commit f03cf99d5c
2 changed files with 57 additions and 0 deletions

View File

@@ -9,10 +9,19 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.wfc.common.core.constant.WifiConstants;
import org.wfc.common.core.domain.LoginUser;
import org.wfc.common.core.utils.ResponseUtils;
import org.wfc.common.security.utils.SecurityUtils;
import org.wfc.omada.api.client.OmadaClientApi;
import org.wfc.omada.api.client.model.ClientInfo;
import org.wfc.omada.api.client.model.OperationResponseClientGridVoClientInfo;
import org.wfc.omada.api.organization.OmadaSiteApi;
import org.wfc.omada.api.organization.model.OperationResponseGridVoSiteSummaryInfo;
import org.wfc.omada.api.organization.model.SiteSummaryInfo;
import org.wfc.user.api.IWifiApi;
import org.wfc.user.api.domain.bo.UClientBo;
import org.wfc.user.api.omada.domain.convert.OmadaConvert;
@@ -67,6 +76,12 @@ public class UAccountServiceImpl extends ServiceImpl<UAccountMapper, UAccount> i
@Autowired
private UBillRuleMapper billRuleMapper;
@Autowired
private OmadaSiteApi omadaSiteApi;
@Autowired
private OmadaClientApi omadaClientApi;
// 定时任务时间间隔
private static final int JOB_PERIOD = -30;
@@ -221,6 +236,42 @@ public class UAccountServiceImpl extends ServiceImpl<UAccountMapper, UAccount> i
}
}
cancelAuthClient();
}
private void cancelAuthClient() {
// 查出所有已授权client, 根据client的site和mac去查当前user, 再查user的account是否有可用套餐和余额没有则取消授权
ResponseEntity<OperationResponseGridVoSiteSummaryInfo> siteRes = omadaSiteApi.getSiteList(WifiConstants.PAGE, WifiConstants.PAGE_SIZE);
Date current = new Date();
if (ObjectUtil.isNotNull(siteRes.getBody())) {
ResponseUtils.logResponse(siteRes.getBody().getErrorCode(), siteRes.getBody().getMsg());
List<SiteSummaryInfo> sites = siteRes.getBody().getResult().getData();
for (SiteSummaryInfo site : sites) {
ResponseEntity<OperationResponseClientGridVoClientInfo> clientRes = omadaClientApi.getGridActiveClients(site.getSiteId(), WifiConstants.PAGE, WifiConstants.PAGE_SIZE);
if (ObjectUtil.isNull(clientRes.getBody())) {
continue;
}
ResponseUtils.logResponse(clientRes.getBody().getErrorCode(), clientRes.getBody().getMsg());
List<ClientInfo> clients = clientRes.getBody().getResult().getData().stream()
.filter(c -> c.getAuthStatus() == WifiConstants.AUTH_STATUS_AUTHORIZED).collect(Collectors.toList());
for (ClientInfo client : clients) {
UClient loginClient = clientMapper.selectOne(Wrappers.<UClient>lambdaQuery().eq(UClient::getSiteId, site.getSiteId())
.eq(UClient::getClientMac, client.getMac()), false);
if (ObjectUtil.isNull(loginClient) || ObjectUtil.isNull(loginClient.getUserId())) {
wifiApi.cancelAuthClient(site.getSiteId(), client.getMac());
}
UAccount account = this.getOne(Wrappers.<UAccount>lambdaQuery().eq(UAccount::getUserId, loginClient.getUserId()), false);
if (ObjectUtil.isNull(account)) {
wifiApi.cancelAuthClient(site.getSiteId(), client.getMac());
}
if (!AccountUtil.isValid(account, current)) {
wifiApi.cancelAuthClient(site.getSiteId(), client.getMac());
}
}
}
}
}
public void authClientAndRateLimit(UClientBo client) {