From bb5bf872de5e67d7b406e3a305c9dfcbd0f218a6 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 26 六月 2025 18:03:55 +0800
Subject: [PATCH] 采购,正式库优化

---
 main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
index a38e13b..412e7bb 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
@@ -20,8 +20,10 @@
 import com.ruoyi.business.service.InputInventoryRecordService;
 import com.ruoyi.business.service.InventorySummaryService;
 import com.ruoyi.business.service.PendingInventoryService;
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.system.mapper.SysUserMapper;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -52,6 +54,8 @@
     private final CoalFieldMapper coalFieldMapper;
 
     private final CoalInfoMapper coalInfoMapper;
+
+    private final SysUserMapper sysUserMapper;
 
     private final InputInventoryRecordService inputInventoryRecordService;
 
@@ -91,6 +95,20 @@
             coalInfoMap = new HashMap<>();
         }
 
+        // 5. 鎵归噺鏌ヨ鐧昏浜篿d
+        List<Long> registrantIds = pendingInventoryPage.getRecords().stream()
+                .map(PendingInventory::getRegistrantId)
+                .distinct()
+                .toList();
+        // 鎵归噺鏌ヨ鐧昏浜�
+        Map<Long, SysUser> sysUserMap;
+        if (!registrantIds.isEmpty()) {
+            List<SysUser> sysUsers = sysUserMapper.selectList(registrantIds);
+            sysUserMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity()));
+        } else {
+            sysUserMap = new HashMap<>();
+        }
+
         // 鎵归噺鏌ヨ姝e紡搴撳瓨淇℃伅
         Map<Long, Long> pendingToOfficialMap = getOfficialInventoryMap(pendingIds);
 
@@ -103,6 +121,12 @@
             CoalInfo coalInfo = coalInfoMap.get(record.getCoalId());
             if (coalInfo != null) {
                 dto.setCoal(coalInfo.getCoal());
+            }
+
+            // 璁剧疆鐧昏浜�
+            SysUser sysUser = sysUserMap.get(record.getRegistrantId());
+            if (sysUser != null) {
+                dto.setRegistrant(sysUser.getNickName());
             }
 
             // 浠庨鍔犺浇鐨凪ap涓幏鍙杘fficialId
@@ -209,6 +233,7 @@
             BigDecimal left = pendingInventory.getInventoryQuantity().subtract(quantity);
             if (left.compareTo(BigDecimal.ZERO) > 0) {
                 pendingInventory.setInventoryQuantity(left);
+                pendingInventory.setCoalPlanId(pendingInventoryDto.getCoalPlanId());
                 pendingInventoryMapper.updateById(pendingInventory);
             } else {
                 pendingInventoryMapper.deleteById(pendingInventoryDto.getPId());
@@ -218,8 +243,11 @@
                 OfficialInventory officialInventory = new OfficialInventory();
                 BeanUtils.copyProperties(pendingInventory, officialInventory);
                 officialInventory.setId(null);
+                officialInventory.setCoalPlanId(pendingInventoryDto.getCoalPlanId());
                 officialInventory.setPendingId(pendingInventoryDto.getPId());
                 officialInventory.setInventoryQuantity(quantity);
+                officialInventory.setRegistrantId(1L);
+                officialInventory.setSupplierId(pendingInventoryDto.getSupplierId());
                 officialInventoryMapper.insert(officialInventory);
             } else {
                 OfficialInventory officialInventory = officialInventoryMapper.selectById(pendingInventoryDto.getOfficialId());

--
Gitblit v1.9.3