From d1fac30e634e33edd29e3440de1f91da84c150c1 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 05 六月 2026 15:38:39 +0800
Subject: [PATCH] feat(account): 新增付款状态管理功能并优化生产任务查询

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 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 19aa02f..4dc8bab 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.mapper.ProductModelMapper;
+import com.ruoyi.basic.pojo.ProductModel;
 import com.ruoyi.framework.web.domain.R;
 import com.ruoyi.procurementrecord.utils.StockUtils;
 import com.ruoyi.production.mapper.*;
@@ -86,6 +88,8 @@
     private StockUtils stockUtils;
     @Autowired
     private StockInventoryMapper stockInventoryMapper;
+    @Autowired
+    private ProductModelMapper productModelMapper;
 
     @Override
     public SalesLedgerProduct selectSalesLedgerProductById(Long id) {
@@ -167,6 +171,12 @@
 
         int result;
         Long salesLedgerId = salesLedgerProduct.getSalesLedgerId();
+        salesLedgerProduct.setSingleQuantity(normalizeSingleQuantity(salesLedgerProduct.getSingleQuantity()));
+        salesLedgerProduct.setTotalQuantity(normalizeTotalQuantity(
+                salesLedgerProduct.getTotalQuantity(),
+                salesLedgerProduct.getQuantity(),
+                salesLedgerProduct.getSingleQuantity()
+        ));
         if (salesLedgerProduct.getId() == null) {
             salesLedgerProduct.setRegisterDate(LocalDateTime.now());
             result = salesLedgerProductMapper.insert(salesLedgerProduct);
@@ -219,12 +229,32 @@
             return;
         }
         SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerProduct.getSalesLedgerId());
+        // 鑾峰彇鍗曚綅锛氫紭鍏堜娇鐢ㄥ墠绔紶鍏ョ殑unit锛屽惁鍒欎粠浜у搧瑙勬牸鑾峰彇
+        String unit = salesLedgerProduct.getUnit();
+        if (unit == null || unit.isEmpty()) {
+            ProductModel productModel = productModelMapper.selectById(salesLedgerProduct.getProductModelId());
+            unit = productModel != null ? productModel.getUnit() : null;
+        }
+
         ProductionPlan productionPlan = new ProductionPlan();
         productionPlan.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId());
         productionPlan.setSalesLedgerProductId(salesLedgerProduct.getId());
         productionPlan.setMpsNo(generateNextPlanNo(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))));
         productionPlan.setProductModelId(salesLedgerProduct.getProductModelId());
+        // 闇�姹傛暟閲� = 浜у搧鏁伴噺锛堜笉鏄�绘暟锛�
         productionPlan.setQtyRequired(salesLedgerProduct.getQuantity());
+        // 鍚屾鍗曚綅
+        productionPlan.setUnit(unit);
+        // 鍚屾浜у搧鏁伴噺
+        productionPlan.setQuantity(salesLedgerProduct.getQuantity());
+        // 鍚屾姣忎欢鏁伴噺
+        productionPlan.setSingleQuantity(normalizeSingleQuantity(salesLedgerProduct.getSingleQuantity()));
+        // 鍚屾鎬绘暟
+        productionPlan.setTotalQuantity(normalizeTotalQuantity(
+                salesLedgerProduct.getTotalQuantity(),
+                salesLedgerProduct.getQuantity(),
+                salesLedgerProduct.getSingleQuantity()
+        ));
         productionPlan.setSource("閿�鍞�");
         productionPlan.setStatus(0);
         productionPlan.setRequiredDate(salesLedger.getDeliveryDate());//闇�姹傛棩鏈�=浜よ揣鏃ユ湡
@@ -336,6 +366,23 @@
         return R.ok();
     }
 
+    private BigDecimal normalizeSingleQuantity(BigDecimal singleQuantity) {
+        if (singleQuantity == null || singleQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+            return BigDecimal.ONE;
+        }
+        return singleQuantity;
+    }
+
+    private BigDecimal normalizeTotalQuantity(BigDecimal totalQuantity, BigDecimal quantity, BigDecimal singleQuantity) {
+        if (totalQuantity != null && totalQuantity.compareTo(BigDecimal.ZERO) > 0) {
+            return totalQuantity;
+        }
+        if (quantity == null || quantity.compareTo(BigDecimal.ZERO) <= 0) {
+            return BigDecimal.ZERO;
+        }
+        return quantity.multiply(normalizeSingleQuantity(singleQuantity));
+    }
+
     private String generateNextPlanNo(String datePrefix) {
         QueryWrapper<ProductionPlan> queryWrapper = new QueryWrapper<>();
         queryWrapper.likeRight("mps_no", "JH" + datePrefix);

--
Gitblit v1.9.3