91 lines
3.4 KiB
Java
91 lines
3.4 KiB
Java
package com.ff.quartz.task;
|
|
|
|
|
|
import com.ff.base.constant.Constants;
|
|
import com.ff.base.enums.OperationType;
|
|
import com.ff.base.enums.QuotaType;
|
|
import com.ff.base.utils.DateUtils;
|
|
import com.ff.common.domain.TenantGameQuota;
|
|
import com.ff.common.domain.TenantGameQuotaFlow;
|
|
import com.ff.common.domain.TenantQuotaExchange;
|
|
import com.ff.common.domain.TenantSecretKey;
|
|
import com.ff.common.dto.BalanceChangesDTO;
|
|
import com.ff.common.dto.BalanceRealChangesDTO;
|
|
import com.ff.common.service.ITenantGameQuotaFlowService;
|
|
import com.ff.common.service.ITenantGameQuotaService;
|
|
import com.ff.common.service.ITenantQuotaExchangeService;
|
|
import com.ff.common.service.ITenantSecretKeyService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 租户配额任务
|
|
*
|
|
* @author shi
|
|
* @date 2025/02/22
|
|
*/
|
|
@Slf4j
|
|
@Component("tenantQuotaTask")
|
|
public class TenantQuotaTask {
|
|
|
|
@Resource
|
|
private ITenantGameQuotaService tenantGameQuotaService;
|
|
|
|
@Resource
|
|
private ITenantGameQuotaFlowService tenantGameQuotaFlowService;
|
|
|
|
@Resource
|
|
private ITenantSecretKeyService tenantSecretKeyService;
|
|
|
|
@Resource
|
|
private ITenantQuotaExchangeService tenantQuotaExchangeService;
|
|
|
|
/**
|
|
* 更新租户实际配额
|
|
*/
|
|
public void updateTenantRealQuota() {
|
|
Long yesterdayStart = DateUtils.getYesterdayStart();
|
|
Long yesterdayEnd = DateUtils.getYesterdayEnd();
|
|
TenantGameQuotaFlow gameQuotaFlow = TenantGameQuotaFlow.builder()
|
|
.quotaType(QuotaType.BALANCE.getCode())
|
|
.operationType(OperationType.API_BALANCE.getCode())
|
|
.build();
|
|
Map<String, Object> params = gameQuotaFlow.getParams();
|
|
params.put("beginTime", yesterdayStart);
|
|
params.put("endTime", yesterdayEnd);
|
|
List<TenantGameQuotaFlow> balanceByTenantKey = tenantGameQuotaFlowService.getBalanceByTenantKey(gameQuotaFlow);
|
|
for (TenantGameQuotaFlow tenantGameQuotaFlow : balanceByTenantKey) {
|
|
BigDecimal balance = tenantGameQuotaFlow.getExchangeMoney();
|
|
Boolean isOut = Boolean.TRUE;
|
|
// 添加判断逻辑
|
|
if (balance.compareTo(BigDecimal.ZERO) < 0) {
|
|
balance = balance.abs();
|
|
isOut = Boolean.FALSE;
|
|
}
|
|
TenantQuotaExchange tenantQuotaExchange = tenantQuotaExchangeService.getTenantQuotaExchange(Constants.USDT, tenantGameQuotaFlow.getCurrencyCode());
|
|
//更新额度
|
|
BalanceRealChangesDTO realChangesDTO = BalanceRealChangesDTO.builder()
|
|
.isOut(isOut)
|
|
.tenantKey(tenantGameQuotaFlow.getTenantKey())
|
|
.balance(balance)
|
|
.remark(OperationType.REAL_BALANCE_SETTLEMENT.getDescription())
|
|
.operationType(OperationType.REAL_BALANCE_SETTLEMENT.getCode())
|
|
.currencyCode(tenantGameQuotaFlow.getCurrencyCode())
|
|
.actualBalance(tenantQuotaExchange.getActualBalance())
|
|
.build();
|
|
Boolean result = tenantGameQuotaService.balanceRealChanges(realChangesDTO);
|
|
//如果没成功重新跑
|
|
while (!result) {
|
|
result = tenantGameQuotaService.balanceRealChanges(realChangesDTO);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|