|
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.item.entity.product.po.ProductClassify;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
import com.fjhx.item.service.product.ProductClassifyService;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
@@ -24,6 +25,7 @@ import com.ruoyi.common.utils.wrapper.SqlField;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.function.Function;
|
|
@@ -198,8 +200,61 @@ public class SupplierPriceServiceImpl extends ServiceImpl<SupplierPriceMapper, S
|
|
|
if (ObjectUtils.isEmpty(productIdList)) {
|
|
|
throw new ServiceException("产品id数组不能为空");
|
|
|
}
|
|
|
- List<SupplierPrice> list = list(q -> q.eq(SupplierPrice::getSupplierInfoId, supplierId).in(SupplierPrice::getProductInfoId, productIdList));
|
|
|
- return list.stream().collect(Collectors.toMap(SupplierPrice::getProductInfoId, Function.identity()));
|
|
|
+
|
|
|
+ //获取基础供应商价格
|
|
|
+ Map<Long, SupplierPrice> outMap = this.mapKEntity(SupplierPrice::getProductInfoId, q -> q.eq(SupplierPrice::getSupplierInfoId, supplierId).in(SupplierPrice::getProductInfoId, productIdList));
|
|
|
+
|
|
|
+ //赋值有属性物料价格
|
|
|
+ setAttrProductPrice(supplierId, productIdList, outMap);
|
|
|
+
|
|
|
+ return outMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setAttrProductPrice(Long supplierId, List<Long> productIdList, Map<Long, SupplierPrice> outMap) {
|
|
|
+ //单独赋值有属性产品价格
|
|
|
+ List<Long> classifyIds = productClassifyService.listObject(ProductClassify::getId, q -> q
|
|
|
+ .apply("FIND_IN_SET(parent_id_set, 100) or id = 100")
|
|
|
+ );
|
|
|
+ List<ProductInfo> list1 = productInfoService.list(q -> q
|
|
|
+ .in(ProductInfo::getId, productIdList)
|
|
|
+ .in(ProductInfo::getProductClassifyId, classifyIds)
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(list1)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取无属性原材料 价格
|
|
|
+ List<Long> collect = list1.stream().map(ProductInfo::getAttrRawMaterialId).collect(Collectors.toList());
|
|
|
+ Map<Long, SupplierPrice> supplierPriceMap1 = this.mapKEntity(SupplierPrice::getProductInfoId, q -> q
|
|
|
+ .eq(SupplierPrice::getSupplierInfoId, supplierId).in(SupplierPrice::getProductInfoId, collect)
|
|
|
+ );
|
|
|
+
|
|
|
+ for (ProductInfo productInfo : list1) {
|
|
|
+ BigDecimal price = BigDecimal.ZERO;
|
|
|
+ BigDecimal includingTaxPrice = BigDecimal.ZERO;
|
|
|
+ SupplierPrice orDefault = supplierPriceMap1.get(productInfo.getAttrRawMaterialId());
|
|
|
+ if (orDefault != null) {
|
|
|
+ price = orDefault.getPrice();
|
|
|
+ includingTaxPrice = orDefault.getPrice();
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算体积
|
|
|
+ BigDecimal productLength = ObjectUtil.defaultIfNull(productInfo.getLength(), BigDecimal.ZERO);
|
|
|
+ BigDecimal productWidth = ObjectUtil.defaultIfNull(productInfo.getWidth(), BigDecimal.ZERO);
|
|
|
+ BigDecimal productHeight = ObjectUtil.defaultIfNull(productInfo.getHeight(), BigDecimal.ZERO);
|
|
|
+ BigDecimal productVolume = productLength.multiply(productWidth).multiply(productHeight);
|
|
|
+
|
|
|
+ //生成输出实体
|
|
|
+ SupplierPrice out = new SupplierPrice();
|
|
|
+ out.setSupplierInfoId(supplierId);
|
|
|
+ out.setProductInfoId(productInfo.getId());
|
|
|
+ //产品无属性 原材料价格*长*宽*高
|
|
|
+ out.setPrice(price.multiply(productVolume).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ out.setIncludingTaxPrice(includingTaxPrice.multiply(productVolume).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+
|
|
|
+ //添加有属性产品价格
|
|
|
+ outMap.put(productInfo.getId(), out);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|