流水记录优化

This commit is contained in:
lu7213 committed 2026-10-14 04:47:06 -04:00
1 parent dcd8eadd20
commit abdafd5c9d
11 files changed
+238 -28

No files matched your search

@@ -0,0 +1,35 @@
package com.ruoyi.task;
import com.ruoyi.system.service.WalletLedgerPostingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.List;
/** 定期结算已检测链上交易的订单,并补齐已支付订单缺失的流水。 */
@Component
public class PaymentLedgerReconciliationTask {
private static final Logger log = LoggerFactory.getLogger(PaymentLedgerReconciliationTask.class);
private static final int BATCH_SIZE = 100;
private final WalletLedgerPostingService ledgerPostingService;
public PaymentLedgerReconciliationTask(WalletLedgerPostingService ledgerPostingService) {
this.ledgerPostingService = ledgerPostingService;
}
@org.springframework.scheduling.annotation.Scheduled(fixedDelay = 30000L)
public void reconcile() {
List<Long> orderIds = ledgerPostingService.findOrderIdsRequiringSettlement(BATCH_SIZE);
for (Long orderId : orderIds) {
try {
if (ledgerPostingService.settleDetectedOrRepairPaidOrder(orderId)) {
log.info("支付订单账务补偿完成,订单ID={}", orderId);
}
} catch (Exception ex) {
log.error("支付订单账务补偿失败,订单ID={},原因={}", orderId, ex.getMessage());
}
}
}
}
@@ -18,6 +18,8 @@ public class PaymentOrderExpireTask {
public void expireOrders() {
LambdaQueryWrapper<UsdtOrdersPlus> query = new LambdaQueryWrapper<UsdtOrdersPlus>()
.eq(UsdtOrdersPlus::getStatus, 1)
.and(wrapper -> wrapper.isNull(UsdtOrdersPlus::getBlockTransactionId)
.or().eq(UsdtOrdersPlus::getBlockTransactionId, ""))
.isNotNull(UsdtOrdersPlus::getCreatedAt)
.lt(UsdtOrdersPlus::getCreatedAt, new Date(System.currentTimeMillis() - 10 * 60 * 1000L));
for (UsdtOrdersPlus order : orders.list(query)) {
@@ -47,7 +47,10 @@ public class TronPaymentTask {
log.warn("无法读取 TRON 全局网络配置,跳过本轮支付扫描:{}", e.getMessage());
return;
}
for (UsdtOrdersPlus order : orders.list(new LambdaQueryWrapper<UsdtOrdersPlus>().eq(UsdtOrdersPlus::getStatus, 1))) {
for (UsdtOrdersPlus order : orders.list(new LambdaQueryWrapper<UsdtOrdersPlus>()
.eq(UsdtOrdersPlus::getStatus, 1)
.and(wrapper -> wrapper.isNull(UsdtOrdersPlus::getBlockTransactionId)
.or().eq(UsdtOrdersPlus::getBlockTransactionId, "")))) {
if (order.getToken() == null || order.getActualAmount() == null) continue;
try {
String url = tron.tronscanApiUrl() + "/v1/accounts/" + order.getToken() + "/transactions/trc20?limit=200&only_confirmed=true&contract_address=" + tron.contractAddress();
@@ -63,7 +66,17 @@ public class TronPaymentTask {
if (value.compareTo(order.getActualAmount().setScale(6, RoundingMode.DOWN)) != 0) continue;
String hash = tx.getString("transaction_id");
if (hash == null || hash.trim().isEmpty()) continue;
if (ledgerPostingService.settlePaidOrder(order.getId(), hash)) {
if (!ledgerPostingService.recordDetectedPayment(order.getId(), hash)) {
log.warn("记录链上支付交易失败,订单ID={}", order.getId());
break;
}
try {
if (ledgerPostingService.settlePaidOrder(order.getId(), hash)) {
break;
}
} catch (RuntimeException settlementException) {
log.error("支付订单账务结算失败,订单ID={},原因={}",
order.getId(), settlementException.getMessage());
break;
}
}