From a85ac2fba03244c3e93a74e498681483e466dc08 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期六, 25 四月 2026 14:23:03 +0800
Subject: [PATCH] Merge branch 'dev_New_pro' of http://114.132.189.42:9002/r/product-inventory-management-after into dev_New_pro

---
 src/main/java/com/ruoyi/basic/utils/FileUtil.java |  176 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 156 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/ruoyi/basic/utils/FileUtil.java b/src/main/java/com/ruoyi/basic/utils/FileUtil.java
index bf0b9b2..8a33947 100644
--- a/src/main/java/com/ruoyi/basic/utils/FileUtil.java
+++ b/src/main/java/com/ruoyi/basic/utils/FileUtil.java
@@ -1,7 +1,10 @@
 package com.ruoyi.basic.utils;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.basic.dto.StorageAttachmentDTO;
 import com.ruoyi.basic.dto.StorageAttachmentVO;
 import com.ruoyi.basic.dto.StorageBlobDTO;
 import com.ruoyi.basic.dto.StorageBlobVO;
@@ -52,9 +55,6 @@
      * @param storageBlobDTOS 鏂囦欢淇℃伅
      */
     public void saveStorageAttachment(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId, List<StorageBlobDTO> storageBlobDTOS) {
-        if (CollectionUtils.isEmpty(storageBlobDTOS)) {
-            throw new RuntimeException("鏂囦欢淇℃伅涓嶈兘涓虹┖");
-        }
         if (application == null) {
             throw new RuntimeException("鏂囦欢鐢ㄩ�斾笉鑳戒负绌�");
         }
@@ -66,6 +66,9 @@
         }
         // 鍒犻櫎鏃ч檮浠朵俊鎭�
         deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
