From 4d99e718536ac77dff26dde8da7a59cdc9b52de8 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期三, 20 五月 2026 10:13:57 +0800
Subject: [PATCH] fix:1.生产报工优化
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 339 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 312 insertions(+), 27 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 2e0b507..3e7bc29 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -34,12 +34,16 @@
import com.ruoyi.sales.dto.*;
import com.ruoyi.sales.mapper.*;
import com.ruoyi.sales.pojo.*;
+import com.ruoyi.sales.service.ISalesLedgerProductService;
import com.ruoyi.sales.service.ISalesLedgerService;
-import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.mapper.StockInventoryMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -49,11 +53,13 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -131,6 +137,8 @@
private final StockInventoryMapper stockInventoryMapper;
+ private ISalesLedgerProductService salesLedgerProductService;
+
@Autowired
private SysDeptMapper sysDeptMapper;
@@ -207,6 +215,275 @@
resultDto.setSalesLedgerFiles(salesLedgerFiles);
}
return resultDto;
+ }
+
+ @Override
+ public void exportShippingNote(HttpServletResponse response, List<Long> ids) {
+ try {
+ List<SalesLedger> ledgerList = salesLedgerMapper.selectBatchIds(ids);
+ String fileName = "閫佽揣鍗�.xlsx";
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
+ response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
+
+ XSSFWorkbook workbook = new XSSFWorkbook();
+
+ for (SalesLedger ledger : ledgerList) {
+ XSSFSheet sheet = workbook.createSheet(ledger.getSalesContractNo());
+
+ // 璁剧疆椤佃竟璺濓紙鍗曚綅锛氳嫳瀵革紝1鑻卞=2.54鍘樼背锛�
+ sheet.getPrintSetup().setLandscape(false); // 绾靛悜鎵撳嵃
+ sheet.setMargin(Sheet.TopMargin, 0.54 / 2.54); // 涓婇〉杈硅窛锛�0.54鍘樼背
+ sheet.setMargin(Sheet.BottomMargin, 0.54 / 2.54); // 涓嬮〉杈硅窛锛�0.54鍘樼背
+ sheet.setMargin(Sheet.LeftMargin, 0.41 / 2.54); // 宸﹂〉杈硅窛锛�0.41鍘樼背
+ sheet.setMargin(Sheet.RightMargin, 0.41 / 2.54); // 鍙抽〉杈硅窛锛�0.41鍘樼背
+ sheet.setMargin(Sheet.HeaderMargin, 0.77 / 2.54); // 椤电湁锛�0.77鍘樼背
+ sheet.setMargin(Sheet.FooterMargin, 0.27 / 2.54); // 椤佃剼锛�0.27鍘樼背
+
+ sheet.setColumnWidth(0, 1310);
+ sheet.setColumnWidth(1, 4000);
+ sheet.setColumnWidth(2, 8980);
+ sheet.setColumnWidth(3, 1820);
+ sheet.setColumnWidth(4, 2880);
+ sheet.setColumnWidth(5, 5090);
+ sheet.setColumnWidth(6, 1410);
+
+ CellStyle companyTitle = createBaseStyle(workbook, "瀹嬩綋", (short) 20, true, true);
+ CellStyle billTitle = createBaseStyle(workbook, "瀹嬩綋", (short) 18, false, true);
+ CellStyle headerStyle = createBorderStyle(workbook, "瀹嬩綋", (short) 12, true, true);
+ CellStyle dataCenterStyle = createBorderStyle(workbook, "瀹嬩綋", (short) 11, false, true);
+
+ // 鏍峰紡1锛氬甫铏氱嚎 + 灞呬腑
+ CellStyle dashStyle = createDashBottomStyle(workbook);
+ dashStyle.setAlignment(HorizontalAlignment.CENTER);
+ dashStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+
+ // 鏍峰紡2锛氭棤杈规 + 灞呬腑锛堢粰浠撳簱鐢級
+ CellStyle centerNoBorder = createNoBorderStyle(workbook);
+ centerNoBorder.setAlignment(HorizontalAlignment.CENTER);
+ centerNoBorder.setVerticalAlignment(VerticalAlignment.CENTER);
+
+ // 鏍囬
+ Row row0 = sheet.createRow(0);
+ row0.createCell(0).setCellValue("婀栧崡楣忓垱鐢靛瓙鏈夐檺鍏徃");
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
+ fillMergeRange(sheet, 0, 0, 0, 6, companyTitle);
+
+ Row row1 = sheet.createRow(1);
+ row1.createCell(0).setCellValue("閫� 璐� 鍗�");
+ sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6));
+ fillMergeRange(sheet, 1, 1, 0, 6, billTitle);
+
+ Customer customer = customerMapper.selectById(ledger.getCustomerId());
+
+ Row row2 = sheet.createRow(2);
+ row2.setHeightInPoints(13);
+ row2.createCell(0).setCellValue("瀹㈡埛鍚嶇О锛�" + ledger.getCustomerName());
+ row2.createCell(4).setCellValue("鍗曟嵁缂栧彿锛�" + ledger.getSalesContractNo());
+
+ Row row3 = sheet.createRow(3);
+ row3.setHeightInPoints(13);
+ row3.createCell(0).setCellValue("閫佽揣鍦板潃锛�" + customer.getCompanyAddress());
+ row3.createCell(4).setCellValue("閫佽揣鏃ユ湡锛�" + formatDate(LocalDate.now()));
+
+ // 绌鸿
+ Row row4 = sheet.createRow(4);
+ row4.setHeightInPoints(13);
+ row4.createCell(4).setCellValue("鑱旂郴鐢佃瘽锛�" + customer.getCompanyPhone());
+
+ Row row5 = sheet.createRow(5);
+ row5.createCell(0).setCellValue("鑱旂郴鏂瑰紡锛�" + customer.getContactPerson() + " " + customer.getContactPhone());
+ Row row6 = sheet.createRow(6);
+ row6.createCell(0).setCellValue("閫佽揣鍗曚綅锛氭箹鍗楅箯鍒涚數瀛愭湁闄愬叕鍙�");
+ Row row7 = sheet.createRow(7);
+ row7.createCell(0).setCellValue("鍦板潃锛氭箹鍗楃渷鑰掗槼甯傚垱鏂板垱涓氬洯A1鏍�");
+ Row row8 = sheet.createRow(8);
+ row8.setHeightInPoints((short) 3); // 琛岄珮3纾�
+ Row row9 = sheet.createRow(9);
+ row9.createCell(0).setCellValue("璐х墿璇︾粏淇℃伅锛�");
+
+ int tableStart = 10;
+ Row headerRow = sheet.createRow(tableStart);
+ headerRow.setHeightInPoints((short) 18);
+
+ String[] headers = {"搴忓彿", "鐗╂枡缂栧彿", "鍝佸悕/瑙勬牸", "鍗曚綅", "鏁伴噺", "璁㈠崟鍙�", "鍏卞洓鑱�"};
+ for (int i = 0; i < headers.length; i++) {
+ Cell hc = headerRow.createCell(i);
+ hc.setCellValue(headers[i]);
+ 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 p : productList) {
+ if (p.getQuantity() != null) totalQuantity = totalQuantity.add(p.getQuantity());
+ }
+
+ int currentRow = tableStart + 1;
+ String[] fourNames = {"瀛樻牴", "鍥炲崟", "瀹㈡埛", "浠撳簱"};
+
+ // 1. 鎵�鏈変骇鍝�
+ for (int i = 0; i < productList.size(); i++) {
+ SalesLedgerProduct p = productList.get(i);
+ Row dataRow = sheet.createRow(currentRow++);
+ dataRow.setHeightInPoints((short) 18);
+
+ 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());
+
+ 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]);
+ if (i <= 2) {
+ fourCell.setCellStyle(dashStyle);
+ } else {
+ fourCell.setCellStyle(centerNoBorder);
+ }
+ } else {
+ fourCell.setCellStyle(centerNoBorder);
+ }
+ }
+
+ // 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++);
+ dataRow.setHeightInPoints((short) 18);
+
+ 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(centerNoBorder);
+ }
+ } else {
+ fourCell.setCellStyle(centerNoBorder);
+ }
+ }
+
+ // 鍚堣
+ Row totalRow = sheet.createRow(currentRow);
+ totalRow.setHeightInPoints((short) 18);
+
+ // 鍚堣鏀惧湪绗簩鍒楋紝涓嶅悎骞跺崟鍏冩牸
+ totalRow.createCell(1).setCellValue("鍚堣");
+ totalRow.createCell(4).setCellValue(totalQuantity.doubleValue());
+
+ // 璁剧疆鏍峰紡
+ for (int c = 0; c <= 5; c++) {
+ Cell cell = totalRow.getCell(c) != null ? totalRow.getCell(c) : totalRow.createCell(c);
+ cell.setCellStyle(dataCenterStyle);
+ }
+ totalRow.createCell(6).setCellStyle(centerNoBorder);
+
+ currentRow++;
+ Row emptyRow1 = sheet.createRow(currentRow);
+ emptyRow1.setHeightInPoints((short) 9); // 琛岄珮9纾�
+
+ currentRow++;
+ Row remarkRow = sheet.createRow(currentRow);
+ remarkRow.createCell(0).setCellValue("澶囨敞锛氳吹鍙稿湪鏀惰揣鍚庤鍗冲埢鏍稿疄鏁伴噺鍙婂搧璐紝鑻ユ湁寮傝锛岃鍦�3鏃ュ唴鎻愬嚭锛屽惁鍒欒涓烘敹濡ャ��");
+ sheet.addMergedRegion(new CellRangeAddress(currentRow, currentRow, 0, 6));
+
+ currentRow++;
+ Row emptyRow2 = sheet.createRow(currentRow);
+ emptyRow2.setHeightInPoints((short) 9); // 琛岄珮9纾�
+
+ currentRow++;
+ Row sign1 = sheet.createRow(currentRow);
+ sign1.createCell(0).setCellValue("閫佽揣鍗曚綅锛堢绔狅級锛�");
+ sign1.createCell(4).setCellValue("鏀惰揣鍗曚綅锛�");
+
+ currentRow++;
+ Row sign2 = sheet.createRow(currentRow);
+ sign2.createCell(0).setCellValue("閫佽揣浜猴細");
+ sign2.createCell(4).setCellValue("鏀惰揣浜猴細");
+ }
+
+ workbook.write(response.getOutputStream());
+ workbook.close();
+
+ } catch (Exception e) {
+ log.error("鎵归噺瀵煎嚭閫佽揣鍗曞紓甯�", e);
+ throw new RuntimeException("瀵煎嚭澶辫触");
+ }
+ }
+
+ // 宸ュ叿绫�
+ private CellStyle createBaseStyle(Workbook workbook, String fontName, short fontSize, boolean bold, boolean center) {
+ CellStyle style = workbook.createCellStyle();
+ Font font = workbook.createFont();
+ font.setFontName(fontName);
+ font.setFontHeightInPoints(fontSize);
+ font.setBold(bold);
+ style.setFont(font);
+ if (center) {
+ style.setAlignment(HorizontalAlignment.CENTER);
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
+ }
+ return style;
+ }
+
+ private CellStyle createBorderStyle(Workbook workbook, String fontName, short fontSize, boolean bold, boolean center) {
+ CellStyle style = createBaseStyle(workbook, fontName, fontSize, bold, center);
+ style.setBorderTop(BorderStyle.THIN);
+ style.setBorderBottom(BorderStyle.THIN);
+ style.setBorderLeft(BorderStyle.THIN);
+ style.setBorderRight(BorderStyle.THIN);
+ return style;
+ }
+
+ private CellStyle createNoBorderStyle(Workbook workbook) {
+ return createBaseStyle(workbook, "瀹嬩綋", (short) 11, false, false);
+ }
+
+ private CellStyle createDashBottomStyle(Workbook workbook) {
+ CellStyle style = createNoBorderStyle(workbook);
+ style.setBorderBottom(BorderStyle.DASHED);
+ return style;
+ }
+
+ private void fillMergeRange(Sheet sheet, int startR, int endR, int startC, int endC, CellStyle style) {
+ for (int r = startR; r <= endR; r++) {
+ Row row = sheet.getRow(r) == null ? sheet.createRow(r) : sheet.getRow(r);
+ for (int c = startC; c <= endC; c++) {
+ Cell cell = row.getCell(c) == null ? row.createCell(c) : row.getCell(c);
+ cell.setCellStyle(style);
+ }
+ }
+ }
+
+ public static String formatDate(LocalDate date) {
+ if (date == null) {
+ return null;
+ }
+ return date.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
}
@Override
@@ -329,7 +606,7 @@
}
@Override
- public IPage<SalesLedger> selectSalesLedgerListPage(Page page, SalesLedgerDto salesLedgerDto) {
+ public IPage<SalesLedgerDto> selectSalesLedgerListPage(Page page, SalesLedgerDto salesLedgerDto) {
return salesLedgerMapper.selectSalesLedgerListPage(page, salesLedgerDto);
}
@@ -606,7 +883,7 @@
// 4. 澶勭悊瀛愯〃鏁版嵁
List<SalesLedgerProduct> productList = salesLedgerDto.getProductData();
if (productList != null && !productList.isEmpty()) {
- handleSalesLedgerProducts(salesLedger.getId(), productList, salesLedgerDto.getType());
+ handleSalesLedgerProducts(salesLedger.getId(), productList, salesLedgerDto.getType(), Boolean.TRUE.equals(salesLedgerDto.getProduce()));
updateMainContractAmount(
salesLedger.getId(),
productList,
@@ -704,7 +981,7 @@
}
- private void handleSalesLedgerProducts(Long salesLedgerId, List<SalesLedgerProduct> products, Integer type) {
+ private void handleSalesLedgerProducts(Long salesLedgerId, List<SalesLedgerProduct> products, Integer type, boolean isProduce) {
// 鎸塈D鍒嗙粍锛屽尯鍒嗘柊澧炲拰鏇存柊鐨勮褰�
Map<Boolean, List<SalesLedgerProduct>> partitionedProducts = products.stream()
.peek(p -> p.setSalesLedgerId(salesLedgerId))
@@ -713,26 +990,26 @@
List<SalesLedgerProduct> updateList = partitionedProducts.get(true);
List<SalesLedgerProduct> insertList = partitionedProducts.get(false);
- List<StockInventoryDto> stockInventoryDtos = stockInventoryMapper.selectProductList();
+// List<StockInventoryDto> stockInventoryDtos = stockInventoryMapper.selectProductList();
// 鎵ц鏇存柊鎿嶄綔
if (!updateList.isEmpty()) {
for (SalesLedgerProduct product : updateList) {
- // 鏌ヨ搴撳瓨鏁伴噺
- SalesLedgerProduct oldProduct = salesLedgerProductMapper.selectById(product.getId());
- BigDecimal quantityChange = product.getQuantity().subtract(oldProduct.getQuantity());
-
- // 濡傛灉鏁伴噺澧炲姞浜嗭紝妫�鏌ュ簱瀛�
- if (quantityChange.compareTo(BigDecimal.ZERO) > 0) {
- for (StockInventoryDto stockInventoryDto : stockInventoryDtos) {
- if (stockInventoryDto.getProductId().equals(product.getId())) {
- if (quantityChange.compareTo(stockInventoryDto.getQualitity()) > 0) {
- throw new RuntimeException("搴撳瓨涓嶈冻");
- }
- break;
- }
- }
- }
+// // 鏌ヨ搴撳瓨鏁伴噺
+// SalesLedgerProduct oldProduct = salesLedgerProductMapper.selectById(product.getId());
+// BigDecimal quantityChange = product.getQuantity().subtract(oldProduct.getQuantity());
+//
+// // 濡傛灉鏁伴噺澧炲姞浜嗭紝妫�鏌ュ簱瀛�
+// if (quantityChange.compareTo(BigDecimal.ZERO) > 0) {
+// for (StockInventoryDto stockInventoryDto : stockInventoryDtos) {
+// if (stockInventoryDto.getProductId().equals(product.getId())) {
+// if (quantityChange.compareTo(stockInventoryDto.getQualitity()) > 0) {
+// throw new RuntimeException("搴撳瓨涓嶈冻");
+// }
+// break;
+// }
+// }
+// }
product.setType(type);
salesLedgerProductMapper.updateById(product);
}
@@ -740,18 +1017,25 @@
// 鎵ц鎻掑叆鎿嶄綔
if (!insertList.isEmpty()) {
for (SalesLedgerProduct salesLedgerProduct : insertList) {
- for (StockInventoryDto stockInventoryDto : stockInventoryDtos) {
- if (stockInventoryDto.getProductId().equals(salesLedgerProduct.getId())) {
- if (salesLedgerProduct.getQuantity().compareTo(stockInventoryDto.getQualitity()) > 0) {
- throw new RuntimeException("搴撳瓨涓嶈冻");
- }
- }
- }
+// for (StockInventoryDto stockInventoryDto : stockInventoryDtos) {
+// if (stockInventoryDto.getProductId().equals(salesLedgerProduct.getId())) {
+// if (salesLedgerProduct.getQuantity().compareTo(stockInventoryDto.getQualitity()) > 0) {
+// throw new RuntimeException("搴撳瓨涓嶈冻");
+// }
+// }
+// }
salesLedgerProduct.setType(type);
salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProduct.getTaxInclusiveTotalPrice());
salesLedgerProductMapper.insert(salesLedgerProduct);
+
+ }
+ }
+ if (isProduce) {
+ for (SalesLedgerProduct salesLedgerProduct : products) {
+ // 娣诲姞鐢熶骇鏁版嵁
+ salesLedgerProductServiceImpl.addProductionData(salesLedgerProduct);
}
}
}
@@ -759,6 +1043,7 @@
private SalesLedger convertToEntity(SalesLedgerDto dto) {
SalesLedger entity = new SalesLedger();
BeanUtils.copyProperties(dto, entity);
+ entity.setProduce(dto.getProduce());
return entity;
}
--
Gitblit v1.9.3