map映射
This commit is contained in:
@@ -268,7 +268,7 @@ public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic>
|
||||
" product.shop_id = #{shopId} " +
|
||||
" AND sku.cost_price > 0")
|
||||
@MapKey("skuId")
|
||||
Map<Long, BigDecimal> getSkuCostAmount(Long shopId);
|
||||
List<ProductCostAmountVO> getSkuCostAmount(Long shopId);
|
||||
|
||||
@Select("SELECT" +
|
||||
" relation.product_id as productId," +
|
||||
@@ -279,8 +279,7 @@ public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic>
|
||||
" WHERE" +
|
||||
" relation.shop_id = #{shopId} " +
|
||||
" order by relation.product_id")
|
||||
@MapKey("productId")
|
||||
Map<Long, BigDecimal> getConsCostAmount(Long shopId);
|
||||
List<ProductCostAmountVO> getConsCostAmount(Long shopId);
|
||||
|
||||
|
||||
@Select("SELECT " +
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
@@ -192,9 +193,9 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
|
||||
*/
|
||||
private BigDecimal getProductCostAmount(Long shopId, LocalDate day) {
|
||||
//获取商品sku成本价 productId skuId price
|
||||
Map<Long, BigDecimal> skuCostAmountList = mapper.getSkuCostAmount(shopId);
|
||||
List<ProductCostAmountVO> skuCostAmountList = mapper.getSkuCostAmount(shopId);
|
||||
// //获取商品耗材成本价 productId price
|
||||
Map<Long, BigDecimal> consCostAmountList = mapper.getConsCostAmount(shopId);
|
||||
List<ProductCostAmountVO> consCostAmountList = mapper.getConsCostAmount(shopId);
|
||||
//获取orderDetail信息 productId skuId 数量
|
||||
BigDecimal productCostAmount = BigDecimal.ZERO;
|
||||
if (CollUtil.isEmpty(skuCostAmountList) && CollUtil.isEmpty(consCostAmountList)) {
|
||||
@@ -204,12 +205,16 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
|
||||
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 (skuCostAmountList.containsKey(productCostAmountVO.getSkuId())) {
|
||||
BigDecimal costAmount = skuCostAmountList.get(productCostAmountVO.getSkuId());
|
||||
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));
|
||||
} else if (consCostAmountList.containsKey(productCostAmountVO.getProductId())) {
|
||||
BigDecimal costAmount = consCostAmountList.get(productCostAmountVO.getProductId());
|
||||
} else if (consCostAmountMap.containsKey(productCostAmountVO.getProductId())) {
|
||||
BigDecimal costAmount = consCostAmountMap.get(productCostAmountVO.getProductId());
|
||||
productCostAmount = productCostAmount.add(costAmount.multiply(new BigDecimal(productCostAmountVO.getCount())).setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user