From a759e8dea01d10fb354803c99635da97c4d26472 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 17 Apr 2026 14:12:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E6=95=B0=E6=8D=AE=20?= =?UTF-8?q?=E7=A9=BA=E6=8C=87=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ShopProdStatisticServiceImpl.java | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) 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 2a489ee3d..a4190660b 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 @@ -119,53 +119,53 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl> groupByCategory = prodStatisticList.stream() + .collect(Collectors.groupingBy(ShopProdStatistic::getCategoryId)); - // 4. 先按分类ID分组商品 - Map> groupByCategory = prodStatisticList.stream() - .collect(Collectors.groupingBy(ShopProdStatistic::getCategoryId)); + // 5. 组装成新结构 List + List categoryItems = new ArrayList<>(); - // 5. 组装成新结构 List - List categoryItems = new ArrayList<>(); + for (Map.Entry> entry : groupByCategory.entrySet()) { + Long categoryId = entry.getKey(); + List productList = entry.getValue(); - for (Map.Entry> entry : groupByCategory.entrySet()) { - Long categoryId = entry.getKey(); - List productList = entry.getValue(); + // 分类名称 + String categoryName = categoryMap.getOrDefault(categoryId, "未分类"); - // 分类名称 - String categoryName = categoryMap.getOrDefault(categoryId, "未分类"); + // 商品列表 + List productItems = new ArrayList<>(); + BigDecimal categoryTotalNumber = BigDecimal.ZERO; + BigDecimal categoryTotalActual = BigDecimal.ZERO; + BigDecimal categoryTotalSales = BigDecimal.ZERO; - // 商品列表 - List productItems = new ArrayList<>(); - BigDecimal categoryTotalNumber = BigDecimal.ZERO; - BigDecimal categoryTotalActual = BigDecimal.ZERO; - BigDecimal categoryTotalSales = BigDecimal.ZERO; + for (ShopProdStatistic s : productList) { + ProductReportPrintDTO.ProductItem item = new ProductReportPrintDTO.ProductItem(); + item.setProductName(s.getProductName()); + item.setNumber(s.getValidSaleCount()); + item.setActualAmount(s.getValidSaleAmount()); + item.setSalesAmount(s.getSaleAmount()); + productItems.add(item); - for (ShopProdStatistic s : productList) { - ProductReportPrintDTO.ProductItem item = new ProductReportPrintDTO.ProductItem(); - item.setProductName(s.getProductName()); - item.setNumber(s.getValidSaleCount()); - item.setActualAmount(s.getValidSaleAmount()); - item.setSalesAmount(s.getSaleAmount()); - productItems.add(item); + // 分类汇总累加 + categoryTotalNumber = categoryTotalNumber.add(s.getValidSaleCount()); + categoryTotalActual = categoryTotalActual.add(s.getValidSaleAmount()); + categoryTotalSales = categoryTotalSales.add(s.getSaleAmount()); + } - // 分类汇总累加 - categoryTotalNumber = categoryTotalNumber.add(s.getValidSaleCount()); - categoryTotalActual = categoryTotalActual.add(s.getValidSaleAmount()); - categoryTotalSales = categoryTotalSales.add(s.getSaleAmount()); + // 构建分类项 + ProductReportPrintDTO.CategoryItem categoryItem = new ProductReportPrintDTO.CategoryItem(); + categoryItem.setCategoryName(categoryName); + categoryItem.setNumber(categoryTotalNumber); + categoryItem.setActualAmount(categoryTotalActual); + categoryItem.setSalesAmount(categoryTotalSales); + categoryItem.setProductItems(productItems); + + categoryItems.add(categoryItem); } - - // 构建分类项 - ProductReportPrintDTO.CategoryItem categoryItem = new ProductReportPrintDTO.CategoryItem(); - categoryItem.setCategoryName(categoryName); - categoryItem.setNumber(categoryTotalNumber); - categoryItem.setActualAmount(categoryTotalActual); - categoryItem.setSalesAmount(categoryTotalSales); - categoryItem.setProductItems(productItems); - - categoryItems.add(categoryItem); + printDTO.setItems(categoryItems); } - - printDTO.setItems(categoryItems); rabbitPublisher.sendOtherPrintMsg(param.getShopId(), printDTO, "PRODUCT_REPORT"); }