feat(ccdi-project): harden bank statement dedup import
This commit is contained in:
@@ -56,7 +56,7 @@ public class CcdiFileUploadServiceImpl implements ICcdiFileUploadService {
|
||||
private static class FetchBankStatementResult {
|
||||
private boolean success;
|
||||
private int totalCount;
|
||||
private int savedCount;
|
||||
private int attemptedCount;
|
||||
private String errorMessage;
|
||||
}
|
||||
|
||||
@@ -352,6 +352,14 @@ public class CcdiFileUploadServiceImpl implements ICcdiFileUploadService {
|
||||
return errorMessage.substring(0, MAX_ERROR_MESSAGE_LENGTH);
|
||||
}
|
||||
|
||||
private String trimAccountNo(String value) {
|
||||
return value == null ? null : value.trim();
|
||||
}
|
||||
|
||||
private void normalizeDedupFields(CcdiBankStatement statement) {
|
||||
statement.setLeAccountNo(trimAccountNo(statement.getLeAccountNo()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步处理单个文件的完整流程
|
||||
* 包含:上传 → 轮询解析状态 → 获取结果 → 保存流水数据
|
||||
@@ -583,14 +591,13 @@ public class CcdiFileUploadServiceImpl implements ICcdiFileUploadService {
|
||||
if (totalCount == null || totalCount <= 0) {
|
||||
log.warn("【文件上传】无流水数据需要保存: totalCount={}", totalCount);
|
||||
result.setSuccess(true);
|
||||
result.setSavedCount(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
int pageSize = 1000;
|
||||
int batchSize = 1000;
|
||||
int totalPages = (int) Math.ceil((double) totalCount / pageSize);
|
||||
int totalSaved = 0;
|
||||
int totalAttempted = 0;
|
||||
List<CcdiBankStatement> batchList = new ArrayList<>(batchSize);
|
||||
|
||||
log.info("【文件上传】获取到总数: totalCount={}", totalCount);
|
||||
@@ -622,13 +629,14 @@ public class CcdiFileUploadServiceImpl implements ICcdiFileUploadService {
|
||||
if (statement != null) {
|
||||
statement.setBatchId(logId);
|
||||
statement.setProjectId(projectId);
|
||||
normalizeDedupFields(statement);
|
||||
batchList.add(statement);
|
||||
|
||||
if (batchList.size() >= batchSize) {
|
||||
int currentBatchSize = batchList.size();
|
||||
bankStatementMapper.insertBatch(batchList);
|
||||
totalSaved += batchList.size();
|
||||
log.debug("【文件上传】批量插入流水 {}条, 累计{}条",
|
||||
batchList.size(), totalSaved);
|
||||
totalAttempted += currentBatchSize;
|
||||
log.debug("【文件上传】批量写入流水 {}条", currentBatchSize);
|
||||
batchList.clear();
|
||||
}
|
||||
}
|
||||
@@ -643,14 +651,16 @@ public class CcdiFileUploadServiceImpl implements ICcdiFileUploadService {
|
||||
}
|
||||
|
||||
if (!batchList.isEmpty()) {
|
||||
int currentBatchSize = batchList.size();
|
||||
bankStatementMapper.insertBatch(batchList);
|
||||
totalSaved += batchList.size();
|
||||
totalAttempted += currentBatchSize;
|
||||
log.debug("【文件上传】批量插入剩余流水 {}条", batchList.size());
|
||||
}
|
||||
|
||||
log.info("【文件上传】流水数据保存完成: 总共保存{}条", totalSaved);
|
||||
log.info("【文件上传】流水入库完成: fetchedCount={}, attemptedCount={}",
|
||||
totalCount, totalAttempted);
|
||||
result.setSuccess(true);
|
||||
result.setSavedCount(totalSaved);
|
||||
result.setAttemptedCount(totalAttempted);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("【文件上传】获取或保存流水数据失败: logId={}", logId, e);
|
||||
|
||||
@@ -84,6 +84,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
#{item.overrideBsId}, #{item.paymentMethod}, #{item.cretNo}
|
||||
)
|
||||
</foreach>
|
||||
on duplicate key update
|
||||
bank_statement_id = bank_statement_id
|
||||
</insert>
|
||||
|
||||
<delete id="deleteByProjectIdAndBatchId">
|
||||
|
||||
Reference in New Issue
Block a user