From 82778133aaee9c4c510c349017b0cf85ddbe8688 Mon Sep 17 00:00:00 2001 From: chenhao <852066789@qq.com> Date: Tue, 22 Apr 2025 17:34:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(file):=20=E6=B7=BB=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=BE=84=E5=AD=97=E6=AE=B5=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E5=92=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 ProjectFile 模型中添加 filePath 字段,用于存储文件路径 - 修改文件上传逻辑,保存文件路径信息 - 更新文件删除逻辑,根据文件路径删除文件- 在 application-dev.yml 和 application-pro.yml 中添加 profile 配置项 --- .../pms/web/controller/common/CommonController.java | 5 +++++ pms-admin/src/main/resources/application-dev.yml | 4 +++- pms-admin/src/main/resources/application-pro.yml | 4 +++- .../pms/business/projectFile/domain/ProjectFile.java | 4 ++++ .../projectFile/service/impl/ProjectFileServiceImpl.java | 3 ++- .../mapper/business/ProjectFile/ProjectFileMapper.xml | 4 ++-- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pms-admin/src/main/java/tech/unissense/pms/web/controller/common/CommonController.java b/pms-admin/src/main/java/tech/unissense/pms/web/controller/common/CommonController.java index 071e6dc..5c7b55e 100644 --- a/pms-admin/src/main/java/tech/unissense/pms/web/controller/common/CommonController.java +++ b/pms-admin/src/main/java/tech/unissense/pms/web/controller/common/CommonController.java @@ -1,5 +1,6 @@ package tech.unissense.pms.web.controller.common; +import java.io.File; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -85,6 +86,7 @@ public class CommonController AjaxResult ajax = AjaxResult.success(); ajax.put("url", url); ajax.put("fileName", fileName); + ajax.put("filePath", fileName.replace(Constants.RESOURCE_PREFIX, "")); ajax.put("newFileName", FileUtils.getName(fileName)); ajax.put("originalFilename", file.getOriginalFilename()); return ajax; @@ -106,6 +108,7 @@ public class CommonController // 上传文件路径 String filePath = RuoYiConfig.getUploadPath(); List urls = new ArrayList(); + List filePathList = new ArrayList(); List fileNames = new ArrayList(); List newFileNames = new ArrayList(); List originalFilenames = new ArrayList(); @@ -115,6 +118,7 @@ public class CommonController String fileName = FileUploadUtils.upload(filePath, file); String url = serverConfig.getUrl() + fileName; urls.add(url); + filePathList.add(fileName.replace(Constants.RESOURCE_PREFIX, "")); fileNames.add(fileName); newFileNames.add(FileUtils.getName(fileName)); originalFilenames.add(file.getOriginalFilename()); @@ -122,6 +126,7 @@ public class CommonController AjaxResult ajax = AjaxResult.success(); ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER)); ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); + ajax.put("filePath", StringUtils.join(filePathList, FILE_DELIMETER)); ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); return ajax; diff --git a/pms-admin/src/main/resources/application-dev.yml b/pms-admin/src/main/resources/application-dev.yml index bba4571..d4de216 100644 --- a/pms-admin/src/main/resources/application-dev.yml +++ b/pms-admin/src/main/resources/application-dev.yml @@ -58,4 +58,6 @@ spring: merge-sql: true wall: config: - multi-statement-allow: true \ No newline at end of file + multi-statement-allow: true +ruoyi: + profile: /home/uploadPath/dev \ No newline at end of file diff --git a/pms-admin/src/main/resources/application-pro.yml b/pms-admin/src/main/resources/application-pro.yml index 0eb7ffd..05c8056 100644 --- a/pms-admin/src/main/resources/application-pro.yml +++ b/pms-admin/src/main/resources/application-pro.yml @@ -81,4 +81,6 @@ spring: # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) - max-wait: -1ms \ No newline at end of file + max-wait: -1ms +ruoyi: + profile: /home/uploadPath/prod \ No newline at end of file diff --git a/pms-business/src/main/java/tech/unissense/pms/business/projectFile/domain/ProjectFile.java b/pms-business/src/main/java/tech/unissense/pms/business/projectFile/domain/ProjectFile.java index 13d2f39..b329ba4 100644 --- a/pms-business/src/main/java/tech/unissense/pms/business/projectFile/domain/ProjectFile.java +++ b/pms-business/src/main/java/tech/unissense/pms/business/projectFile/domain/ProjectFile.java @@ -44,6 +44,10 @@ public class ProjectFile { */ private String fileUrl; + /** + * 文件路径 + */ + private String filePath; /** * 文件名 */ diff --git a/pms-business/src/main/java/tech/unissense/pms/business/projectFile/service/impl/ProjectFileServiceImpl.java b/pms-business/src/main/java/tech/unissense/pms/business/projectFile/service/impl/ProjectFileServiceImpl.java index 43f6633..75c4a86 100644 --- a/pms-business/src/main/java/tech/unissense/pms/business/projectFile/service/impl/ProjectFileServiceImpl.java +++ b/pms-business/src/main/java/tech/unissense/pms/business/projectFile/service/impl/ProjectFileServiceImpl.java @@ -6,6 +6,7 @@ import tech.unissense.pms.business.projectFile.domain.ProjectFile; import tech.unissense.pms.business.projectFile.mapper.ProjectFileMapper; import tech.unissense.pms.business.projectFile.service.IProjectFileService; import org.springframework.stereotype.Service; +import tech.unissense.pms.common.config.RuoYiConfig; import tech.unissense.pms.common.utils.file.FileUtils; import javax.annotation.Resource; @@ -61,7 +62,7 @@ public class ProjectFileServiceImpl implements IProjectFileService { public int deleteById(Integer id) { ProjectFile projectFile = projectFileMapper.queryById(id); try { - FileUtils.deleteFile(projectFile.getFileUrl()); + FileUtils.deleteFile(RuoYiConfig.getProfile()+projectFile.getFileUrl()); } catch (Exception e) { log.error("删除文件失败,失败详情:{}", e.getStackTrace()); } diff --git a/pms-business/src/main/resources/mapper/business/ProjectFile/ProjectFileMapper.xml b/pms-business/src/main/resources/mapper/business/ProjectFile/ProjectFileMapper.xml index dc3118f..0e4a8e9 100644 --- a/pms-business/src/main/resources/mapper/business/ProjectFile/ProjectFileMapper.xml +++ b/pms-business/src/main/resources/mapper/business/ProjectFile/ProjectFileMapper.xml @@ -190,10 +190,10 @@ - INSERT INTO pms_project_file( project_id, demand_id, logger_id, file_type, file_url, file_new_name, file_name, create_by, create_time) + INSERT INTO pms_project_file( project_id, demand_id, logger_id, file_type, file_url,file_path, file_new_name, file_name, create_by, create_time) values - (#{item.projectId},#{item.demandId},#{item.loggerId},#{item.fileType},#{item.fileUrl},#{item.fileNewName},#{item.fileName},#{item.createBy},#{item.createTime}) + (#{item.projectId},#{item.demandId},#{item.loggerId},#{item.fileType},#{item.fileUrl},#{item.filePath},#{item.fileNewName},#{item.fileName},#{item.createBy},#{item.createTime})