🔥 移除账单导出模板收款账户一致性校验
This commit is contained in:
+12
-30
@@ -112,38 +112,20 @@ class ArBillTemplateSelectionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void fixedPayeeTemplatesRejectMismatchesBeforeCreatingExportTasks() {
|
||||
ArExportTemplate fixed = template(3L, ArBillWorkbookWriters.GUANGZHOU_TEMPLATE_CODE);
|
||||
fixed.setStorageKey("templates/receivable/ar_bill_template_gz.xlsx");
|
||||
when(templates.selectEnabledById(3L, "AR_BILL", bill.getBillDate())).thenReturn(fixed);
|
||||
bill.setBankAccountName("威狮国际供应链(深圳)有限公司广州分公司");
|
||||
bill.setBankAccountNo("44050129162500001250");
|
||||
bill.setBankName("中国建设银行股份有限公司广州设计之都支行");
|
||||
assertEquals(3L, service.exportBill(7L, 3L, "admin", "matching").getTemplateId());
|
||||
|
||||
void fixedPayeeTemplatesAllowDifferentBillAccountSnapshots() {
|
||||
bill.setBankAccountName("其他收款单位");
|
||||
bill.setBankAccountNo("1234567890");
|
||||
ServiceException error = assertThrows(ServiceException.class,
|
||||
() -> service.exportBill(7L, 3L, "admin", "mismatch"));
|
||||
assertTrue(error.getMessage().contains("收款信息"));
|
||||
verify(exports, times(1)).insert(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fixedPayeeTemplateValidationChecksNameAccountAndBankForBothTemplates() {
|
||||
ArBillWorkbookWriters writers = new ArBillWorkbookWriters(new DefaultArBillWorkbookWriter(), new SummaryArBillWorkbookWriter());
|
||||
ArExportTemplate fixed = template(3L, ArBillWorkbookWriters.JIYUN_TEMPLATE_CODE);
|
||||
fixed.setStorageKey("templates/receivable/ar_bill_template_jy.xlsx");
|
||||
bill.setBankAccountName("威狮国际集运物流(深圳)有限公司");
|
||||
bill.setBankAccountNo("86021110000892050");
|
||||
bill.setBankName("宁波银行深圳后海支行");
|
||||
assertDoesNotThrow(() -> writers.validatePayee(bill, fixed));
|
||||
bill.setBankName("其他银行");
|
||||
assertThrows(ServiceException.class, () -> writers.validatePayee(bill, fixed));
|
||||
bill.setBankName("宁波银行深圳后海支行");
|
||||
bill.setBankAccountName("其他公司");
|
||||
assertThrows(ServiceException.class, () -> writers.validatePayee(bill, fixed));
|
||||
bill.setBankAccountName(null);
|
||||
assertThrows(ServiceException.class, () -> writers.validatePayee(bill, fixed));
|
||||
ArExportTemplate guangzhou = template(3L, ArBillWorkbookWriters.GUANGZHOU_TEMPLATE_CODE);
|
||||
guangzhou.setStorageKey("templates/receivable/ar_bill_template_gz.xlsx");
|
||||
ArExportTemplate jiyun = template(4L, ArBillWorkbookWriters.JIYUN_TEMPLATE_CODE);
|
||||
jiyun.setStorageKey("templates/receivable/ar_bill_template_jy.xlsx");
|
||||
when(templates.selectEnabledById(3L, "AR_BILL", bill.getBillDate())).thenReturn(guangzhou);
|
||||
when(templates.selectEnabledById(4L, "AR_BILL", bill.getBillDate())).thenReturn(jiyun);
|
||||
|
||||
assertEquals(3L, service.exportBill(7L, 3L, "admin", "gz-export").getTemplateId());
|
||||
assertEquals(4L, service.exportBill(7L, 4L, "admin", "jy-export").getTemplateId());
|
||||
verify(exports, times(2)).insert(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
-15
@@ -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("无法读取所选模板的收款信息,请检查模板配置");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-24
@@ -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 中的先后顺序。
|
||||
|
||||
-2
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user