From a8e4132c3e2e9c3b3fcb0360901b35571b6464ea Mon Sep 17 00:00:00 2001
From: hsy <1029150275@qq.com>
Date: 星期五, 28 八月 2026 10:13:01 +0800
Subject: [PATCH] feat: 综合业务模块功能补充与实体拓展

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index d19edad..73a5b7f 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -1,9 +1,9 @@
 package com.ruoyi.sales.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -75,6 +75,9 @@
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.stream.Collectors;
+import com.ruoyi.sales.mapper.SalesLedgerContractRelMapper;
+import com.ruoyi.sales.pojo.SalesLedgerContractRel;
+import org.springframework.util.CollectionUtils;
 
 /**
  * 閿�鍞彴璐ervice涓氬姟灞傚鐞�
@@ -106,6 +109,7 @@
     private final FileUtil fileUtil;
     private final AccountInvoiceApplicationMapper accountInvoiceApplicationMapper;
     private final AccountSalesCollectionMapper accountSalesCollectionMapper;
+    private final SalesLedgerContractRelMapper salesLedgerContractRelMapper;
 
     @Autowired
     private SysDeptMapper sysDeptMapper;
@@ -159,6 +163,15 @@
         SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerDto.getId());
         if (salesLedger == null) {
             throw new BaseException("鍙拌处涓嶅瓨鍦�");
+        }
+
+        // 鏌ヨ鍏宠仈鐨勫悎鍚�
+        List<SalesLedgerContractRel> rels = salesLedgerContractRelMapper.selectList(
+                new LambdaQueryWrapper<SalesLedgerContractRel>().eq(SalesLedgerContractRel::getSalesLedgerId, salesLedger.getId())
+        );
+        if (!CollectionUtils.isEmpty(rels)) {
+            List<Long> contractIds = rels.stream().map(SalesLedgerContractRel::getContractId).collect(Collectors.toList());
+            salesLedger.setAssociatedContractIds(contractIds);
         }
 
         // 2. 鏌ヨ瀛愯〃
@@ -385,6 +398,7 @@
                 salesLedger.setContractAmount(salesLedgerProductImportDtos.stream()
                         .map(SalesLedgerProductImportDto::getTaxInclusiveTotalPrice)
                         .reduce(BigDecimal.ZERO, BigDecimal::add));
+                salesLedger.setNetContractAmount(salesLedger.getContractAmount());
                 salesLedgerMapper.insert(salesLedger);
 
 
@@ -529,7 +543,7 @@
         // 鍒犻櫎鍙戣揣鍙拌处璁板綍
         List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
                 .in(ShippingInfo::getSalesLedgerId, idList));
-        if (CollectionUtils.isNotEmpty(shippingInfos)) {
+        if (CollUtil.isNotEmpty(shippingInfos)) {
             shippingInfoServiceImpl.delete(shippingInfos.stream().map(ShippingInfo::getId).collect(Collectors.toList()));
         }
         // 鍒犻櫎闄勪欢琛�
@@ -538,7 +552,7 @@
         // 鍒犻櫎鐢熶骇绠℃帶鏁版嵁
         //鏌ヨ鐢熶骇鎶ュ伐id
         ArrayList<Long> mainIdList = productionProductMainService.listMain(idList);
-        if (CollectionUtils.isNotEmpty(mainIdList)) {
+        if (CollUtil.isNotEmpty(mainIdList)) {
             mainIdList.stream().forEach(mainId -> {
                 productionProductMainService.removeProductMain(mainId);
             });
@@ -576,6 +590,18 @@
             salesLedgerMapper.updateById(salesLedger);
         }
 
+        // 澶勭悊鍏宠仈鍚堝悓鏁版嵁
+        salesLedgerContractRelMapper.delete(
+                new LambdaQueryWrapper<SalesLedgerContractRel>().eq(SalesLedgerContractRel::getSalesLedgerId, salesLedger.getId())
+        );
+        if (!CollectionUtils.isEmpty(salesLedgerDto.getAssociatedContractIds())) {
+            for (Long contractId : salesLedgerDto.getAssociatedContractIds()) {
+                SalesLedgerContractRel rel = new SalesLedgerContractRel();
+                rel.setSalesLedgerId(salesLedger.getId());
+                rel.setContractId(contractId);
+                salesLedgerContractRelMapper.insert(rel);
+            }
+        }
 
         // 4. 澶勭悊瀛愯〃鏁版嵁
         List<SalesLedgerProduct> productList = salesLedgerDto.getProductData();

--
Gitblit v1.9.3