This commit is contained in:
2026-08-17 18:32:38 +08:00
parent 5c22018edd
commit 5199146e97
13 changed files with 194 additions and 17 deletions
@@ -48,6 +48,7 @@ public class FinanceExportProviderService {
private static final int SCHEMA_VERSION = 1;
private static final int MAX_BATCH_SIZE = 500;
private static final int QUERY_PAGE_SIZE = 200;
private static final int MAX_SNAPSHOT_TOKEN_LENGTH = 512;
private static final Set<String> TYPES = Set.of(CUSTOMER_ACCOUNT_LIST, CUSTOMER_ACCOUNT_LEDGER,
FEE_SOURCE_LIST, RECONCILIATION_STATEMENT_LIST, RECEIVABLE_SETTLEMENT_LIST,
@@ -148,13 +149,15 @@ public class FinanceExportProviderService {
int limit = request.source().limit();
Map<String, Object> p = request.parameters();
if (CUSTOMER_ACCOUNT_LIST.equals(type)) {
int page = offset / limit + 1;
var result = accountService.list(page, limit, null, text(p, "status"), longValue(p, "customerId", false));
int querySize = Math.min(limit, QUERY_PAGE_SIZE);
int page = offset / querySize + 1;
var result = accountService.list(page, querySize, null, text(p, "status"), longValue(p, "customerId", false));
return new BatchRows(result.data().stream().map(this::accountRow).toList(), result.page().total());
}
if (CUSTOMER_ACCOUNT_LEDGER.equals(type)) {
int page = offset / limit + 1;
var result = operationService.listDerivedCustomerAccountLedger(longValue(p, "customerId", true), page, limit,
int querySize = Math.min(limit, QUERY_PAGE_SIZE);
int page = offset / querySize + 1;
var result = operationService.listDerivedCustomerAccountLedger(longValue(p, "customerId", true), page, querySize,
text(p, "businessType"), date(p, "startDate"), date(p, "endDate"));
return new BatchRows(result.data().stream().map(this::ledgerRow).toList(), result.page().total());
}
@@ -3,6 +3,7 @@ package com.baiyue.finance.service;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.common.core.export.ExportContracts.ExportBatchRequest;
import com.baiyue.finance.dto.FinancePhase1Dtos.FeeSourceDetail;
import com.baiyue.finance.dto.FinancePhase1Dtos.PageEnvelope;
import com.baiyue.finance.dto.FinanceReadModels.Statement;
import com.baiyue.finance.dto.ReconciliationStatementDtos.PaymentHistory;
import com.baiyue.finance.dto.ReconciliationStatementDtos.ReconciliationDetail;
@@ -23,6 +24,7 @@ import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
@ExtendWith(MockitoExtension.class)
class FinanceExportProviderServiceTest {
@@ -87,7 +89,27 @@ class FinanceExportProviderServiceTest {
.isInstanceOf(BizException.class).hasMessageContaining("snapshotToken");
}
@Test
void capsFileBatchSizeToFinanceQueryPageLimitForAccountAndLedgerExports() {
when(accountService.list(1, 200, null, null, 10001L))
.thenReturn(PageEnvelope.success(List.of(), 1, 200, 0));
when(operationService.listDerivedCustomerAccountLedger(10001L, 1, 200, null, null, null))
.thenReturn(PageEnvelope.success(List.of(), 1, 200, 0));
service.exportBatch(FinanceExportProviderService.CUSTOMER_ACCOUNT_LIST,
request(Map.of("customerId", "10001"), null, null, 500));
service.exportBatch(FinanceExportProviderService.CUSTOMER_ACCOUNT_LEDGER,
request(Map.of("customerId", "10001"), null, null, 500));
verify(accountService).list(1, 200, null, null, 10001L);
verify(operationService).listDerivedCustomerAccountLedger(10001L, 1, 200, null, null, null);
}
private ExportBatchRequest request(Map<String, Object> parameters, String cursor, String snapshot) {
return new ExportBatchRequest("9001", "0", "PLATFORM", "7", 1, parameters, cursor, snapshot, 100);
return request(parameters, cursor, snapshot, 100);
}
private ExportBatchRequest request(Map<String, Object> parameters, String cursor, String snapshot, int limit) {
return new ExportBatchRequest("9001", "0", "PLATFORM", "7", 1, parameters, cursor, snapshot, limit);
}
}