+        if (CollectionUtils.isEmpty(storageBlobDTOS)) {
+            return;
+        }
         List<StorageAttachment> storageAttachments = new ArrayList<>();
         for (StorageBlobDTO storageBlobDTO : storageBlobDTOS) {
             StorageAttachment storageAttachment = new StorageAttachment();
@@ -104,10 +107,10 @@
      *
      * @param application 鏂囦欢鐢ㄩ��
      * @param recordType  鍏宠仈璁板綍绫诲瀷
-     * @param recordId    鍏宠仈璁板綍id
+     * @param recordIds    鍏宠仈璁板綍id
      */
-    public void deleteStorageBlobsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId) {
-        if (recordId == null || recordId <= 0) {
+    public void deleteStorageBlobsByApplicationAndRecordTypeAndRecordIds(ApplicationTypeEnum application, RecordTypeEnum recordType, List<Long> recordIds) {
+        if (recordIds == null || recordIds.isEmpty()) {
             throw new RuntimeException("鍏宠仈璁板綍id涓嶈兘涓虹┖");
         }
         if (application == null) {
@@ -118,7 +121,7 @@
         }
         List<StorageAttachment> storageAttachments = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>()
                 .eq(StorageAttachment::getRecordType, recordType.getType())
-                .eq(StorageAttachment::getRecordId, recordId)
+                .in(StorageAttachment::getRecordId, recordIds)
                 .eq(StorageAttachment::getApplication, application.getType()));
         if (CollectionUtils.isNotEmpty(storageAttachments)) {
             List<Long> storageAttachmentIds = storageAttachments.stream().map(StorageAttachment::getStorageBlobId)
@@ -137,6 +140,13 @@
         storageAttachmentMapper.deleteByIds(storageAttachmentIds);
     }
 
+    /**
+     * 鍒犻櫎鏂囦欢鍏宠仈淇℃伅
+     *
+     * @param application 鏂囦欢鐢ㄩ��
+     * @param recordType  鍏宠仈璁板綍绫诲瀷
+     * @param recordId    鍏宠仈璁板綍id
+     */
     public void deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId) {
         if (recordId == null || recordId <= 0) {
             throw new RuntimeException("鍏宠仈璁板綍id涓嶈兘涓虹┖");
@@ -147,10 +157,34 @@
         if (recordType == null) {
             throw new RuntimeException("鍏宠仈璁板綍绫诲瀷涓嶈兘涓虹┖");
         }
-        deleteStorageBlobsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
+        deleteStorageBlobsByApplicationAndRecordTypeAndRecordIds(application, recordType, Arrays.asList(recordId));
         storageAttachmentMapper.delete(new LambdaQueryWrapper<StorageAttachment>()
                 .eq(StorageAttachment::getRecordType, recordType.getType())
                 .eq(StorageAttachment::getRecordId, recordId)
+                .eq(StorageAttachment::getApplication, application.getType()));
+    }
+
+    /**
+     * 鎵归噺鍒犻櫎鏂囦欢鍏宠仈淇℃伅 attachment
+     *
+     * @param application 鏂囦欢鐢ㄩ��
+     * @param recordType  鍏宠仈璁板綍绫诲瀷
+     * @param recordIds   鍏宠仈璁板綍id
+     */
+    public void deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordIds(ApplicationTypeEnum application, RecordTypeEnum recordType, List<Long> recordIds) {
+        if (recordIds == null || recordIds.isEmpty()) {
+            throw new RuntimeException("鍏宠仈璁板綍id涓嶈兘涓虹┖");
+        }
+        if (application == null) {
+            throw new RuntimeException("鏂囦欢鐢ㄩ�斾笉鑳戒负绌�");
+        }
+        if (recordType == null) {
+            throw new RuntimeException("鍏宠仈璁板綍绫诲瀷涓嶈兘涓虹┖");
+        }
+        deleteStorageBlobsByApplicationAndRecordTypeAndRecordIds(application, recordType, recordIds);
+        storageAttachmentMapper.delete(new LambdaQueryWrapper<StorageAttachment>()
+                .eq(StorageAttachment::getRecordType, recordType.getType())
+                .in(StorageAttachment::getRecordId, recordIds)
                 .eq(StorageAttachment::getApplication, application.getType()));
     }
 
@@ -164,6 +198,46 @@
             throw new RuntimeException("鏂囦欢id涓嶈兘涓虹┖");
         }
         return storageAttachmentMapper.selectByIds(storageAttachmentIds);
+    }
+
+    /**
+     * 閫氳繃璁板綍绫诲瀷鑾峰彇鏂囦欢淇℃伅 attachment锛堝垎椤碉級
+     *
+     * @param page       鍒嗛〉鍙傛暟
+     * @param storageAttachmentDTO 鍏宠仈璁板綍淇℃伅
+     */
+    public IPage<StorageAttachmentVO> getStorageAttachmentVosPageListByApplicationAndRecordTypeAndRecordId(Page page, StorageAttachmentDTO storageAttachmentDTO) {
+        // 鍒嗛〉鏌ヨ绗﹀悎鏉′欢鐨� StorageAttachment 璁板綍
+        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);
+            }
+        }
+
+        // 鏋勫缓鍒嗛〉缁撴灉
+        IPage<StorageAttachmentVO> resultPage = new Page<>();
+        BeanUtils.copyProperties(storageAttachmentIPage, resultPage);
+        resultPage.setRecords(storageAttachmentVOS);
+
+        return resultPage;
     }
 
     /**
@@ -193,7 +267,7 @@
      *
      * @param storageAttachmentIds 鏂囦欢id
      */
