From 9bad721754fe8bbe2e5f459d0706e0fefac569f3 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期日, 20 九月 2026 09:05:41 +0800
Subject: [PATCH] feat(mes): 添加智能质检报告功能与AI导入能力
---
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/storage/SystemStorageBlobServiceImpl.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/storage/SystemStorageBlobServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/storage/SystemStorageBlobServiceImpl.java
index 9592b09..2eb18d3 100644
--- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/storage/SystemStorageBlobServiceImpl.java
+++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/storage/SystemStorageBlobServiceImpl.java
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -84,6 +85,43 @@
result.add(blobRespVO);
}
return result;
+ }
+
+ @Override
+ public SystemStorageBlobRespVO saveBlob(byte[] content, String originalFileName, String contentType, Boolean isPublic) {
+ if (content == null || content.length == 0) {
+ throw exception(STORAGE_FILE_EMPTY);
+ }
+ // 鏂囦欢鍚嶆潵鑷皟鐢ㄦ柟锛屼粛瑕� cleanPath锛氬畠浼氭嫾杩涜惤鐩樻枃浠跺悕锛屼笉鑳藉甫鍑虹洰褰曞眰绾�
+ String safeName = StringUtils.hasText(originalFileName)
+ ? StringUtils.cleanPath(originalFileName)
+ : UUID.randomUUID().toString();
+ String fileName = UUID.randomUUID() + "_" + safeName;
+ String relativePath = fileUtil.buildRelativePath();
+ File targetDirectory = new File(properties.getPath(), relativePath);
+ if (!targetDirectory.exists() && !targetDirectory.mkdirs()) {
+ throw exception(STORAGE_BLOB_UPLOAD_FAILED);
+ }
+ File dest = new File(targetDirectory, fileName);
+ try {
+ Files.write(dest.toPath(), content);
+ SystemStorageBlobRespVO blobRespVO = persistBlob(contentType, safeName, fileName,
+ relativePath, content.length, isPublic);
+ if (blobRespVO == null || blobRespVO.getId() == null) {
+ throw exception(STORAGE_BLOB_UPLOAD_FAILED);
+ }
+ return blobRespVO;
+ } catch (RuntimeException e) {
+ if (dest.exists()) {
+ dest.delete();
+ }
+ throw e;
+ } catch (IOException e) {
+ if (dest.exists()) {
+ dest.delete();
+ }
+ throw exception(STORAGE_BLOB_UPLOAD_FAILED);
+ }
}
@Override
@@ -157,12 +195,24 @@
private SystemStorageBlobRespVO createStorageBlob(MultipartFile file, String originalFileName,
String fileName, String relativePath, Boolean isPublic) {
+ return persistBlob(file.getContentType(), originalFileName, fileName,
+ relativePath, file.getSize(), isPublic);
+ }
+
+ /**
+ * 钀藉簱 + 鎷奸瑙�/涓嬭浇鍦板潃銆�
+ * <p>
+ * 涓ゆ潯涓婁紶璺緞锛坽@link #upload} 鐨� MultipartFile銆亄@link #saveBlob} 鐨� byte[]锛夊叡鐢ㄨ繖涓�姝ワ紝
+ * 鍙湪杩欓噷缁存姢绛惧悕 URL 鐨勬嫾娉曪紝閬垮厤涓ゅ鍚勫啓涓�閬嶅悗鍦板潃鏍煎紡璧板亸銆�
+ */
+ private SystemStorageBlobRespVO persistBlob(String contentType, String originalFileName, String fileName,
+ String relativePath, long byteSize, Boolean isPublic) {
SystemStorageBlobDO blob = new SystemStorageBlobDO();
blob.setResourceKey(UUID.randomUUID().toString().replace("-", ""));
- blob.setContentType(file.getContentType());
+ blob.setContentType(contentType);
blob.setOriginalFilename(originalFileName);
blob.setUidFilename(fileName);
- blob.setByteSize(file.getSize());
+ blob.setByteSize(byteSize);
blob.setPath(relativePath);
storageBlobMapper.insert(blob);
--
Gitblit v1.9.3