Parcourir la source

报价自动取最后一次采购价格

yzc il y a 10 mois
Parent
commit
c95e7c6ebd

+ 1 - 0
hx-sale/src/main/java/com/fjhx/sale/mapper/purchase/EhsdPurchaseProductMapper.java

@@ -61,5 +61,6 @@ public interface EhsdPurchaseProductMapper extends BaseMapper<EhsdPurchaseProduc
 
     List<EhsdPurchaseProductVo> getList(@Param("ew") IWrapper<EhsdPurchaseProduct> wrapper);
 
+    List<EhsdPurchaseProduct> getLastPurchasePrice(@Param("ew") IWrapper<Object> wrapper);
 
 }

+ 5 - 1
hx-sale/src/main/java/com/fjhx/sale/service/purchase/EhsdPurchaseProductService.java

@@ -6,6 +6,7 @@ import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseProductSelectDto;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
 import com.ruoyi.common.core.service.BaseService;
+import com.ruoyi.common.utils.wrapper.IWrapper;
 
 import java.math.BigDecimal;
 import java.util.List;
@@ -63,10 +64,13 @@ public interface EhsdPurchaseProductService extends BaseService<EhsdPurchaseProd
 
     /**
      * 根据合同ID查询采购产品列表
+     *
      * @param contractId
      * @return
      */
     List<EhsdPurchaseProductVo> getListByContractId(Long contractId);
 
-    List<EhsdPurchaseProduct>getPurchaseProductByContractProductIds(List<Long> dataResourceIds);
+    List<EhsdPurchaseProduct> getPurchaseProductByContractProductIds(List<Long> dataResourceIds);
+
+    Map<Long, BigDecimal> getLastPurchasePrice(IWrapper wrapper);
 }

+ 12 - 1
hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseProductServiceImpl.java

@@ -15,7 +15,10 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
 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.stream.Collectors;
 
 
 /**
@@ -68,6 +71,7 @@ public class EhsdPurchaseProductServiceImpl extends ServiceImpl<EhsdPurchaseProd
 
     /**
      * 查询采购产品总金额,通过数据来源ID
+     *
      * @param contractIds
      * @return
      */
@@ -78,6 +82,7 @@ public class EhsdPurchaseProductServiceImpl extends ServiceImpl<EhsdPurchaseProd
 
     /**
      * 查询采购产品总,通过数据来源ID
+     *
      * @param contractIds
      * @return
      */
@@ -97,6 +102,7 @@ public class EhsdPurchaseProductServiceImpl extends ServiceImpl<EhsdPurchaseProd
 
     /**
      * 根据合同ID查询采购产品列表
+     *
      * @param contractId
      * @return
      */
@@ -109,9 +115,14 @@ public class EhsdPurchaseProductServiceImpl extends ServiceImpl<EhsdPurchaseProd
      * 根据采购合同明细id获取采购明细数据
      */
     @Override
-    public List<EhsdPurchaseProduct>getPurchaseProductByContractProductIds(List<Long> dataResourceIds){
+    public List<EhsdPurchaseProduct> getPurchaseProductByContractProductIds(List<Long> dataResourceIds) {
         return baseMapper.getPurchaseProductByContractProductIds(dataResourceIds);
     }
 
+    @Override
+    public Map<Long, BigDecimal> getLastPurchasePrice(IWrapper wrapper) {
+        List<EhsdPurchaseProduct> lastPurchasePrice = baseMapper.getLastPurchasePrice(wrapper);
+        return lastPurchasePrice.stream().collect(Collectors.toMap(EhsdPurchaseProduct::getProductId, EhsdPurchaseProduct::getPrice));
+    }
 
 }

+ 19 - 7
hx-sale/src/main/java/com/fjhx/sale/service/quotation/impl/QuotationEstimateServiceImpl.java

@@ -5,7 +5,6 @@ import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.common.utils.Assert;
 import com.fjhx.item.entity.product.ProcessesBo;
-import com.fjhx.item.entity.product.po.ProductInfo;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.sale.entity.quotation.dto.QuotationEstimateDto;
 import com.fjhx.sale.entity.quotation.po.QuotationEstimate;
@@ -17,6 +16,7 @@ import com.fjhx.sale.entity.quotation.vo.QuotationProductVo;
 import com.fjhx.sale.entity.sale.po.SaleQuotation;
 import com.fjhx.sale.entity.sale.vo.SaleQuotationVo;
 import com.fjhx.sale.mapper.quotation.QuotationEstimateMapper;
+import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
 import com.fjhx.sale.service.quotation.QuotationEstimateService;
 import com.fjhx.sale.service.quotation.QuotationProductBomService;
 import com.fjhx.sale.service.quotation.QuotationProductService;
@@ -51,13 +51,15 @@ public class QuotationEstimateServiceImpl extends ServiceImpl<QuotationEstimateM
     private final QuotationProductService quotationProductService;
     private final ProductInfoService productInfoService;
     private final SaleQuotationService saleQuotationService;
