From 7df30a21e18cbb991c92b8e369c225406c5194f7 Mon Sep 17 00:00:00 2001 From: shi Date: Sat, 22 Feb 2025 13:37:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(ff-admin):=20=E5=A2=9E=E5=8A=A0=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E5=92=8C=E5=B8=81=E7=A7=8D=E4=BB=A3=E7=A0=81=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BD=99=E9=A2=9D=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BalanceChangesDTO 中添加 platformCode 和 currencyCode 字段 - 优化 TenantGameQuotaServiceImpl 中的余额计算逻辑 - 新增 TenantQuotaTask 类,用于更新租户实际配额 --- .../com/ff/common/dto/BalanceChangesDTO.java | 6 ++++ .../impl/TenantGameQuotaServiceImpl.java | 16 +++++++-- .../com/ff/quartz/task/TenantQuotaTask.java | 33 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 ff-admin/src/main/java/com/ff/quartz/task/TenantQuotaTask.java diff --git a/ff-admin/src/main/java/com/ff/common/dto/BalanceChangesDTO.java b/ff-admin/src/main/java/com/ff/common/dto/BalanceChangesDTO.java index 6f136f4..42c2d05 100644 --- a/ff-admin/src/main/java/com/ff/common/dto/BalanceChangesDTO.java +++ b/ff-admin/src/main/java/com/ff/common/dto/BalanceChangesDTO.java @@ -53,4 +53,10 @@ public class BalanceChangesDTO implements Serializable { * 汇率 传值计算 */ private BigDecimal actualBalance; + + /** 平台 */ + private String platformCode; + + /** 币种代码 */ + private String currencyCode; } diff --git a/ff-admin/src/main/java/com/ff/common/service/impl/TenantGameQuotaServiceImpl.java b/ff-admin/src/main/java/com/ff/common/service/impl/TenantGameQuotaServiceImpl.java index 7f9f85a..98c4cfe 100644 --- a/ff-admin/src/main/java/com/ff/common/service/impl/TenantGameQuotaServiceImpl.java +++ b/ff-admin/src/main/java/com/ff/common/service/impl/TenantGameQuotaServiceImpl.java @@ -155,8 +155,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService { BigDecimal balanceBefore = tenantGameQuota.getBalance(); BigDecimal balance = balanceChangesDTO.getBalance(); //如果有汇率 则需要计算真实扣除额度 - if (!ObjectUtils.isEmpty(balanceChangesDTO.getActualBalance())){ - balance=NumberUtil.div(balance,balanceChangesDTO.getActualBalance(),2, RoundingMode.FLOOR); + if (!ObjectUtils.isEmpty(balanceChangesDTO.getActualBalance())) { + balance = NumberUtil.div(balance, balanceChangesDTO.getActualBalance(), 2, RoundingMode.FLOOR); } if (BigDecimal.ZERO.compareTo(balance) >= 0) { @@ -195,6 +195,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService { .quotaType(balanceChangesDTO.getQuotaType()) .tenantKey(balanceChangesDTO.getTenantKey()) .isOut(balanceChangesDTO.getIsOut()) + .platformCode(balanceChangesDTO.getPlatformCode()) + .currencyCode(balanceChangesDTO.getCurrencyCode()) .balanceAfter(balanceAfter) .exchangeRatio(balanceChangesDTO.getActualBalance()) .exchangeMoney(balanceChangesDTO.getBalance()) @@ -286,6 +288,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService { if (platformBalance.compareTo(BigDecimal.ZERO) > 0) { this.balanceChanges(BalanceChangesDTO.builder() .isOut(Boolean.TRUE) + .platformCode(gameBalanceExchange.getPlatformCode()) + .currencyCode(gameBalanceExchange.getCurrencyCode()) .tenantKey(gameBalanceExchange.getTenantKey()) .balance(platformBalance) .memberId(member.getId()) @@ -298,6 +302,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService { // 进行租户余额调整 this.balanceChanges(BalanceChangesDTO.builder() .isOut(isOut) + .platformCode(gameBalanceExchange.getPlatformCode()) + .currencyCode(gameBalanceExchange.getCurrencyCode()) .actualBalance(tenantQuotaExchange.getActualBalance()) .tenantKey(gameBalanceExchange.getTenantKey()) .balance(balanceRequestAmount) @@ -318,6 +324,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService { // 假额度足够扣除本次所需金额 this.balanceChanges(BalanceChangesDTO.builder() .isOut(Boolean.FALSE) + .platformCode(gameBalanceExchange.getPlatformCode()) + .currencyCode(gameBalanceExchange.getCurrencyCode()) .tenantKey(tenantSecretKey.getTenantKey()) .balance(amountToDeduct) .memberId(member.getId()) @@ -331,6 +339,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService { balanceRequestAmount = amountToDeduct.subtract(falseQuotaBalance); this.balanceChanges(BalanceChangesDTO.builder() .isOut(Boolean.FALSE) + .platformCode(gameBalanceExchange.getPlatformCode()) + .currencyCode(gameBalanceExchange.getCurrencyCode()) .tenantKey(tenantSecretKey.getTenantKey()) .balance(falseQuotaBalance) .memberId(member.getId()) @@ -344,6 +354,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService { if (balanceRequestAmount.compareTo(BigDecimal.ZERO) > 0) { this.balanceChanges(BalanceChangesDTO.builder() .isOut(Boolean.FALSE) + .platformCode(gameBalanceExchange.getPlatformCode()) + .currencyCode(gameBalanceExchange.getCurrencyCode()) .actualBalance(tenantQuotaExchange.getActualBalance()) .tenantKey(tenantSecretKey.getTenantKey()) .balance(balanceRequestAmount) diff --git a/ff-admin/src/main/java/com/ff/quartz/task/TenantQuotaTask.java b/ff-admin/src/main/java/com/ff/quartz/task/TenantQuotaTask.java new file mode 100644 index 0000000..3dc0e53 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/quartz/task/TenantQuotaTask.java @@ -0,0 +1,33 @@ +package com.ff.quartz.task; + + +import com.ff.common.domain.TenantGameQuota; +import com.ff.common.service.ITenantGameQuotaService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 租户配额任务 + * + * @author shi + * @date 2025/02/22 + */ +@Slf4j +@Component("tenantQuotaTask") +public class TenantQuotaTask { + + @Resource + private ITenantGameQuotaService tenantGameQuotaService; + + /** + * 更新租户实际配额 + */ +// public void updateTenantRealQuota() { +// List tenantGameQuotas = tenantGameQuotaService.selectTenantGameQuotaList(TenantGameQuota.builder() +// .quotaType(TenantGameQuota.TenantQuotaType.TENANT_REAL_QUOTA.getCode()) +// .build()); +// } +}