From 0cfc88a631024726ac9350db501fc83cab1757d4 Mon Sep 17 00:00:00 2001
From: chenhj <1263187585@qq.com>
Date: 星期五, 24 四月 2026 14:50:19 +0800
Subject: [PATCH] 定时任务记录文件上传
---
src/main/java/com/ruoyi/basic/utils/FileUtil.java | 135 ++++++++++++++++++++++++++++++++++++--------
1 files changed, 109 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 b97f1d1..4092f30 100644
--- a/src/main/java/com/ruoyi/basic/utils/FileUtil.java
+++ b/src/main/java/com/ruoyi/basic/utils/FileUtil.java
@@ -74,6 +74,7 @@
storageAttachment.setRecordId(recordId);
storageAttachment.setStorageBlobId(storageBlobDTO.getId());
storageAttachment.setDeleted(0L);
+ storageAttachments.add(storageAttachment);
}
storageAttachmentMapper.insert(storageAttachments);
}
@@ -103,10 +104,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) {
@@ -117,7 +118,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)
@@ -136,6 +137,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涓嶈兘涓虹┖");
@@ -146,7 +154,7 @@
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)
@@ -154,7 +162,31 @@
}
/**
- * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅
+ * 鎵归噺鍒犻櫎鏂囦欢鍏宠仈淇℃伅 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()));
+ }
+
+ /**
+ * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅 attachment
*
* @param storageAttachmentIds 鏂囦欢id
*/
@@ -166,7 +198,7 @@
}
/**
- * 閫氳繃鏂囦欢鐢ㄩ�斻�佸叧鑱旇褰曠被鍨嬨�佸叧鑱旇褰昳d鑾峰彇鏂囦欢鍏宠仈淇℃伅
+ * 閫氳繃鏂囦欢鐢ㄩ�斻�佸叧鑱旇褰曠被鍨嬨�佸叧鑱旇褰昳d鑾峰彇鏂囦欢鍏宠仈淇℃伅 attachment
*
* @param application 鏂囦欢鐢ㄩ��
* @param recordType 鍏宠仈璁板綍绫诲瀷
@@ -188,11 +220,11 @@
}
/**
- * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅
+ * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅 blob
*
* @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;
@@ -211,12 +243,63 @@
}
/**
- * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅瀛樺湪杩囨湡鏃堕棿
+ * 閫氳繃鏂囦欢鐢ㄩ�斻�佸叧鑱旇褰曠被鍨嬨�佸叧鑱旇褰昳d鑾峰彇鏂囦欢淇℃伅 blob
+ *
+ * @param application 鏂囦欢鐢ㄩ��
+ * @param recordType 鍏宠仈璁板綍绫诲瀷
+ * @param recordId 鍏宠仈璁板綍id
+ */
+ public List<StorageBlobVO> getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum application, RecordTypeEnum recordType, Long recordId) {
+ List<StorageAttachment> storageAttachments = getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(application, recordType, recordId);
+ if (CollectionUtils.isEmpty(storageAttachments)) {
+ return null;
+ }
+ 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));
+ storageBlobDTOS.add(storageBlobVO);
+ }
+ return storageBlobDTOS;
+ }
+
+ /**
+ * 閫氳繃鏂囦欢鐢ㄩ�斻�佸叧鑱旇褰曠被鍨嬨�佸叧鑱旇褰昳d鑾峰彇鏂囦欢淇℃伅 鑷畾涔夎繃鏈熸椂闂达紙鍒嗛挓锛� blob
+ *
+ * @param application 鏂囦欢鐢ㄩ��
+ * @param recordType 鍏宠仈璁板綍绫诲瀷
+ * @param recordId 鍏宠仈璁板綍id
+ * @param 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;
+ }
+ 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(buildSignedUrl(storageBlobVO, "/preview/", expired));
+ storageBlobVO.setDownloadURL(buildSignedUrl(storageBlobVO, "/download/", expired));
+ storageBlobDTOS.add(storageBlobVO);
+ }
+ return storageBlobDTOS;
+ }
+
+ /**
+ * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅瀛樺湪杩囨湡鏃堕棿 鑷畾涔夎繃鏈熸椂闂达紙鍒嗛挓锛� blob
*
* @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;
@@ -235,7 +318,7 @@
}
/**
- * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅
+ * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅 attachment
*
* @param storageAttachmentIds 鏂囦欢id
*/
@@ -248,7 +331,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 {
@@ -260,7 +343,7 @@
}
/**
- * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅瀛樺湪杩囨湡鏃堕棿
+ * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅瀛樺湪杩囨湡鏃堕棿 鑷畾涔夎繃鏈熸椂闂达紙鍒嗛挓锛� attachment
*
* @param storageAttachmentIds 鏂囦欢id
* @param expired 杩囨湡鏃堕棿
@@ -274,7 +357,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 {
@@ -286,7 +369,7 @@
}
/**
- * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅
+ * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅 attachment
*
* @param application 搴旂敤
* @param recordType 璁板綍绫诲瀷
@@ -301,7 +384,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 {
@@ -313,7 +396,7 @@
}
/**
- * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅瀛樺湪杩囨湡鏃堕棿
+ * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢淇℃伅瀛樺湪杩囨湡鏃堕棿 鑷畾涔夎繃鏈熸椂闂达紙鍒嗛挓锛� attachment
*
* @param application 搴旂敤
* @param recordType 璁板綍绫诲瀷
@@ -329,7 +412,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 {
@@ -347,7 +430,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));
}
@@ -355,14 +438,14 @@
}
/**
- * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢棰勮鍦板潃瀛樺湪杩囨湡鏃堕棿
+ * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢棰勮鍦板潃瀛樺湪杩囨湡鏃堕棿 鑷畾涔夎繃鏈熸椂闂达紙鍒嗛挓锛�
*
* @param storageAttachmentIds 鏂囦欢鍏宠仈id
* @param expired 杩囨湡鏃堕棿
*/
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));
}
@@ -376,7 +459,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));
}
@@ -384,14 +467,14 @@
}
/**
- * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢涓嬭浇鍦板潃瀛樺湪杩囨湡鏃堕棿
+ * 閫氳繃鏂囦欢鍏宠仈id鑾峰彇鏂囦欢涓嬭浇鍦板潃瀛樺湪杩囨湡鏃堕棿 鑷畾涔夎繃鏈熸椂闂达紙鍒嗛挓锛�
*
* @param storageAttachmentIds 鏂囦欢鍏宠仈id
* @param expired 杩囨湡鏃堕棿
*/
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));
}
@@ -490,7 +573,7 @@
}
/**
- * 鍘嬬缉鏂囦欢
+ * 鍘嬬缉鏂囦欢 鍥剧墖
*
* @param file 鏂囦欢
* @return 鍘嬬缉鍚庣殑鏂囦欢
--
Gitblit v1.9.3