在租赁用户和供应商用户首页,添加导出对账单功能。包括资金账号出入账汇总和明细。
This commit is contained in:
1 parent
611e020f38
commit
2870c3fb6c
6 files changed
+446
No files matched your search
@@ -0,0 +1,50 @@
|
||||
package com.ruoyi.system.rental;
|
||||
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/** 本人账单下载;不接受userId/accountId,避免通过导出接口越权读取资金明细。 */
|
||||
@RestController
|
||||
public class RentalStatementController {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RentalStatementController.class);
|
||||
private final RentalStatements statements;
|
||||
|
||||
public RentalStatementController(RentalStatements statements) {
|
||||
this.statements = statements;
|
||||
}
|
||||
|
||||
@PostMapping("/rental/statements/export")
|
||||
@PreAuthorize("@ss.hasPermi('rent:statement:export')")
|
||||
public void export(@RequestParam String network,
|
||||
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate from,
|
||||
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate to,
|
||||
HttpServletResponse response) throws IOException {
|
||||
Long user = SecurityUtils.getUserId();
|
||||
RentalValues.require(user != null, "请先登录");
|
||||
LOG.info("租赁对账导出开始 userId={} network={} from={} to={}", user, network, from, to);
|
||||
try {
|
||||
// 所有参数、归属和行数校验在写HTTP头之前完成,失败可以返回正常JSON业务错误。
|
||||
RentalStatements.Statement data = statements.snapshot(user, network, from, to);
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=RentalStatement-" + data.network
|
||||
+ "-" + data.from + "-" + data.to + ".xlsx");
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
RentalStatementExcel.write(data, response.getOutputStream());
|
||||
LOG.info("租赁对账导出完成 userId={} accountId={} network={} rows={}",
|
||||
user, data.accountId, data.network, data.rows.size());
|
||||
} catch (IOException | RuntimeException exception) {
|
||||
LOG.warn("租赁对账导出失败 userId={} network={} from={} to={} exceptionType={}",
|
||||
user, network, from, to, exception.getClass().getSimpleName());
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.ruoyi.system.rental;
|
||||
|
||||
import static com.ruoyi.system.rental.RentalValues.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||
|
||||
/**
|
||||
* 资金对账单Excel输出。金额和编号一律写文本,避免Excel的15位数字精度丢失;
|
||||
* 不写公式,用户填写的备注即使以=、+等开头也只是文本,不会被当作公式执行。
|
||||
*/
|
||||
final class RentalStatementExcel {
|
||||
private static final DateTimeFormatter TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
|
||||
private RentalStatementExcel() { }
|
||||
|
||||
static void write(RentalStatements.Statement data, OutputStream output) throws IOException {
|
||||
SXSSFWorkbook book = new SXSSFWorkbook(100);
|
||||
book.setCompressTempFiles(true);
|
||||
try {
|
||||
CellStyle header = book.createCellStyle();
|
||||
Font font = book.createFont();
|
||||
font.setBold(true);
|
||||
font.setColor(IndexedColors.DARK_BLUE.getIndex());
|
||||
header.setFont(font);
|
||||
Sheet summary = sheet(book, "账户收支汇总", header, "项目", "金额或说明");
|
||||
line(summary, "账户编号", String.valueOf(data.accountId));
|
||||
line(summary, "网络 / 币种", data.network + " / USDT");
|
||||
line(summary, "开始日期(含)", data.from.toString());
|
||||
line(summary, "结束日期(含)", data.to.toString());
|
||||
line(summary, "生成时间", TIME.format(data.generated));
|
||||
line(summary, "服务器时区", zone().getId());
|
||||
line(summary, "流水笔数", String.valueOf(data.rows.size()));
|
||||
BigDecimal opening = ZERO;
|
||||
BigDecimal closing = ZERO;
|
||||
for (Map<String, Object> bucket : data.buckets) {
|
||||
opening = opening.add(amount(bucket, "opening"));
|
||||
closing = closing.add(amount(bucket, "closing"));
|
||||
}
|
||||
line(summary, "期初总资产", decimal(opening));
|
||||
line(summary, "区间资产增加", decimal(data.inflow));
|
||||
line(summary, "区间资产减少", decimal(data.outflow));
|
||||
line(summary, "区间资产净变动", decimal(data.inflow.subtract(data.outflow)));
|
||||
line(summary, "期末总资产", decimal(closing));
|
||||
line(summary, "对账校验", opening.add(data.inflow).subtract(data.outflow).compareTo(closing) == 0 ? "一致" : "不一致,请联系管理员");
|
||||
line(summary, "口径", "总资产=可用+冻结+待结算;资产增减为账本净变化,不等于链上转账金额。");
|
||||
line(summary, "内部划转", "冻结、解冻、收益结算内部转入余额不重复算收支;分户增减包含内部划转。");
|
||||
line(summary, "范围", "本人同网络资金账户全部流水;双角色共用账户不按角色拆分;当天导出截至本次数据库快照。");
|
||||
line(summary, "空区间", "无流水时保留期初期末余额,明细仅有表头。");
|
||||
line(summary, "精度", "金额为6位小数文本,编号为文本,避免Excel自动舍入;业务类型以代码为准。");
|
||||
for (Map<String, Object> bucket : data.buckets) {
|
||||
line(summary, text(bucket, "name") + ":期初 / 增加 / 减少 / 期末",
|
||||
decimal(amount(bucket, "opening")) + " / " + decimal(amount(bucket, "increase"))
|
||||
+ " / " + decimal(amount(bucket, "decrease")) + " / " + decimal(amount(bucket, "closing")));
|
||||
}
|
||||
summary.setColumnWidth(0, 36 * 256);
|
||||
summary.setColumnWidth(1, 100 * 256);
|
||||
|
||||
Sheet events = sheet(book, "业务分类汇总", header, "业务类型代码", "笔数", "资产增加USDT",
|
||||
"资产减少USDT", "可用净变动USDT", "冻结净变动USDT", "待结算净变动USDT");
|
||||
Map<String, BigDecimal[]> totals = new LinkedHashMap<>();
|
||||
for (Map<String, Object> row : data.rows) {
|
||||
BigDecimal[] values = totals.computeIfAbsent(text(row, "event_type"), key ->
|
||||
new BigDecimal[] {BigDecimal.ZERO, ZERO, ZERO, ZERO, ZERO, ZERO});
|
||||
values[0] = values[0].add(BigDecimal.ONE);
|
||||
BigDecimal net = RentalStatements.net(row);
|
||||
values[net.signum() >= 0 ? 1 : 2] = values[net.signum() >= 0 ? 1 : 2].add(net.abs());
|
||||
values[3] = values[3].add(amount(row, "delta_available"));
|
||||
values[4] = values[4].add(amount(row, "delta_frozen"));
|
||||
values[5] = values[5].add(amount(row, "delta_supplier_pending"));
|
||||
}
|
||||
totals.forEach((type, v) -> line(events, type, v[0].toPlainString(), decimal(v[1]), decimal(v[2]),
|
||||
decimal(v[3]), decimal(v[4]), decimal(v[5])));
|
||||
|
||||
Sheet details = sheet(book, "资金流水明细", header, "流水编号", "记账时间(服务器本地)", "业务类型代码",
|
||||
"资产增加USDT", "资产减少USDT", "资产净变动USDT", "可用变动USDT", "冻结变动USDT",
|
||||
"待结算变动USDT", "变更后可用USDT", "变更后冻结USDT", "变更后待结算USDT",
|
||||
"租赁订单ID", "结算单ID", "退款单ID", "提现单ID", "原冲正流水ID", "记账说明");
|
||||
for (Map<String, Object> row : data.rows) {
|
||||
BigDecimal net = RentalStatements.net(row);
|
||||
line(details, text(row, "id"), TIME.format(time(row.get("created_at")).atZone(zone())),
|
||||
text(row, "event_type"), decimal(net.max(ZERO)), decimal(net.min(ZERO).negate()), decimal(net),
|
||||
decimal(amount(row, "delta_available")), decimal(amount(row, "delta_frozen")),
|
||||
decimal(amount(row, "delta_supplier_pending")), decimal(amount(row, "after_available")),
|
||||
decimal(amount(row, "after_frozen")), decimal(amount(row, "after_supplier_pending")),
|
||||
text(row, "order_id"), text(row, "settlement_id"), text(row, "refund_id"),
|
||||
text(row, "withdraw_id"), text(row, "reversal_of_id"), text(row, "reason"));
|
||||
}
|
||||
events.setAutoFilter(new org.apache.poi.ss.util.CellRangeAddress(0, events.getLastRowNum(), 0, 6));
|
||||
details.setAutoFilter(new org.apache.poi.ss.util.CellRangeAddress(0, details.getLastRowNum(), 0, 17));
|
||||
book.write(output);
|
||||
} finally {
|
||||
try {
|
||||
book.close();
|
||||
} finally {
|
||||
// SXSSF的窗口文件含用户资金明细,不在磁盘长期保留。
|
||||
book.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Sheet sheet(SXSSFWorkbook book, String name, CellStyle header, String... titles) {
|
||||
Sheet sheet = book.createSheet(name);
|
||||
line(sheet, titles);
|
||||
for (Cell cell : sheet.getRow(0)) {
|
||||
cell.setCellStyle(header);
|
||||
sheet.setColumnWidth(cell.getColumnIndex(), 24 * 256);
|
||||
}
|
||||
sheet.createFreezePane(0, 1);
|
||||
return sheet;
|
||||
}
|
||||
|
||||
private static void line(Sheet sheet, String... values) {
|
||||
Row row = sheet.createRow(sheet.getPhysicalNumberOfRows() == 0 ? 0 : sheet.getLastRowNum() + 1);
|
||||
for (int index = 0; index < values.length; index++) {
|
||||
row.createCell(index).setCellValue(values[index]);
|
||||
}
|
||||
}
|
||||
|
||||
private static String decimal(BigDecimal value) {
|
||||
return value.setScale(6).toPlainString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.ruoyi.system.rental;
|
||||
|
||||
import static com.ruoyi.system.rental.RentalValues.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 本人资金对账快照。只读查询,不创建账户,不调用链上服务,也不改变财务状态。
|
||||
* 同一用户同时具有两种角色时仍共用同网络资金账户,不能按订单角色截断账本。
|
||||
*/
|
||||
@Service
|
||||
public class RentalStatements {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RentalStatements.class);
|
||||
private static final int MAX_DAYS = 366;
|
||||
private static final int MAX_ROWS = 50000;
|
||||
private static final List<String> DELTAS = Arrays.asList(
|
||||
"delta_available", "delta_frozen", "delta_supplier_pending");
|
||||
private final RentalStore store;
|
||||
|
||||
public RentalStatements(RentalStore store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期包含首尾两天,均按服务器本地时区解释;SQL采用[start,end)避免毫秒边界遗漏。
|
||||
* REPEATABLE_READ保证账户余额、期后流水和区间明细来自同一个数据库快照。
|
||||
* 超出限制明确拒绝,不截断后生成金额不完整的对账单。
|
||||
*/
|
||||
@Transactional(readOnly = true, isolation = Isolation.REPEATABLE_READ)
|
||||
public Statement snapshot(long user, String selectedNetwork, LocalDate from, LocalDate to) {
|
||||
require(user > 0, "请先登录");
|
||||
String network = network(selectedNetwork);
|
||||
require(from != null && to != null && !from.isAfter(to), "请选择有效的起止日期");
|
||||
require(ChronoUnit.DAYS.between(from, to) < MAX_DAYS, "单次最多导出366天,请缩小日期范围");
|
||||
LocalDateTime generated = now();
|
||||
require(!to.isAfter(generated.toLocalDate()), "结束日期不能晚于服务器当天");
|
||||
Map<String, Object> account = store.one(
|
||||
"SELECT id,available_amount,frozen_amount,supplier_pending_amount FROM rent_account"
|
||||
+ " WHERE user_id=? AND network=?", user, network);
|
||||
require(account != null, "当前网络尚未开通资金账户");
|
||||
long accountId = number(account, "id");
|
||||
LocalDateTime start = from.atStartOfDay();
|
||||
LocalDateTime end = to.plusDays(1).atStartOfDay();
|
||||
List<Map<String, Object>> rows = store.rows(
|
||||
"SELECT id,event_type,created_at,delta_available,delta_frozen,delta_supplier_pending,"
|
||||
+ "after_available,after_frozen,after_supplier_pending,order_id,settlement_id,"
|
||||
+ "refund_id,withdraw_id,reversal_of_id,reason FROM rent_ledger"
|
||||
+ " WHERE account_id=? AND created_at>=? AND created_at<? ORDER BY id LIMIT ?",
|
||||
accountId, start, end, MAX_ROWS + 1);
|
||||
require(rows.size() <= MAX_ROWS, "区间流水超过50000条,请缩小日期范围后导出");
|
||||
// 从一致性快照余额扣除期后变动还原期末,再扣区间变动还原期初。
|
||||
// 即使期初没有流水,仍能保留合法的历史账户初始余额,而不是强行当作0。
|
||||
Map<String, Object> later = store.one("SELECT COALESCE(SUM(delta_available),0) delta_available,"
|
||||
+ "COALESCE(SUM(delta_frozen),0) delta_frozen,"
|
||||
+ "COALESCE(SUM(delta_supplier_pending),0) delta_supplier_pending"
|
||||
+ " FROM rent_ledger WHERE account_id=? AND created_at>=?", accountId, end);
|
||||
List<Map<String, Object>> buckets = new ArrayList<>();
|
||||
String[] balanceKeys = {"available_amount", "frozen_amount", "supplier_pending_amount"};
|
||||
String[] names = {"可用余额", "冻结余额", "待结算收益"};
|
||||
for (int index = 0; index < DELTAS.size(); index++) {
|
||||
BigDecimal increase = ZERO;
|
||||
BigDecimal decrease = ZERO;
|
||||
for (Map<String, Object> row : rows) {
|
||||
BigDecimal delta = amount(row, DELTAS.get(index));
|
||||
if (delta.signum() > 0) {
|
||||
increase = increase.add(delta);
|
||||
} else {
|
||||
decrease = decrease.subtract(delta);
|
||||
}
|
||||
}
|
||||
BigDecimal closing = amount(account, balanceKeys[index]).subtract(amount(later, DELTAS.get(index)));
|
||||
BigDecimal opening = closing.subtract(increase).add(decrease);
|
||||
buckets.add(map("name", names[index], "opening", opening, "increase", increase,
|
||||
"decrease", decrease, "closing", closing));
|
||||
}
|
||||
BigDecimal inflow = ZERO;
|
||||
BigDecimal outflow = ZERO;
|
||||
for (Map<String, Object> row : rows) {
|
||||
BigDecimal net = net(row);
|
||||
if (net.signum() > 0) {
|
||||
inflow = inflow.add(net);
|
||||
} else {
|
||||
outflow = outflow.subtract(net);
|
||||
}
|
||||
}
|
||||
LOG.info("租赁对账快照生成 userId={} accountId={} network={} from={} to={} rows={}",
|
||||
user, accountId, network, from, to, rows.size());
|
||||
return new Statement(accountId, network, from, to, generated, rows, buckets, inflow, outflow);
|
||||
}
|
||||
|
||||
/** 三个资金分户之和才是总资产变化。内部冻结/结算划转的净变动为0。 */
|
||||
static BigDecimal net(Map<String, Object> row) {
|
||||
return amount(row, "delta_available").add(amount(row, "delta_frozen"))
|
||||
.add(amount(row, "delta_supplier_pending"));
|
||||
}
|
||||
|
||||
/** 仅供导出器使用的内部快照,不作为带敏感字段的通用数据库响应。 */
|
||||
static final class Statement {
|
||||
final long accountId;
|
||||
final String network;
|
||||
final LocalDate from;
|
||||
final LocalDate to;
|
||||
final LocalDateTime generated;
|
||||
final List<Map<String, Object>> rows;
|
||||
final List<Map<String, Object>> buckets;
|
||||
final BigDecimal inflow;
|
||||
final BigDecimal outflow;
|
||||
|
||||
Statement(long accountId, String network, LocalDate from, LocalDate to, LocalDateTime generated,
|
||||
List<Map<String, Object>> rows, List<Map<String, Object>> buckets,
|
||||
BigDecimal inflow, BigDecimal outflow) {
|
||||
this.accountId = accountId;
|
||||
this.network = network;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.generated = generated;
|
||||
this.rows = rows;
|
||||
this.buckets = buckets;
|
||||
this.inflow = inflow;
|
||||
this.outflow = outflow;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user