Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
|
||||
public class ArBillWorkbookWriters {
|
||||
public static final String SUMMARY_TEMPLATE_CODE = "AR_BILL_SUMMARY";
|
||||
public static final String GUANGZHOU_TEMPLATE_CODE = "AR_BILL_GZ";
|
||||
public static final String JIYUN_TEMPLATE_CODE = "AR_BILL_JY";
|
||||
private final DefaultArBillWorkbookWriter defaultWriter;
|
||||
private final SummaryArBillWorkbookWriter summaryWriter;
|
||||
|
||||
|
||||
+16
-16
@@ -31,7 +31,7 @@ import com.bms.receivable.domain.ArBillDetail;
|
||||
import com.bms.receivable.domain.ArBillDetailFee;
|
||||
import com.bms.receivable.domain.ArExportTemplate;
|
||||
|
||||
/** 默认及广州应收账单模板共用的 21 列明细和银行页脚排版。 */
|
||||
/** 默认、广州及集运应收账单模板共用的 21 列明细和银行页脚排版。 */
|
||||
@Component
|
||||
public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
private static final int TEMPLATE_DATA_START_ROW = 5;
|
||||
@@ -49,7 +49,6 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
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_FEE_TYPE_COLUMN_WIDTH = 10.0;
|
||||
private static final int TEMPLATE_DETAIL_STYLE_INDEX = 31;
|
||||
private static final String TEMPLATE_SHEET_XML = "xl/worksheets/sheet1.xml";
|
||||
private static final String TEMPLATE_SHEET_RELATIONSHIPS_XML = "xl/worksheets/_rels/sheet1.xml.rels";
|
||||
private static final String TEMPLATE_STYLES_XML = "xl/styles.xml";
|
||||
@@ -79,9 +78,10 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
public void write(ArBill bill, ArExportTemplate template, Path target) throws IOException {
|
||||
// 样式表单独读取;不加载整张工作簿,且不依赖 styles.xml 和 sheet1.xml 在 ZIP 中的先后顺序。
|
||||
StylesTable styles = readExportStyles(template);
|
||||
boolean guangzhouTemplate = ArBillWorkbookWriters.GUANGZHOU_TEMPLATE_CODE.equals(template.getTemplateCode());
|
||||
// 广州模板的样式编号与默认模板不同,使用其明细合计单元格的完整边框样式。
|
||||
int detailStyleIndex = guangzhouTemplate ? readGuangzhouDetailStyleIndex(template) : TEMPLATE_DETAIL_STYLE_INDEX;
|
||||
boolean preserveTemplatePayee = ArBillWorkbookWriters.GUANGZHOU_TEMPLATE_CODE.equals(template.getTemplateCode())
|
||||
|| ArBillWorkbookWriters.JIYUN_TEMPLATE_CODE.equals(template.getTemplateCode());
|
||||
// 所有模板都从实际单元格读取样式,兼容新增 Sheet 或重新保存后变化的样式编号。
|
||||
int detailStyleIndex = readTemplateDetailStyleIndex(template);
|
||||
if (detailStyleIndex >= styles.getNumCellStyles()) {
|
||||
throw new IOException("应收账单导出模板明细样式不存在: " + detailStyleIndex);
|
||||
}
|
||||
@@ -157,7 +157,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
}
|
||||
if (TEMPLATE_SHEET_XML.equals(entry.getName())) {
|
||||
output.putNextEntry(new ZipEntry(entryName));
|
||||
int rowOffset = writeOoxmlSheet(readUtf8(templateZip), bill, output, exportStyleIndexes, guangzhouTemplate);
|
||||
int rowOffset = writeOoxmlSheet(readUtf8(templateZip), bill, output, exportStyleIndexes, preserveTemplatePayee);
|
||||
output.closeEntry();
|
||||
replaced = true;
|
||||
drawingRowOffset = Integer.valueOf(rowOffset);
|
||||
@@ -184,7 +184,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private int readGuangzhouDetailStyleIndex(ArExportTemplate template) throws IOException {
|
||||
private int readTemplateDetailStyleIndex(ArExportTemplate template) throws IOException {
|
||||
try (InputStream input = openTemplateStream(template); ZipInputStream zip = new ZipInputStream(input)) {
|
||||
for (ZipEntry entry; (entry = zip.getNextEntry()) != null; ) {
|
||||
if (TEMPLATE_SHEET_XML.equals(entry.getName())) {
|
||||
@@ -199,12 +199,12 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IOException("广州应收账单模板缺少 S6 合计单元格样式");
|
||||
throw new IOException("应收账单模板缺少 S6 合计单元格样式: " + template.getTemplateCode());
|
||||
}
|
||||
zip.closeEntry();
|
||||
}
|
||||
}
|
||||
throw new IOException("广州应收账单模板缺少运费工作表");
|
||||
throw new IOException("应收账单模板缺少运费工作表: " + template.getTemplateCode());
|
||||
}
|
||||
|
||||
private String readTemplateDrawingPartPath(ArExportTemplate template) throws IOException {
|
||||
@@ -274,7 +274,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
}
|
||||
|
||||
private int writeOoxmlSheet(String templateXml, ArBill bill, OutputStream output,
|
||||
ExportStyleIndexes styleIndexes, boolean guangzhouTemplate) throws IOException {
|
||||
ExportStyleIndexes styleIndexes, boolean preserveTemplatePayee) throws IOException {
|
||||
int sheetDataStart = templateXml.indexOf("<sheetData");
|
||||
int sheetDataOpenEnd = templateXml.indexOf('>', sheetDataStart);
|
||||
int sheetDataEnd = templateXml.indexOf("</sheetData>", sheetDataOpenEnd);
|
||||
@@ -288,7 +288,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
removeSheetDimension(templateXml.substring(0, sheetDataOpenEnd + 1)));
|
||||
writeUtf8(output, prefix);
|
||||
|
||||
String headerRow = guangzhouTemplate ? templateRows.get(1) : replaceCellXml(templateRows.get(1), "A1",
|
||||
String headerRow = preserveTemplatePayee ? templateRows.get(1) : replaceCellXml(templateRows.get(1), "A1",
|
||||
StringUtils.isEmpty(bill.getBankAccountName()) ? "威狮国际供应链(深圳)有限公司" : bill.getBankAccountName(), false);
|
||||
writeUtf8(output, headerRow);
|
||||
writeUtf8(output, templateRows.get(2));
|
||||
@@ -316,7 +316,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
int rowOffset = lastDetailRow - TEMPLATE_LAST_DETAIL_ROW + EXPORT_FOOTER_GAP_ROWS;
|
||||
writeUtf8(output, "<row r=\"" + (lastDetailRow + 1) + "\" ht=\""
|
||||
+ EXPORT_DETAIL_ROW_HEIGHT + "\" customHeight=\"true\"/>");
|
||||
writeOoxmlFooter(output, templateRows, rowOffset, bill, styleIndexes.generalNumber(), guangzhouTemplate);
|
||||
writeOoxmlFooter(output, templateRows, rowOffset, bill, styleIndexes.generalNumber(), preserveTemplatePayee);
|
||||
String suffix = shiftFooterMerges(templateXml.substring(sheetDataEnd), rowOffset);
|
||||
writeUtf8(output, suffix);
|
||||
return rowOffset;
|
||||
@@ -419,7 +419,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
}
|
||||
|
||||
private void writeOoxmlFooter(OutputStream output, Map<Integer, String> templateRows, int rowOffset,
|
||||
ArBill bill, int generalNumberStyleIndex, boolean guangzhouTemplate) throws IOException {
|
||||
ArBill bill, int generalNumberStyleIndex, boolean preserveTemplatePayee) throws IOException {
|
||||
String totalAmountFormula = "SUM(S" + TEMPLATE_DATA_START_ROW + ":INDEX(S:S,ROW()-1))";
|
||||
for (int offset = 0; offset < 4; offset++) {
|
||||
int sourceRowNumber = TEMPLATE_LAST_DETAIL_ROW + offset + 1;
|
||||
@@ -432,7 +432,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
nvl(bill.getTotalAmount()), generalNumberStyleIndex);
|
||||
} else if (offset == 1) {
|
||||
row = replaceCellXml(row, "B" + targetRowNumber, "开户名", false);
|
||||
if (!guangzhouTemplate) {
|
||||
if (!preserveTemplatePayee) {
|
||||
row = replaceCellXml(row, "C" + targetRowNumber, bill.getBankAccountName(), false);
|
||||
}
|
||||
row = replaceCellXml(row, "P" + targetRowNumber, "本期已核销金额", false);
|
||||
@@ -440,7 +440,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
generalNumberStyleIndex);
|
||||
} else if (offset == 2) {
|
||||
row = replaceCellXml(row, "B" + targetRowNumber, "账号", false);
|
||||
if (!guangzhouTemplate) {
|
||||
if (!preserveTemplatePayee) {
|
||||
row = replaceCellXml(row, "C" + targetRowNumber, exportBankAccountNo(bill.getBankAccountNo()), false);
|
||||
}
|
||||
row = replaceCellXml(row, "P" + targetRowNumber, "本期未核销金额", false);
|
||||
@@ -449,7 +449,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
nvl(bill.getUnwrittenAmount()), generalNumberStyleIndex);
|
||||
} else {
|
||||
row = replaceCellXml(row, "B" + targetRowNumber, "开户行", false);
|
||||
if (!guangzhouTemplate) {
|
||||
if (!preserveTemplatePayee) {
|
||||
row = replaceCellXml(row, "C" + targetRowNumber, bill.getBankName(), false);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user