diff --git a/SC-boot/linkage-scm/src/main/java/jnpf/purchaseorder/mapper/PurchaseorderitemMapper.java b/SC-boot/linkage-scm/src/main/java/jnpf/purchaseorder/mapper/PurchaseorderitemMapper.java index acd85464..3cd9f77b 100644 --- a/SC-boot/linkage-scm/src/main/java/jnpf/purchaseorder/mapper/PurchaseorderitemMapper.java +++ b/SC-boot/linkage-scm/src/main/java/jnpf/purchaseorder/mapper/PurchaseorderitemMapper.java @@ -25,6 +25,7 @@ import java.util.List; public interface PurchaseorderitemMapper extends BaseMapper { // List getPurchorderItemMap(@Param("ew")Wrapper queryWrapper); List> getPdfInfo(@Param("ew")Wrapper queryWrapper); + List> getOrderInfo(@Param("ew")Wrapper queryWrapper); List> getTitleInfo(@Param("ew")Wrapper queryWrapper); List> getWordExcelInfo(@Param("ew")Wrapper queryWrapper); List> getVehicleInfo(@Param("ew")Wrapper queryWrapper); diff --git a/SC-boot/linkage-scm/src/main/java/jnpf/purchaseorder/service/impl/PurchaseorderitemServiceImpl.java b/SC-boot/linkage-scm/src/main/java/jnpf/purchaseorder/service/impl/PurchaseorderitemServiceImpl.java index c45680d6..08af46f5 100644 --- a/SC-boot/linkage-scm/src/main/java/jnpf/purchaseorder/service/impl/PurchaseorderitemServiceImpl.java +++ b/SC-boot/linkage-scm/src/main/java/jnpf/purchaseorder/service/impl/PurchaseorderitemServiceImpl.java @@ -444,6 +444,291 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl> list, String templateFilePath) throws Exception { + //声明要创建的文件名 + String filename = templateFilePath + "\\订单信息表.xls"; +//创建 HSSFWorkbook 类的实例 + HSSFWorkbook workbook = new HSSFWorkbook(); + FileOutputStream fileOut = new FileOutputStream(filename); + + try { +//调用 creatSheet() 方法并传递要创建的工作表的名称 + HSSFSheet sheet = workbook.createSheet("磅单信息"); + HSSFCellStyle cellStyle = workbook.createCellStyle(); + HSSFCellStyle headLineStyle = workbook.createCellStyle(); + HSSFCellStyle headStyle = workbook.createCellStyle(); + HSSFCellStyle headTitleStyle = workbook.createCellStyle(); + HSSFCellStyle lineStyle = workbook.createCellStyle(); +// 水平居中 + cellStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER); +// 垂直居中 + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); + cellStyle.setHidden(true); +// 水平居左 + headStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.LEFT); +// 垂直居中 + headStyle.setVerticalAlignment(VerticalAlignment.CENTER); + headStyle.setHidden(true); + // 水平居中 + headLineStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER); +// 垂直居中 + headLineStyle.setVerticalAlignment(VerticalAlignment.CENTER); +// 边框 + headLineStyle.setBorderBottom(BorderStyle.THIN); + headLineStyle.setBorderLeft(BorderStyle.THIN); + headLineStyle.setBorderTop(BorderStyle.THIN); + headLineStyle.setBorderRight(BorderStyle.THIN); +// 自动换行 +// headLineStyle.setWrapText(true); + headLineStyle.setHidden(true); + // 水平居中 + + lineStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER); +// 垂直居中 + lineStyle.setVerticalAlignment(VerticalAlignment.CENTER); +// 边框 + lineStyle.setBorderBottom(BorderStyle.THIN); + lineStyle.setBorderLeft(BorderStyle.THIN); + lineStyle.setBorderTop(BorderStyle.THIN); + lineStyle.setBorderRight(BorderStyle.THIN); +// 自动换行 +// lineStyle.setWrapText(true); + lineStyle.setHidden(true); + + + HSSFFont font = workbook.createFont(); + HSSFFont headFont = workbook.createFont(); + HSSFFont tieleFont = workbook.createFont(); + HSSFFont lineFont = workbook.createFont(); + font.setFontName("宋体"); + font.setFontHeightInPoints((short) 18); + font.setBold(true); + cellStyle.setFont(font); + headFont.setFontName("宋体"); + headFont.setFontHeightInPoints((short) 11); + headFont.setBold(true); + headLineStyle.setFont(headFont); + tieleFont.setFontName("宋体"); + tieleFont.setFontHeightInPoints((short) 11); + tieleFont.setBold(true); + headStyle.setFont(tieleFont); + lineFont.setFontName("宋体"); + lineFont.setFontHeightInPoints((short) 12); + lineStyle.setFont(lineFont); + + sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 10)); + sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 10)); + + + BigDecimal sum = BigDecimal.ZERO; + BigDecimal priceSum = BigDecimal.ZERO; + BigDecimal numSum = BigDecimal.ZERO; + if (list != null && list.size() > 0) { + for (int i = 0; i < list.size(); i++) { + HashMap map = list.get(i); + + //创建第二行 + HSSFRow row2 = sheet.createRow((short) i + 3 ); + row2.setHeight((short) 500); +//在第二行插入数据 + HSSFCell lineCell1 = row2.createCell(0); + HSSFCell lineCell2 = row2.createCell(1); + HSSFCell lineCell3 = row2.createCell(2); + HSSFCell lineCell4 = row2.createCell(3); + HSSFCell lineCell5 = row2.createCell(4); + HSSFCell lineCell6 = row2.createCell(5); + HSSFCell lineCell7 = row2.createCell(6); + HSSFCell lineCell8 = row2.createCell(7); + HSSFCell lineCell9 = row2.createCell(8); + HSSFCell lineCell10 = row2.createCell(9); + HSSFCell lineCell11 = row2.createCell(10); + lineCell1.setCellValue(i + 1); + lineCell1.setCellStyle(lineStyle); + lineCell2.setCellValue(String.valueOf(map.get("supplierName")).equals("null") ? "" : String.valueOf(map.get("supplierName"))); + lineCell2.setCellStyle(lineStyle); + lineCell3.setCellValue(String.valueOf(map.get("documentNo")).equals("null") ? "" : String.valueOf(map.get("documentNo"))); + lineCell3.setCellStyle(lineStyle); + lineCell4.setCellValue(String.valueOf(map.get("itemCode")).equals("null") ? "" : String.valueOf(map.get("itemCode"))); + lineCell4.setCellStyle(lineStyle); + lineCell5.setCellValue(String.valueOf(map.get("itemName")).equals("null") ? "" : String.valueOf(map.get("itemName"))); + lineCell5.setCellStyle(lineStyle); + + lineCell6.setCellValue(String.valueOf(map.get("spec")).equals("null") ? "" : String.valueOf(map.get("spec"))); + lineCell6.setCellStyle(lineStyle); + + lineCell7.setCellValue(String.valueOf(map.get("settlement")).equals("null") ? "" : String.valueOf(map.get("settlement"))); + lineCell7.setCellStyle(lineStyle); + + lineCell8.setCellValue(String.valueOf(map.get("unit")).equals("null") ? "" : String.valueOf(map.get("unit"))); + lineCell8.setCellStyle(lineStyle); + + lineCell9.setCellValue(String.valueOf(map.get("price")).equals("null") ? "" : String.valueOf(map.get("price"))); + lineCell9.setCellStyle(lineStyle); + + lineCell10.setCellValue(String.valueOf(map.get("amount")).equals("null") ? "" : String.valueOf(map.get("amount"))); + lineCell10.setCellStyle(lineStyle); + + lineCell11.setCellValue(String.valueOf(map.get("rate")).equals("null") ? "" : String.valueOf(map.get("rate"))); + lineCell11.setCellStyle(lineStyle); + String ss=String.valueOf(map.get("price")).equals("null") ? "" : String.valueOf(map.get("price")); + priceSum= priceSum.add(new BigDecimal(ss)); + String s = String.valueOf(map.get("amount")).equals("null") ? "0" : String.valueOf(map.get("amount")); + sum = sum.add(new BigDecimal(s)); + String num = String.valueOf(map.get("settlement")).equals("null") ? "" : String.valueOf(map.get("settlement")); + numSum = numSum.add(new BigDecimal(num)); + + if (i == list.size() - 1) { + //使用 createRow() 方法创建第 0 行 +// HSSFRow rowhead = sheet.createRow((short) 0); +// rowhead.setHeight((short) 500); +//// 使用 createCell() 方法创建单元格,并使用 setCellValue() 方法为单元格设置值 +// +// HSSFCell cell = rowhead.createCell(0); + +// String s1 = String.valueOf(map.get("supplierNm")).equals("null") ? "" : String.valueOf(map.get("supplierNm")); +// if (s1.equals("")) { +// for (int i1 = 0; i1 < list.size(); i1++) { +// HashMap map1 = list.get(i1); +// if (!String.valueOf(map1.get("supplierNm")).equals("null")) { +// s1 = String.valueOf(map1.get("supplierNm")); +// } +// } +// } +// String s2 = String.valueOf(map.get("supplierName")).equals("null") ? "" : String.valueOf(map.get("supplierName")); +// if (s2.equals("")) { +// for (int i1 = 0; i1 < list.size(); i1++) { +// HashMap map1 = list.get(i1); +// if (!String.valueOf(map1.get("supplierName")).equals("null")) { +// s2 = String.valueOf(map1.get("supplierName")); +// } +// } +// } +// cell.setCellValue(s1 + "收货明细表"); +// cell.setCellValue(111+ "收货明细表"); +// cell.setCellStyle(cellStyle); +// //创建第一行 +// HSSFRow row = sheet.createRow((short) 1); +// row.setHeight((short) 500); +////在第一行插入数据 +// HSSFCell cell1 = row.createCell(0); +// +// cell1.setCellValue("供货单位:" + s2 + " 收货单位:"); +// cell1.setCellStyle(headStyle); + //创建第二行 + HSSFRow row1 = sheet.createRow((short) 2); + row1.setHeight((short) 500); +//在第二行插入数据 + HSSFCell cell2 = row1.createCell(0); + HSSFCell cell3 = row1.createCell(1); + HSSFCell cell4 = row1.createCell(2); + HSSFCell cell5 = row1.createCell(3); + HSSFCell cell6 = row1.createCell(4); + HSSFCell cell7 = row1.createCell(5); + HSSFCell cell8 = row1.createCell(6); + HSSFCell cell9 = row1.createCell(7); + HSSFCell cell10 = row1.createCell(8); + HSSFCell cell11 = row1.createCell(9); + HSSFCell cell12 = row1.createCell(10); + cell2.setCellValue("序号"); + cell2.setCellStyle(headLineStyle); + cell3.setCellValue("客户名称"); + cell3.setCellStyle(headLineStyle); + cell4.setCellValue("订单号"); + cell4.setCellStyle(headLineStyle); + cell5.setCellValue("物料编码"); + cell5.setCellStyle(headLineStyle); + cell6.setCellValue("物料名称"); + cell6.setCellStyle(headLineStyle); + cell7.setCellValue("规格"); + cell7.setCellStyle(headLineStyle); + cell8.setCellValue("数量"); + cell8.setCellStyle(headLineStyle); + cell9.setCellValue("单位"); + cell9.setCellStyle(headLineStyle); + cell10.setCellValue("含税单价(元)"); + cell10.setCellStyle(headLineStyle); + cell11.setCellValue("含税金额(元)"); + cell11.setCellStyle(headLineStyle); + cell12.setCellValue("税率(%)"); + cell12.setCellStyle(headLineStyle); + HSSFRow lowRow = sheet.createRow((short) i + 4); + lowRow.setHeight((short) 500); + HSSFCell lowCell1 = lowRow.createCell(0); + HSSFCell lowCell6 = lowRow.createCell(6); + HSSFCell lowCell8 = lowRow.createCell(8); + HSSFCell lowCell9 = lowRow.createCell(9); + lowCell1.setCellValue("合计"); + lowCell1.setCellStyle(lineStyle); + sum.setScale(2, RoundingMode.HALF_UP); + priceSum.setScale(6, RoundingMode.HALF_UP); + lowCell6.setCellValue(numSum.toString()); + lowCell6.setCellStyle(lineStyle); +// lowCell10.setCellValue(priceSum.toString()); +// 合计 + lowCell8.setCellValue(priceSum.toString()); + lowCell8.setCellStyle(lineStyle); + lowCell9.setCellValue(sum.toString()); + lowCell9.setCellStyle(lineStyle); + lowRow.createCell(1).setCellStyle(lineStyle); + lowRow.createCell(2).setCellStyle(lineStyle); + lowRow.createCell(3).setCellStyle(lineStyle); + lowRow.createCell(4).setCellStyle(lineStyle); + lowRow.createCell(5).setCellStyle(lineStyle); + lowRow.createCell(7).setCellStyle(lineStyle); + lowRow.createCell(10).setCellStyle(lineStyle); + } + } + } + + for (int i = 0; i <= 10; i++) { + + sheet.autoSizeColumn(i); + sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 17 / 10); + } + + sheet.setAutobreaks(true);//这个是sheet缩放设置,默认打印一页要true + + sheet.setMargin(Sheet.BottomMargin, 0.5);// 页边距(下) + + sheet.setMargin(Sheet.LeftMargin, 0.1);// 页边距(左) + + sheet.setMargin(Sheet.RightMargin, 0.1);// 页边距(右) + + sheet.setMargin(Sheet.TopMargin, 0.5);// 页边距(上) + + sheet.setHorizontallyCenter(true);//设置打印页面为水平居中 + + sheet.setVerticallyCenter(true);//设置打印页面为垂直居中 + +//使用POI输出Excel时打印页面 + +//启用“适合页面”打印选项的标志。(默认选择的是“将工作表调整为一页”) + + sheet.setFitToPage(true); + + + HSSFPrintSetup printSetup = sheet.getPrintSetup(); + + printSetup.setLandscape(false); // 打印方向,true:横向,false:纵向 + + printSetup.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE); //纸张大小,自选A4 作者:大萌音音 https://www.bilibili.com/read/cv15053559 出处:bilibili + + + workbook.write(fileOut); + + } finally { +//关闭流 + fileOut.close(); +//关闭工作簿 + workbook.close(); + } + +//在控制台打印消息 + log.warn("订单信息Excel文件生成成功。"); + + } + /** * @param wrapper 条件构造器 * @param templateFilePath 临时文件路径 @@ -689,24 +974,90 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl { + try { + + this.getPdf(wrapper, templateFilePath,settlementPdf); + } catch (Exception e) { + throw new RuntimeException(e); + } + // 关闭子线程 + countDownLatch.countDown(); + }); + + executorService.execute(() -> { + try { + this.getWord(info, templateFilePath,settlement); + } catch (Exception e) { + throw new RuntimeException(e); + } + // 关闭子线程 + countDownLatch.countDown(); + }); + ArrayList bigDecimals = new ArrayList<>(); + bigDecimals.add(amount); + executorService.execute(() -> { + try { + this.getExcel(info, templateFilePath,settlementExcel,bigDecimals); + } catch (Exception e) { + throw new RuntimeException(e); + } + // 关闭子线程 + countDownLatch.countDown(); + }); + executorService.execute(() -> { + try { + this.getVehicle(vehicleInfo, templateFilePath,settlement); + } catch (Exception e) { + throw new RuntimeException(e); + } + // 关闭子线程 + countDownLatch.countDown(); + }); + List> orderInfo = purchaseorderitemMapper.getOrderInfo(wrapper); executorService.execute(() -> { try { - - this.getPdf(wrapper, templateFilePath,settlementPdf); + this.getOrderInfoExcel(orderInfo, templateFilePath); } catch (Exception e) { throw new RuntimeException(e); } // 关闭子线程 countDownLatch.countDown(); }); + // 等待所有子线程执行完 + countDownLatch.await(); + } catch (Exception e) { + log.error("等待所有子线程执行完发生错误:" + e.getMessage()); + e.printStackTrace(); + } finally { + // 线程池不接受新任务 + executorService.shutdown(); + } + this.getZIP(templateFilePath, response,settlement); + }else{ + // 子线程计数器 + CountDownLatch countDownLatch = new CountDownLatch(4); + // 创建线程池 + ExecutorService executorService = Executors.newFixedThreadPool(4); + try { + + executorService.execute(() -> { + try { + + this.getPdf(wrapper, templateFilePath,settlementPdf); + } catch (Exception e) { + throw new RuntimeException(e); + } + // 关闭子线程 + countDownLatch.countDown(); + }); executorService.execute(() -> { try { @@ -737,7 +1088,6 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl + @@ -69,6 +70,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +