🐛 修复账单导出运单号格式和列宽

This commit is contained in:
caojia
2026-10-21 14:18:27 +08:00
parent 9e61f7f55c
commit 26a3285571
@@ -115,13 +115,13 @@ public class ArBillServiceImpl implements IArBillService {
private static final int TEMPLATE_FOOTER_START_ROW = 5; private static final int TEMPLATE_FOOTER_START_ROW = 5;
private static final int TEMPLATE_COLUMN_COUNT = 21; private static final int TEMPLATE_COLUMN_COUNT = 21;
private static final double EXPORT_DETAIL_ROW_HEIGHT = 20.0; private static final double EXPORT_DETAIL_ROW_HEIGHT = 20.0;
/** 客户订单号、运单号位于 Excel 的 C、D 列,按给定样例长度并额外保留两字符边距。 */ /** 客户订单号、运单号位于 Excel 的 C、D 列,并保持相同列宽。 */
private static final int CUSTOMER_ORDER_NO_COLUMN_INDEX = 3; private static final int CUSTOMER_ORDER_NO_COLUMN_INDEX = 3;
private static final int TRACKING_NO_COLUMN_INDEX = 4; private static final int TRACKING_NO_COLUMN_INDEX = 4;
private static final int FORMULA_COLUMN_INDEX = 16; private static final int FORMULA_COLUMN_INDEX = 16;
private static final int FEE_TYPE_COLUMN_INDEX = 17; private static final int FEE_TYPE_COLUMN_INDEX = 17;
private static final double MIN_CUSTOMER_ORDER_NO_COLUMN_WIDTH = 16.0; private static final double MIN_CUSTOMER_ORDER_NO_COLUMN_WIDTH = 16.0;
private static final double MIN_TRACKING_NO_COLUMN_WIDTH = 30.0; private static final double MIN_TRACKING_NO_COLUMN_WIDTH = MIN_CUSTOMER_ORDER_NO_COLUMN_WIDTH;
private static final double MIN_FORMULA_COLUMN_WIDTH = 17.0; private static final double MIN_FORMULA_COLUMN_WIDTH = 17.0;
private static final double MIN_FEE_TYPE_COLUMN_WIDTH = 10.0; private static final double MIN_FEE_TYPE_COLUMN_WIDTH = 10.0;
/** /**
@@ -1337,6 +1337,14 @@ public class ArBillServiceImpl implements IArBillService {
failedDetailStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); failedDetailStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
failedDetailStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); failedDetailStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
int failedDetailStyleIndex = Short.toUnsignedInt(failedDetailStyle.getIndex()); int failedDetailStyleIndex = Short.toUnsignedInt(failedDetailStyle.getIndex());
XSSFCellStyle trackingNoStyle = styles.createCellStyle();
trackingNoStyle.cloneStyleFrom(styles.getStyleAt(TEMPLATE_DETAIL_STYLE_INDEX));
trackingNoStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("@"));
int trackingNoStyleIndex = Short.toUnsignedInt(trackingNoStyle.getIndex());
XSSFCellStyle failedTrackingNoStyle = styles.createCellStyle();
failedTrackingNoStyle.cloneStyleFrom(failedDetailStyle);
failedTrackingNoStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("@"));
int failedTrackingNoStyleIndex = Short.toUnsignedInt(failedTrackingNoStyle.getIndex());
XSSFCellStyle failedDetailNoStyle = styles.createCellStyle(); XSSFCellStyle failedDetailNoStyle = styles.createCellStyle();
failedDetailNoStyle.cloneStyleFrom(failedDetailStyle); failedDetailNoStyle.cloneStyleFrom(failedDetailStyle);
failedDetailNoStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("0")); failedDetailNoStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("0"));
@@ -1357,6 +1365,7 @@ public class ArBillServiceImpl implements IArBillService {
output.putNextEntry(outputEntry); output.putNextEntry(outputEntry);
if (TEMPLATE_SHEET_XML.equals(entry.getName())) { if (TEMPLATE_SHEET_XML.equals(entry.getName())) {
writeOoxmlSheet(readUtf8(templateZip), bill, output, failedDetailStyleIndex, writeOoxmlSheet(readUtf8(templateZip), bill, output, failedDetailStyleIndex,
trackingNoStyleIndex, failedTrackingNoStyleIndex,
detailNoStyleIndex, failedDetailNoStyleIndex, formulaStyleIndex, failedFormulaStyleIndex); detailNoStyleIndex, failedDetailNoStyleIndex, formulaStyleIndex, failedFormulaStyleIndex);
replaced = true; replaced = true;
} else if (TEMPLATE_STYLES_XML.equals(entry.getName())) { } else if (TEMPLATE_STYLES_XML.equals(entry.getName())) {
@@ -1417,6 +1426,7 @@ public class ArBillServiceImpl implements IArBillService {
* 以 XML 流方式写入表头、分页明细和银行信息,避免 POI 在大数据量下移动行。 * 以 XML 流方式写入表头、分页明细和银行信息,避免 POI 在大数据量下移动行。
*/ */
private void writeOoxmlSheet(String templateXml, ArBill bill, OutputStream output, int failedDetailStyleIndex, private void writeOoxmlSheet(String templateXml, ArBill bill, OutputStream output, int failedDetailStyleIndex,
int trackingNoStyleIndex, int failedTrackingNoStyleIndex,
int detailNoStyleIndex, int failedDetailNoStyleIndex, int detailNoStyleIndex, int failedDetailNoStyleIndex,
int formulaStyleIndex, int failedFormulaStyleIndex) throws IOException { int formulaStyleIndex, int failedFormulaStyleIndex) throws IOException {
int sheetDataStart = templateXml.indexOf("<sheetData"); int sheetDataStart = templateXml.indexOf("<sheetData");
@@ -1452,6 +1462,7 @@ public class ArBillServiceImpl implements IArBillService {
attachFees(details); attachFees(details);
for (ArBillDetail detail : details) { for (ArBillDetail detail : details) {
writeOoxmlDetailRow(output, rowIndex++, detail, failedDetailStyleIndex, writeOoxmlDetailRow(output, rowIndex++, detail, failedDetailStyleIndex,
trackingNoStyleIndex, failedTrackingNoStyleIndex,
detailNoStyleIndex, failedDetailNoStyleIndex, formulaStyleIndex, failedFormulaStyleIndex); detailNoStyleIndex, failedDetailNoStyleIndex, formulaStyleIndex, failedFormulaStyleIndex);
} }
lastDetailNo = details.get(details.size() - 1).getDetailNo(); lastDetailNo = details.get(details.size() - 1).getDetailNo();
@@ -1601,6 +1612,7 @@ public class ArBillServiceImpl implements IArBillService {
} }
private void writeOoxmlDetailRow(OutputStream output, int rowNumber, ArBillDetail detail, int failedDetailStyleIndex, private void writeOoxmlDetailRow(OutputStream output, int rowNumber, ArBillDetail detail, int failedDetailStyleIndex,
int trackingNoStyleIndex, int failedTrackingNoStyleIndex,
int detailNoStyleIndex, int failedDetailNoStyleIndex, int detailNoStyleIndex, int failedDetailNoStyleIndex,
int formulaStyleIndex, int failedFormulaStyleIndex) throws IOException { int formulaStyleIndex, int failedFormulaStyleIndex) throws IOException {
String failureDescription = exportBillingFailDescription(detail.getBillingFailStatus()); String failureDescription = exportBillingFailDescription(detail.getBillingFailStatus());
@@ -1623,9 +1635,14 @@ public class ArBillServiceImpl implements IArBillService {
row.append("<row r=\"").append(rowNumber).append("\" ht=\"") row.append("<row r=\"").append(rowNumber).append("\" ht=\"")
.append(EXPORT_DETAIL_ROW_HEIGHT).append("\" customHeight=\"true\" spans=\"1:21\">"); .append(EXPORT_DETAIL_ROW_HEIGHT).append("\" customHeight=\"true\" spans=\"1:21\">");
for (int index = 0; index < TEMPLATE_COLUMN_COUNT; index++) { for (int index = 0; index < TEMPLATE_COLUMN_COUNT; index++) {
int cellStyleIndex = index == 0 ? sequenceStyleIndex int cellStyleIndex = styleIndex;
: index == FORMULA_COLUMN_INDEX - 1 if (index == 0) {
? (failedDetail ? failedFormulaStyleIndex : formulaStyleIndex) : styleIndex; cellStyleIndex = sequenceStyleIndex;
} else if (index == TRACKING_NO_COLUMN_INDEX - 1) {
cellStyleIndex = failedDetail ? failedTrackingNoStyleIndex : trackingNoStyleIndex;
} else if (index == FORMULA_COLUMN_INDEX - 1) {
cellStyleIndex = failedDetail ? failedFormulaStyleIndex : formulaStyleIndex;
}
appendOoxmlCell(row, (char) ('A' + index) + String.valueOf(rowNumber), values[index], cellStyleIndex); appendOoxmlCell(row, (char) ('A' + index) + String.valueOf(rowNumber), values[index], cellStyleIndex);
} }
row.append("</row>"); row.append("</row>");