From 271f4a25576ac6c2c8f2c4eb4c9782d6eef85124 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期四, 07 五月 2026 13:13:55 +0800
Subject: [PATCH] 修改报错
---
src/main/java/com/ruoyi/basic/utils/FileUtil.java | 170 ++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 144 insertions(+), 26 deletions(-)
diff --git a/src/main/java/com/ruoyi/basic/utils/FileUtil.java b/src/main/java/com/ruoyi/basic/utils/FileUtil.java
index fde28b4..c57468a 100644
--- a/src/main/java/com/ruoyi/basic/utils/FileUtil.java
+++ b/src/main/java/com/ruoyi/basic/utils/FileUtil.java
@@ -83,6 +83,47 @@
}
/**
+ * 淇濆瓨闄勪欢淇℃伅
+ *
+ * @param recordType 鍏宠仈璁板綍绫诲瀷
+ * @param recordId 鍏宠仈璁板綍id
+ * @param storageBlobDTOS 鏂囦欢淇℃伅
+ */
+ public void saveStorageAttachmentByRecordTypeAndRecordId(String application,RecordTypeEnum recordType, Long recordId, List<StorageBlobDTO> storageBlobDTOS) {
+ if (recordType == null) {
+ throw new RuntimeException("鍏宠仈璁板綍绫诲瀷涓嶈兘涓虹┖");
+ }
+ if (recordId == null) {
+ throw new RuntimeException("鍏宠仈璁板綍id涓嶈兘涓虹┖");
+ }
+
+ // 鍒犻櫎鏃ч檮浠朵俊鎭�
+ if (application == null) {
+ for (StorageBlobDTO storageBlobDTO : storageBlobDTOS) {
+ deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.getByType(storageBlobDTO.getApplication()), recordType, recordId);
+ }
+ } else {
+ deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.getByType(application), recordType, recordId);
+ }
+
+ if (CollectionUtils.isEmpty(storageBlobDTOS)) {
+ deleteStorageAttachmentsByRecordTypeAndRecordId(recordType, recordId);
+ }
+
+ List<StorageAttachment> storageAttachments = new ArrayList<>();
+ for (StorageBlobDTO storageBlobDTO : storageBlobDTOS) {
+ StorageAttachment storageAttachment = new StorageAttachment();
+ storageAttachment.setApplication(Objects.requireNonNullElseGet(application, () -> ApplicationTypeEnum.getByType(storageBlobDTO.getApplication()).getType()));
+ storageAttachment.setRecordType(recordType.getType());
+ storageAttachment.setRecordId(recordId);
+ storageAttachment.setStorageBlobId(storageBlobDTO.getId());
+ storageAttachment.setDeleted(0L);
+ storageAttachments.add(storageAttachment);
+ }
+ storageAttachmentMapper.insert(storageAttachments);
+ }
+
+ /**
* 鍒犻櫎鏂囦欢淇℃伅
*
* @param storageBlobIds 鏂囦欢id
@@ -131,6 +172,29 @@
}
/**
+ * 閫氳繃鍏宠仈璁板綍绫诲瀷銆佸叧鑱旇褰昳d鍒犻櫎鏂囦欢淇℃伅
+ *
+ * @param recordType 鍏宠仈璁板綍绫诲瀷
+ * @param recordId 鍏宠仈璁板綍id
+ */
+ public void deleteStorageBlobsByRecordTypeAndRecordId(RecordTypeEnum recordType, Long recordId) {
+ if (recordId == null || recordId <= 0) {
+ throw new RuntimeException("鍏宠仈璁板綍id涓嶈兘涓虹┖");
+ }
+ if (recordType == null) {
+ throw new RuntimeException("鍏宠仈璁板綍绫诲瀷涓嶈兘涓虹┖");
+ }
+ List<StorageAttachment> storageAttachments = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>()
+ .eq(StorageAttachment::getRecordType, recordType.getType())
+ .eq(StorageAttachment::getRecordId, recordId));
+ if (CollectionUtils.isNotEmpty(storageAttachments)) {
+ List<Long> storageAttachmentIds = storageAttachments.stream().map(StorageAttachment::getStorageBlobId)
+ .collect(Collectors.toList());
+ deleteStorageBlobsByStorageAttachmentIds(storageAttachmentIds);
+ }
+ }
+
+ /**
* 鍒犻櫎鏂囦欢鍏宠仈淇℃伅
*
* @param storageAttachmentIds 鏂囦欢鍏宠仈id
@@ -162,6 +226,25 @@
.eq(StorageAttachment::getRecordType, recordType.getType())
.eq(StorageAttachment::getRecordId, recordId)
.eq(StorageAttachment::getApplication, application.getType()));
+ }
+
+ /**
+ * 鍒犻櫎鏂囦欢鍏宠仈淇℃伅
+ *
+ * @param recordType 鍏宠仈璁板綍绫诲瀷
+ * @param recordId 鍏宠仈璁板綍id
+ */
+ public void deleteStorageAttachmentsByRecordTypeAndRecordId(RecordTypeEnum recordType, Long recordId) {
+ if (recordId == null || recordId <= 0) {
+ throw new RuntimeException("鍏宠仈璁板綍id涓嶈兘涓虹┖");
+ }
+ if (recordType == null) {
+ throw new RuntimeException("鍏宠仈璁板綍绫诲瀷涓嶈兘涓虹┖");
+ }
+ deleteStorageBlobsByRecordTypeAndRecordId(recordType, recordId);
+ storageAttachmentMapper.delete(new LambdaQueryWrapper<StorageAttachment>()
+ .eq(StorageAttachment::getRecordType, recordType.getType())
+ .eq(StorageAttachment::getRecordId, recordId));
}
/**
@@ -203,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()));
}
/**
@@ -272,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<>();
@@ -280,9 +345,28 @@
BeanUtils.copyProperties(storageBlob, storageBlobVO);
storageBlobVO.setPreviewURL(buildSignedPreviewUrl(storageBlobVO));
storageBlobVO.setDownloadURL(buildSignedDownloadUrl(storageBlobVO));
+ storageBlobVO.setStorageAttachmentId(blobIdToAttachmentIdMap.get(storageBlob.getId()));
storageBlobDTOS.add(storageBlobVO);
}
return storageBlobDTOS;
+ }
+
+ /**
+ * 閫氳繃鏂囦欢鐢ㄩ�斻�佸叧鑱旇褰曠被鍨嬨�佸叧鑱旇褰昳d鑾峰彇鏂囦欢鍏宠仈淇℃伅 attachment
+ *
+ * @param recordType 鍏宠仈璁板綍绫诲瀷
+ * @param recordId 鍏宠仈璁板綍id
+ */
+ public List<StorageAttachment> getStorageAttachmentsByRecordTypeAndRecordId(RecordTypeEnum recordType, Long recordId) {
+ if (recordId == null || recordId <= 0) {
+ throw new RuntimeException("鍏宠仈璁板綍id涓嶈兘涓虹┖");
+ }
+ if (recordType == null) {
+ throw new RuntimeException("鍏宠仈璁板綍绫诲瀷涓嶈兘涓虹┖");
+ }
+ return storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>()
+ .eq(StorageAttachment::getRecordType, recordType.getType())
+ .eq(StorageAttachment::getRecordId, recordId));
}
/**
@@ -294,6 +378,35 @@
*/
public List<StorageBlobVO> getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId) {
List<StorageAttachment> storageAttachments = getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
+ 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<>();
+ for (StorageBlob storageBlob : storageBlobs) {
+ StorageBlobVO storageBlobVO = new StorageBlobVO();
+ BeanUtils.copyProperties(storageBlob, storageBlobVO);
+ storageBlobVO.setPreviewURL(buildSignedPreviewUrl(storageBlobVO));
+ storageBlobVO.setDownloadURL(buildSignedDownloadUrl(storageBlobVO));
+ storageBlobVO.setStorageAttachmentId(blobIdToAttachmentIdMap.get(storageBlob.getId()));
+ storageBlobDTOS.add(storageBlobVO);
+ }
+ return storageBlobDTOS;
+ }
+
+ /**
+ * 閫氳繃鏂囦欢鐢ㄩ�斻�佸叧鑱旇褰曠被鍨嬨�佸叧鑱旇褰昳d鑾峰彇鏂囦欢淇℃伅 blob
+ *
+ * @param recordType 鍏宠仈璁板綍绫诲瀷
+ * @param recordId 鍏宠仈璁板綍id
+ */
+ public List<StorageBlobVO> getStorageBlobVOsByRecordTypeAndRecordId(RecordTypeEnum recordType, Long recordId) {
+ List<StorageAttachment> storageAttachments = getStorageAttachmentsByRecordTypeAndRecordId(recordType, recordId);
if (CollectionUtils.isEmpty(storageAttachments)) {
return null;
}
@@ -323,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<>();
@@ -331,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