Răsfoiți Sursa

待采购可超采

yzc 1 an în urmă
părinte
comite
db62d83182

+ 5 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/po/EhsdPurchaseProduct.java

@@ -99,4 +99,9 @@ public class EhsdPurchaseProduct extends BasePo {
      * 原采购产品id
      */
     private Long oldPurchaseProductId;
+
+    /**
+     * 合同来源-超采数量
+     */
+    private BigDecimal exceedQuantity;
 }

+ 32 - 3
hx-sale/src/main/java/com/fjhx/sale/flow/EhsdPurchaseFlow.java

@@ -18,17 +18,19 @@ import com.fjhx.item.enums.ProductAvailableRecordType;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.purchase.entity.purchase.enums.PurchaseDataResourceEnum;
 import com.fjhx.purchase.entity.purchase.enums.PurchaseStatusEnum;
+import com.fjhx.purchase.entity.subscribe.po.SubscribeDetail;
+import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
 import com.fjhx.sale.entity.contract.po.Contract;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseDto;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProject;
 import com.fjhx.sale.entity.sample.po.Sample;
+import com.fjhx.sale.mapper.purchase.EhsdPurchaseProductMapper;
 import com.fjhx.sale.service.contract.ContractService;
 import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
 import com.fjhx.sale.service.purchase.EhsdPurchaseProjectService;
 import com.fjhx.sale.service.purchase.EhsdPurchaseService;
-import com.fjhx.sale.service.sample.SampleProductService;
 import com.fjhx.sale.service.sample.SampleService;
 import com.fjhx.wms.entity.stock.emums.JournalType;
 import com.fjhx.wms.entity.stock.po.StockWait;
@@ -42,6 +44,7 @@ import com.ruoyi.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -64,8 +67,6 @@ public class EhsdPurchaseFlow extends FlowDelegate {
 
     @Autowired
     private EhsdPurchaseProjectService purchaseProjectService;
-    @Autowired
-    private SampleProductService sampleProductService;
 
     @Autowired
     private CodingRuleService codingRuleService;
@@ -79,6 +80,10 @@ public class EhsdPurchaseFlow extends FlowDelegate {
     private StockWaitService stockWaitService;
     @Autowired
     private StockWaitDetailsService stockWaitDetailsService;
+    @Autowired
+    private EhsdPurchaseProductMapper purchaseProductMapper;
+    @Autowired
+    private SubscribeDetailService subscribeDetailService;
 
     @Override
     public String getFlowKey() {
@@ -220,6 +225,30 @@ public class EhsdPurchaseFlow extends FlowDelegate {
                 inOutBo.setQuantity(purchaseProduct.getQuantity());
                 inOutBoList.add(inOutBo);
             }
+
+            //数据来源是合同
+            if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey())) {
+                //获取采购,待采购信息
+                Long subscribeDetailId = purchaseProduct.getSubscribeDetailId();
+                BigDecimal purchaseSumCount = purchaseProductMapper.getPurchaseQuantitySumBySubscribeDetailId(subscribeDetailId);
+                SubscribeDetail subscribeDetail = subscribeDetailService.getById(subscribeDetailId);
+                Assert.notEmpty(subscribeDetail, "查询不到待采购信息!");
+
+                //已采购数量>待采购 本次超采量=已采购数量-待采购量-((已采购-本次采购)-待采购量)
+                if (purchaseSumCount.compareTo(subscribeDetail.getCount()) > 0) {
+                    //计算超采量
+                    BigDecimal oldPurchaseCount = purchaseSumCount.subtract(purchaseProduct.getQuantity());//(已采购-本次采购)
+                    BigDecimal subtract = oldPurchaseCount.subtract(subscribeDetail.getCount());//((已采购-本次采购)-待采购量)
+                    BigDecimal exceedQuantity = purchaseSumCount.subtract(subscribeDetail.getCount()).subtract(subtract);
+
+                    purchaseProduct.setExceedQuantity(exceedQuantity);
+
+                    AvailableStockBo inOutBo = new AvailableStockBo();
+                    inOutBo.setProductId(purchaseProduct.getProductId());
+                    inOutBo.setQuantity(exceedQuantity);
+                    inOutBoList.add(inOutBo);
+                }
+            }
         }
         productInfoService.editAvailableQuantity(inOutBoList, businessId, ProductAvailableRecordType.PURCHASE_PASS, purchase.getCompanyId());
 

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

@@ -8,6 +8,7 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 
@@ -54,4 +55,7 @@ public interface EhsdPurchaseProductMapper extends BaseMapper<EhsdPurchaseProduc
 
     List<EhsdPurchaseProductVo> getPurchaseQuantitySumByContractId(Long contractId);
 
+    BigDecimal getPurchaseQuantitySumBySubscribeDetailId(Long subscribeDetailId);
+
+
 }

+ 9 - 1
hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseServiceImpl.java

@@ -468,12 +468,20 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         List<EhsdPurchaseProduct> purchaseProductList = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getPurchaseId, id));
         for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
             //如果数据来源是申购 操作可用库存(可用库存 = 当前可用库存 - 采购明细数量)
-            if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_0)) {
+            if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_0.getKey())) {
                 AvailableStockBo inOutBo = new AvailableStockBo();
                 inOutBo.setProductId(purchaseProduct.getProductId());
                 inOutBo.setQuantity(purchaseProduct.getQuantity());
                 inOutBoList.add(inOutBo);
             }
+
+            //如果数据来源是合同 操作可用库存(可用库存 = 当前可用库存 - 采购超采量)
+            if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey())) {
+                AvailableStockBo inOutBo = new AvailableStockBo();
+                inOutBo.setProductId(purchaseProduct.getProductId());
+                inOutBo.setQuantity(purchaseProduct.getExceedQuantity());
+                inOutBoList.add(inOutBo);
+            }
         }
         productInfoService.editAvailableQuantity(inOutBoList, id, ProductAvailableRecordType.PURCHASE_CANCEL, purchase.getCompanyId());
         //检查待入库是否存在,已入库或者部分入库的数据

+ 10 - 1
hx-sale/src/main/resources/mapper/purchase/EhsdPurchaseProductMapper.xml

@@ -94,8 +94,17 @@
                sum(epp.quantity) AS quantity
         FROM ehsd_purchase_product epp
                  LEFT JOIN ehsd_purchase ep ON epp.purchase_id = ep.id
-        WHERE ep.`status` IN (10, 30)
+        WHERE ep.`status` IN (10, 30, 99)
           AND ep.data_resource_id = #{contractId}
         GROUP BY epp.product_id
     </select>
+
+    <select id="getPurchaseQuantitySumBySubscribeDetailId" resultType="java.math.BigDecimal">
+        SELECT IFNULL(sum(epp.quantity), 0)
+        FROM ehsd_purchase_product epp
+                 LEFT JOIN ehsd_purchase ep ON epp.purchase_id = ep.id
+        WHERE ep.`status` IN (10, 30, 99)
+          AND epp.subscribe_detailId = #{subscribeDetailId}
+        GROUP BY epp.product_id
+    </select>
 </mapper>