From 5640d1300795c002438962386049bb65fb4f2216 Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期二, 22 九月 2026 18:05:34 +0800
Subject: [PATCH] feat: 采购台账产品层级自动注册与材质字段、大类删除限制、审批模板启用后仅可修改状态

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java |   51 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 41 insertions(+), 10 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 b8042d8..b2c002f 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -4,6 +4,8 @@
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.basic.pojo.ProductModel;
+import com.ruoyi.basic.service.IProductService;
 import com.ruoyi.framework.web.domain.R;
 import com.ruoyi.procurementrecord.utils.StockUtils;
 import com.ruoyi.production.mapper.*;
@@ -25,6 +27,8 @@
 import com.ruoyi.technology.mapper.TechnologyBomStructureMapper;
 import com.ruoyi.technology.mapper.TechnologyRoutingMapper;
 import com.ruoyi.technology.pojo.TechnologyRouting;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -33,9 +37,7 @@
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.Arrays;
 import java.util.List;
@@ -87,6 +89,8 @@
     private StockUtils stockUtils;
     @Autowired
     private StockInventoryMapper stockInventoryMapper;
+    @Autowired
+    private IProductService productService;
 
     @Override
     public SalesLedgerProduct selectSalesLedgerProductById(Long id) {
@@ -98,16 +102,29 @@
         List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectSalesLedgerProductList(salesLedgerProduct);
         if(!CollectionUtils.isEmpty(salesLedgerProducts)){
             salesLedgerProducts.forEach(item -> {
-                // 鍙戣揣淇℃伅
-                ShippingInfo shippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
+                // 鍙戣揣淇℃伅锛堝彇鏈�鏂颁竴鏉★紝鍙煡璇㈠鏍搁�氳繃鎴栧凡鍙戣揣鐨勮褰曪級
+                ShippingInfo latestShippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
                         .eq(ShippingInfo::getSalesLedgerProductId, item.getId())
+                        .in(ShippingInfo::getStatus, "瀹℃牳閫氳繃", "宸插彂璐�")
                         .orderByDesc(ShippingInfo::getCreateTime)
                         .last("limit 1"));
-                if(shippingInfo != null){
-                    item.setShippingDate(shippingInfo.getShippingDate());
-                    item.setShippingCarNumber(shippingInfo.getShippingCarNumber());
-                    item.setExpressCompany(shippingInfo.getExpressCompany());
-                    item.setExpressNumber(shippingInfo.getExpressNumber());
+                if(latestShippingInfo != null){
+                    item.setShippingDate(latestShippingInfo.getShippingDate());
+                    item.setExpressCompany(latestShippingInfo.getExpressCompany());
+                    item.setExpressNumber(latestShippingInfo.getExpressNumber());
+                }
+                // 杞︾墝鍙凤細鍙栨墍鏈夊鏍搁�氳繃鎴栧凡鍙戣揣璁板綍鐨勮溅鐗屽彿锛岄�楀彿鎷兼帴
+                List<ShippingInfo> allShippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
+                        .eq(ShippingInfo::getSalesLedgerProductId, item.getId())
+                        .in(ShippingInfo::getStatus, "瀹℃牳閫氳繃", "宸插彂璐�")
+                        .orderByAsc(ShippingInfo::getCreateTime));
+                if(!CollectionUtils.isEmpty(allShippingInfos)){
+                    String carNumbers = allShippingInfos.stream()
+                            .map(ShippingInfo::getShippingCarNumber)
+                            .filter(carNo -> carNo != null && !carNo.trim().isEmpty())
+                            .distinct()
+                            .collect(Collectors.joining(","));
+                    item.setShippingCarNumber(carNumbers);
                 }
             });
         }
@@ -166,6 +183,20 @@
     @Transactional(rollbackFor = Exception.class)
     public int addOrUpdateSalesLedgerProduct(SalesLedgerProduct salesLedgerProduct) {
 
+        // 閲囪喘鍙拌处(type=2)鎵嬪伐褰曞叆鍝佸悕/鏉愯川/瑙勬牸鍨嬪彿鏃讹紝鑷姩娉ㄥ唽鍒颁骇鍝佺淮鎶�
+        if (Integer.valueOf(2).equals(salesLedgerProduct.getType())
+                && StringUtils.isNotBlank(salesLedgerProduct.getMaterial())) {
+            ProductModel productModel = productService.ensureProductHierarchy(
+                    salesLedgerProduct.getProductCategory(),
+                    salesLedgerProduct.getMaterial(),
+                    salesLedgerProduct.getSpecificationModel(),
+                    salesLedgerProduct.getUnit());
+            if (productModel != null) {
+                salesLedgerProduct.setProductId(productModel.getProductId());
+                salesLedgerProduct.setProductModelId(productModel.getId());
+            }
+        }
+
         int result;
         Long salesLedgerId = salesLedgerProduct.getSalesLedgerId();
         if (salesLedgerProduct.getId() == null) {
@@ -216,7 +247,7 @@
      */
     public void addProductionData(SalesLedgerProduct salesLedgerProduct) {
         //鍏堝垽鏂浜у搧鏄惁闇�瑕佺敓浜�
-        if (!salesLedgerProduct.getIsProduction()) {
+        if (!BooleanUtils.isTrue(salesLedgerProduct.getIsProduction())) {
             return;
         }
         SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerProduct.getSalesLedgerId());

--
Gitblit v1.9.3