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"); }