From ed9dc095818297a652fabe63757f73cd25e2c6da Mon Sep 17 00:00:00 2001 From: chuang <994001556@qq.com> Date: Mon, 3 Apr 2023 09:54:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E7=A5=A8=E6=96=87=E4=BB=B6=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=A4=84=E7=90=86=E6=96=87=E4=BB=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=9A=E7=BA=BF=E7=A8=8B=E5=A4=84=E7=90=86=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/PurchaseorderitemServiceImpl.java | 71 +++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) 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 e567ce7d..77bb2eb2 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 @@ -76,6 +76,9 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.List; import java.util.*; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.stream.Collectors; /** @@ -149,7 +152,8 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl> list, String templateFilePath,String settlements,BigDecimal amount) throws Exception { + public void getExcel(List> list, String templateFilePath,String settlements,ArrayList amountt) throws Exception { + BigDecimal amount = amountt.get(0); //声明要创建的文件名 String filename = templateFilePath + "\\废钢收货明细表("+settlements+"吨).xls"; //创建 HSSFWorkbook 类的实例 @@ -605,10 +609,67 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl> vehicleInfo = purchaseorderitemMapper.getVehicleInfo(wrapper); List> titleInfo = purchaseorderitemMapper.getTitleInfo(wrapper); String settlement = String.valueOf(titleInfo.get(0).get("settlement")); - this.getPdf(wrapper, templateFilePath,settlement); - this.getWord(info, templateFilePath,settlement); - this.getExcel(info, templateFilePath,settlement,amount); - this.getVehicle(vehicleInfo, templateFilePath,settlement); + + + + // 任务集合 + + + // 子线程计数器 + CountDownLatch countDownLatch = new CountDownLatch(4); + // 创建线程池 + ExecutorService executorService = Executors.newFixedThreadPool(4); + try { + + executorService.execute(() -> { + try { + this.getPdf(wrapper, templateFilePath,settlement); + } 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,settlement,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(); + }); + + // 等待所有子线程执行完 + countDownLatch.await(); + } catch (Exception e) { + log.error("等待所有子线程执行完发生错误:" + e.getMessage()); + e.printStackTrace(); + } finally { + // 线程池不接受新任务 + executorService.shutdown(); + } this.getZIP(templateFilePath, response,settlement); } else { log.error("采购订单号出错!查不到该采购订单!");