莫名的null值情况

This commit is contained in:
2025-11-25 14:55:48 +08:00
parent 1acde33a44
commit 0126591784
2 changed files with 15 additions and 13 deletions

View File

@@ -1,10 +1,9 @@
package com.czg.service.order.mapper;
import com.czg.order.entity.ShopOrderStatistic;
import com.czg.order.vo.ProductCostAmountVO;
import com.czg.order.vo.TotalVo;
import com.mybatisflex.core.BaseMapper;
import com.czg.order.entity.ShopOrderStatistic;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Select;
import java.math.BigDecimal;
@@ -283,7 +282,7 @@ public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic>
@Select("SELECT " +
" detail.product_id as productId," +
" detail.product_id as productId," +
" detail.sku_id as skuId," +
" sum(detail.num - detail.return_num) as count " +
"FROM " +

View File

@@ -19,10 +19,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
@@ -192,24 +189,30 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
* 获取商品成本价
*/
private BigDecimal getProductCostAmount(Long shopId, LocalDate day) {
BigDecimal productCostAmount = BigDecimal.ZERO;
////获取orderDetail信息 productId skuId 数量
List<ProductCostAmountVO> orderDetailProduct = mapper.getOrderDetailProduct(shopId, day);
orderDetailProduct = orderDetailProduct.stream()
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (CollUtil.isEmpty(orderDetailProduct)) {
return productCostAmount;
}
//获取商品sku成本价 productId skuId price
List<ProductCostAmountVO> skuCostAmountList = mapper.getSkuCostAmount(shopId);
// //获取商品耗材成本价 productId price
List<ProductCostAmountVO> consCostAmountList = mapper.getConsCostAmount(shopId);
//获取orderDetail信息 productId skuId 数量
BigDecimal productCostAmount = BigDecimal.ZERO;
if (CollUtil.isEmpty(skuCostAmountList) && CollUtil.isEmpty(consCostAmountList)) {
return productCostAmount;
}
List<ProductCostAmountVO> orderDetailProduct = mapper.getOrderDetailProduct(shopId, day);
if (CollUtil.isEmpty(orderDetailProduct)) {
return productCostAmount;
}
Map<Long, BigDecimal> skuCostAmountMap = skuCostAmountList.stream()
.collect(Collectors.toMap(ProductCostAmountVO::getSkuId, ProductCostAmountVO::getCostAmount));
Map<Long, BigDecimal> consCostAmountMap = consCostAmountList.stream()
.collect(Collectors.toMap(ProductCostAmountVO::getProductId, ProductCostAmountVO::getCostAmount));
for (ProductCostAmountVO productCostAmountVO : orderDetailProduct) {
if (productCostAmountVO == null || productCostAmountVO.getCount() <= 0) {
continue;
}
if (skuCostAmountMap.containsKey(productCostAmountVO.getSkuId())) {
BigDecimal costAmount = skuCostAmountMap.get(productCostAmountVO.getSkuId());
productCostAmount = productCostAmount.add(costAmount.multiply(new BigDecimal(productCostAmountVO.getCount())).setScale(2, RoundingMode.HALF_UP));