在租赁用户和供应商用户首页,添加导出对账单功能。包括资金账号出入账汇总和明细。

This commit is contained in:
lu7213 committed 2026-11-03 05:37:41 -05:00
1 parent 611e020f38
commit 2870c3fb6c
6 files changed
+446

No files matched your search

@@ -46,6 +46,92 @@ public class RentalBusinessTest {
private static final String OWNER = "TR7NHqjeKQxGTCi8q8ZY4pL8otgjLj6t";
private final ObjectMapper json = new ObjectMapper();
/** 全账本核对:内部划转不重复计收支,历史区间扣除期后变动,跨用户/跨网络隔离。 */
@Test
public void accountStatementReconcilesTransfersAndHistoricalBoundary() throws Exception {
java.time.LocalDate from = now().toLocalDate().minusDays(4);
java.time.LocalDate to = from.plusDays(2);
java.time.LocalDateTime at = from.atStartOfDay();
store.execute("UPDATE rent_ledger SET created_at=? WHERE account_id=?", at.minusDays(1), payer);
statementPost(payer, "HOLD", "-10", "10", "0", at);
statementPost(payer, "CHARGE", "0", "-10", "0", at.plusHours(1));
statementPost(payer, "REFUND", "2", "0", "0", at.plusHours(2));
statementPost(payer, "SUPPLIER_EARN", "0", "0", "5", at.plusHours(3));
statementPost(payer, "SUPPLIER_FEE", "0", "0", "-1", at.plusHours(4));
statementPost(payer, "INCOME_SETTLE", "4", "0", "-4", at.plusHours(5));
statementPost(payer, "WITHDRAW_HOLD", "-3", "3", "0", at.plusHours(6));
statementPost(payer, "WITHDRAW_COMPLETE", "0", "-3", "0", at.plusHours(7));
statementPost(payer, "TOPUP", "7", "0", "0", to.plusDays(1).atStartOfDay());
statementPost(supplier, "SUPPLIER_EARN", "0", "0", "400", at);
long mainnet = number(funds.account(10, "MAINNET"), "id");
statementPost(mainnet, "TOPUP", "80", "0", "0", at);
RentalStatements.Statement report = tx.execute(status -> new RentalStatements(store).snapshot(10, "NILE", from, to));
assertEquals(payer, report.accountId);
assertEquals(8, report.rows.size());
assertEquals(money("7"), report.inflow);
assertEquals(money("14"), report.outflow);
assertEquals(money("100"), amount(report.buckets.get(0), "opening"));
assertEquals(money("93"), amount(report.buckets.get(0), "closing"));
assertEquals(money("0"), amount(report.buckets.get(1), "closing"));
assertEquals(money("0"), amount(report.buckets.get(2), "closing"));
RentalStatements.Statement foreign = tx.execute(status -> new RentalStatements(store).snapshot(20, "NILE", from, to));
assertEquals(1, foreign.rows.size());
assertEquals(money("400"), foreign.inflow);
java.io.ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream();
RentalStatementExcel.write(report, bytes);
// 留存隔离数据生成的工作簿,供本地页面下载联调;不含真实账户信息。
Files.write(Paths.get("target/rental-statement-preview.xlsx"), bytes.toByteArray());
try (org.apache.poi.xssf.usermodel.XSSFWorkbook book = new org.apache.poi.xssf.usermodel.XSSFWorkbook(
new java.io.ByteArrayInputStream(bytes.toByteArray()))) {
assertEquals(3, book.getNumberOfSheets());
org.apache.poi.ss.usermodel.Sheet details = book.getSheet("资金流水明细");
assertEquals(8, details.getLastRowNum());
assertEquals("0.000000", details.getRow(1).getCell(5).getStringCellValue());
assertEquals("-10.000000", details.getRow(1).getCell(6).getStringCellValue());
assertEquals(org.apache.poi.ss.usermodel.CellType.STRING, details.getRow(1).getCell(17).getCellType());
assertEquals("=untrusted-note", details.getRow(1).getCell(17).getStringCellValue());
}
}
/** 无流水仍需期初期末一致;非法日期/网络、未开通账户不能创建或导出其他账户。 */
@Test
public void accountStatementValidatesScopeAndExportsEmptyPrecision() throws Exception {
java.time.LocalDate date = now().toLocalDate().minusDays(1);
RentalStatements service = new RentalStatements(store);
expectFailure(() -> service.snapshot(10, "UNKNOWN", date, date));
expectFailure(() -> service.snapshot(10, "NILE", date, date.minusDays(1)));
expectFailure(() -> service.snapshot(10, "NILE", date.minusDays(366), date));
expectFailure(() -> service.snapshot(10, "NILE", date, now().toLocalDate().plusDays(1)));
expectFailure(() -> service.snapshot(999, "NILE", date, date));
assertNull(store.one("SELECT id FROM rent_account WHERE user_id=999"));
store.execute("UPDATE rent_ledger SET created_at=? WHERE account_id=?", date.minusDays(1).atStartOfDay(), payer);
statementPost(payer, "TOPUP", "999999999999999.123456", "0", "0", date.minusDays(1).atStartOfDay());
RentalStatements.Statement empty = tx.execute(status -> service.snapshot(10, "NILE", date, date));
assertTrue(empty.rows.isEmpty());
assertEquals(money("1000000000000099.123456"), amount(empty.buckets.get(0), "closing"));
assertEquals(amount(empty.buckets.get(0), "closing"), amount(empty.buckets.get(0), "opening"));
java.io.ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream();
RentalStatementExcel.write(empty, bytes);
try (org.apache.poi.xssf.usermodel.XSSFWorkbook book = new org.apache.poi.xssf.usermodel.XSSFWorkbook(
new java.io.ByteArrayInputStream(bytes.toByteArray()))) {
assertEquals(0, book.getSheet("资金流水明细").getLastRowNum());
assertEquals("1000000000000099.123456", book.getSheetAt(0).getRow(8).getCell(1).getStringCellValue());
}
}
private void statementPost(long account, String type, String available, String frozen, String pending,
java.time.LocalDateTime at) {
String key = "STATEMENT-TEST:" + UUID.randomUUID();
tx.execute(status -> {
funds.post(account, key, type, money(available), money(frozen), money(pending), ZERO,
null, null, null, 0, null, "=untrusted-note");
store.execute("UPDATE rent_ledger SET created_at=? WHERE business_key=?", at, key);
return null;
});
}
/** 待验证地址仅本人可删除,验证后或状态变化后必须保留。 */
@Test
public void pendingWalletDeletionChecksOwnershipAndVerification() {