From 74260d0eb5ce27531cd2f7b79538170edcd042bb Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 30 三月 2026 18:50:00 +0800
Subject: [PATCH] fix: 产品入库的库存返回产品大类、规则型号、单位

---
 src/main/resources/mapper/procurementrecord/ProcurementRecordOutMapper.xml               |   20 +++++++++++++-------
 src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java |   29 ++++++++++++++++++-----------
 2 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java b/src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java
index 7361c0a..8a11f1c 100644
--- a/src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java
@@ -181,11 +181,13 @@
         String entryDateStr = procurementDto.getEntryDate() + " 00:00:00";
         String createTimeStr = procurementDto.getCreateTime() + " 00:00:00";
         SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(procurementDto.getSalesLedgerProductId());
-        if (salesLedgerProduct == null) {
+        if (procurementDto.getSalesLedgerProductId() != null && salesLedgerProduct == null) {
             throw new RuntimeException("閿�鍞彴璐︿骇鍝佷笉瀛樺湪");
         }
-        salesLedgerProduct.setMinStock(procurementDto.getMinStock());
-        salesLedgerProductMapper.updateById(salesLedgerProduct);
+        if (procurementDto.getSalesLedgerProductId() != null && salesLedgerProduct != null) {
+            salesLedgerProduct.setMinStock(procurementDto.getMinStock());
+            salesLedgerProductMapper.updateById(salesLedgerProduct);
+        }
         ProcurementRecordStorage procurementRecordStorageById = getProcurementRecordById(procurementDto.getId());
         procurementRecordStorageById.setCreateBy(sysUser.getNickName());
         procurementRecordStorageById.setCreateUser(sysUser.getUserId());
@@ -440,20 +442,25 @@
     @Override
     public int addProduct(Details detail) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
-        ProcurementRecordStorage.ProcurementRecordStorageBuilder procurementRecordBuilder = ProcurementRecordStorage.builder()
+
+        ProcurementRecordStorage.ProcurementRecordStorageBuilder builder = ProcurementRecordStorage.builder()
+                .id(detail.getId())
                 .inboundBatches("绗�1鎵规")
                 .inboundNum(detail.getInboundQuantity())
                 .warnNum(detail.getWarnNum())
                 .outStockQuantity(detail.getOutStockQuantity())
                 .shortageDescription(detail.getShortageDescription())
-                .createTime(LocalDateTime.now())
-                .createUser(loginUser.getUserId())
+                .productModelId(detail.getProductModelId())
                 .updateTime(LocalDateTime.now())
-                .updateUser(loginUser.getUserId())
-                .createBy(loginUser.getNickName())
-                .productModelId(detail.getProductModelId());
-        this.save(procurementRecordBuilder.build());
-        return 1;
+                .updateUser(loginUser.getUserId());
+        if (detail.getId() == null) {
+            builder.createTime(LocalDateTime.now())
+                    .createUser(loginUser.getUserId())
+                    .createBy(loginUser.getNickName());
+        }
+
+        boolean success = this.saveOrUpdate(builder.build());
+        return success ? 1 : 0;
     }
 
     @Override
diff --git a/src/main/resources/mapper/procurementrecord/ProcurementRecordOutMapper.xml b/src/main/resources/mapper/procurementrecord/ProcurementRecordOutMapper.xml
index 2a880ba..33be8e2 100644
--- a/src/main/resources/mapper/procurementrecord/ProcurementRecordOutMapper.xml
+++ b/src/main/resources/mapper/procurementrecord/ProcurementRecordOutMapper.xml
@@ -5,11 +5,11 @@
     <select id="listPage" resultType="com.ruoyi.procurementrecord.dto.ProcurementRecordOutPageDto">
         select
         t3.supplier_name,
-        t2.product_category,
+        COALESCE(t2.product_category, t6.product_name) as product_category,
         t1.id,
         t1.code,
-        t2.specification_model,
-        t2.unit,
+        COALESCE(t2.specification_model, t5.model) as specification_model,
+        COALESCE(t2.unit, t5.unit) as unit,
         t2.tax_rate,
         t2.tax_inclusive_unit_price,
         t2.tax_inclusive_total_price,
@@ -17,10 +17,13 @@
         t1.inbound_num,
         t1.create_time,
         t1.create_by,
-        t2.warn_num
+        COALESCE(t2.warn_num, t4.warn_num) as warn_num
         from  procurement_record_out t1
         left join sales_ledger_product t2 on t2.id = t1.sales_ledger_product_id
         left join purchase_ledger t3 on t3.id = t2.sales_ledger_id
+        left join procurement_record_storage t4 on t4.id = t1.procurement_record_storage_id
+        left join product_model t5 on t5.id = t4.product_model_id
+        left join product t6 on t6.id = t5.product_id
         <where>
             1 = 1
             <if test="req.supplierName != null and req.supplierName != ''">
@@ -34,10 +37,10 @@
     <select id="list" resultType="com.ruoyi.procurementrecord.dto.ProcurementRecordOutPageDto">
         select
             t3.supplier_name,
-            t2.product_category,
+            COALESCE(t2.product_category, t6.product_name) as product_category,
             t1.id,
-            t2.specification_model,
-            t2.unit,
+            COALESCE(t2.specification_model, t5.model) as specification_model,
+            COALESCE(t2.unit, t5.unit) as unit,
             t2.tax_rate,
             t2.tax_inclusive_unit_price,
             t2.tax_inclusive_total_price,
@@ -49,6 +52,9 @@
         from  procurement_record_out t1
                   left join sales_ledger_product t2 on t2.id = t1.sales_ledger_product_id
                   left join purchase_ledger t3 on t3.id = t2.sales_ledger_id
+                  left join procurement_record_storage t4 on t4.id = t1.procurement_record_storage_id
+                  left join product_model t5 on t5.id = t4.product_model_id
+                  left join product t6 on t6.id = t5.product_id
     </select>
     <select id="getSumQuantity" resultType="BigDecimal">
         select COALESCE(sum(inbound_num), 0)

--
Gitblit v1.9.3