From 867ebb2c2110a79899bc9e58afdd89d97e956426 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期四, 23 四月 2026 14:18:40 +0800
Subject: [PATCH] 导出销售台账送货单
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 96 ++++++++++++++++++++++++++++--------------------
1 files changed, 56 insertions(+), 40 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index 3b6ea8c..e5bd365 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -240,7 +240,6 @@
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
- // 鍥哄畾浣跨敤 XSSFWorkbook
XSSFWorkbook workbook = new XSSFWorkbook();
for (SalesLedger ledger : ledgerList) {
@@ -254,7 +253,6 @@
sheet.setColumnWidth(5, 4500);
sheet.setColumnWidth(6, 3500);
- // 鏍峰紡
CellStyle companyTitle = createBaseStyle(workbook, "瀹嬩綋", (short) 20, true, true);
CellStyle billTitle = createBaseStyle(workbook, "瀹嬩綋", (short) 18, true, true);
CellStyle headerStyle = createBorderStyle(workbook, "瀹嬩綋", (short) 12, true, true);
@@ -294,72 +292,90 @@
Row row7 = sheet.createRow(7);
row7.createCell(0).setCellValue("璐х墿璇︾粏淇℃伅锛�");
- // 琛ㄥご
+ // 琛ㄥご锛氬叡鍥涜仈 + 铏氱嚎
int tableStart = 8;
Row headerRow = sheet.createRow(tableStart);
String[] headers = {"搴忓彿", "鐗╂枡缂栧彿", "鍝佸悕/瑙勬牸", "鍗曚綅", "鏁伴噺", "璁㈠崟鍙�", "鍏卞洓鑱�"};
for (int i = 0; i < headers.length; i++) {
Cell hc = headerRow.createCell(i);
hc.setCellValue(headers[i]);
- hc.setCellStyle(i == 6 ? noBorder : headerStyle);
+ if (i == 6) {
+ hc.setCellStyle(dashStyle);
+ } else {
+ hc.setCellStyle(headerStyle);
+ }
}
- // 鏌ヨ鍟嗗搧
+ // 鏌ヨ褰撳墠鍗曟嵁鎵�鏈変骇鍝�
SalesLedgerProduct cond = new SalesLedgerProduct();
cond.setSalesLedgerId(ledger.getId());
List<SalesLedgerProduct> productList = salesLedgerProductServiceImpl.selectSalesLedgerProductList(cond);
BigDecimal totalQuantity = BigDecimal.ZERO;
- for (SalesLedgerProduct product : productList) {
- totalQuantity = totalQuantity.add(product.getQuantity() == null ? BigDecimal.ZERO : product.getQuantity());
+ for (SalesLedgerProduct p : productList) {
+ if (p.getQuantity() != null) {
+ totalQuantity = totalQuantity.add(p.getQuantity());
+ }
}
int currentRow = tableStart + 1;
String[] fourNames = {"瀛樻牴", "鍥炲崟", "瀹㈡埛", "浠撳簱"};
- int minDataRow = 5;
- int totalNeedRow = Math.max(minDataRow, fourNames.length);
- // 鏁版嵁琛� + 鍥哄畾鍥涜仈琛�
- for (int i = 0; i < totalNeedRow; i++) {
- SalesLedgerProduct p = i < productList.size() ? productList.get(i) : null;
- Row dataRow = sheet.createRow(currentRow);
+ // ===================== 1. 鍏堟覆鏌撴墍鏈変骇鍝� =====================
+ for (int i = 0; i < productList.size(); i++) {
+ SalesLedgerProduct p = productList.get(i);
+ Row dataRow = sheet.createRow(currentRow++);
- // 鍓�6鍒楄祴鍊�
- if (p != null) {
- String materialCode = "";
- if (p.getProductModelId() != null) {
- ProductModel m = productModelMapper.selectById(p.getProductModelId());
- if (m != null) {
- materialCode = m.getMaterialCode();
- }
- }
- dataRow.createCell(0).setCellValue(i + 1);
- dataRow.createCell(1).setCellValue(materialCode);
- dataRow.createCell(2).setCellValue(p.getProductCategory() + "/" + p.getSpecificationModel());
- dataRow.createCell(3).setCellValue(p.getUnit());
- dataRow.createCell(4).setCellValue(p.getQuantity() == null ? 0 : p.getQuantity().doubleValue());
- dataRow.createCell(5).setCellValue(ledger.getSalesContractNo());
- } else {
- for (int c = 0; c <= 5; c++) {
- dataRow.createCell(c);
- }
+ String materialCode = "";
+ if (p.getProductModelId() != null) {
+ ProductModel m = productModelMapper.selectById(p.getProductModelId());
+ if (m != null) materialCode = m.getMaterialCode();
}
- // 鍓�6鍒楁牱寮�
- for (int c = 0; c <= 5; c++) {
- dataRow.getCell(c).setCellStyle(dataCenterStyle);
- }
+ dataRow.createCell(0).setCellValue(i + 1);
+ dataRow.createCell(1).setCellValue(materialCode);
+ dataRow.createCell(2).setCellValue(p.getProductCategory() + "/" + p.getSpecificationModel());
+ dataRow.createCell(3).setCellValue(p.getUnit());
+ dataRow.createCell(4).setCellValue(p.getQuantity() == null ? 0 : p.getQuantity().doubleValue());
+ dataRow.createCell(5).setCellValue(ledger.getSalesContractNo());
- // 鍏卞洓鑱斿垪
+ for (int c = 0; c <= 5; c++) dataRow.getCell(c).setCellStyle(dataCenterStyle);
+
Cell fourCell = dataRow.createCell(6);
if (i < fourNames.length) {
fourCell.setCellValue(fourNames[i]);
- fourCell.setCellStyle(dashStyle);
+ if (i <= 2) {
+ fourCell.setCellStyle(dashStyle);
+ } else {
+ fourCell.setCellStyle(noBorder);
+ }
} else {
fourCell.setCellStyle(noBorder);
}
+ }
- currentRow++;
+ // ===================== 2. 涓嶈冻6琛� 鈫� 琛ョ┖琛� =====================
+ int minRow = 6;
+ int needEmpty = Math.max(0, minRow - productList.size());
+ for (int i = 0; i < needEmpty; i++) {
+ int seq = productList.size() + i;
+ Row dataRow = sheet.createRow(currentRow++);
+
+ for (int c = 0; c <= 5; c++) {
+ dataRow.createCell(c).setCellStyle(dataCenterStyle);
+ }
+
+ Cell fourCell = dataRow.createCell(6);
+ if (seq < fourNames.length) {
+ fourCell.setCellValue(fourNames[seq]);
+ if (seq <= 2) {
+ fourCell.setCellStyle(dashStyle);
+ } else {
+ fourCell.setCellStyle(noBorder);
+ }
+ } else {
+ fourCell.setCellStyle(noBorder);
+ }
}
// 鍚堣琛�
@@ -392,7 +408,7 @@
} catch (Exception e) {
log.error("鎵归噺瀵煎嚭閫佽揣鍗曞紓甯�", e);
- throw new BaseException("鎵归噺瀵煎嚭澶辫触");
+ throw new RuntimeException("瀵煎嚭澶辫触");
}
}
--
Gitblit v1.9.3