From 506b7d5577e797cb65b89e953daed75da0d6512b Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期二, 28 四月 2026 14:22:39 +0800
Subject: [PATCH] 修改上传文件相关

---
 src/main/java/com/ruoyi/basic/service/impl/StorageAttachmentServiceImpl.java |   10 +---
 src/main/java/com/ruoyi/basic/service/StorageAttachmentService.java          |    4 +-
 src/main/java/com/ruoyi/basic/controller/StorageAttachmentController.java    |    9 ++--
 src/main/java/com/ruoyi/basic/utils/FileUtil.java                            |   45 +++++++++-------------
 src/main/java/com/ruoyi/basic/dto/StorageBlobVO.java                         |    2 +
 5 files changed, 30 insertions(+), 40 deletions(-)

diff --git a/src/main/java/com/ruoyi/basic/controller/StorageAttachmentController.java b/src/main/java/com/ruoyi/basic/controller/StorageAttachmentController.java
index 17cbb47..d79f911 100644
--- a/src/main/java/com/ruoyi/basic/controller/StorageAttachmentController.java
+++ b/src/main/java/com/ruoyi/basic/controller/StorageAttachmentController.java
@@ -18,19 +18,18 @@
 
 @RestController
 @AllArgsConstructor
-@RequestMapping("/basic/storage_attachment")
+    @RequestMapping("/basic/storage_attachment")
 public class StorageAttachmentController {
     private StorageAttachmentService storageAttachmentService;
 
     /**
      * 鍒嗛〉鏌ヨ閫氱敤鏂囦欢涓婁紶鐨勯檮浠朵俊鎭�
-     * @param page 鍒嗛〉鍙傛暟
      * @param storageAttachmentDTO 鍏宠仈璁板綍淇℃伅
      * @return 鍒嗛〉缁撴灉
      */
-    @GetMapping("/listPage")
-    public R listPage(Page page, StorageAttachmentDTO storageAttachmentDTO) {
-        return R.ok(storageAttachmentService.listPage(page, storageAttachmentDTO));
+    @GetMapping("/list")
+    public R list(StorageAttachmentDTO storageAttachmentDTO) {
+        return R.ok(storageAttachmentService.list(storageAttachmentDTO));
     }
 
     /**
diff --git a/src/main/java/com/ruoyi/basic/dto/StorageBlobVO.java b/src/main/java/com/ruoyi/basic/dto/StorageBlobVO.java
index 88fa3a2..75eed4f 100644
--- a/src/main/java/com/ruoyi/basic/dto/StorageBlobVO.java
+++ b/src/main/java/com/ruoyi/basic/dto/StorageBlobVO.java
@@ -14,4 +14,6 @@
      * 涓嬭浇鍦板潃
      */
     private String downloadURL;
+
+    private Long storageAttachmentId;
 }
diff --git a/src/main/java/com/ruoyi/basic/service/StorageAttachmentService.java b/src/main/java/com/ruoyi/basic/service/StorageAttachmentService.java
index b8a3f8a..be7e0cb 100644
--- a/src/main/java/com/ruoyi/basic/service/StorageAttachmentService.java
+++ b/src/main/java/com/ruoyi/basic/service/StorageAttachmentService.java
@@ -6,6 +6,7 @@
 import com.ruoyi.basic.dto.StorageAttachmentDTO;
 import com.ruoyi.basic.dto.StorageAttachmentVO;
 import com.ruoyi.basic.dto.StorageBlobDTO;
+import com.ruoyi.basic.dto.StorageBlobVO;
 import com.ruoyi.basic.enums.ApplicationTypeEnum;
 import com.ruoyi.basic.enums.RecordTypeEnum;
 import com.ruoyi.basic.pojo.StorageAttachment;
@@ -31,11 +32,10 @@
 
     /**
      * 鍒嗛〉鏌ヨ閫氱敤鏂囦欢涓婁紶鐨勯檮浠朵俊鎭�
-     * @param page 鍒嗛〉鍙傛暟
      * @param storageAttachmentDTO 鍏宠仈璁板綍淇℃伅
      * @return 鍒嗛〉缁撴灉
      */
-    public IPage<StorageAttachmentVO> listPage(Page page, StorageAttachmentDTO storageAttachmentDTO);
+    public List<StorageBlobVO> list(StorageAttachmentDTO storageAttachmentDTO);
 
     /**
      * 鍒犻櫎閫氱敤鏂囦欢涓婁紶鐨勯檮浠朵俊鎭�
diff --git a/src/main/java/com/ruoyi/basic/service/impl/StorageAttachmentServiceImpl.java b/src/main/java/com/ruoyi/basic/service/impl/StorageAttachmentServiceImpl.java
index e645380..fda9f26 100644
--- a/src/main/java/com/ruoyi/basic/service/impl/StorageAttachmentServiceImpl.java
+++ b/src/main/java/com/ruoyi/basic/service/impl/StorageAttachmentServiceImpl.java
@@ -1,12 +1,8 @@
 package com.ruoyi.basic.service.impl;
 
-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.dto.StorageAttachmentDTO;
-import com.ruoyi.basic.dto.StorageAttachmentVO;
-import com.ruoyi.basic.dto.StorageBlobDTO;
-import com.ruoyi.basic.enums.ApplicationTypeEnum;
+import com.ruoyi.basic.dto.StorageBlobVO;
 import com.ruoyi.basic.enums.RecordTypeEnum;
 import com.ruoyi.basic.mapper.StorageAttachmentMapper;
 import com.ruoyi.basic.mapper.StorageBlobMapper;
@@ -45,8 +41,8 @@
     }
 
     @Override
-    public IPage<StorageAttachmentVO> listPage(Page page, StorageAttachmentDTO storageAttachmentDTO) {
-        return fileUtil.getStorageAttachmentVosPageListByApplicationAndRecordTypeAndRecordId(page, storageAttachmentDTO);
+    public List<StorageBlobVO> list(StorageAttachmentDTO storageAttachmentDTO) {
+        return fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(storageAttachmentDTO);
     }
 
     @Override
diff --git a/src/main/java/com/ruoyi/basic/utils/FileUtil.java b/src/main/java/com/ruoyi/basic/utils/FileUtil.java
index 0e3d10d..c57468a 100644
--- a/src/main/java/com/ruoyi/basic/utils/FileUtil.java
+++ b/src/main/java/com/ruoyi/basic/utils/FileUtil.java
@@ -286,41 +286,20 @@
     /**
      * 閫氳繃璁板綍绫诲瀷鑾峰彇鏂囦欢淇℃伅 attachment锛堝垎椤碉級
      *
-     * @param page       鍒嗛〉鍙傛暟
      * @param storageAttachmentDTO 鍏宠仈璁板綍淇℃伅
      */
-    public IPage<StorageAttachmentVO> getStorageAttachmentVosPageListByApplicationAndRecordTypeAndRecordId(Page page, StorageAttachmentDTO storageAttachmentDTO) {
-        // 鍒嗛〉鏌ヨ绗﹀悎鏉′欢鐨� StorageAttachment 璁板綍
+    public List<StorageBlobVO> getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(StorageAttachmentDTO storageAttachmentDTO) {
         LambdaQueryWrapper<StorageAttachment> queryWrapper = new LambdaQueryWrapper<StorageAttachment>()
                 .eq(StorageAttachment::getRecordType, storageAttachmentDTO.getRecordType())
                 .eq(StorageAttachment::getRecordId, storageAttachmentDTO.getRecordId());
         if (storageAttachmentDTO.getApplication() != null) {
             queryWrapper.eq(StorageAttachment::getApplication, storageAttachmentDTO.getApplication());
         }
-        IPage<StorageAttachmentVO> storageAttachmentIPage = storageAttachmentMapper.selectPage(page, queryWrapper);
-
-        // 杞崲涓� StorageAttachmentVO 骞惰幏鍙栧搴旂殑 StorageBlobVO
-        List<StorageAttachmentVO> storageAttachmentVOS = new ArrayList<>();
-        if (CollectionUtils.isNotEmpty(storageAttachmentIPage.getRecords())) {
-            for (StorageAttachment storageAttachment : storageAttachmentIPage.getRecords()) {
-                StorageAttachmentVO storageAttachmentVO = new StorageAttachmentVO();
-                BeanUtils.copyProperties(storageAttachment, storageAttachmentVO);
-                List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()));
-                if (CollectionUtils.isEmpty(storageBlobVOS)) {
-                    storageAttachmentVO.setStorageBlobVOS(new ArrayList<>());
-                } else {
-                    storageAttachmentVO.setStorageBlobVOS(storageBlobVOS);
-                }
-                storageAttachmentVOS.add(storageAttachmentVO);
-            }
+        List<StorageAttachment> storageAttachments = storageAttachmentMapper.selectList(queryWrapper);
+        if (CollectionUtils.isEmpty(storageAttachments)) {
+            return null;
         }
-
-        // 鏋勫缓鍒嗛〉缁撴灉
-        IPage<StorageAttachmentVO> resultPage = new Page<>();
-        BeanUtils.copyProperties(storageAttachmentIPage, resultPage);
-        resultPage.setRecords(storageAttachmentVOS);
-
-        return resultPage;
+        return getStorageBlobVOsByStorageAttachmentIds(storageAttachments.stream().map(StorageAttachment::getId).collect(Collectors.toList()));
     }
 
     /**
@@ -355,6 +334,9 @@
         if (CollectionUtils.isEmpty(storageAttachments)) {
             return null;
         }
+        Map<Long, Long> blobIdToAttachmentIdMap = storageAttachments.stream()
+                .collect(Collectors.toMap(StorageAttachment::getStorageBlobId, StorageAttachment::getId));
+
         List<Long> storageBlobIds = storageAttachments.stream().map(StorageAttachment::getStorageBlobId).collect(Collectors.toList());
         List<StorageBlob> storageBlobs = storageBlobMapper.selectByIds(storageBlobIds);
         List<StorageBlobVO> storageBlobDTOS = new ArrayList<>();
@@ -363,6 +345,7 @@
             BeanUtils.copyProperties(storageBlob, storageBlobVO);
             storageBlobVO.setPreviewURL(buildSignedPreviewUrl(storageBlobVO));
             storageBlobVO.setDownloadURL(buildSignedDownloadUrl(storageBlobVO));
+            storageBlobVO.setStorageAttachmentId(blobIdToAttachmentIdMap.get(storageBlob.getId()));
             storageBlobDTOS.add(storageBlobVO);
         }
         return storageBlobDTOS;
@@ -398,6 +381,10 @@
         if (CollectionUtils.isEmpty(storageAttachments)) {
             return null;
         }
+        // 鏋勫缓 storageBlobId -> storageAttachmentId 鐨勬槧灏�
+        Map<Long, Long> blobIdToAttachmentIdMap = storageAttachments.stream()
+                .collect(Collectors.toMap(StorageAttachment::getStorageBlobId, StorageAttachment::getId));
+
         List<Long> storageBlobIds = storageAttachments.stream().map(StorageAttachment::getStorageBlobId).collect(Collectors.toList());
         List<StorageBlob> storageBlobs = storageBlobMapper.selectByIds(storageBlobIds);
         List<StorageBlobVO> storageBlobDTOS = new ArrayList<>();
@@ -406,6 +393,7 @@
             BeanUtils.copyProperties(storageBlob, storageBlobVO);
             storageBlobVO.setPreviewURL(buildSignedPreviewUrl(storageBlobVO));
             storageBlobVO.setDownloadURL(buildSignedDownloadUrl(storageBlobVO));
+            storageBlobVO.setStorageAttachmentId(blobIdToAttachmentIdMap.get(storageBlob.getId()));
             storageBlobDTOS.add(storageBlobVO);
         }
         return storageBlobDTOS;
@@ -448,6 +436,10 @@
         if (CollectionUtils.isEmpty(storageAttachments)) {
             return null;
         }
+        // 鏋勫缓 storageBlobId -> storageAttachmentId 鐨勬槧灏�
+        Map<Long, Long> blobIdToAttachmentIdMap = storageAttachments.stream()
+                .collect(Collectors.toMap(StorageAttachment::getStorageBlobId, StorageAttachment::getId));
+
         List<Long> storageBlobIds = storageAttachments.stream().map(StorageAttachment::getStorageBlobId).collect(Collectors.toList());
         List<StorageBlob> storageBlobs = storageBlobMapper.selectByIds(storageBlobIds);
         List<StorageBlobVO> storageBlobDTOS = new ArrayList<>();
@@ -456,6 +448,7 @@
             BeanUtils.copyProperties(storageBlob, storageBlobVO);
             storageBlobVO.setPreviewURL(buildSignedUrl(storageBlobVO, "/preview/", expired));
             storageBlobVO.setDownloadURL(buildSignedUrl(storageBlobVO, "/download/", expired));
+            storageBlobVO.setStorageAttachmentId(blobIdToAttachmentIdMap.get(storageBlob.getId()));
             storageBlobDTOS.add(storageBlobVO);
         }
         return storageBlobDTOS;

--
Gitblit v1.9.3