From d3a5c4420a7daf89bc9832f22ca8ed9d7e1adaf9 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 27 三月 2026 17:34:32 +0800
Subject: [PATCH] yys 1.完善销售下单,生成生产订单

---
 src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java |  146 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 123 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
index 72bd074..21049c7 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -7,16 +7,23 @@
 import com.ruoyi.approve.pojo.ApproveProcess;
 import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl;
 import com.ruoyi.common.enums.FileNameType;
-import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum;
-import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
 import com.ruoyi.other.service.impl.TempFileServiceImpl;
+import com.ruoyi.procurementrecord.mapper.ReturnManagementMapper;
+import com.ruoyi.procurementrecord.mapper.ReturnSaleProductMapper;
+import com.ruoyi.procurementrecord.pojo.ReturnManagement;
+import com.ruoyi.procurementrecord.pojo.ReturnSaleProduct;
+import com.ruoyi.procurementrecord.service.impl.ReturnManagementServiceImpl;
 import com.ruoyi.procurementrecord.utils.StockUtils;
+import com.ruoyi.sales.dto.SalesLedgerProductDto;
 import com.ruoyi.sales.dto.ShippingInfoDto;
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.sales.mapper.ShippingInfoDetailMapper;
 import com.ruoyi.sales.mapper.ShippingInfoMapper;
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import com.ruoyi.sales.pojo.ShippingInfo;
-import com.ruoyi.sales.service.ICommonFileService;
+import com.ruoyi.sales.pojo.ShippingInfoDetail;
+import com.ruoyi.sales.service.ShippingInfoDetailService;
 import com.ruoyi.sales.service.ShippingInfoService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
@@ -24,8 +31,9 @@
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author :yys
@@ -39,8 +47,6 @@
     private ShippingInfoMapper shippingInfoMapper;
 
     @Autowired
-    private TempFileServiceImpl tempFileService;
-    @Autowired
     private SalesLedgerProductMapper salesLedgerProductMapper;
     @Autowired
     private StockUtils stockUtils;
@@ -50,11 +56,106 @@
     @Autowired
     private ApproveProcessServiceImpl approveProcessService;
 
-    @Override
-    public IPage<ShippingInfo> listPage(Page page, ShippingInfo req) {
-        IPage<ShippingInfo> listPage = shippingInfoMapper.listPage(page, req);
+    @Autowired
+    private ShippingInfoDetailMapper shippingInfoDetailMapper;
 
+    @Autowired
+    private ShippingInfoDetailService shippingInfoDetailService;
+
+    @Autowired
+    private ReturnManagementMapper returnManagementMapper;
+
+    @Autowired
+    private ReturnSaleProductMapper returnSaleProductMapper;
+
+    @Autowired
+    private ReturnManagementServiceImpl returnManagementService;
+
+    @Override
+    public List<SalesLedgerProductDto> getReturnManagementDtoById(Long shippingId) {
+        return shippingInfoMapper.getReturnManagementDtoById(shippingId );
+
+    }
+
+    /**
+     * 鑾峰彇閿�鍞骇鍝佸崟鐨勫凡鍙戣揣鏁伴噺
+     */
+    @Override
+    public Map<String, BigDecimal> getNumberOfSalesLedgerProduct(Long salesLedgerProductId) {
+        Map<String, BigDecimal> map = new HashMap<>();
+        map.put("shippingNum",BigDecimal.ZERO); // 鍙戣揣鏁伴噺
+        map.put("returnNum",BigDecimal.ZERO); // 閫�璐ф暟閲�
+        List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
+                .eq(ShippingInfo::getSalesLedgerProductId, salesLedgerProductId)
+                // 鍙瓫閫夆�滃彂璐т腑鈥濆拰鈥滃凡鍙戣揣鈥濅袱绉嶇姸鎬�
+                .in(ShippingInfo::getStatus, "鍙戣揣涓�", "宸插彂璐�"));
+        if(CollectionUtils.isEmpty(shippingInfos)){
+            return map;
+        }
+        List<ShippingInfoDetail> shippingInfoDetails = shippingInfoDetailMapper.selectList(new LambdaQueryWrapper<ShippingInfoDetail>()
+                .in(ShippingInfoDetail::getShippingInfoId, shippingInfos.stream().map(ShippingInfo::getId).collect(Collectors.toList())));
+        if(CollectionUtils.isEmpty(shippingInfoDetails)){
+            return map;
+        }
+        // 鑾峰彇鍙戣揣鏁伴噺
+        map.put("shippingNum",shippingInfoDetails.stream().map(ShippingInfoDetail::getShippingNum).reduce(BigDecimal.ZERO, BigDecimal::add));
+        // 鑾峰彇閫�璐ф暟閲�
+        List<ReturnSaleProduct> returnSaleProducts = returnSaleProductMapper.selectList(new LambdaQueryWrapper<ReturnSaleProduct>()
+                .eq(ReturnSaleProduct::getReturnSaleLedgerProductId, salesLedgerProductId)
+                .eq(ReturnSaleProduct::getStatus,1));
+        if(CollectionUtils.isEmpty(returnSaleProducts)){
+            return map;
+        }
+        map.put("returnNum",returnSaleProducts.stream().map(ReturnSaleProduct::getNum).reduce(BigDecimal.ZERO, BigDecimal::add));
+        return map;
+    }
+
+    @Override
+    public ShippingInfoDto getDateil(Long id) {
+        ShippingInfoDto shippingInfoDto =  shippingInfoMapper.getDateil(id);
+        if(shippingInfoDto != null){
+            assembleDetails(shippingInfoDto);
+        }
+        return shippingInfoDto;
+    }
+
+    @Override
+    public List<ShippingInfo> getShippingInfoByCustomerName(String customerName) {
+        return shippingInfoMapper.getShippingInfoByCustomerName(customerName);
+    }
+
+    @Override
+    public IPage<ShippingInfoDto> listPage(Page page, ShippingInfo req) {
+        IPage<ShippingInfoDto> listPage = shippingInfoMapper.listPage(page, req);
+        listPage.getRecords().forEach(this::assembleDetails);
         return listPage;
+    }
+
+
+    /**
+     * 灏佽璇︽儏
+     * @param item
+     */
+    public void assembleDetails(ShippingInfoDto item) {
+        item.setCommonFileList(commonFileService.getFileListByBusinessId(item.getId(), FileNameType.SHIP.getValue()));
+        List<ShippingInfoDetail> shippingInfoDetails = shippingInfoDetailMapper.selectList(new LambdaQueryWrapper<ShippingInfoDetail>()
+                .eq(ShippingInfoDetail::getShippingInfoId, item.getId()));
+        // 鏍稿績浼樺寲锛氬眰灞傞槻鎶ょ┖鎸囬拡 + 澶勭悊绌洪泦鍚堝満鏅�
+        item.setShippingSuccessTotal(Optional.ofNullable(shippingInfoDetails)
+                .orElse(Collections.emptyList())
+                .stream()
+                .filter(Objects::nonNull)
+                .map(ShippingInfoDetail::getShippingNum)
+                .filter(Objects::nonNull)
+                .reduce(BigDecimal.ZERO, BigDecimal::add)); // 鐢↙ambda鏇夸唬鏂规硶寮曠敤
+        item.setWaitShippingTotal(item.getShippingTotal().subtract(item.getShippingSuccessTotal()));
+        // 鏌ヨ閫�璐ф暟閲�
+        if(CollectionUtils.isNotEmpty(shippingInfoDetails)){
+            item.setReturnTotal(returnManagementService.getReturnSaleProductCountByShippingId(shippingInfoDetails
+                    .stream()
+                    .map(ShippingInfoDetail::getId)
+                    .collect(Collectors.toList())));
+        }
     }
 
     @Override
