商品数据 空指针

This commit is contained in:
2026-04-17 14:12:12 +08:00
parent 98468c4872
commit a759e8dea0

View File

@@ -119,53 +119,53 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
printDTO.setTotalProductCount(BigDecimal.ZERO); printDTO.setTotalProductCount(BigDecimal.ZERO);
printDTO.setTotalActualAmount(BigDecimal.ZERO); printDTO.setTotalActualAmount(BigDecimal.ZERO);
} }
if(CollUtil.isNotEmpty(prodStatisticList)){
// 4. 先按分类ID分组商品
Map<Long, List<ShopProdStatistic>> groupByCategory = prodStatisticList.stream()
.collect(Collectors.groupingBy(ShopProdStatistic::getCategoryId));
// 4. 先按分类ID分组商品 // 5. 组装成新结构 List<CategoryItem>
Map<Long, List<ShopProdStatistic>> groupByCategory = prodStatisticList.stream() List<ProductReportPrintDTO.CategoryItem> categoryItems = new ArrayList<>();
.collect(Collectors.groupingBy(ShopProdStatistic::getCategoryId));
// 5. 组装成新结构 List<CategoryItem> for (Map.Entry<Long, List<ShopProdStatistic>> entry : groupByCategory.entrySet()) {
List<ProductReportPrintDTO.CategoryItem> categoryItems = new ArrayList<>(); Long categoryId = entry.getKey();
List<ShopProdStatistic> productList = entry.getValue();
for (Map.Entry<Long, List<ShopProdStatistic>> entry : groupByCategory.entrySet()) { // 分类名称
Long categoryId = entry.getKey(); String categoryName = categoryMap.getOrDefault(categoryId, "未分类");
List<ShopProdStatistic> productList = entry.getValue();
// 分类名称 // 商品列表
String categoryName = categoryMap.getOrDefault(categoryId, "未分类"); List<ProductReportPrintDTO.ProductItem> productItems = new ArrayList<>();
BigDecimal categoryTotalNumber = BigDecimal.ZERO;
BigDecimal categoryTotalActual = BigDecimal.ZERO;
BigDecimal categoryTotalSales = BigDecimal.ZERO;
// 商品列表 for (ShopProdStatistic s : productList) {
List<ProductReportPrintDTO.ProductItem> productItems = new ArrayList<>(); ProductReportPrintDTO.ProductItem item = new ProductReportPrintDTO.ProductItem();
BigDecimal categoryTotalNumber = BigDecimal.ZERO; item.setProductName(s.getProductName());
BigDecimal categoryTotalActual = BigDecimal.ZERO; item.setNumber(s.getValidSaleCount());
BigDecimal categoryTotalSales = BigDecimal.ZERO; item.setActualAmount(s.getValidSaleAmount());
item.setSalesAmount(s.getSaleAmount());
productItems.add(item);
for (ShopProdStatistic s : productList) { // 分类汇总累加
ProductReportPrintDTO.ProductItem item = new ProductReportPrintDTO.ProductItem(); categoryTotalNumber = categoryTotalNumber.add(s.getValidSaleCount());
item.setProductName(s.getProductName()); categoryTotalActual = categoryTotalActual.add(s.getValidSaleAmount());
item.setNumber(s.getValidSaleCount()); categoryTotalSales = categoryTotalSales.add(s.getSaleAmount());
item.setActualAmount(s.getValidSaleAmount()); }
item.setSalesAmount(s.getSaleAmount());
productItems.add(item);
// 分类汇总累加 // 构建分类项
categoryTotalNumber = categoryTotalNumber.add(s.getValidSaleCount()); ProductReportPrintDTO.CategoryItem categoryItem = new ProductReportPrintDTO.CategoryItem();
categoryTotalActual = categoryTotalActual.add(s.getValidSaleAmount()); categoryItem.setCategoryName(categoryName);
categoryTotalSales = categoryTotalSales.add(s.getSaleAmount()); categoryItem.setNumber(categoryTotalNumber);
categoryItem.setActualAmount(categoryTotalActual);
categoryItem.setSalesAmount(categoryTotalSales);
categoryItem.setProductItems(productItems);
categoryItems.add(categoryItem);
} }
printDTO.setItems(categoryItems);
// 构建分类项
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);
rabbitPublisher.sendOtherPrintMsg(param.getShopId(), printDTO, "PRODUCT_REPORT"); rabbitPublisher.sendOtherPrintMsg(param.getShopId(), printDTO, "PRODUCT_REPORT");
} }