From 2db6555b40825a3f7b813826d796802105e38da3 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期四, 23 四月 2026 09:53:10 +0800
Subject: [PATCH] 导出销售台账送货单
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 49 ++++++++++++++++++++++++++++++++++---------------
1 files changed, 34 insertions(+), 15 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 c09ccd0..ceefa17 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -246,7 +246,6 @@
response.setHeader("Content-Disposition", "attachment;filename=閫佽揣鍗�.zip");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
- // 鐩存帴鍐呭瓨鎵撳寘锛屾姏寮冧复鏃舵枃浠�
try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) {
for (SalesLedger ledger : salesLedgerList) {
@@ -259,11 +258,25 @@
// 鑷姩搴忓彿
for (int i = 0; i < productList.size(); i++) {
- productList.get(i).setSerialNumber(i + 1);
+ SalesLedgerProduct product = productList.get(i);
+ if (product != null) {
+ product.setSerialNumber(i + 1);
+ product.setOrderNo(ledger.getSalesContractNo());
+ // 瀹夊叏鑾峰彇鐗╂枡缂栫爜
+ Long productModelId = product.getProductModelId();
+ if (productModelId != null) {
+ ProductModel productModel = productModelMapper.selectById(productModelId);
+ if (productModel != null) {
+ product.setMaterialCode(productModel.getMaterialCode());
+ }
+ }
+ }
+
}
// 鍏宠仈鏌ヨ瀹㈡埛淇℃伅
Customer customer = customerMapper.selectById(ledger.getCustomerId());
+
// 缁勮鏁版嵁
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("customerName", ledger.getCustomerName());
@@ -273,24 +286,30 @@
dataMap.put("companyPhone", customer.getCompanyPhone());
dataMap.put("salesContractNo", ledger.getSalesContractNo());
dataMap.put("deliveryDate", formatDate(LocalDate.now()));
- // 鏀惧叆鍟嗗搧闆嗗悎
- dataMap.put("products", productList);
+ BigDecimal totalQuantity = new BigDecimal(0);
+ for (SalesLedgerProduct product : productList) {
+ totalQuantity = totalQuantity.add(product.getQuantity() == null ? BigDecimal.ZERO : product.getQuantity());
+ }
+ dataMap.put("totalQuantity", totalQuantity);
- // 姣忔寰幆鍏ㄦ柊璇诲彇妯℃澘锛屽交搴曡В鍐虫祦闂
+ // 鐢熸垚Excel
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (InputStream templateIs = this.getClass().getResourceAsStream("/static/shipping-note.xlsx")) {
- if (templateIs == null) throw new BaseException("妯℃澘鏂囦欢涓嶅瓨鍦�");
+ InputStream templateIs = this.getClass().getResourceAsStream("/static/shipping-note.xlsx");
- // EasyExcel濉厖
- ExcelWriter writer = EasyExcel.write(bos).withTemplate(templateIs).build();
- WriteSheet sheet = EasyExcel.writerSheet().build();
- writer.fill(dataMap, sheet);
- writer.finish();
+ ExcelWriter writer = EasyExcel.write(bos).withTemplate(templateIs).build();
+ WriteSheet sheet = EasyExcel.writerSheet().build();
+
+ writer.fill(dataMap, sheet);
+
+ if (!productList.isEmpty()) {
+ writer.fill(productList, sheet);
}
- // 鎵撳寘杩沍IP
- String excelName = String.format("閫佽揣鍗昣%s.xlsx",
- Optional.ofNullable(ledger.getSalesContractNo()).orElse(String.valueOf(ledger.getId())));
+ writer.finish();
+ templateIs.close();
+
+ // 鍐欏叆ZIP
+ String excelName = String.format("閫佽揣鍗昣%s.xlsx", Optional.ofNullable(ledger.getSalesContractNo()).orElse(String.valueOf(ledger.getId())));
ZipEntry entry = new ZipEntry(excelName);
zos.putNextEntry(entry);
zos.write(bos.toByteArray());
--
Gitblit v1.9.3