-    public List<StorageBlobVO> getStorageBlobDTOsByStorageAttachmentIds(List<Long> storageAttachmentIds) {
+    public List<StorageBlobVO> getStorageBlobVOsByStorageAttachmentIds(List<Long> storageAttachmentIds) {
         List<StorageAttachment> storageAttachments = getStorageAttachmentsByStorageAttachmentIds(storageAttachmentIds);
         if (CollectionUtils.isEmpty(storageAttachments)) {
             return null;
@@ -218,7 +292,7 @@
      * @param recordType  鍏宠仈璁板綍绫诲瀷
      * @param recordId    鍏宠仈璁板綍id
      */
-    public List<StorageBlobVO> getStorageBlobDTOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId) {
+    public List<StorageBlobVO> getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId) {
         List<StorageAttachment> storageAttachments = getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
         if (CollectionUtils.isEmpty(storageAttachments)) {
             return null;
@@ -244,7 +318,7 @@
      * @param recordId    鍏宠仈璁板綍id
      * @param expired     杩囨湡鏃堕棿
      */
-    public List<StorageBlobVO> getStorageBlobDTOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId, BigDecimal expired) {
+    public List<StorageBlobVO> getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId, BigDecimal expired) {
         List<StorageAttachment> storageAttachments = getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
         if (CollectionUtils.isEmpty(storageAttachments)) {
             return null;
@@ -268,7 +342,7 @@
      * @param storageAttachmentIds 鏂囦欢id
      * @param expired              杩囨湡鏃堕棿
      */
-    public List<StorageBlobVO> getStorageBlobDTOsByStorageAttachmentIds(List<Long> storageAttachmentIds, BigDecimal expired) {
+    public List<StorageBlobVO> getStorageBlobVOsByStorageAttachmentIds(List<Long> storageAttachmentIds, BigDecimal expired) {
         List<StorageAttachment> storageAttachments = getStorageAttachmentsByStorageAttachmentIds(storageAttachmentIds);
         if (CollectionUtils.isEmpty(storageAttachments)) {
             return null;
@@ -300,7 +374,7 @@
         for (StorageAttachment storageAttachment : storageAttachments) {
             StorageAttachmentVO storageAttachmentVO = new StorageAttachmentVO();
             BeanUtils.copyProperties(storageAttachment, storageAttachmentVO);
-            List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()));
+            List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()));
             if (CollectionUtils.isEmpty(storageBlobVOS)) {
                 storageAttachmentVO.setStorageBlobVOS(new ArrayList<>());
             } else {
@@ -326,7 +400,7 @@
         for (StorageAttachment storageAttachment : storageAttachments) {
             StorageAttachmentVO storageAttachmentVO = new StorageAttachmentVO();
             BeanUtils.copyProperties(storageAttachment, storageAttachmentVO);
-            List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()), expired);
+            List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()), expired);
             if (CollectionUtils.isEmpty(storageBlobVOS)) {
                 storageAttachmentVO.setStorageBlobVOS(new ArrayList<>());
             } else {
@@ -353,7 +427,7 @@
         for (StorageAttachment storageAttachment : storageAttachments) {
             StorageAttachmentVO storageAttachmentVO = new StorageAttachmentVO();
             BeanUtils.copyProperties(storageAttachment, storageAttachmentVO);
-            List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()));
+            List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()));
             if (CollectionUtils.isEmpty(storageBlobVOS)) {
                 storageAttachmentVO.setStorageBlobVOS(new ArrayList<>());
             } else {
@@ -381,7 +455,7 @@
         for (StorageAttachment storageAttachment : storageAttachments) {
             StorageAttachmentVO storageAttachmentVO = new StorageAttachmentVO();
             BeanUtils.copyProperties(storageAttachment, storageAttachmentVO);
-            List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()), expired);
+            List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(Collections.singletonList(storageAttachment.getId()), expired);
             if (CollectionUtils.isEmpty(storageBlobVOS)) {
                 storageAttachmentVO.setStorageBlobVOS(new ArrayList<>());
             } else {
@@ -399,7 +473,7 @@
      */
     public List<String> getFilePreviewURLByStorageAttachmentIds(List<Long> storageAttachmentIds) {
         List<String> res = new ArrayList<>();
-        List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(storageAttachmentIds);
+        List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(storageAttachmentIds);
         for (StorageBlobVO storageBlobVO : storageBlobVOS) {
             res.add(buildSignedPreviewUrl(storageBlobVO));
         }
@@ -414,7 +488,7 @@
      */
     public List<String> getFilePreviewURLByStorageAttachmentIds(List<Long> storageAttachmentIds, BigDecimal expired) {
         List<String> res = new ArrayList<>();
-        List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(storageAttachmentIds);
+        List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(storageAttachmentIds);
         for (StorageBlobVO storageBlobVO : storageBlobVOS) {
             res.add(buildSignedUrl(storageBlobVO, "/preview/", expired));
         }
@@ -428,7 +502,7 @@
      */
     public List<String> getFileDownloadURLByStorageAttachmentIds(List<Long> storageAttachmentIds) {
         List<String> res = new ArrayList<>();
-        List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(storageAttachmentIds);
+        List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(storageAttachmentIds);
         for (StorageBlobVO storageBlobVO : storageBlobVOS) {
             res.add(buildSignedDownloadUrl(storageBlobVO));
         }
@@ -443,13 +517,75 @@
      */
     public List<String> getFileDownloadURLByStorageAttachmentIds(List<Long> storageAttachmentIds, BigDecimal expired) {
         List<String> res = new ArrayList<>();
-        List<StorageBlobVO> storageBlobVOS = getStorageBlobDTOsByStorageAttachmentIds(storageAttachmentIds);
+        List<StorageBlobVO> storageBlobVOS = getStorageBlobVOsByStorageAttachmentIds(storageAttachmentIds);
         for (StorageBlobVO storageBlobVO : storageBlobVOS) {
             res.add(buildSignedUrl(storageBlobVO, "/download/", expired));
         }
         return res;
     }
 
+    /**
+     * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢棰勮鍦板潃
+     *
+     * @param application 搴旂敤
+     * @param recordType  璁板綍绫诲瀷
+     * @param recordId    璁板綍id
+     */
+    public List<String> getFilePreviewURLByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId) {
+        List<StorageAttachment> storageAttachments = getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
+        if (CollectionUtils.isEmpty(storageAttachments)) {
+            return new ArrayList<>();
+        }
+        return getFilePreviewURLByStorageAttachmentIds(storageAttachments.stream().map(StorageAttachment::getId).collect(Collectors.toList()));
+    }
+
+    /**
+     * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢棰勮鍦板潃瀛樺湪杩囨湡鏃堕棿
+     *
+     * @param application 搴旂敤
+     * @param recordType  璁板綍绫诲瀷
+     * @param recordId    璁板綍id
+     * @param expired     杩囨湡鏃堕棿锛堝垎閽燂級
+     */
+    public List<String> getFilePreviewURLByApplicationAndRecordTypeAndRecordIdAndExpired(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId, BigDecimal expired) {
+        List<StorageAttachment> storageAttachments = getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
+        if (CollectionUtils.isEmpty(storageAttachments)) {
+            return new ArrayList<>();
+        }
+        return getFilePreviewURLByStorageAttachmentIds(storageAttachments.stream().map(StorageAttachment::getId).collect(Collectors.toList()), expired);
+    }
+
+    /**
+     * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢涓嬭浇鍦板潃
+     *
+     * @param application 搴旂敤
+     * @param recordType  璁板綍绫诲瀷
+     * @param recordId    璁板綍id
+     */
+    public List<String> getFileDownloadURLByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId) {
+        List<StorageAttachment> storageAttachments = getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
+        if (CollectionUtils.isEmpty(storageAttachments)) {
+            return new ArrayList<>();
+        }
+        return getFileDownloadURLByStorageAttachmentIds(storageAttachments.stream().map(StorageAttachment::getId).collect(Collectors.toList()));
+    }
+
+    /**
+     * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢涓嬭浇鍦板潃瀛樺湪杩囨湡鏃堕棿
+     *
+     * @param application 搴旂敤
+     * @param recordType  璁板綍绫诲瀷
+     * @param recordId    璁板綍id
+     * @param expired     杩囨湡鏃堕棿锛堝垎閽燂級
+     */
+    public List<String> getFileDownloadURLByApplicationAndRecordTypeAndRecordIdAndExpired(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId, BigDecimal expired) {
+        List<StorageAttachment> storageAttachments = getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
+        if (CollectionUtils.isEmpty(storageAttachments)) {
+            return new ArrayList<>();
+        }
+        return getFileDownloadURLByStorageAttachmentIds(storageAttachments.stream().map(StorageAttachment::getId).collect(Collectors.toList()), expired);
+    }
+
     public String buildSignedPreviewUrl(StorageBlobVO storageBlob) {
         return buildSignedUrl(storageBlob, "/preview/", properties.getExpired());
     }

--
Gitblit v1.9.3