feat(ff-admin): 增加平台和币种代码字段并优化余额计算逻辑

- 在 BalanceChangesDTO 中添加 platformCode 和 currencyCode 字段
- 优化 TenantGameQuotaServiceImpl 中的余额计算逻辑
- 新增 TenantQuotaTask 类,用于更新租户实际配额
main-p
shi 2025-02-22 13:37:41 +08:00
parent d717350e61
commit 7df30a21e1
3 changed files with 53 additions and 2 deletions

View File

@ -53,4 +53,10 @@ public class BalanceChangesDTO implements Serializable {
* *
*/ */
private BigDecimal actualBalance; private BigDecimal actualBalance;
/** 平台 */
private String platformCode;
/** 币种代码 */
private String currencyCode;
} }

View File

@ -155,8 +155,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
BigDecimal balanceBefore = tenantGameQuota.getBalance(); BigDecimal balanceBefore = tenantGameQuota.getBalance();
BigDecimal balance = balanceChangesDTO.getBalance(); BigDecimal balance = balanceChangesDTO.getBalance();
//如果有汇率 则需要计算真实扣除额度 //如果有汇率 则需要计算真实扣除额度
if (!ObjectUtils.isEmpty(balanceChangesDTO.getActualBalance())){ if (!ObjectUtils.isEmpty(balanceChangesDTO.getActualBalance())) {
balance=NumberUtil.div(balance,balanceChangesDTO.getActualBalance(),2, RoundingMode.FLOOR); balance = NumberUtil.div(balance, balanceChangesDTO.getActualBalance(), 2, RoundingMode.FLOOR);
} }
if (BigDecimal.ZERO.compareTo(balance) >= 0) { if (BigDecimal.ZERO.compareTo(balance) >= 0) {
@ -195,6 +195,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
.quotaType(balanceChangesDTO.getQuotaType()) .quotaType(balanceChangesDTO.getQuotaType())
.tenantKey(balanceChangesDTO.getTenantKey()) .tenantKey(balanceChangesDTO.getTenantKey())
.isOut(balanceChangesDTO.getIsOut()) .isOut(balanceChangesDTO.getIsOut())
.platformCode(balanceChangesDTO.getPlatformCode())
.currencyCode(balanceChangesDTO.getCurrencyCode())
.balanceAfter(balanceAfter) .balanceAfter(balanceAfter)
.exchangeRatio(balanceChangesDTO.getActualBalance()) .exchangeRatio(balanceChangesDTO.getActualBalance())
.exchangeMoney(balanceChangesDTO.getBalance()) .exchangeMoney(balanceChangesDTO.getBalance())
@ -286,6 +288,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
if (platformBalance.compareTo(BigDecimal.ZERO) > 0) { if (platformBalance.compareTo(BigDecimal.ZERO) > 0) {
this.balanceChanges(BalanceChangesDTO.builder() this.balanceChanges(BalanceChangesDTO.builder()
.isOut(Boolean.TRUE) .isOut(Boolean.TRUE)
.platformCode(gameBalanceExchange.getPlatformCode())
.currencyCode(gameBalanceExchange.getCurrencyCode())
.tenantKey(gameBalanceExchange.getTenantKey()) .tenantKey(gameBalanceExchange.getTenantKey())
.balance(platformBalance) .balance(platformBalance)
.memberId(member.getId()) .memberId(member.getId())
@ -298,6 +302,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
// 进行租户余额调整 // 进行租户余额调整
this.balanceChanges(BalanceChangesDTO.builder() this.balanceChanges(BalanceChangesDTO.builder()
.isOut(isOut) .isOut(isOut)
.platformCode(gameBalanceExchange.getPlatformCode())
.currencyCode(gameBalanceExchange.getCurrencyCode())
.actualBalance(tenantQuotaExchange.getActualBalance()) .actualBalance(tenantQuotaExchange.getActualBalance())
.tenantKey(gameBalanceExchange.getTenantKey()) .tenantKey(gameBalanceExchange.getTenantKey())
.balance(balanceRequestAmount) .balance(balanceRequestAmount)
@ -318,6 +324,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
// 假额度足够扣除本次所需金额 // 假额度足够扣除本次所需金额
this.balanceChanges(BalanceChangesDTO.builder() this.balanceChanges(BalanceChangesDTO.builder()
.isOut(Boolean.FALSE) .isOut(Boolean.FALSE)
.platformCode(gameBalanceExchange.getPlatformCode())
.currencyCode(gameBalanceExchange.getCurrencyCode())
.tenantKey(tenantSecretKey.getTenantKey()) .tenantKey(tenantSecretKey.getTenantKey())
.balance(amountToDeduct) .balance(amountToDeduct)
.memberId(member.getId()) .memberId(member.getId())
@ -331,6 +339,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
balanceRequestAmount = amountToDeduct.subtract(falseQuotaBalance); balanceRequestAmount = amountToDeduct.subtract(falseQuotaBalance);
this.balanceChanges(BalanceChangesDTO.builder() this.balanceChanges(BalanceChangesDTO.builder()
.isOut(Boolean.FALSE) .isOut(Boolean.FALSE)
.platformCode(gameBalanceExchange.getPlatformCode())
.currencyCode(gameBalanceExchange.getCurrencyCode())
.tenantKey(tenantSecretKey.getTenantKey()) .tenantKey(tenantSecretKey.getTenantKey())
.balance(falseQuotaBalance) .balance(falseQuotaBalance)
.memberId(member.getId()) .memberId(member.getId())
@ -344,6 +354,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
if (balanceRequestAmount.compareTo(BigDecimal.ZERO) > 0) { if (balanceRequestAmount.compareTo(BigDecimal.ZERO) > 0) {
this.balanceChanges(BalanceChangesDTO.builder() this.balanceChanges(BalanceChangesDTO.builder()
.isOut(Boolean.FALSE) .isOut(Boolean.FALSE)
.platformCode(gameBalanceExchange.getPlatformCode())
.currencyCode(gameBalanceExchange.getCurrencyCode())
.actualBalance(tenantQuotaExchange.getActualBalance()) .actualBalance(tenantQuotaExchange.getActualBalance())
.tenantKey(tenantSecretKey.getTenantKey()) .tenantKey(tenantSecretKey.getTenantKey())
.balance(balanceRequestAmount) .balance(balanceRequestAmount)

View File

@ -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<TenantGameQuota> tenantGameQuotas = tenantGameQuotaService.selectTenantGameQuotaList(TenantGameQuota.builder()
// .quotaType(TenantGameQuota.TenantQuotaType.TENANT_REAL_QUOTA.getCode())
// .build());
// }
}