From 23ec64ed997fc206fba9f0d6a84975f7b36c47be Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期日, 11 十月 2026 16:09:26 +0800
Subject: [PATCH] 天津-奇缘恒艺 录数据需求修改

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java |  133 ++++++++++++++------------------------------
 1 files changed, 43 insertions(+), 90 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 817bfc6..66285d4 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,9 +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.InvoiceRegistrationProductDto;
-import com.ruoyi.sales.dto.SalesLedgerProductDto;
-import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper;
 import com.ruoyi.sales.mapper.SalesLedgerMapper;
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
 import com.ruoyi.sales.mapper.ShippingInfoMapper;
@@ -30,7 +27,8 @@
 import com.ruoyi.technology.mapper.TechnologyBomStructureMapper;
 import com.ruoyi.technology.mapper.TechnologyRoutingMapper;
 import com.ruoyi.technology.pojo.TechnologyRouting;
-import lombok.RequiredArgsConstructor;
+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;
@@ -39,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;
@@ -77,8 +74,6 @@
     @Autowired
     private TechnologyBomStructureMapper technologyBomStructureMapper;
     @Autowired
-    private InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
-    @Autowired
     private ProductionProductMainMapper productionProductMainMapper;
     @Autowired
     private ProductionProductOutputMapper productionProductOutputMapper;
@@ -94,6 +89,8 @@
     private StockUtils stockUtils;
     @Autowired
     private StockInventoryMapper stockInventoryMapper;
+    @Autowired
+    private IProductService productService;
 
     @Override
     public SalesLedgerProduct selectSalesLedgerProductById(Long id) {
@@ -102,53 +99,34 @@
 
     @Override
     public List<SalesLedgerProduct> selectSalesLedgerProductList(SalesLedgerProduct salesLedgerProduct) {
-//        LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
-//        queryWrapper.eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerProduct.getSalesLedgerId())
-//                .eq(SalesLedgerProduct::getType, salesLedgerProduct.getType());
         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.setShippingStatus(shippingInfo.getStatus());
-                    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);
                 }
             });
-            // 寮�绁�
-            InvoiceRegistrationProductDto invoiceRegistrationProductDto = new InvoiceRegistrationProductDto();
-            invoiceRegistrationProductDto.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId().intValue());
-            List<InvoiceRegistrationProductDto> invoiceRegistrationProductDtoList = invoiceRegistrationProductMapper.invoiceRegistrationProductList(invoiceRegistrationProductDto);
-            // 缁熻寮�绁ㄧ櫥璁颁骇鍝佺殑宸插紑绁ㄦ暟/宸插紑绁ㄩ噾棰�
-            if (!CollectionUtils.isEmpty(invoiceRegistrationProductDtoList)) {
-                for (SalesLedgerProduct ledgerProduct : salesLedgerProducts) {
-                    BigDecimal invoiceNum = BigDecimal.ZERO;
-                    BigDecimal invoiceAmount = BigDecimal.ZERO;
-                    BigDecimal noInvoiceNum = BigDecimal.ZERO;
-                    BigDecimal noInvoiceAmount = BigDecimal.ZERO;
-                    for (InvoiceRegistrationProductDto registrationProductDto : invoiceRegistrationProductDtoList) {
-                        if(ledgerProduct.getId().intValue() == registrationProductDto.getSalesLedgerProductId()){
-                            invoiceNum =  invoiceNum.add(registrationProductDto.getInvoiceNum());
-                            invoiceAmount = invoiceAmount.add(registrationProductDto.getInvoiceAmount());
-                        }
-                    }
-                    noInvoiceNum = ledgerProduct.getQuantity().subtract(invoiceNum);
-                    noInvoiceAmount = ledgerProduct.getTaxInclusiveTotalPrice().subtract(invoiceAmount);
-                    ledgerProduct.setInvoiceNum(invoiceNum);
-                    ledgerProduct.setInvoiceAmount(invoiceAmount);
-                    ledgerProduct.setNoInvoiceNum(noInvoiceNum);
-                    ledgerProduct.setNoInvoiceAmount(noInvoiceAmount);
-
-
-                }
-            }
-
         }
         return salesLedgerProducts;
     }
@@ -204,17 +182,17 @@
     @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())) {
+            ProductModel productModel = productService.ensureProductHierarchy(
+                    salesLedgerProduct.getProductCategory(),
+                    salesLedgerProduct.getSpecificationModel(),
+                    salesLedgerProduct.getUnit());
+            if (productModel != null) {
+                salesLedgerProduct.setProductId(productModel.getProductId());
+                salesLedgerProduct.setProductModelId(productModel.getId());
+            }
         }
 
         int result;
@@ -225,7 +203,6 @@
             addProductionData(salesLedgerProduct);
         } else {
             //鏌ヨ鍘熸湰鐨勪骇鍝佸瀷鍙穒d
-            salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity());
             result = salesLedgerProductMapper.updateById(salesLedgerProduct);
             /*鍒犻櫎瀵瑰簲鐨勭敓浜ф暟鎹苟閲嶆柊鏂板*/
             deleteProductionData(Arrays.asList(salesLedgerProduct.getId()));
@@ -268,14 +245,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("閿�鍞�");
@@ -290,6 +268,9 @@
      * 鍒犻櫎鐢熶骇璁″垝
      */
     public void deleteProductionData(List<Long> productIds) {
+        if (CollectionUtils.isEmpty(productIds)) {
+            return;
+        }
         List<ProductionPlan> productionPlans = productionPlanMapper.selectList(
                 new LambdaQueryWrapper<ProductionPlan>()
                         .in(ProductionPlan::getSalesLedgerProductId, productIds.stream().map(Long::intValue).collect(Collectors.toList())));
@@ -302,34 +283,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