商品数据 空指针

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.setTotalActualAmount(BigDecimal.ZERO);
}
if(CollUtil.isNotEmpty(prodStatisticList)){
// 4. 先按分类ID分组商品
Map<Long, List<ShopProdStatistic>> groupByCategory = prodStatisticList.stream()
.collect(Collectors.groupingBy(ShopProdStatistic::getCategoryId));
// 4. 先按分类ID分组商品
Map<Long, List<ShopProdStatistic>> groupByCategory = prodStatisticList.stream()
.collect(Collectors.groupingBy(ShopProdStatistic::getCategoryId));
// 5. 组装成新结构 List<CategoryItem>
List<ProductReportPrintDTO.CategoryItem> categoryItems = new ArrayList<>();
// 5. 组装成新结构 List<CategoryItem>
List<ProductReportPrintDTO.CategoryItem> categoryItems = new ArrayList<>();
for (Map.Entry<Long, List<ShopProdStatistic>> entry : groupByCategory.entrySet()) {
Long categoryId = entry.getKey();
List<ShopProdStatistic> productList = entry.getValue();
for (Map.Entry<Long, List<ShopProdStatistic>> entry : groupByCategory.entrySet()) {
Long categoryId = entry.getKey();
List<ShopProdStatistic> productList = entry.getValue();
// 分类名称
String categoryName = categoryMap.getOrDefault(categoryId, "未分类");
// 分类名称
String categoryName = categoryMap.getOrDefault(categoryId, "未分类");
// 商品列表
List<ProductReportPrintDTO.ProductItem> productItems = new ArrayList<>();
BigDecimal categoryTotalNumber = BigDecimal.ZERO;
BigDecimal categoryTotalActual = BigDecimal.ZERO;
BigDecimal categoryTotalSales = BigDecimal.ZERO;
// 商品列表
List<ProductReportPrintDTO.ProductItem> 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");
}