| | |
| | | sheet.setColumnWidth(3, 2500); |
| | | sheet.setColumnWidth(4, 3000); |
| | | sheet.setColumnWidth(5, 4500); |
| | | sheet.setColumnWidth(6, 2000); |
| | | sheet.setColumnWidth(6, 3500); |
| | | |
| | | CellStyle companyTitle = createBaseStyle(workbook, "宋体", (short) 20, true, true); |
| | | CellStyle billTitle = createBaseStyle(workbook, "宋体", (short) 18, true, true); |
| | |
| | | Cell hc = headerRow.createCell(i); |
| | | hc.setCellValue(headers[i]); |
| | | if (i == 6) { |
| | | hc.setCellStyle(dashStyle); // 共四联 → 虚线 |
| | | 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(); |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | // 前6列样式 |
| | | for (int c = 0; c <= 5; c++) { |
| | | dataRow.getCell(c).setCellStyle(dataCenterStyle); |
| | | } |
| | | 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 == 0 || i == 1 || i == 2) { |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | // 合计行 |
| | |
| | | |
| | | } catch (Exception e) { |
| | | log.error("批量导出送货单异常", e); |
| | | throw new BaseException("导出失败"); |
| | | throw new RuntimeException("导出失败"); |
| | | } |
| | | } |
| | | |