| | |
| | | CompletableFuture<List<MgtAmountChartVO>> auctionOrderTotalAmountFuture = CompletableFuture.supplyAsync( |
| | | () -> getMgtAmountChartVOS(datesBetween, orderList, OrderTypeEnum.AUCTION_ORDER), |
| | | executorService); |
| | | // 等待所有任务完成 |
| | | CompletableFuture<Void> futureAll = CompletableFuture.allOf(mallOrderCountFuture, |
| | | mallOrderTotalAmountFuture, auctionOrderCountFuture, auctionOrderTotalAmountFuture); |
| | | // 使用 join 方法阻塞当前线程,直到所有任务完成 |
| | | CompletableFuture.allOf(mallOrderCountFuture, |
| | | mallOrderTotalAmountFuture, auctionOrderCountFuture, auctionOrderTotalAmountFuture) |
| | | .join(); |
| | | MgtOrderStaticsChartVO mgtOrderStaticsChartVO = new MgtOrderStaticsChartVO(); |
| | | futureAll.thenRun(() -> { |
| | | try { |
| | | mgtOrderStaticsChartVO.setMallOrderCountList(mallOrderCountFuture.get()); |
| | | mgtOrderStaticsChartVO.setMallOrderTotalAmountList( |
| | | mallOrderTotalAmountFuture.get()); |
| | | mgtOrderStaticsChartVO.setAuctionOrderCount(auctionOrderCountFuture.get()); |
| | | mgtOrderStaticsChartVO.setAuctionOrderTotalAmount( |
| | | auctionOrderTotalAmountFuture.get()); |
| | | } catch (InterruptedException | ExecutionException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | executorService.shutdown(); // 关闭线程池 |
| | | }); |
| | | try { |
| | | // 设置结果 |
| | | mgtOrderStaticsChartVO.setMallOrderCountList(mallOrderCountFuture.get()); |
| | | mgtOrderStaticsChartVO.setMallOrderTotalAmountList(mallOrderTotalAmountFuture.get()); |
| | | mgtOrderStaticsChartVO.setAuctionOrderCountList(auctionOrderCountFuture.get()); |
| | | mgtOrderStaticsChartVO.setAuctionOrderTotalAmountList( |
| | | auctionOrderTotalAmountFuture.get()); |
| | | } catch (InterruptedException | ExecutionException e) { |
| | | throw new RuntimeException(e); |
| | | } finally { |
| | | executorService.shutdown(); // 确保关闭线程池 |
| | | } |
| | | return mgtOrderStaticsChartVO; |
| | | } |
| | | |