From 1d22bd91fdfeac2c24eb5503a8450d6c824fe79d Mon Sep 17 00:00:00 2001
From: caojia <1301869380@qq.com>
Date: Fri, 16 Oct 2026 17:43:00 +0800
Subject: [PATCH] =?UTF-8?q?:lipstick:=20=E8=B0=83=E6=95=B4=E5=BA=94?=
=?UTF-8?q?=E6=94=B6=E8=B4=A6=E5=8D=95=E5=AF=BC=E5=87=BA=E8=A1=A8=E6=A0=BC?=
=?UTF-8?q?=E5=B8=83=E5=B1=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ar/service/impl/ArBillServiceImpl.java | 33 +++++++++++++++----
1 file changed, 26 insertions(+), 7 deletions(-)
diff --git a/bms-back/bms-system/src/main/java/com/bms/ar/service/impl/ArBillServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/ar/service/impl/ArBillServiceImpl.java
index 49bb55f9..f18758ac 100644
--- a/bms-back/bms-system/src/main/java/com/bms/ar/service/impl/ArBillServiceImpl.java
+++ b/bms-back/bms-system/src/main/java/com/bms/ar/service/impl/ArBillServiceImpl.java
@@ -31,6 +31,7 @@ import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFFont;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.io.ClassPathResource;
@@ -113,6 +114,7 @@ public class ArBillServiceImpl implements IArBillService {
private static final int TEMPLATE_DATA_START_ROW = 5;
private static final int TEMPLATE_FOOTER_START_ROW = 5;
private static final int TEMPLATE_COLUMN_COUNT = 21;
+ private static final double EXPORT_DETAIL_ROW_HEIGHT = 20.0;
/** 客户订单号、运单号位于 Excel 的 C、D 列,按给定样例长度并额外保留两字符边距。 */
private static final int CUSTOMER_ORDER_NO_COLUMN_INDEX = 3;
private static final int TRACKING_NO_COLUMN_INDEX = 4;
@@ -121,7 +123,7 @@ public class ArBillServiceImpl implements IArBillService {
private static final double MIN_CUSTOMER_ORDER_NO_COLUMN_WIDTH = 20.0;
private static final double MIN_TRACKING_NO_COLUMN_WIDTH = 35.0;
private static final double MIN_FORMULA_COLUMN_WIDTH = 25.0;
- private static final double MIN_FEE_TYPE_COLUMN_WIDTH = 25.0;
+ private static final double MIN_FEE_TYPE_COLUMN_WIDTH = 10.0;
/**
* 单次查询订单数;费用仅查询当前订单批次,避免大账单占满堆内存。
*/
@@ -1305,6 +1307,18 @@ public class ArBillServiceImpl implements IArBillService {
failedDetailNoStyle.cloneStyleFrom(failedDetailStyle);
failedDetailNoStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("0"));
int failedDetailNoStyleIndex = Short.toUnsignedInt(failedDetailNoStyle.getIndex());
+ XSSFFont formulaFont = new XSSFFont();
+ formulaFont.getCTFont().set(styles.getFontAt(
+ styles.getStyleAt(TEMPLATE_DETAIL_STYLE_INDEX).getFontIndexAsInt()).getCTFont());
+ formulaFont.setFontHeightInPoints((short) 9);
+ XSSFCellStyle formulaStyle = styles.createCellStyle();
+ formulaStyle.cloneStyleFrom(styles.getStyleAt(TEMPLATE_DETAIL_STYLE_INDEX));
+ formulaStyle.setFont(formulaFont);
+ int formulaStyleIndex = Short.toUnsignedInt(formulaStyle.getIndex());
+ XSSFCellStyle failedFormulaStyle = styles.createCellStyle();
+ failedFormulaStyle.cloneStyleFrom(failedDetailStyle);
+ failedFormulaStyle.setFont(formulaFont);
+ int failedFormulaStyleIndex = Short.toUnsignedInt(failedFormulaStyle.getIndex());
try (InputStream input = openTemplateStream(template); ZipInputStream templateZip = new ZipInputStream(input);
OutputStream fileOutput = Files.newOutputStream(target); ZipOutputStream output = new ZipOutputStream(fileOutput)) {
boolean replaced = false;
@@ -1313,7 +1327,7 @@ public class ArBillServiceImpl implements IArBillService {
output.putNextEntry(outputEntry);
if (TEMPLATE_SHEET_XML.equals(entry.getName())) {
writeOoxmlSheet(readUtf8(templateZip), bill, output, failedDetailStyleIndex,
- detailNoStyleIndex, failedDetailNoStyleIndex);
+ detailNoStyleIndex, failedDetailNoStyleIndex, formulaStyleIndex, failedFormulaStyleIndex);
replaced = true;
} else if (TEMPLATE_STYLES_XML.equals(entry.getName())) {
styles.writeTo(output);
@@ -1373,7 +1387,8 @@ public class ArBillServiceImpl implements IArBillService {
* 以 XML 流方式写入表头、分页明细和银行信息,避免 POI 在大数据量下移动行。
*/
private void writeOoxmlSheet(String templateXml, ArBill bill, OutputStream output, int failedDetailStyleIndex,
- int detailNoStyleIndex, int failedDetailNoStyleIndex) throws IOException {
+ int detailNoStyleIndex, int failedDetailNoStyleIndex,
+ int formulaStyleIndex, int failedFormulaStyleIndex) throws IOException {
int sheetDataStart = templateXml.indexOf("', sheetDataStart);
int sheetDataEnd = templateXml.indexOf("", sheetDataOpenEnd);
@@ -1407,7 +1422,7 @@ public class ArBillServiceImpl implements IArBillService {
attachFees(details);
for (ArBillDetail detail : details) {
writeOoxmlDetailRow(output, rowIndex++, detail, failedDetailStyleIndex,
- detailNoStyleIndex, failedDetailNoStyleIndex);
+ detailNoStyleIndex, failedDetailNoStyleIndex, formulaStyleIndex, failedFormulaStyleIndex);
}
lastDetailNo = details.get(details.size() - 1).getDetailNo();
}
@@ -1552,7 +1567,8 @@ public class ArBillServiceImpl implements IArBillService {
}
private void writeOoxmlDetailRow(OutputStream output, int rowNumber, ArBillDetail detail, int failedDetailStyleIndex,
- int detailNoStyleIndex, int failedDetailNoStyleIndex) throws IOException {
+ int detailNoStyleIndex, int failedDetailNoStyleIndex,
+ int formulaStyleIndex, int failedFormulaStyleIndex) throws IOException {
String failureDescription = exportBillingFailDescription(detail.getBillingFailStatus());
boolean failedDetail = !failureDescription.isEmpty();
int styleIndex = failedDetail ? failedDetailStyleIndex : TEMPLATE_DETAIL_STYLE_INDEX;
@@ -1570,9 +1586,12 @@ public class ArBillServiceImpl implements IArBillService {
failureDescription
};
StringBuilder row = new StringBuilder(2048);
- row.append("");
+ row.append("");
for (int index = 0; index < TEMPLATE_COLUMN_COUNT; index++) {
- int cellStyleIndex = index == 0 ? sequenceStyleIndex : styleIndex;
+ int cellStyleIndex = index == 0 ? sequenceStyleIndex
+ : index == FORMULA_COLUMN_INDEX - 1
+ ? (failedDetail ? failedFormulaStyleIndex : formulaStyleIndex) : styleIndex;
appendOoxmlCell(row, (char) ('A' + index) + String.valueOf(rowNumber), values[index], cellStyleIndex);
}
row.append("
");