🔥 移除账单导出模板收款账户一致性校验

This commit is contained in:
caojia
2026-11-20 14:56:44 +08:00
parent 0caeb2ce88
commit 4fdb1d5802
4 changed files with 12 additions and 71 deletions
@@ -1,8 +1,5 @@
package com.bms.receivable.export;
import java.io.IOException;
import com.bms.common.exception.ServiceException;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.domain.ArExportTemplate;
import org.springframework.stereotype.Component;
@@ -28,16 +25,4 @@ public class ArBillWorkbookWriters {
return SUMMARY_TEMPLATE_CODE.equals(template.getTemplateCode());
}
/** 固定收款信息的模板必须与账单快照一致,避免导出错误的收款账户。 */
public void validatePayee(ArBill bill, ArExportTemplate template) {
if (!GUANGZHOU_TEMPLATE_CODE.equals(template.getTemplateCode())
&& !JIYUN_TEMPLATE_CODE.equals(template.getTemplateCode())) return;
try {
if (!defaultWriter.matchesTemplatePayee(bill, template)) {
throw new ServiceException("所选模板的固定收款信息与账单收款账户不一致,请选择匹配的模板");
}
} catch (IOException e) {
throw new ServiceException("无法读取所选模板的收款信息,请检查模板配置");
}
}
}
@@ -19,10 +19,8 @@ import java.util.zip.ZipOutputStream;
import org.apache.poi.ss.usermodel.BuiltinFormats;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Component;
import com.bms.common.utils.StringUtils;
import com.bms.receivable.domain.ArBill;
@@ -73,28 +71,6 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
int formula, int failedFormula) {
}
/** 首表 C7:C9 是固定开户名、账号和开户行;空值不得通过匹配。 */
public boolean matchesTemplatePayee(ArBill bill, ArExportTemplate template) throws IOException {
try (InputStream input = openTemplateStream(template); XSSFWorkbook workbook = new XSSFWorkbook(input)) {
if (workbook.getNumberOfSheets() == 0) return false;
var sheet = workbook.getSheetAt(0);
DataFormatter formatter = new DataFormatter();
String[] expected = {bill.getBankAccountName(), bill.getBankAccountNo(), bill.getBankName()};
for (int i = 0; i < expected.length; i++) {
var row = sheet.getRow(6 + i);
var cell = row == null ? null : row.getCell(2);
String actual = cell == null ? "" : formatter.formatCellValue(cell);
String snapshot = normalizePayeeValue(expected[i]);
if (snapshot.isEmpty() || !snapshot.equals(normalizePayeeValue(actual))) return false;
}
return true;
}
}
private String normalizePayeeValue(String value) {
return value == null ? "" : value.replaceAll("[\\s\\p{Z}]+", "");
}
@Override
public void write(ArBill bill, ArExportTemplate template, Path target) throws IOException {
// 样式表单独读取;不加载整张工作簿,且不依赖 styles.xml 和 sheet1.xml 在 ZIP 中的先后顺序。
@@ -1051,7 +1051,6 @@ public class ArBillServiceImpl implements IArBillService {
bill.getStatus(), templateId == null ? "未配置启用中的应收账单默认导出模板"
: "所选应收账单模板不存在、已停用或不在生效期内,请重新选择", operator, requestId);
}
workbookWriters.validatePayee(bill, template);
ArBillExport processing = exportMapper.selectProcessingByBillAndTemplate(arBillId, template.getTemplateId());
if (processing != null) {
log.info("应收账单导出任务已存在,operator={}, requestId={}, arBillId={}, exportId={}, status={}, costMs={}",
@@ -1129,7 +1128,6 @@ public class ArBillServiceImpl implements IArBillService {
String objectKey = "ar/bill/" + DateUtils.datePath() + "/" + IdUtils.fastSimpleUUID() + ".xlsx";
temp = Files.createTempFile("ar-bill-export-", ".xlsx");
ArExportTemplate template = resolveExportTemplate(export, bill);
workbookWriters.validatePayee(bill, template);
workbookWriters.select(template).write(bill, template, temp);
export.setFileSize(Files.size(temp));
export.setFileHash(sha256(temp));