| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | |
| | | */ |
| | | public MgtOrderStaticsVO getOverview(MgtOrderStaticsQuery query) { |
| | | |
| | | LocalDateTime startTime = null; |
| | | LocalDateTime endTime = null; |
| | | getTimeByTimeType(query, startTime, endTime); |
| | | List<LocalDateTime> timeByTimeType = getTimeByTimeType(query); |
| | | LocalDateTime startTime = timeByTimeType.get(0); |
| | | LocalDateTime endTime = timeByTimeType.get(1); |
| | | List<Order> orderList = orderService.getStaticsOrderList(startTime, endTime); |
| | | if (orderList.isEmpty()) { |
| | | throw new ServiceException("暂无数据"); |
| | |
| | | long auctionOrderTotalCount = orderList.stream() |
| | | .filter(order -> order.getOrderFrom().equals(OrderFromEnum.AUCTION_ORDERS)) |
| | | .count(); |
| | | // 商城订单统计-订单总数 |
| | | // 拍卖订单统计-拍卖商品订单 |
| | | long auctionGoodsOrderCount = orderList.stream() |
| | | .filter(order -> order.getOrderFrom().equals(OrderFromEnum.AUCTION_ORDERS) |
| | | && order.getAuctionOrderType().equals(AuctionOrderTypeEnum.REGULAR_ITEMS)) |
| | | .count(); |
| | | // 拍卖订单统计-拍卖商品订单 |
| | | // 拍卖订单统计-拍卖场订单 |
| | | long auctionSalesroomOrderCount = orderList.stream() |
| | | .filter(order -> order.getOrderFrom().equals(OrderFromEnum.AUCTION_ORDERS) |
| | | && order.getAuctionOrderType().equals(AuctionOrderTypeEnum.AUCTION_ITEMS)) |
| | |
| | | return mgtOrderStaticsVO; |
| | | } |
| | | |
| | | private void getTimeByTimeType(MgtOrderStaticsQuery query, LocalDateTime startTime, |
| | | LocalDateTime endTime) { |
| | | private List<LocalDateTime> getTimeByTimeType(MgtOrderStaticsQuery query) { |
| | | LocalDateTime startTime; |
| | | LocalDateTime endTime; |
| | | List<LocalDateTime> range = new ArrayList<>(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | if (Objects.equals(TimeTypeEnum.TODAY.getCode(), query.getTimeType())) { |
| | | startTime = DateUtils.getDayStart(now); |
| | |
| | | startTime = DateUtils.getDayStart(now); |
| | | endTime = DateUtils.getDayEnd(now); |
| | | } |
| | | range.add(startTime); |
| | | range.add(endTime); |
| | | return range; |
| | | } |
| | | |
| | | /** |
| | |
| | | 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; |
| | | } |
| | | |