From 9689c1b3a70eb206edcf958f2085d50853a829c0 Mon Sep 17 00:00:00 2001 From: haozq <1611483981@qq.com> Date: Wed, 7 May 2025 10:58:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bonus/common/utils/file/FileUploadUtils.java | 2 +- .../com/bonus/framework/config/ResourcesConfig.java | 12 ++++++++---- .../system/service/impl/LocalSysFileServiceImpl.java | 8 +------- pom.xml | 2 +- .../com/bonus/tool/service/impl/EpcServiceImpl.java | 3 ++- .../tool/service/impl/StateGridServiceImpl.java | 12 ++++++++++-- search-tool/src/main/resources/application.yml | 2 +- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/bonus-common/src/main/java/com/bonus/common/utils/file/FileUploadUtils.java b/bonus-common/src/main/java/com/bonus/common/utils/file/FileUploadUtils.java index 81d8975..e40b5bf 100644 --- a/bonus-common/src/main/java/com/bonus/common/utils/file/FileUploadUtils.java +++ b/bonus-common/src/main/java/com/bonus/common/utils/file/FileUploadUtils.java @@ -153,7 +153,7 @@ public class FileUploadUtils { int dirLastIndex = RuoYiConfig.getProfile().length() + 1; String currentDir = StringUtils.substring(uploadDir, dirLastIndex); - return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; + return "/" + fileName; } /** diff --git a/bonus-framework/src/main/java/com/bonus/framework/config/ResourcesConfig.java b/bonus-framework/src/main/java/com/bonus/framework/config/ResourcesConfig.java index 8c530fc..cb09c2b 100644 --- a/bonus-framework/src/main/java/com/bonus/framework/config/ResourcesConfig.java +++ b/bonus-framework/src/main/java/com/bonus/framework/config/ResourcesConfig.java @@ -3,6 +3,7 @@ package com.bonus.framework.config; import java.io.File; import java.util.concurrent.TimeUnit; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.CacheControl; @@ -27,6 +28,12 @@ public class ResourcesConfig implements WebMvcConfigurer @Autowired private RepeatSubmitInterceptor repeatSubmitInterceptor; + /** + * 上传文件存储在本地的根路径 + */ + @Value("${file.path}") + private String localFilePath; + // @Override // public void addResourceHandlers(ResourceHandlerRegistry registry) // { @@ -42,11 +49,8 @@ public class ResourcesConfig implements WebMvcConfigurer @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/files/**").addResourceLocations("file:/usr/local/bonus/uploadPath"+ File.separator); - //super.addResourceHandlers(registry); + registry.addResourceHandler("/files/**").addResourceLocations("file:"+localFilePath+ File.separator); -// registry.addResourceHandler("/files/**").addResourceLocations("file:E:\\file\\"); -// super.addResourceHandlers(registry); } /** diff --git a/bonus-system/src/main/java/com/bonus/system/service/impl/LocalSysFileServiceImpl.java b/bonus-system/src/main/java/com/bonus/system/service/impl/LocalSysFileServiceImpl.java index 01f932e..baae928 100644 --- a/bonus-system/src/main/java/com/bonus/system/service/impl/LocalSysFileServiceImpl.java +++ b/bonus-system/src/main/java/com/bonus/system/service/impl/LocalSysFileServiceImpl.java @@ -60,7 +60,6 @@ public class LocalSysFileServiceImpl implements ISysFileService public TbFileSourceVo uploadFile(MultipartFile file) throws Exception { String url = FileUploadUtils.upload(localFilePath, file); - // String url = domain + localFilePrefix + name; String name = FileUtils.getName(url); String fileSuffix = FileUploadUtils.getExtension(file); return TbFileSourceVo.builder().filePath(url).fileName(name).fileSuffix(fileSuffix).build(); @@ -97,12 +96,7 @@ public class LocalSysFileServiceImpl implements ISysFileService @Override public void deleteFile(String urlStr) throws Exception { - // String regex = String.format("^(.*?%s)", localFilePrefix); - // String updatePath = urlStr.replaceFirst(regex, localFilePath); - // Path path = Paths.get(updatePath); - String oldPart = "/profile/oadPath"; - String updatePath = urlStr.replace(oldPart, localFilePath); - Path path = Paths.get(updatePath); + Path path = Paths.get(localFilePath+urlStr); if (Files.exists(path)){ try { Files.deleteIfExists(path); diff --git a/pom.xml b/pom.xml index f8c22ca..34af5d8 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ search_tool_service 3.8.9 - ruoyi + bonus http://www.ruoyi.vip 若依管理系统 diff --git a/search-tool/src/main/java/com/bonus/tool/service/impl/EpcServiceImpl.java b/search-tool/src/main/java/com/bonus/tool/service/impl/EpcServiceImpl.java index 197505f..ff23c63 100644 --- a/search-tool/src/main/java/com/bonus/tool/service/impl/EpcServiceImpl.java +++ b/search-tool/src/main/java/com/bonus/tool/service/impl/EpcServiceImpl.java @@ -201,7 +201,8 @@ public class EpcServiceImpl implements EpcService { } } - @Value("file.path") + + @Value("${file.path}") private String filePath; diff --git a/search-tool/src/main/java/com/bonus/tool/service/impl/StateGridServiceImpl.java b/search-tool/src/main/java/com/bonus/tool/service/impl/StateGridServiceImpl.java index ba7ddf7..ec69f38 100644 --- a/search-tool/src/main/java/com/bonus/tool/service/impl/StateGridServiceImpl.java +++ b/search-tool/src/main/java/com/bonus/tool/service/impl/StateGridServiceImpl.java @@ -11,6 +11,7 @@ import com.bonus.tool.service.StateGridService; import com.bonus.tool.template.util.FreeMarkerUtil; import com.bonus.tool.template.util.WordUtils; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -264,9 +265,14 @@ public class StateGridServiceImpl implements StateGridService { return AjaxResult.success(); } - @Value("file.path") + + @Value("${file.path}") private String filePath; + public static void main(String[] args) throws Exception { + String bast64= FreeMarkerUtil.getImageBase("F:\\File\\tool\\2025\\05\\07\\3_20250507104937A005.png"); + System.err.println(bast64); + } /** * 将数据转换为模版数据 @@ -312,7 +318,8 @@ public class StateGridServiceImpl implements StateGridService { imgMap.put("index", 100 * index + imgIndex++); imgMap.put("width", "5325745"); imgMap.put("height", "7534910"); - imgMap.put("base64Url", file.getFilePath() != null ? FreeMarkerUtil.getImageBase(filePath+file.getFilePath()) : ""); + String bast64=FreeMarkerUtil.getImageBase(filePath+file.getFilePath()); + imgMap.put("base64Url", file.getFilePath() != null ? bast64: ""); imgList.add(imgMap); } perfImgMap.put("imgList", imgList); @@ -321,6 +328,7 @@ public class StateGridServiceImpl implements StateGridService { } } + // 处理分包商数据(核心分包商业绩证明) if (tbData.getSubList() != null && !tbData.getSubList().isEmpty()) { int subIndex = 1; diff --git a/search-tool/src/main/resources/application.yml b/search-tool/src/main/resources/application.yml index 5818800..406ec96 100644 --- a/search-tool/src/main/resources/application.yml +++ b/search-tool/src/main/resources/application.yml @@ -133,5 +133,5 @@ xss: file: domain: http://192.168.0.14:58089 - path: /usr/local/bonus/uploadPath + path: F:\File\tool prefix: /statics