From 55d694aaae4e421b5e55cd941500e08f85cb5d4d Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 27 八月 2026 18:21:33 +0800
Subject: [PATCH] feat(sales): 添加框架合同订单功能并优化销售台账管理

---
 src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java
index b3f424d..b40885e 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java
@@ -24,6 +24,10 @@
 import com.ruoyi.production.pojo.ProductionPlan;
 import com.ruoyi.production.service.ProductionOrderService;
 import com.ruoyi.production.service.ProductionPlanService;
+import com.ruoyi.sales.mapper.SalesLedgerMapper;
+import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.sales.pojo.SalesLedger;
+import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
@@ -50,6 +54,8 @@
     private final ProductionOrderService productionOrderService;
     private final ProductModelMapper productModelMapper;
     private final ProductMapper productMapper;
+    private final SalesLedgerMapper salesLedgerMapper;
+    private final SalesLedgerProductMapper salesLedgerProductMapper;
 
     @Override
     public IPage<ProductionPlanVo> listPage(Page<ProductionPlanDto> page, ProductionPlanDto productionPlanDto) {
@@ -151,6 +157,7 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean add(ProductionPlanDto dto) {
+        validateSalesSource(dto);
         // 鏂板涓荤敓浜ц鍒�
         if (StringUtils.isBlank(dto.getMpsNo())) {
             String datePrefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
@@ -173,6 +180,7 @@
             throw new ServiceException("缂栬緫澶辫触锛屾暟鎹笉鑳戒负绌�");
         }
 
+        validateSalesSource(dto);
         ProductionPlan old = getById(dto.getId());
         if (old == null) {
             throw new ServiceException("缂栬緫澶辫触锛岀敓浜ц鍒掍笉瀛樺湪");
@@ -321,6 +329,32 @@
         util.exportExcel(response, exportList, "涓荤敓浜ц鍒�");
     }
 
+    private void validateSalesSource(ProductionPlanDto dto) {
+        if (dto == null) {
+            throw new ServiceException("鐢熶骇璁″垝涓嶈兘涓虹┖");
+        }
+        if (dto.getSalesLedgerId() == null && dto.getSalesLedgerProductId() == null) {
+            return;
+        }
+        if (dto.getSalesLedgerId() == null || dto.getSalesLedgerProductId() == null) {
+            throw new ServiceException("閿�鍞彴璐﹀拰閿�鍞骇鍝佸繀椤诲悓鏃跺~鍐�");
+        }
+        SalesLedgerProduct product = salesLedgerProductMapper.selectById(dto.getSalesLedgerProductId());
+        if (product == null || !Objects.equals(product.getSalesLedgerId(), dto.getSalesLedgerId())) {
+            throw new ServiceException("閿�鍞骇鍝佷笌閿�鍞彴璐︿笉鍖归厤");
+        }
+        SalesLedger ledger = salesLedgerMapper.selectById(dto.getSalesLedgerId());
+        if (ledger == null || (!Objects.equals(ledger.getContractType(), 1)
+                && !Objects.equals(ledger.getContractType(), 3))) {
+            throw new ServiceException("鐢熶骇璁″垝鍙兘鍏宠仈鏅�氶攢鍞骇鍝佹垨妗嗘灦璁㈠崟浜у搧");
+        }
+        if (dto.getProductModelId() == null) {
+            dto.setProductModelId(product.getProductModelId());
+        } else if (!Objects.equals(dto.getProductModelId(), product.getProductModelId())) {
+            throw new ServiceException("鐢熶骇璁″垝浜у搧鍨嬪彿涓庨攢鍞骇鍝佷笉涓�鑷�");
+        }
+    }
+
     /**
      * 鏍¢獙涓荤敓浜ц鍒掑彿鍞竴鎬э紝鍙�氳繃 excludeId 鎺掗櫎褰撳墠璁板綍銆�
      */

--
Gitblit v1.9.3