From 7b4fdb4289ded1adc3dc8466a8d0225a86a81e6a Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期三, 28 一月 2026 16:21:24 +0800
Subject: [PATCH] refactor(home): 删除质检信息,删除销售信息,回滚对应的库存信息

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java |   44 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
index 8fdf4f9..f87ebd8 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -7,6 +7,8 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum;
+import com.ruoyi.common.enums.StockUnQualifiedRecordTypeEnum;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.framework.web.domain.R;
 import com.ruoyi.procurementrecord.utils.StockUtils;
@@ -22,10 +24,14 @@
 import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper;
 import com.ruoyi.sales.mapper.SalesLedgerMapper;
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.sales.mapper.ShippingInfoMapper;
 import com.ruoyi.sales.pojo.InvoiceRegistrationProduct;
 import com.ruoyi.sales.pojo.SalesLedger;
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
+import com.ruoyi.sales.pojo.ShippingInfo;
 import com.ruoyi.sales.service.ISalesLedgerProductService;
+import com.ruoyi.stock.mapper.StockInventoryMapper;
+import com.ruoyi.stock.pojo.StockInventory;
 import lombok.AllArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -74,6 +80,8 @@
     private ProductionProductOutputMapper productionProductOutputMapper;
     private ProductionProductInputMapper productionProductInputMapper;
     private QualityInspectMapper qualityInspectMapper;
+    private ShippingInfoMapper shippingInfoMapper;
+    private ShippingInfoServiceImpl shippingInfoService;
 
     private StockUtils stockUtils;
 
@@ -81,6 +89,8 @@
 
     @Autowired
     private ProductStructureMapper productStructureMapper;
+    @Autowired
+    private StockInventoryMapper stockInventoryMapper;
 
     @Override
     public SalesLedgerProduct selectSalesLedgerProductById(Long id) {
@@ -94,6 +104,20 @@
 //                .eq(SalesLedgerProduct::getType, salesLedgerProduct.getType());
         List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectSalesLedgerProductList(salesLedgerProduct);
         if(!CollectionUtils.isEmpty(salesLedgerProducts)){
+            salesLedgerProducts.forEach(item -> {
+                // 鍙戣揣淇℃伅
+                ShippingInfo shippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
+                        .eq(ShippingInfo::getSalesLedgerProductId, item.getId())
+                        .orderByDesc(ShippingInfo::getCreateTime)
+                        .last("limit 1"));
+                if(shippingInfo != null){
+                    item.setShippingDate(shippingInfo.getShippingDate());
+                    item.setShippingCarNumber(shippingInfo.getShippingCarNumber());
+                    item.setShippingStatus(shippingInfo.getStatus());
+                    item.setExpressCompany(shippingInfo.getExpressCompany());
+                    item.setExpressNumber(shippingInfo.getExpressNumber());
+                }
+            });
             // 寮�绁�
             InvoiceRegistrationProductDto invoiceRegistrationProductDto = new InvoiceRegistrationProductDto();
             invoiceRegistrationProductDto.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId().intValue());
@@ -117,6 +141,8 @@
                     ledgerProduct.setInvoiceAmount(invoiceAmount);
                     ledgerProduct.setNoInvoiceNum(noInvoiceNum);
                     ledgerProduct.setNoInvoiceAmount(noInvoiceAmount);
+
+
                 }
             }
 
@@ -135,6 +161,12 @@
         List<SalesLedgerProduct> deletedProducts = salesLedgerProductMapper.selectBatchIds(Arrays.asList(ids));
         if (deletedProducts.isEmpty()) {
             return 0; // 娌℃湁鍙垹闄ょ殑鏁版嵁
+        }
+        //鍒犻櫎鍙戣揣淇℃伅
+        List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
+                .in(ShippingInfo::getSalesLedgerProductId, Arrays.asList(ids)));
+        if(!CollectionUtils.isEmpty(shippingInfos)){
+            shippingInfoService.delete(shippingInfos.stream().map(ShippingInfo::getId).collect(Collectors.toList()));
         }
 
         // 鍙兘灞炰簬澶氫釜涓昏〃
@@ -358,6 +390,13 @@
                                 new LambdaQueryWrapper<QualityInspect>()
                                         .in(QualityInspect::getProductMainId, productMainIds)
                         );
+                        //鍒犻櫎鍑哄簱璁板綍
+                        for (Long productMainId : productMainIds) {
+                            //鍒犻櫎鐢熶骇鍑哄簱璁板綍
+                            stockUtils.deleteStockOutRecord(productMainId, StockQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode());
+                            //鍒犻櫎鎶ュ簾鐨勫叆搴撹褰�
+                            stockUtils.deleteStockInRecord(productMainId, StockUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode());
+                        }
                         qualityInspects.forEach(qualityInspect -> {
                             //inspectState=1 宸叉彁浜� 涓嶈兘鍒犻櫎
                             if (qualityInspect.getInspectState() == 1) {
@@ -465,10 +504,11 @@
         int count = 0;
         StringBuilder stringBuffer = new StringBuilder();
         for (ProductStructureDto productStructureDto : productStructureDtos) {
-            BigDecimal stockQuantity = stockUtils.getStockQuantity(productStructureDto.getProductModelId()).get("stockQuantity");
+            StockInventory stockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, productStructureDto.getProductModelId()));
+
             //鎵�闇�鏁伴噺
             BigDecimal multiply = salesLedgerProduct.getQuantity().multiply(productStructureDto.getUnitQuantity());
-            BigDecimal subtract =stockQuantity.subtract(multiply).divide(BigDecimal.ONE, 2, RoundingMode.CEILING);
+            BigDecimal subtract =stockInventory.getQualitity().subtract(stockInventory.getLockedQuantity()).subtract(multiply).divide(BigDecimal.ONE, 2, RoundingMode.CEILING);
             if (subtract.compareTo(BigDecimal.ZERO) <= 0) {
                 count++;
                 stringBuffer.append(productStructureDto.getProductName())

--
Gitblit v1.9.3