建议统一成“收益结算 + 提现付款” 按建议的逻辑帮我实现。
This commit is contained in:
1 parent
1151dc2535
commit
be6ac23844
18 files changed
+352
-16
No files matched your search
@@ -25,6 +25,18 @@ public class RentSettlement extends BaseEntity
|
||||
@Excel(name = "结算单号")
|
||||
private String settlementNo;
|
||||
|
||||
/** INTERNAL_TRANSFER为收益入账;LEGACY_PAYOUT仅处理升级前付款单。 */
|
||||
@Excel(name = "结算模式")
|
||||
private String settlementMode;
|
||||
/** 内部结算完成时间,与历史链上付款时间分开记录。 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date settledAt;
|
||||
|
||||
public String getSettlementMode() { return settlementMode; }
|
||||
public void setSettlementMode(String settlementMode) { this.settlementMode = settlementMode; }
|
||||
public Date getSettledAt() { return settledAt; }
|
||||
public void setSettledAt(Date settledAt) { this.settledAt = settledAt; }
|
||||
|
||||
/** 供应商rent_account.id */
|
||||
@Excel(name = "供应商rent_account.id")
|
||||
private Long accountId;
|
||||
|
||||
@@ -26,6 +26,18 @@ public class RentSettlementPlus implements Serializable
|
||||
/** 结算单号 */
|
||||
@Excel(name = "结算单号")
|
||||
private String settlementNo;
|
||||
|
||||
/** INTERNAL_TRANSFER为收益入账;LEGACY_PAYOUT仅处理升级前付款单。 */
|
||||
@Excel(name = "结算模式")
|
||||
private String settlementMode;
|
||||
/** 内部结算完成时间,与历史链上付款时间分开记录。 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date settledAt;
|
||||
|
||||
public String getSettlementMode() { return settlementMode; }
|
||||
public void setSettlementMode(String settlementMode) { this.settlementMode = settlementMode; }
|
||||
public Date getSettledAt() { return settledAt; }
|
||||
public void setSettledAt(Date settledAt) { this.settledAt = settledAt; }
|
||||
/** 供应商rent_account.id */
|
||||
@Excel(name = "供应商rent_account.id")
|
||||
private Long accountId;
|
||||
|
||||
@@ -362,6 +362,8 @@ public class RentalController {
|
||||
Map<String, Object> row = store.get("settlement", id, false),
|
||||
account = store.get("account", number(row, "account_id"), false);
|
||||
Map<String, Object> authorization;
|
||||
require("LEGACY_PAYOUT".equals(text(row, "settlement_mode")),
|
||||
"收益结算不接受链上付款登记,请使用提现功能");
|
||||
try {
|
||||
authorization =
|
||||
new com.fasterxml.jackson.databind.ObjectMapper()
|
||||
|
||||
@@ -209,6 +209,15 @@ public class RentalOrders {
|
||||
log.info("地址上链幂等命中 orderId={} network={}", existing.get("id"), network);
|
||||
return existing;
|
||||
}
|
||||
// 跨应用、跨用户检查;人工核对仍可能已广播,不能视为可重新下单。
|
||||
Map<String, Object> pending = store.one("SELECT id FROM rent_order WHERE network=?"
|
||||
+ " AND receiver_address=? AND order_type='ADDRESS_ONCHAIN'"
|
||||
+ " AND status NOT IN ('SUCCESS','FAILED','CANCELLED') LIMIT 1", network, receiver);
|
||||
if (pending != null) {
|
||||
log.warn("地址上链重复下单已拒绝 network={} receiver={} pendingOrderId={} userId={}",
|
||||
network, receiver, pending.get("id"), user);
|
||||
throw new IllegalArgumentException("该地址在当前网络已有待处理的上链订单,请等待原订单完成");
|
||||
}
|
||||
Map<String, Object> price = onchain.quote(request);
|
||||
// 在任何账户创建、订单写入和资金冻结前查询最新链上状态;RPC未知时直接中止。
|
||||
// 必须位于原单幂等返回之后,已成功激活的原订单仍可安全重试和查询。
|
||||
@@ -234,7 +243,19 @@ public class RentalOrders {
|
||||
"status", "WAITING", "payer_account_id", account.get("id"), "fund_status", "HELD",
|
||||
"dispatch_deadline", after(300), "reclaim_status", "NOT_REQUIRED",
|
||||
"notify_url", notify.isEmpty() ? null : notify);
|
||||
long orderId = store.insert("order", order);
|
||||
long orderId;
|
||||
try {
|
||||
// 数据库唯一索引兜底,防止不同应用或服务实例同时通过上面的预检查。
|
||||
orderId = store.insert("order", order);
|
||||
} catch (org.springframework.dao.DuplicateKeyException exception) {
|
||||
if (exception.getMostSpecificCause().getMessage() != null
|
||||
&& exception.getMostSpecificCause().getMessage().toLowerCase(java.util.Locale.ROOT)
|
||||
.contains("uk_order_onchain_pending")) {
|
||||
log.warn("地址上链并发重复下单已拒绝 network={} receiver={} userId={}", network, receiver, user);
|
||||
throw new IllegalArgumentException("该地址在当前网络已有待处理的上链订单,请等待原订单完成");
|
||||
}
|
||||
throw exception;
|
||||
}
|
||||
order.put("id", orderId);
|
||||
funds.hold(order);
|
||||
log.info("地址上链分账已锁定 orderId={} platformPercent={} platformFeeUsdt={} supplierNetUsdt={}",
|
||||
|
||||
@@ -10,7 +10,10 @@ import java.util.*;
|
||||
|
||||
/** 人工退款及结算审批;审批者与发起者分离,付款未知绝不释放来源。 */
|
||||
@Service
|
||||
@lombok.extern.slf4j.Slf4j
|
||||
public class RentalReviews {
|
||||
/** 新单仅内部划转;历史单继续按原付款授权处理,禁止混用两种记账方式。 */
|
||||
private static final String INTERNAL_TRANSFER = "INTERNAL_TRANSFER";
|
||||
private final RentalStore store;
|
||||
private final RentalFunds funds;
|
||||
private final RentalOrders orders;
|
||||
@@ -202,6 +205,9 @@ public class RentalReviews {
|
||||
for (long orderId : sorted) {
|
||||
Map<String, Object> order = store.get("order", orderId, true);
|
||||
require("CHARGED".equals(text(order, "fund_status")), "来源订单尚未确认收入");
|
||||
require("SUCCESS".equals(text(order, "status")), "仅履约成功订单允许收益结算");
|
||||
require(store.one("SELECT id FROM rent_settlement_item WHERE order_id=? AND active_slot=1", orderId)
|
||||
== null, "来源订单已被结算占用或已结算");
|
||||
long current = number(order, "supplier_account_id");
|
||||
require(account == null || account == current, "只允许同一供应商同网络的来源");
|
||||
account = current;
|
||||
@@ -225,6 +231,8 @@ public class RentalReviews {
|
||||
total,
|
||||
"status",
|
||||
"PENDING",
|
||||
"settlement_mode",
|
||||
INTERNAL_TRANSFER,
|
||||
"created_by",
|
||||
actor));
|
||||
for (Map<String, Object> source : sources) {
|
||||
@@ -233,6 +241,8 @@ public class RentalReviews {
|
||||
store.insert("settlement_item", source);
|
||||
}
|
||||
store.event("SETTLEMENT", id, "CREATE", actor, "占用订单净应收来源");
|
||||
log.info("收益结算单创建 settlementId={} accountId={} amountUsdt={} sourceCount={} actorId={} mode={}",
|
||||
id, account, total, sorted.size(), actor, INTERNAL_TRANSFER);
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -240,6 +250,12 @@ public class RentalReviews {
|
||||
public Map<String, Object> transition(long id, String action, long actor, String reason) {
|
||||
Map<String, Object> row = store.get("settlement", id, true);
|
||||
String state = text(row, "status");
|
||||
log.info("结算操作检查 settlementId={} mode={} state={} action={} actorId={}",
|
||||
id, text(row, "settlement_mode"), state, action, actor);
|
||||
if (INTERNAL_TRANSFER.equals(text(row, "settlement_mode"))) {
|
||||
return internalSettlement(row, action, actor, reason);
|
||||
}
|
||||
require("LEGACY_PAYOUT".equals(text(row, "settlement_mode")), "结算模式无效,请检查数据库升级");
|
||||
if ("approve".equals(action)) {
|
||||
require("PENDING".equals(state) && number(row, "created_by") != actor, "审批须职责分离");
|
||||
store.update(
|
||||
@@ -279,10 +295,67 @@ public class RentalReviews {
|
||||
return store.get("settlement", id, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用方已锁结算单。审批、来源核对、余额划转及审计在同一事务提交。
|
||||
* SETTLED不代表对外付款;来源占位永久保留,之后仅可从可用余额申请提现。
|
||||
*/
|
||||
private Map<String, Object> internalSettlement(Map<String, Object> row, String action, long actor, String reason) {
|
||||
long id = number(row, "id");
|
||||
String state = text(row, "status");
|
||||
if ("approve".equals(action)) {
|
||||
if ("SETTLED".equals(state)) {
|
||||
log.info("收益结算审批幂等返回 settlementId={} actorId={}", id, actor);
|
||||
return row;
|
||||
}
|
||||
require("PENDING".equals(state) && number(row, "created_by") != actor, "审批须职责分离且结算单待审核");
|
||||
List<Map<String, Object>> items = store.rows(
|
||||
"SELECT * FROM rent_settlement_item WHERE settlement_id=? ORDER BY order_id", id);
|
||||
require(!items.isEmpty(), "结算来源不能为空");
|
||||
BigDecimal total = ZERO;
|
||||
for (Map<String, Object> item : items) {
|
||||
Map<String, Object> order = store.get("order", number(item, "order_id"), true);
|
||||
BigDecimal net = amount(order, "supplier_net_amount")
|
||||
.subtract(amount(order, "supplier_reversed_amount"))
|
||||
.add(amount(order, "supplier_fee_returned_amount"));
|
||||
require(number(item, "active_slot") == 1 && "CHARGED".equals(text(order, "fund_status"))
|
||||
&& "SUCCESS".equals(text(order, "status"))
|
||||
&& number(order, "supplier_account_id") == number(row, "account_id")
|
||||
&& net.signum() > 0 && net.compareTo(amount(item, "amount")) == 0,
|
||||
"来源订单状态或净应收已变更,请拒绝后重新创建结算单");
|
||||
total = total.add(net);
|
||||
}
|
||||
require(total.compareTo(amount(row, "amount")) == 0, "结算明细金额不一致");
|
||||
Map<String, Object> account = store.get("account", number(row, "account_id"), true);
|
||||
require("ACTIVE".equals(text(account, "status")), "供应商账户已冻结,暂不能结算");
|
||||
funds.post(number(row, "account_id"), "INCOME_SETTLE:" + id, "INCOME_SETTLE",
|
||||
total, ZERO, total.negate(), ZERO, null, id, null, actor, null,
|
||||
"收益结算转入可用余额:" + reason);
|
||||
store.update("settlement", id, map("status", "SETTLED", "approved_by", actor,
|
||||
"settled_at", now(), "remark", reason));
|
||||
store.event("SETTLEMENT", id, "INCOME_SETTLE", actor, reason);
|
||||
log.info("收益结算完成 settlementId={} accountId={} amountUsdt={} actorId={} sourceCount={}",
|
||||
id, row.get("account_id"), total, actor, items.size());
|
||||
} else if ("reject".equals(action)) {
|
||||
if ("REJECTED".equals(state)) {
|
||||
return row;
|
||||
}
|
||||
require("PENDING".equals(state) && number(row, "created_by") != actor, "只能由其他审批人拒绝待审收益结算单");
|
||||
store.update("settlement", id, map("status", "REJECTED", "approved_by", actor, "remark", reason));
|
||||
store.execute("UPDATE rent_settlement_item SET active_slot=NULL,version=version+1,updated_at=? WHERE settlement_id=?", now(), id);
|
||||
store.event("SETTLEMENT", id, "REJECT", actor, reason);
|
||||
log.info("收益结算拒绝并释放来源 settlementId={} actorId={}", id, actor);
|
||||
} else {
|
||||
log.warn("收益结算拒绝旧付款操作 settlementId={} action={} actorId={}", id, action, actor);
|
||||
throw new IllegalArgumentException("收益结算只支持审核入账或拒绝;对外付款请使用提现功能");
|
||||
}
|
||||
return store.get("settlement", id, false);
|
||||
}
|
||||
|
||||
/** 由链上只读服务独立核对付款后调用;不接受前端的verified=true作为依据。 */
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void paid(long id, String reference, String evidence, long actor) {
|
||||
Map<String, Object> row = store.get("settlement", id, true);
|
||||
require("LEGACY_PAYOUT".equals(text(row, "settlement_mode")), "收益结算不能登记链上付款,请通过提现付款");
|
||||
if ("PAID".equals(text(row, "status"))) {
|
||||
require(reference.equals(text(row, "payment_reference")), "付款凭据冲突");
|
||||
return;
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.Statement;
|
||||
import java.util.*;
|
||||
|
||||
/** 租赁事务仓储。动态标识符只接受内部白名单,业务值全部使用占位符。 行锁由调用方事务持有;RPC必须在事务外执行,避免占用数据库连接等待链上响应。 */
|
||||
@@ -93,7 +92,8 @@ public class RentalStore {
|
||||
jdbc.update(
|
||||
connection -> {
|
||||
PreparedStatement ps =
|
||||
connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||
// 只读取自增主键,避免生成列也被驱动返回为 generated keys。
|
||||
connection.prepareStatement(sql, new String[] {"id"});
|
||||
int index = 1;
|
||||
for (Object value : values.values()) {
|
||||
ps.setObject(index++, value);
|
||||
|
||||
@@ -7,6 +7,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<resultMap type="RentSettlement" id="RentSettlementResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="settlementNo" column="settlement_no" />
|
||||
<result property="settlementMode" column="settlement_mode" />
|
||||
<result property="settledAt" column="settled_at" />
|
||||
<result property="accountId" column="account_id" />
|
||||
<result property="amount" column="amount" />
|
||||
<result property="status" column="status" />
|
||||
@@ -24,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRentSettlementVo">
|
||||
select id, settlement_no, account_id, amount, status, payout_no, payment_started_at, payment_evidence, payment_reference, created_by, approved_by, paid_at, remark, version, created_at, updated_at from rent_settlement
|
||||
select id, settlement_no, settlement_mode, settled_at, account_id, amount, status, payout_no, payment_started_at, payment_evidence, payment_reference, created_by, approved_by, paid_at, remark, version, created_at, updated_at from rent_settlement
|
||||
</sql>
|
||||
|
||||
<select id="selectRentSettlementList" parameterType="RentSettlement" resultMap="RentSettlementResult">
|
||||
@@ -109,4 +111,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
</mapper>
|
||||
@@ -492,6 +492,7 @@ public class RentalBusinessTest {
|
||||
Files.readAllBytes(Paths.get("../sql/rent_init.sql")),
|
||||
StandardCharsets.UTF_8)
|
||||
.replaceAll("(?m)^--.*$", "")
|
||||
.replace("GENERATED ALWAYS AS", "AS")
|
||||
.replaceAll("CHARACTER SET ascii COLLATE ascii_bin", "")
|
||||
.replaceAll("(?i)\\bJSON\\b", "LONGTEXT")
|
||||
.replaceAll(
|
||||
@@ -915,6 +916,139 @@ public class RentalBusinessTest {
|
||||
assertEquals(1, activationChecks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onchainPendingAddressBlocksNewOrderUntilCancelled() {
|
||||
Map<String, Object> original = tx.execute(status -> orders.create(app, 10, onchainRequest("pending-first")));
|
||||
BigDecimal frozen = amount(store.get("account", payer, false), "frozen_amount");
|
||||
long otherApp = store.insert("app", map("user_id", 30, "name", "other-user", "status", "ACTIVE"));
|
||||
expectFailure(() -> tx.execute(status -> orders.create(otherApp, 30, onchainRequest("other-user-order"))));
|
||||
for (String state : new String[] {"WAITING", "EXECUTING", "VERIFYING", "MANUAL_REVIEW"}) {
|
||||
store.update("order", number(original, "id"), map("status", state));
|
||||
expectFailure(() -> tx.execute(status -> orders.create(app, 10, onchainRequest("pending-second"))));
|
||||
assertEquals(frozen, amount(store.get("account", payer, false), "frozen_amount"));
|
||||
}
|
||||
store.update("order", number(original, "id"), map("status", "WAITING"));
|
||||
tx.execute(status -> { orders.cancel(number(original, "id"), 10); return null; });
|
||||
Map<String, Object> next = tx.execute(status -> orders.create(app, 10, onchainRequest("pending-second")));
|
||||
assertNotEquals(number(original, "id"), number(next, "id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onchainPendingIndexRejectsDuplicateEvenWithoutBusinessCheck() {
|
||||
Map<String, Object> original = tx.execute(status -> orders.create(app, 10, onchainRequest("index-first")));
|
||||
Map<String, Object> duplicate = new java.util.HashMap<>(original);
|
||||
duplicate.remove("id");
|
||||
duplicate.remove("onchain_pending_slot");
|
||||
duplicate.put("order_no", "duplicate-index-order");
|
||||
duplicate.put("merchant_order_no", "duplicate-index-merchant");
|
||||
try {
|
||||
tx.execute(status -> store.insert("order", duplicate));
|
||||
fail("数据库必须拒绝同地址的并发待处理订单");
|
||||
} catch (org.springframework.dao.DuplicateKeyException expected) {
|
||||
assertTrue(expected.getMostSpecificCause().getMessage().toLowerCase(java.util.Locale.ROOT)
|
||||
.contains("uk_order_onchain_pending"));
|
||||
}
|
||||
}
|
||||
|
||||
private static void await(CountDownLatch latch) {
|
||||
try {
|
||||
if (!latch.await(10, TimeUnit.SECONDS)) {
|
||||
throw new IllegalStateException("等待并发测试启动超时");
|
||||
}
|
||||
} catch (InterruptedException exception) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
/** 真实冻结与确认记账,链上证明由其他用例覆盖;这里隔离收益结算资金流。 */
|
||||
private long incomeOrder() {
|
||||
return tx.execute(status -> {
|
||||
Map<String, Object> order = orders.create(app, 10, onchainRequest("income-source"));
|
||||
long id = number(order, "id");
|
||||
store.update("order", id, map("status", "SUCCESS", "supplier_account_id", supplier,
|
||||
"supplier_user_id", 20));
|
||||
funds.charge(store.get("order", id, true));
|
||||
return id;
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incomeApprovalMovesBalanceExactlyOnceAndCannotPayOrResettle() throws Exception {
|
||||
long order = incomeOrder();
|
||||
long settlement = tx.execute(status -> reviews.settlement(Collections.singletonList(order), 90));
|
||||
expectFailure(() -> tx.execute(status -> reviews.transition(settlement, "approve", 90, "self")));
|
||||
expectFailure(() -> tx.execute(status -> reviews.transition(settlement, "pay", 91, "wrong-mode")));
|
||||
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
try {
|
||||
Future<?> first = executor.submit(() -> { await(start); tx.execute(status -> reviews.transition(settlement, "approve", 91, "审核")); });
|
||||
Future<?> second = executor.submit(() -> { await(start); tx.execute(status -> reviews.transition(settlement, "approve", 92, "重试")); });
|
||||
start.countDown();
|
||||
first.get(15, TimeUnit.SECONDS);
|
||||
second.get(15, TimeUnit.SECONDS);
|
||||
} finally { executor.shutdownNow(); }
|
||||
assertEquals("SETTLED", text(store.get("settlement", settlement, false), "status"));
|
||||
assertNotNull(store.get("settlement", settlement, false).get("settled_at"));
|
||||
assertNull(store.get("settlement", settlement, false).get("paid_at"));
|
||||
assertEquals(money("0.163457"), amount(store.get("account", supplier, false), "available_amount"));
|
||||
assertEquals(ZERO, amount(store.get("account", supplier, false), "supplier_pending_amount"));
|
||||
assertEquals(1, store.rows("SELECT id FROM rent_ledger WHERE business_key=?", "INCOME_SETTLE:" + settlement).size());
|
||||
expectFailure(() -> tx.execute(status -> reviews.settlement(Collections.singletonList(order), 90)));
|
||||
expectFailure(() -> tx.execute(status -> reviews.transition(settlement, "reject", 91, "too-late")));
|
||||
expectFailure(() -> tx.execute(status -> { reviews.paid(settlement, "fake", "{}", 91); return null; }));
|
||||
|
||||
// 结算收入进入现有提现入口,不需要供应商专用付款或重复的结算付款逻辑。
|
||||
org.springframework.core.env.StandardEnvironment env = new org.springframework.core.env.StandardEnvironment();
|
||||
env.getPropertySources().addFirst(new org.springframework.core.env.MapPropertySource("withdraw-income", map(
|
||||
"rental.enabled", true, "rental.withdraw.enabled", true, "rental.withdraw.min-amount-usdt", "0.01",
|
||||
"rental.withdraw.nile.payout-addresses", "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb")));
|
||||
RentalWithdrawals withdraw = new RentalWithdrawals(store, funds, null, env,
|
||||
new ObjectMapper(), null, tx.getTransactionManager());
|
||||
Map<String, Object> request = map("network", "NILE", "receiver_address", ADDRESS,
|
||||
"client_request_no", "income-withdraw", "amount", "0.1");
|
||||
withdraw.create(20, request);
|
||||
withdraw.create(20, request);
|
||||
assertEquals(money("0.063457"), amount(store.get("account", supplier, false), "available_amount"));
|
||||
assertEquals(money("0.100000"), amount(store.get("account", supplier, false), "frozen_amount"));
|
||||
assertEquals(ZERO, amount(store.get("account", supplier, false), "supplier_pending_amount"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incomeRejectReleasesSourcesAndFailedApprovalRollsBack() {
|
||||
long order = incomeOrder();
|
||||
long first = tx.execute(status -> reviews.settlement(Collections.singletonList(order), 90));
|
||||
store.update("account", supplier, map("status", "DISABLED"));
|
||||
expectFailure(() -> tx.execute(status -> reviews.transition(first, "approve", 91, "blocked")));
|
||||
assertEquals("PENDING", text(store.get("settlement", first, false), "status"));
|
||||
assertEquals(ZERO, amount(store.get("account", supplier, false), "available_amount"));
|
||||
assertEquals(money("0.163457"), amount(store.get("account", supplier, false), "supplier_pending_amount"));
|
||||
tx.execute(status -> reviews.transition(first, "reject", 91, "重新核对"));
|
||||
store.update("account", supplier, map("status", "ACTIVE"));
|
||||
long next = tx.execute(status -> reviews.settlement(Collections.singletonList(order), 90));
|
||||
tx.execute(status -> reviews.transition(next, "approve", 91, "重新结算"));
|
||||
assertEquals(money("0.163457"), amount(store.get("account", supplier, false), "available_amount"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void legacyPaidDoesNotCreditWithdrawableBalance() {
|
||||
long order = incomeOrder();
|
||||
long id = tx.execute(status -> reviews.settlement(Collections.singletonList(order), 90));
|
||||
// 模拟升级前已存在的结算单;迁移脚本默认所有历史行均为LEGACY_PAYOUT。
|
||||
store.update("settlement", id, map("settlement_mode", "LEGACY_PAYOUT"));
|
||||
tx.execute(status -> {
|
||||
reviews.transition(id, "approve", 91, "legacy");
|
||||
reviews.transition(id, "pay", 91, "legacy");
|
||||
reviews.paid(id, "NILE:legacy:0", "{}", 91);
|
||||
reviews.paid(id, "NILE:legacy:0", "{}", 91);
|
||||
return null;
|
||||
});
|
||||
assertEquals("PAID", text(store.get("settlement", id, false), "status"));
|
||||
assertEquals(ZERO, amount(store.get("account", supplier, false), "available_amount"));
|
||||
assertEquals(ZERO, amount(store.get("account", supplier, false), "supplier_pending_amount"));
|
||||
expectFailure(() -> tx.execute(status -> reviews.settlement(Collections.singletonList(order), 90)));
|
||||
}
|
||||
|
||||
private Map<String, Object> onchainRequest(String merchant) {
|
||||
return map("order_type", "ADDRESS_ONCHAIN", "network", "NILE", "merchant_order_no", merchant,
|
||||
"receiver_address", ADDRESS, "expected_amount", "0.173457");
|
||||
@@ -1305,7 +1439,7 @@ public class RentalBusinessTest {
|
||||
@Test
|
||||
public void historyCleanupReadsRealBusinessSchemaAndKeepsFunds() throws Exception {
|
||||
String ddl = new String(Files.readAllBytes(Paths.get("../sql/rent_history_init.sql")), StandardCharsets.UTF_8)
|
||||
.replaceAll("(?m)^--.*$", "")
|
||||
.replaceAll("(?m)^--.*$", "").replace("GENERATED ALWAYS AS", "AS")
|
||||
.replace("ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", "");
|
||||
for (String statement : ddl.split(";")) {
|
||||
if (!statement.trim().isEmpty()) { store.execute(statement); }
|
||||
@@ -2225,6 +2359,8 @@ public class RentalBusinessTest {
|
||||
tx.execute(status -> reviews.settlement(Collections.singletonList(id), 90));
|
||||
tx.execute(
|
||||
status -> {
|
||||
// 仅历史模式仍允许领取付款授权,验证旧单UNKNOWN/PAYING占用保护。
|
||||
store.update("settlement", settlement, map("settlement_mode", "LEGACY_PAYOUT"));
|
||||
reviews.transition(settlement, "approve", 91, "test");
|
||||
reviews.transition(settlement, "pay", 91, "test");
|
||||
return null;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class RentalHistoryCleanupTest {
|
||||
store = new RentalStore(jdbc);
|
||||
manager = new DataSourceTransactionManager(source);
|
||||
String ddl = new String(Files.readAllBytes(Paths.get("../sql/rent_history_init.sql")), StandardCharsets.UTF_8)
|
||||
.replaceAll("(?m)^--.*$", "")
|
||||
.replaceAll("(?m)^--.*$", "").replace("GENERATED ALWAYS AS", "AS")
|
||||
.replace("ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", "");
|
||||
for (String statement : ddl.split(";")) {
|
||||
if (!statement.trim().isEmpty()) { jdbc.execute(statement); }
|
||||
|
||||
@@ -51,7 +51,7 @@ public class RentalHistoryTest {
|
||||
jdbc.execute("CREATE ALIAS UTC_TIMESTAMP FOR \"com.ruoyi.system.rental.RentalHistoryTest.utcTimestamp\"");
|
||||
store = new RentalStore(jdbc);
|
||||
String ddl = new String(Files.readAllBytes(Paths.get("../sql/rent_history_init.sql")),
|
||||
StandardCharsets.UTF_8).replaceAll("(?m)^--.*$", "")
|
||||
StandardCharsets.UTF_8).replaceAll("(?m)^--.*$", "").replace("GENERATED ALWAYS AS", "AS")
|
||||
.replace("ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", "");
|
||||
for (String statement : ddl.split(";")) {
|
||||
if (!statement.trim().isEmpty()) {
|
||||
|
||||
@@ -64,7 +64,7 @@ public class RentalTopupTest {
|
||||
store = new RentalStore(jdbc);
|
||||
for (String file : Arrays.asList("rent_init.sql", "rent_topup_init.sql")) {
|
||||
String ddl = new String(Files.readAllBytes(Paths.get("../sql/" + file)), StandardCharsets.UTF_8)
|
||||
.replaceAll("(?m)^--.*$", "").replace("CHARACTER SET ascii COLLATE ascii_bin", "")
|
||||
.replaceAll("(?m)^--.*$", "").replace("GENERATED ALWAYS AS", "AS").replace("CHARACTER SET ascii COLLATE ascii_bin", "")
|
||||
.replaceAll("(?i)\\bJSON\\b", "LONGTEXT")
|
||||
.replace("ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", "");
|
||||
for (String sql : ddl.split(";")) if (!sql.trim().isEmpty()) jdbc.execute(sql);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class RentalWithdrawTest {
|
||||
JdbcTemplate jdbc = new JdbcTemplate(source);
|
||||
store = new RentalStore(jdbc);
|
||||
String ddl = new String(Files.readAllBytes(Paths.get("../sql/rent_init.sql")), StandardCharsets.UTF_8)
|
||||
.replaceAll("(?m)^--.*$", "").replace("CHARACTER SET ascii COLLATE ascii_bin", "")
|
||||
.replaceAll("(?m)^--.*$", "").replace("GENERATED ALWAYS AS", "AS").replace("CHARACTER SET ascii COLLATE ascii_bin", "")
|
||||
.replaceAll("(?i)\\bJSON\\b", "LONGTEXT")
|
||||
.replace("ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", "");
|
||||
for (String sql : ddl.split(";")) { if (!sql.trim().isEmpty()) { jdbc.execute(sql); } }
|
||||
|
||||
Reference in new issue
Block a user