From 0d4d20eca75ad94698c14c2171adab665b598277 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 21 Apr 2026 11:02:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E6=8A=A5=E8=A1=A8=20?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../czg/service/order/print/PrintConfig.java | 9 ++-- .../impl/ShopProdStatisticServiceImpl.java | 48 +++++++++++-------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/print/PrintConfig.java b/cash-service/order-service/src/main/java/com/czg/service/order/print/PrintConfig.java index 1fdbd6902..9c5187d4d 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/print/PrintConfig.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/print/PrintConfig.java @@ -214,9 +214,12 @@ public class PrintConfig implements ApplicationRunner { } break; case PrinterHandler.PrintTypeEnum.PRODUCT_REPORT: - getPrintMachine(shopId, printTypeEnum) - .forEach(machine -> getPrinter(machine.getBrand()) - .productReportPrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), ProductReportPrintDTO.class))); + Map map3 = data.to(new TypeReference<>() { + }); + for (PrintMachine machine : getPrintMachine(shopId, printTypeEnum)) { + PrinterHandler printer = getPrinter(machine.getBrand()); + map3.forEach((day, value) -> printer.productReportPrint(machine, shopInfo.getShopName(), value)); + } break; case PrinterHandler.PrintTypeEnum.RECHARGE: getPrintMachine(shopId, printTypeEnum) diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/ShopProdStatisticServiceImpl.java b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/ShopProdStatisticServiceImpl.java index a4190660b..09bff6f81 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/ShopProdStatisticServiceImpl.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/ShopProdStatisticServiceImpl.java @@ -23,6 +23,7 @@ import java.time.LocalDate; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.LongStream; import java.util.stream.Stream; /** @@ -86,40 +87,45 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl printDTO = new HashMap<>(); // 1. 获取统计数据 + Map categoryMap = shopProdCategoryService.getCategoryIdNameMap(param.getShopId()); + if (param.getBeginDate() != null && param.getEndDate() != null) { + // 计算相差天数 + long days = java.time.temporal.ChronoUnit.DAYS.between(param.getBeginDate(), param.getEndDate()); + List dateList = LongStream.rangeClosed(0, days) + .mapToObj(param.getBeginDate()::plusDays) + .toList(); + for (LocalDate localDate : dateList) { + SaleSummaryCountParam queryDay = new SaleSummaryCountParam() + .setShopId(param.getShopId()) + .setBeginDate(localDate) + .setEndDate(localDate); + ProductReportPrintDTO print = buildProductReportPrint(queryDay, categoryMap); + printDTO.put(localDate.toString(), print); + } + } + rabbitPublisher.sendOtherPrintMsg(param.getShopId(), printDTO, "PRODUCT_REPORT"); + } + + + private ProductReportPrintDTO buildProductReportPrint(SaleSummaryCountParam param, Map categoryMap) { SaleSummaryCountVo saleSummaryCountVo = summaryCount(param); List prodStatisticList = getArchiveTradeData(param); - LocalDate currentDate = LocalDate.now(); - Map categoryMap = shopProdCategoryService.getCategoryIdNameMap(param.getShopId()); ProductReportPrintDTO printDTO = new ProductReportPrintDTO(); - String statisticsTime = ""; - if ("today".equals(param.getRangeType())) { - statisticsTime = LocalDateTimeUtil.format(currentDate, "yyyy/MM/dd"); - } - if ("yesterday".equals(param.getRangeType())) { - statisticsTime = LocalDateTimeUtil.format(currentDate.minusDays(1), "yyyy/MM/dd"); - } + String statisticsTime = LocalDateTimeUtil.format(param.getBeginDate(), "yyyy/MM/dd"); - if (param.getBeginDate().isAfter(currentDate)) { - throw new CzgException("开始时间不能晚于当前时间"); - } - if (param.getBeginDate().equals(param.getEndDate())) { - statisticsTime = LocalDateTimeUtil.format(param.getBeginDate(), "yyyy/MM/dd"); - } - if (param.getEndDate().isBefore(currentDate)) { - statisticsTime = LocalDateTimeUtil.format(param.getBeginDate(), "yyyy/MM/dd") + " ~ " + LocalDateTimeUtil.format(param.getEndDate(), "yyyy/MM/dd"); - } printDTO.setStatisticsTime(statisticsTime); printDTO.setOperator(param.getOperator()); if (saleSummaryCountVo != null) { printDTO.setTotalProductCount(saleSummaryCountVo.getSaleCount()); printDTO.setTotalActualAmount(saleSummaryCountVo.getTotalAmount()); - }else { + } else { printDTO.setTotalProductCount(BigDecimal.ZERO); printDTO.setTotalActualAmount(BigDecimal.ZERO); } - if(CollUtil.isNotEmpty(prodStatisticList)){ + if (CollUtil.isNotEmpty(prodStatisticList)) { // 4. 先按分类ID分组商品 Map> groupByCategory = prodStatisticList.stream() .collect(Collectors.groupingBy(ShopProdStatistic::getCategoryId)); @@ -166,7 +172,7 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl