🐛 补全应收账单汇总模板附加费并统一零金额展示

This commit is contained in:
caojia
2026-11-18 17:29:27 +08:00
parent ad7cf3c18c
commit 837633be3c
2 changed files with 33 additions and 4 deletions
@@ -75,7 +75,11 @@ class ArBillWorkbookWriterTest {
assertEquals("说明", freight.getRow(3).getCell(19).getStringCellValue());
assertEquals("备注 & <快照>", freight.getRow(4).getCell(18).getStringCellValue());
assertEquals("", freight.getRow(4).getCell(19).getStringCellValue());
for (int column : new int[]{7, 10, 14, 16, 17}) {
for (int column : new int[]{10, 14}) {
assertEquals(0.0, freight.getRow(4).getCell(column).getNumericCellValue());
assertEquals("0.00", freight.getRow(4).getCell(column).getCellStyle().getDataFormatString());
}
for (int column : new int[]{7, 16, 17}) {
assertEquals("", freight.getRow(4).getCell(column).getStringCellValue());
}
assertEquals("SUM(P5:P7)", freight.getRow(8).getCell(15).getCellFormula());
@@ -94,6 +98,8 @@ class ArBillWorkbookWriterTest {
int count = 4001;
SummaryArBillWorkbookWriter writer = new SummaryArBillWorkbookWriter();
writer.detailMapper = mock(ArBillDetailMapper.class);
writer.detailFeeMapper = mock(ArBillDetailFeeMapper.class);
when(writer.detailFeeMapper.selectByDetailIds(anyList())).thenReturn(List.of());
List<Integer> cursors = new ArrayList<>();
when(writer.detailMapper.selectExportPage(eq(7L), anyInt(), eq(2000))).thenAnswer(invocation -> {
int previous = invocation.getArgument(1);
@@ -182,6 +188,8 @@ class ArBillWorkbookWriterTest {
private SummaryArBillWorkbookWriter summaryWriter(List<ArBillDetail> details) {
SummaryArBillWorkbookWriter writer = new SummaryArBillWorkbookWriter();
writer.detailMapper = mapper(details);
writer.detailFeeMapper = mock(ArBillDetailFeeMapper.class);
when(writer.detailFeeMapper.selectByDetailIds(anyList())).thenReturn(List.of());
return writer;
}
@@ -23,6 +23,7 @@ import java.util.zip.ZipOutputStream;
import com.bms.common.utils.StringUtils;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.domain.ArBillDetail;
import com.bms.receivable.domain.ArBillDetailFee;
import com.bms.receivable.domain.ArExportTemplate;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.FillPatternType;
@@ -42,6 +43,9 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
private static final int DETAIL_COLUMN_COUNT = 20;
private static final int SUMMARY_START_ROW = 4;
private static final String SUMMARY_REMARK = "国际货物运输代理服务费";
private static final String REMOTE_FEE_TYPE = "REMOTE";
private static final String ROMANIA_FEE_TYPE = "REGISTRATION";
private static final String ROMANIA_FEE_NAME = "罗马尼亚费用";
private static final Pattern MERGE = Pattern.compile("(<mergeCell\\b[^>]*\\bref=\")([A-Z]+)(\\d+):([A-Z]+)(\\d+)(\")");
private static final Pattern FILTER = Pattern.compile("(<autoFilter\\b[^>]*\\bref=\")[^\"]*(\")");
@@ -145,7 +149,8 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
XSSFCellStyle style = workbook.createCellStyle();
style.cloneStyleFrom(cell.getCellStyle());
boolean identifier = column == 0 || column == 2 || column == 3 || column == 6;
String format = identifier ? "@" : (column == 13 || column == 15 ? "0.00" : "General");
String format = identifier ? "@"
: (column == 10 || column == 13 || column == 14 || column == 15 ? "0.00" : "General");
style.setDataFormat(workbook.createDataFormat().getFormat(format));
cell.setCellStyle(style);
}
@@ -197,6 +202,7 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
while (true) {
List<ArBillDetail> details = detailMapper.selectExportPage(bill.getArBillId(), lastDetailNo, EXPORT_PAGE_SIZE);
if (details.isEmpty()) break;
attachFees(details);
for (ArBillDetail detail : details) {
if (rowNumber + 2 > SpreadsheetVersion.EXCEL2007.getMaxRows()) {
throw new IOException("账单订单数超过 Excel 单个工作表容量,请拆分账单后导出");
@@ -234,8 +240,10 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
detail.getTransferNo(), detail.getTrackingNo(),
StringUtils.isEmpty(detail.getProductName()) ? detail.getProductCode() : detail.getProductName(),
StringUtils.isEmpty(detail.getCountryName()) ? detail.getCountryCode() : detail.getCountryName(),
detail.getDestPostcode(), null, detail.getReceiveWeight(), detail.getChargeWeight(), null,
exportUnitPrice(detail), exportProcessingFee(detail), null, null, detail.getTotalAmount(), null, null,
detail.getDestPostcode(), null, detail.getReceiveWeight(), detail.getChargeWeight(),
exportFeeAmount(detail, REMOTE_FEE_TYPE, null),
exportUnitPrice(detail), exportProcessingFee(detail), null,
exportFeeAmount(detail, ROMANIA_FEE_TYPE, ROMANIA_FEE_NAME), detail.getTotalAmount(), null, null,
exportRemark(detail), failure
};
StringBuilder row = new StringBuilder(2048).append("<row r=\"").append(rowNumber)
@@ -256,6 +264,19 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
return row.append("</row>").toString();
}
/** 从当前账单的费用快照汇总应收金额;无匹配项输出零,负金额照常输出。 */
private BigDecimal exportFeeAmount(ArBillDetail detail, String feeType, String feeName) {
if (detail.getFees() == null) return BigDecimal.ZERO;
BigDecimal amount = BigDecimal.ZERO;
for (ArBillDetailFee fee : detail.getFees()) {
if (fee == null || !feeType.equalsIgnoreCase(StringUtils.trim(fee.getFeeType()))) continue;
// REGISTRATION 也用于其他处理费,罗马尼亚费用必须同时精确匹配名称。
if (feeName != null && !feeName.equals(StringUtils.trim(fee.getFeeName()))) continue;
amount = amount.add(nvl(fee.getAmount()));
}
return amount;
}
private void writeSummary(SheetXml sheet, ArBill bill, Map<String, ProductSummary> groups,
BigDecimal total, OutputStream output) throws IOException {
writeUtf8(output, sheet.prefix());