2
0

fix: 修复套餐有效期

This commit is contained in:
caiyuchao
2024-12-31 18:21:25 +08:00
parent 727e5d94fd
commit d55b89b337
3 changed files with 45 additions and 14 deletions

View File

@@ -14,7 +14,6 @@ import org.wfc.common.security.utils.SecurityUtils;
import org.wfc.omada.api.client.OmadaClientApi;
import org.wfc.omada.api.client.model.OperationResponseClientDetail;
import org.wfc.omada.api.hotspot.OmadaAuthorizedClientApi;
import org.wfc.omada.api.hotspot.model.OperationResponseWithoutResult;
import org.wfc.user.api.domain.UUser;
import java.util.Objects;
@@ -49,8 +48,9 @@ public class ClientController extends BaseController {
if (StringUtils.isBlank(site) || StringUtils.isBlank(clientMac)) {
return error("not mac address");
}
ResponseEntity<OperationResponseWithoutResult> posts = omadaAuthorizedClientApi.authClient(site, clientMac);
return success(Objects.requireNonNull(posts.getBody()).getMsg());
// ResponseEntity<OperationResponseWithoutResult> posts = omadaAuthorizedClientApi.authClient(site, clientMac);
// return success(Objects.requireNonNull(posts.getBody()).getMsg());
return success();
}
/**
@@ -69,8 +69,9 @@ public class ClientController extends BaseController {
if (StringUtils.isBlank(site) || StringUtils.isBlank(clientMac)) {
return error("not mac address");
}
ResponseEntity<OperationResponseWithoutResult> posts = omadaAuthorizedClientApi.cancelAuthClient(site, clientMac);
return success(Objects.requireNonNull(posts.getBody()).getMsg());
// ResponseEntity<OperationResponseWithoutResult> posts = omadaAuthorizedClientApi.cancelAuthClient(site, clientMac);
// return success(Objects.requireNonNull(posts.getBody()).getMsg());
return success();
}
/**

View File

@@ -26,6 +26,7 @@ import org.wfc.user.mapper.UAccountMapper;
import org.wfc.user.mapper.UCdrMapper;
import org.wfc.user.mapper.UClientMapper;
import org.wfc.user.service.IUAccountService;
import org.wfc.user.util.AccountUtil;
import java.math.BigDecimal;
import java.util.Date;
@@ -56,12 +57,17 @@ public class UAccountServiceImpl extends ServiceImpl<UAccountMapper, UAccount> i
@Autowired
private OmadaClientApi omadaClientApi;
// 定时任务时间间隔
private static final int JOB_PERIOD = -30;
@Transactional(rollbackFor = Exception.class)
public void statAndCancelAuthUser() {
// 定时任务查询所有未过期或刚过期(失效时间+定时任务间隔时间)的账户套餐,套餐过期/流量用完/时长用完则取消授权
Date current = new Date();
DateTime endTime = DateUtil.offsetSecond(current, -30);
List<UAccount> accounts = this.list(Wrappers.<UAccount>lambdaQuery().gt(UAccount::getEndTime, endTime).isNotNull(UAccount::getUserId));
DateTime endTime = DateUtil.offsetSecond(current, JOB_PERIOD);
List<UAccount> accounts = this.list(Wrappers.<UAccount>lambdaQuery()
.le(UAccount::getStartTime, endTime).gt(UAccount::getEndTime, endTime)
.isNotNull(UAccount::getUserId));
// 更新账户已使用流量,已使用时长
for (UAccount account : accounts) {
if (ObjectUtil.isNull(account.getUserId())) {
@@ -75,10 +81,8 @@ public class UAccountServiceImpl extends ServiceImpl<UAccountMapper, UAccount> i
}
this.updateBatchById(accounts);
// 过期/流量已用完/时长已用完应取消授权
List<Long> userIds = accounts.stream().filter(account -> (account.getEndTime().before(endTime) && account.getEndTime().after(current))
|| (account.getTrafficEnable() && account.getTrafficUsed() > account.getTraffic())
|| (account.getDurationEnable() && account.getDurationUsed() > account.getDuration()))
// 取消授权
List<Long> userIds = accounts.stream().filter(account -> !AccountUtil.isValid(account, current))
.map(UAccount::getUserId)
.collect(Collectors.toList());
@@ -111,9 +115,7 @@ public class UAccountServiceImpl extends ServiceImpl<UAccountMapper, UAccount> i
return;
}
Date current = new Date();
if (account.getStartTime().before(current) && account.getEndTime().after(current)
&& (!account.getTrafficEnable() || account.getTrafficUsed() <= account.getTraffic())
&& (!account.getDurationEnable() || account.getDurationUsed() <= account.getDuration())) {
if (AccountUtil.isValid(account, current)) {
wifiApi.authClient(client.getSiteId(), client.getClientMac());
// 带宽限速

View File

@@ -0,0 +1,28 @@
package org.wfc.user.util;
import cn.hutool.core.date.DateUtil;
import org.wfc.user.domain.UAccount;
import java.util.Date;
/**
* @description: 账户工具
* @author: cyc
* @since: 2024-12-31
*/
public class AccountUtil {
/**
* 检验账户有效
*
* @param account 账户
* @param current 当前时间
* @return boolean
*/
public static boolean isValid(UAccount account, Date current) {
// 过期/流量已用完/时长已用完应取消授权
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());
}
}