From 554109d766905590854b2c00c11b71077fd859c2 Mon Sep 17 00:00:00 2001 From: caiyuchao Date: Wed, 25 Dec 2024 15:53:53 +0800 Subject: [PATCH] fix: buy package --- .../user/domain/vo/UAccountDashboardVo.java | 68 +++++++++++++++++++ .../wfc/user/service/IUAccountService.java | 7 ++ .../service/impl/UAccountServiceImpl.java | 28 ++++++++ .../user/service/impl/UOrderServiceImpl.java | 19 ++++-- 4 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/domain/vo/UAccountDashboardVo.java diff --git a/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/domain/vo/UAccountDashboardVo.java b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/domain/vo/UAccountDashboardVo.java new file mode 100644 index 0000000..95aad78 --- /dev/null +++ b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/domain/vo/UAccountDashboardVo.java @@ -0,0 +1,68 @@ +package org.wfc.user.domain.vo; + + +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @description: 账户仪表盘Vo + * @author: cyc + * @since: 2024-12-25 + */ +@Data +public class UAccountDashboardVo { + + private Long id; + + private BigDecimal balance; + + private Long packageId; + + private Date startTime; + + private Date endTime; + + private Long trafficUsed; + + private Long durationUsed; + + private Integer clientNumUsed; + + private String packageName; + + private Integer periodNum; + + private Integer periodType; + + private BigDecimal price; + + private Long traffic; + + private Long duration; + + private Integer clientNum; + + private String remark; + + private Boolean rateLimitEnable; + + private Boolean trafficEnable; + + private Boolean durationEnable; + + private Boolean clientNumEnable; + + private String rateLimitName; + + private Long downLimit; + + private Boolean downLimitEnable; + + private Long upLimit; + + private Boolean upLimitEnable; + + private Long activity; +} diff --git a/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/IUAccountService.java b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/IUAccountService.java index 09d4836..c9f55bf 100644 --- a/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/IUAccountService.java +++ b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/IUAccountService.java @@ -3,6 +3,7 @@ package org.wfc.user.service; import org.wfc.user.api.domain.bo.UClientBo; import org.wfc.user.domain.UAccount; import com.baomidou.mybatisplus.extension.service.IService; +import org.wfc.user.domain.vo.UAccountDashboardVo; /** *

@@ -25,4 +26,10 @@ public interface IUAccountService extends IService { */ void authClientAndRateLimit(UClientBo client); + /** + * 首页仪表盘查询 + * @return + */ + UAccountDashboardVo getByUser(); + } diff --git a/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/impl/UAccountServiceImpl.java b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/impl/UAccountServiceImpl.java index a52afc1..7012d7a 100644 --- a/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/impl/UAccountServiceImpl.java +++ b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/impl/UAccountServiceImpl.java @@ -6,9 +6,12 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.wfc.common.core.domain.LoginUser; +import org.wfc.common.security.utils.SecurityUtils; import org.wfc.omada.api.client.OmadaClientApi; import org.wfc.omada.api.client.model.ClientRateLimitSetting; import org.wfc.omada.api.client.model.CustomRateLimitEntity; @@ -16,12 +19,14 @@ import org.wfc.omada.api.hotspot.OmadaAuthorizedClientApi; import org.wfc.user.api.domain.bo.UClientBo; import org.wfc.user.domain.UAccount; import org.wfc.user.domain.UClient; +import org.wfc.user.domain.vo.UAccountDashboardVo; import org.wfc.user.domain.vo.UCdrUserVo; 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 java.math.BigDecimal; import java.util.Date; import java.util.List; import java.util.Objects; @@ -113,4 +118,27 @@ public class UAccountServiceImpl extends ServiceImpl i } + @Override + public UAccountDashboardVo getByUser() { + LoginUser loginUser = SecurityUtils.getLoginUser(); + UAccount account = this.getOne(Wrappers.lambdaQuery().eq(UAccount::getUserId, loginUser.getUserid()), false); + UAccountDashboardVo dashboardVo = new UAccountDashboardVo(); + if (ObjectUtil.isNull(account)) { + dashboardVo.setId(loginUser.getUserid()); + dashboardVo.setBalance(BigDecimal.ZERO); + dashboardVo.setTraffic(0L); + dashboardVo.setDuration(0L); + dashboardVo.setTrafficUsed(0L); + dashboardVo.setDurationUsed(0L); + dashboardVo.setClientNum(0); + dashboardVo.setClientNumUsed(0); + dashboardVo.setActivity(0L); + } else { + BeanUtils.copyProperties(account, dashboardVo); + dashboardVo.setId(loginUser.getUserid()); + dashboardVo.setActivity(0L); + } + return dashboardVo; + } + } diff --git a/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java index 739c2f0..97098d9 100644 --- a/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java +++ b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.BeanUtils; @@ -28,6 +29,7 @@ import org.wfc.user.service.IURateLimitService; import java.math.BigDecimal; import java.util.Date; +import java.util.List; import java.util.Optional; /** @@ -64,18 +66,24 @@ public class UOrderServiceImpl extends ServiceImpl impleme order.setStatus(OrderStatusEnum.PAID.getCode()); this.updateById(order); - // 授权当前设备访问wifi - UClient client = clientService.getOne(Wrappers.lambdaQuery().eq(UClient::getUserId, order.getUserId()), false); - if (ObjectUtil.isNull(client)) { - omadaAuthorizedClientApi.authClient(client.getSiteId(), client.getClientMac()); + // 授权当前用户的所有设备访问wifi + List clients = clientService.list(Wrappers.lambdaQuery().eq(UClient::getUserId, order.getUserId())); + for (UClient client : clients) { + if (StrUtil.isNotBlank(client.getSiteId())) { + omadaAuthorizedClientApi.authClient(client.getSiteId(), client.getClientMac()); + } } // 保存或更新账户信息 UAccount account = accountService.getOne(Wrappers.lambdaQuery().eq(UAccount::getUserId, order.getUserId()), false); + Long accountId = null; if (ObjectUtil.isNull(account)) { account = new UAccount(); + account.setUserId(order.getUserId()); + account.setBalance(BigDecimal.ZERO); + } else { + accountId = account.getId(); } - Long accountId = account.getId(); if (OrderTypeEnum.PACKAGE.getCode().equals(order.getType())) { // 套餐 callbackPackage(order, account); @@ -100,6 +108,7 @@ public class UOrderServiceImpl extends ServiceImpl impleme BeanUtils.copyProperties(rateLimit, account); } BeanUtils.copyProperties(uPackage, account); + account.setPackageId(order.getPackageId()); account.setTrafficUsed(0L); account.setDurationUsed(0L); account.setClientNumUsed(0);