@@ -63,19 +164,14 @@
         if (byId == null) {
             throw new RuntimeException("鍙戣揣淇℃伅涓嶅瓨鍦�");
         }
+        //鎵e噺搴撳瓨
+        SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(byId.getSalesLedgerProductId());
+        stockUtils.substractStock(salesLedgerProduct.getProductModelId(), req.getShippingTotal(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId());
         byId.setExpressNumber(req.getExpressNumber());
         byId.setExpressCompany(req.getExpressCompany());
-        byId.setStatus("宸插彂璐�");
+        byId.setStatus(req.getStatus());
         byId.setShippingCarNumber(req.getShippingCarNumber());
-        boolean update = this.updateById(req);
-        //鎵e噺搴撳瓨
-        SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(req.getSalesLedgerProductId());
-        stockUtils.substractStock(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId());
-        // 杩佺Щ鏂囦欢
-        if(CollectionUtils.isNotEmpty(req.getTempFileIds())){
-            tempFileService.migrateTempFilesToFormal(req.getId(), req.getTempFileIds(), FileNameType.SHIP.getValue());
-        }
-        return update ;
+        return this.updateById(byId);
     }
 
     @Override
@@ -83,12 +179,16 @@
         List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
                 .in(ShippingInfo::getId, ids));
         if(CollectionUtils.isEmpty(shippingInfos)) return false;
-        // 鍒犻櫎闄勪欢
-        commonFileService.deleteByBusinessIds(ids, FileNameType.SHIP.getValue());
+        // 鍒犻櫎瀛愯〃
+        List<ShippingInfoDetail> shippingInfoDetails = shippingInfoDetailMapper.selectList(new LambdaQueryWrapper<ShippingInfoDetail>()
+                .in(ShippingInfoDetail::getShippingInfoId, ids));
+        if(CollectionUtils.isNotEmpty(shippingInfoDetails)){
+            shippingInfoDetailService.delete(shippingInfoDetails.stream().map(ShippingInfoDetail::getId).collect(Collectors.toList()));
+        }
         // 鎵e凡鍙戣揣搴撳瓨
         for (ShippingInfo shippingInfo : shippingInfos) {
             if("宸插彂璐�".equals(shippingInfo.getStatus())) {
-                stockUtils.deleteStockRecord(shippingInfo.getId(), StockQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode());
+                stockUtils.deleteStockOutRecord(shippingInfo.getId(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode());
             }
         }
         // 鍒犻櫎鍙戣揣瀹℃壒

--
Gitblit v1.9.3