+    private final EhsdPurchaseProductService purchaseProductService;
 
     @Autowired
-    public QuotationEstimateServiceImpl(QuotationProductBomService quotationProductBomService, QuotationProductService quotationProductService, ProductInfoService productInfoService, SaleQuotationService saleQuotationService) {
+    public QuotationEstimateServiceImpl(QuotationProductBomService quotationProductBomService, QuotationProductService quotationProductService, ProductInfoService productInfoService, SaleQuotationService saleQuotationService, EhsdPurchaseProductService purchaseProductService) {
         this.quotationProductBomService = quotationProductBomService;
         this.quotationProductService = quotationProductService;
         this.productInfoService = productInfoService;
         this.saleQuotationService = saleQuotationService;
+        this.purchaseProductService = purchaseProductService;
     }
 
     @Override
@@ -68,6 +70,9 @@ public class QuotationEstimateServiceImpl extends ServiceImpl<QuotationEstimateM
         QuotationProduct quotationProduct = quotationProductService.getById(quotationProductId);
         Assert.notEmpty(quotationProduct, "查询不到报价明细信息!");
 
+        SaleQuotation saleQuotation = saleQuotationService.getById(quotationProduct.getSaleQuotationId());
+        Assert.notEmpty(saleQuotation, "查询不到报价单信息!");
+
 //        Long technologyId = quotationProduct.getTechnologyId();
 
         //查询现有报价信息
@@ -84,12 +89,18 @@ public class QuotationEstimateServiceImpl extends ServiceImpl<QuotationEstimateM
             );
 
             List<Long> mIds = list1.stream().map(QuotationProductBom::getMaterialId).collect(Collectors.toList());
-            Map<Long, ProductInfo> materialInfoMap = productInfoService.mapKEntity(ProductInfo::getId, q -> q.in(ProductInfo::getId, mIds));
+//            Map<Long, ProductInfo> materialInfoMap = productInfoService.mapKEntity(ProductInfo::getId, q -> q.in(ProductInfo::getId, mIds));
 
             //获取工序信息
             List<ProcessesBo> processesList = baseMapper.getProductionProcessesList();
             Map<Long, ProcessesBo> collect = processesList.stream().collect(Collectors.toMap(ProcessesBo::getId, Function.identity()));
 
+            //获取最后一次采购价格
+            Map<Long, BigDecimal> lastPurchasePriceMap = purchaseProductService.getLastPurchasePrice(IWrapper.getWrapper()
+                    .in("epp.product_id", mIds)
+                    .eq("ep.company_id", saleQuotation.getOfCompanyId())
+            );
+
             //获取产品BOM
             for (QuotationProductBom quotationProductBom : list1) {
                 QuotationEstimateVo quotationEstimate = new QuotationEstimateVo();
@@ -99,10 +110,11 @@ public class QuotationEstimateServiceImpl extends ServiceImpl<QuotationEstimateM
                 quotationEstimate.setType(quotationProductBom.getType());
 
                 //赋值单价信息
-                ProductInfo materialId = materialInfoMap.get(quotationProductBom.getMaterialId());
-                if (ObjectUtil.isNotEmpty(materialId)) {
-                    quotationEstimate.setPrice(materialId.getPrice());
-                }
+                quotationEstimate.setPrice(lastPurchasePriceMap.get(quotationProductBom.getMaterialId()));
+//                ProductInfo materialId = materialInfoMap.get(quotationProductBom.getMaterialId());
+//                if (ObjectUtil.isNotEmpty(materialId)) {
+//                    quotationEstimate.setPrice(materialId.getPrice());
+//                }
 
                 //原材料不赋值数量
                 if (ObjectUtil.notEqual(quotationProductBom.getType(), 1)) {

+ 19 - 0
hx-sale/src/main/resources/mapper/purchase/EhsdPurchaseProductMapper.xml

@@ -145,4 +145,23 @@
                             GROUP BY swd.purchase_detail_id) t1 ON t1.purchase_detail_id = epp.id
             ${ew.customSqlSegment}
     </select>
+    <select id="getLastPurchasePrice" resultType="com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct">
+        SELECT epp.product_id,
+               (SELECT epp.price
+                FROM ehsd_purchase_product epp_1
+                         JOIN ehsd_purchase ep_1 ON epp_1.purchase_id = ep_1.id
+                WHERE epp_1.product_id = epp.product_id
+                  AND ep_1.sell_corporation_id = ep.sell_corporation_id
+                  AND ep_1.company_id = ep.company_id
+                ORDER BY ep_1.purchase_time DESC,
+                         epp_1.create_time DESC,
+                         ep_1.id DESC
+                   LIMIT 1 ) AS price
+        FROM
+            ehsd_purchase_product epp JOIN ehsd_purchase ep
+        ON epp.purchase_id = ep.id
+        WHERE ${ew.sqlSegment}
+        GROUP BY
+            epp.product_id
+    </select>
 </mapper>