From d75958896efd4c8a6daee9c56d048641b99cacf6 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期二, 24 六月 2025 17:54:50 +0800
Subject: [PATCH] 1.二维码巡检记录以及文件上传记录 2.部分优化

---
 main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java
index d2a2112..1ddb4c2 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java
@@ -1,15 +1,26 @@
 package com.ruoyi.business.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.business.dto.OfficialInventoryDto;
 import com.ruoyi.business.dto.PendingInventoryDto;
 import com.ruoyi.business.entity.InputInventoryRecord;
+import com.ruoyi.business.entity.InventorySummary;
 import com.ruoyi.business.mapper.InputInventoryRecordMapper;
+import com.ruoyi.business.mapper.InventorySummaryMapper;
 import com.ruoyi.business.service.InputInventoryRecordService;
+import com.ruoyi.business.service.InventorySummaryService;
+import com.ruoyi.business.utils.InventoryUtils;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 import static com.ruoyi.business.constant.InventoryRecordConstant.OFFICIAL_INVENTORY;
 import static com.ruoyi.business.constant.InventoryRecordConstant.PENDING_INVENTORY;
@@ -26,6 +37,9 @@
 @RequiredArgsConstructor
 public class InputInventoryRecordServiceImpl extends ServiceImpl<InputInventoryRecordMapper, InputInventoryRecord> implements InputInventoryRecordService {
     private final InputInventoryRecordMapper inputInventoryRecordMapper;
+    private final InventorySummaryService inventorySummaryService;
+    private final InventorySummaryMapper inventorySummaryMapper;
+    private final InventoryUtils inventoryUtils;
 
     @Override
     public int insertInputInventoryRecord(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto, BigDecimal quantity) {
@@ -43,18 +57,52 @@
         }
         inputInventoryRecord.setQuantity(quantity);
 
-        return inputInventoryRecordMapper.insert(inputInventoryRecord);
+        inputInventoryRecordMapper.insert(inputInventoryRecord);
 
         // 鏇存柊搴撳瓨
-//         inventorySummaryService.updateInventory(pendingInventoryDto, officialInventoryDto);
+        return inventorySummaryService.updateInventory(pendingInventoryDto, officialInventoryDto);
     }
 
     @Override
-    public int deleteInputInventoryRecord(Long[] ids) {
+    public int deleteInputInventoryRecord(List<Long> ids) {
+        if (CollectionUtils.isEmpty(ids)) {
+            throw new RuntimeException("璇蜂紶鍏ヨ鍒犻櫎鐨刬d璁板綍");
+        }
+        List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordMapper.selectBatchIds(ids);
+        // 鏍规嵁id杩涜闄嶅簭鎺掑簭
+        List<InputInventoryRecord> inputInventoryRecordList = inputInventoryRecords.stream()
+                .sorted(Comparator.comparing(InputInventoryRecord::getId).reversed())
+                .toList();
+
+        String InventoryType = inputInventoryRecords.get(0).getInventoryType();
+        List<Long> inventoryIds = inputInventoryRecords.stream().map(InputInventoryRecord::getInventoryId).toList().stream().distinct().collect(Collectors.toList());
+        List<InventorySummary> inventorySummaries = inventorySummaryMapper.selectList(new LambdaQueryWrapper<InventorySummary>()
+                .eq(InventorySummary::getInventoryType, InventoryType)
+                .in(InventorySummary::getInventoryId, inventoryIds));
+        if (CollectionUtils.isNotEmpty(inventorySummaries)) {
+            List<InventorySummary> updates = new ArrayList<>();
+            for (InventorySummary inventorySummary : inventorySummaries) {
+                for (InputInventoryRecord inputInventoryRecord : inputInventoryRecordList) {
+                    // 濡傛灉鑺傜偣涓婄殑鍏ュ簱璁板綍id澶т簬鍙樻洿鐨刬d锛岃鏄庢id鍓嶆墍鏈夊叆搴撹褰曢兘瑕侀噸鏂拌绠�
+                    if (Objects.equals(inventorySummary.getInventoryId(), inputInventoryRecord.getInventoryId()) && inventorySummary.getInputEndRecordId() > inputInventoryRecord.getId()) {
+                        inventorySummary.setInputEndRecordId(inputInventoryRecord.getId());
+                        updates.add(inventorySummary);
+                    }
+                }
+
+            }
+            // 閲嶇疆鑺傜偣鏈�缁坕d
+            inventorySummaryMapper.updateById(updates);
+        }
+
+        // 閲嶆柊璁$畻鑺傜偣搴撳瓨
+        inventorySummaryService.updateInventorySummary(ids);
+
+        // 鏇存柊搴撳瓨瀹炴椂鏁版嵁
+        inventoryUtils.updateInventoryByIds(inventoryIds, inputInventoryRecords.get(0).getInventoryType());
 
 
-
-
-        return 0;
+        // 鍒犻櫎鍏ュ簱璁板綍
+        return inputInventoryRecordMapper.deleteByIds(ids);
     }
 }

--
Gitblit v1.9.3