From 91968cc6ee3fa8206201fd137f56a20ae4b6dff7 Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期三, 23 九月 2026 15:19:46 +0800
Subject: [PATCH] feat: 销售台账手工录入品名/材质/规格型号自动注册产品层级,回退采购台账相关改动

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java |   95 +++++++++++++++++++++--------------------------
 1 files changed, 42 insertions(+), 53 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 daf5d88..f587a7a 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -3,9 +3,9 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 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.*;
@@ -14,7 +14,6 @@
 import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
 import com.ruoyi.purchase.pojo.PurchaseLedger;
 import com.ruoyi.quality.mapper.QualityInspectMapper;
-import com.ruoyi.sales.dto.SalesLedgerProductDto;
 import com.ruoyi.sales.mapper.SalesLedgerMapper;
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
 import com.ruoyi.sales.mapper.ShippingInfoMapper;
@@ -28,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;
@@ -36,7 +37,6 @@
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.Arrays;
@@ -89,6 +89,8 @@
     private StockUtils stockUtils;
     @Autowired
     private StockInventoryMapper stockInventoryMapper;
+    @Autowired
+    private IProductService productService;
 
     @Override
     public SalesLedgerProduct selectSalesLedgerProductById(Long id) {
@@ -100,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);
                 }
             });
         }
@@ -167,17 +182,19 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public int addOrUpdateSalesLedgerProduct(SalesLedgerProduct salesLedgerProduct) {
-        // 寰呭洖娆撅紝浠樻
-        if(salesLedgerProduct.getType().equals(1)){
-            salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProduct.getTaxInclusiveTotalPrice().subtract(salesLedgerProduct.getInvoiceTotal()));
-            //鏈紑绁ㄦ暟閲�+閲戦
-            salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
-            salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
-        }else{
-            salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getTaxInclusiveTotalPrice().subtract(salesLedgerProduct.getTicketsTotal()));
-            // 鏈潵绁ㄦ暟閲�+閲戦
-            salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity());
-            salesLedgerProduct.setFutureTicketsAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
+
+        // 閿�鍞彴璐�(type=1)鎵嬪伐褰曞叆鍝佸悕/鏉愯川/瑙勬牸鍨嬪彿鏃讹紝鑷姩娉ㄥ唽鍒颁骇鍝佺淮鎶�
+        if (Integer.valueOf(1).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;
@@ -188,7 +205,6 @@
             addProductionData(salesLedgerProduct);
         } else {
             //鏌ヨ鍘熸湰鐨勪骇鍝佸瀷鍙穒d
-            salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity());
             result = salesLedgerProductMapper.updateById(salesLedgerProduct);
             /*鍒犻櫎瀵瑰簲鐨勭敓浜ф暟鎹苟閲嶆柊鏂板*/
             deleteProductionData(Arrays.asList(salesLedgerProduct.getId()));
@@ -231,14 +247,15 @@
      */
     public void addProductionData(SalesLedgerProduct salesLedgerProduct) {
         //鍏堝垽鏂浜у搧鏄惁闇�瑕佺敓浜�
-        if (!salesLedgerProduct.getIsProduction()) {
+        if (!BooleanUtils.isTrue(salesLedgerProduct.getIsProduction())) {
             return;
         }
         SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerProduct.getSalesLedgerId());
         ProductionPlan productionPlan = new ProductionPlan();
         productionPlan.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId());
         productionPlan.setSalesLedgerProductId(salesLedgerProduct.getId());
-        productionPlan.setMpsNo(generateNextPlanNo(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))));
+        productionPlan.setMpsNo(generateNextPlanNo(com.ruoyi.common.utils.DateUtils.toLocalDate(salesLedger.getEntryDate())
+                .format(DateTimeFormatter.ofPattern("yyyyMMdd"))));
         productionPlan.setProductModelId(salesLedgerProduct.getProductModelId());
         productionPlan.setQtyRequired(salesLedgerProduct.getQuantity());
         productionPlan.setSource("閿�鍞�");
@@ -268,34 +285,6 @@
         }
         List<Long> ids = productionPlans.stream().map(ProductionPlan::getId).collect(Collectors.toList());
         productionPlanMapper.deleteByIds(ids);
-    }
-
-    @Override
-    public IPage<SalesLedgerProductDto> listPage(Page page, SalesLedgerProductDto salesLedgerProduct) {
-        IPage<SalesLedgerProductDto> salesLedgerProductDtoIPage = salesLedgerProductMapper.listPage(page, salesLedgerProduct);
-        salesLedgerProductDtoIPage.getRecords().forEach(item -> {
-            // 鍒ゆ柇鐘舵��
-            if(item.getTaxInclusiveTotalPrice().compareTo(item.getInvoiceTotal()) == 0){
-                item.setStatusName("宸插畬鎴愪粯娆�");
-            }else{
-                item.setStatusName("鏈畬鎴愪粯娆�");
-            }
-        });
-        return salesLedgerProductDtoIPage;
-    }
-
-    @Override
-    public IPage<SalesLedgerProductDto> listPagePurchaseLedger(Page page, SalesLedgerProductDto salesLedgerProduct) {
-        IPage<SalesLedgerProductDto> salesLedgerProductDtoIPage = salesLedgerProductMapper.listPagePurchaseLedger(page, salesLedgerProduct);
-        salesLedgerProductDtoIPage.getRecords().forEach(item -> {
-            // 鍒ゆ柇鐘舵��
-            if(item.getTaxInclusiveTotalPrice().compareTo(item.getTicketsTotal()) == 0){
-                item.setStatusName("宸插畬鎴愪粯娆�");
-            }else{
-                item.setStatusName("鏈畬鎴愪粯娆�");
-            }
-        });
-        return salesLedgerProductDtoIPage;
     }
 
     /**

--
Gitblit v1.9.3