feat(file): 添加文件路径字段并优化文件上传和删除功能
- 在 ProjectFile 模型中添加 filePath 字段,用于存储文件路径 - 修改文件上传逻辑,保存文件路径信息 - 更新文件删除逻辑,根据文件路径删除文件- 在 application-dev.yml 和 application-pro.yml 中添加 profile 配置项dev_1.2.1
parent
70954e2e95
commit
82778133aa
|
@ -1,5 +1,6 @@
|
||||||
package tech.unissense.pms.web.controller.common;
|
package tech.unissense.pms.web.controller.common;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -85,6 +86,7 @@ public class CommonController
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
ajax.put("url", url);
|
ajax.put("url", url);
|
||||||
ajax.put("fileName", fileName);
|
ajax.put("fileName", fileName);
|
||||||
|
ajax.put("filePath", fileName.replace(Constants.RESOURCE_PREFIX, ""));
|
||||||
ajax.put("newFileName", FileUtils.getName(fileName));
|
ajax.put("newFileName", FileUtils.getName(fileName));
|
||||||
ajax.put("originalFilename", file.getOriginalFilename());
|
ajax.put("originalFilename", file.getOriginalFilename());
|
||||||
return ajax;
|
return ajax;
|
||||||
|
@ -106,6 +108,7 @@ public class CommonController
|
||||||
// 上传文件路径
|
// 上传文件路径
|
||||||
String filePath = RuoYiConfig.getUploadPath();
|
String filePath = RuoYiConfig.getUploadPath();
|
||||||
List<String> urls = new ArrayList<String>();
|
List<String> urls = new ArrayList<String>();
|
||||||
|
List<String> filePathList = new ArrayList<String>();
|
||||||
List<String> fileNames = new ArrayList<String>();
|
List<String> fileNames = new ArrayList<String>();
|
||||||
List<String> newFileNames = new ArrayList<String>();
|
List<String> newFileNames = new ArrayList<String>();
|
||||||
List<String> originalFilenames = new ArrayList<String>();
|
List<String> originalFilenames = new ArrayList<String>();
|
||||||
|
@ -115,6 +118,7 @@ public class CommonController
|
||||||
String fileName = FileUploadUtils.upload(filePath, file);
|
String fileName = FileUploadUtils.upload(filePath, file);
|
||||||
String url = serverConfig.getUrl() + fileName;
|
String url = serverConfig.getUrl() + fileName;
|
||||||
urls.add(url);
|
urls.add(url);
|
||||||
|
filePathList.add(fileName.replace(Constants.RESOURCE_PREFIX, ""));
|
||||||
fileNames.add(fileName);
|
fileNames.add(fileName);
|
||||||
newFileNames.add(FileUtils.getName(fileName));
|
newFileNames.add(FileUtils.getName(fileName));
|
||||||
originalFilenames.add(file.getOriginalFilename());
|
originalFilenames.add(file.getOriginalFilename());
|
||||||
|
@ -122,6 +126,7 @@ public class CommonController
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
|
ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
|
||||||
ajax.put("fileNames", StringUtils.join(fileNames, 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("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
|
||||||
ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
|
ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
|
||||||
return ajax;
|
return ajax;
|
||||||
|
|
|
@ -58,4 +58,6 @@ spring:
|
||||||
merge-sql: true
|
merge-sql: true
|
||||||
wall:
|
wall:
|
||||||
config:
|
config:
|
||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
||||||
|
ruoyi:
|
||||||
|
profile: /home/uploadPath/dev
|
|
@ -81,4 +81,6 @@ spring:
|
||||||
# 连接池的最大数据库连接数
|
# 连接池的最大数据库连接数
|
||||||
max-active: 8
|
max-active: 8
|
||||||
# #连接池最大阻塞等待时间(使用负值表示没有限制)
|
# #连接池最大阻塞等待时间(使用负值表示没有限制)
|
||||||
max-wait: -1ms
|
max-wait: -1ms
|
||||||
|
ruoyi:
|
||||||
|
profile: /home/uploadPath/prod
|
|
@ -44,6 +44,10 @@ public class ProjectFile {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private String fileUrl;
|
private String fileUrl;
|
||||||
|
/**
|
||||||
|
* 文件路径
|
||||||
|
*/
|
||||||
|
private String filePath;
|
||||||
/**
|
/**
|
||||||
* 文件名
|
* 文件名
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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.mapper.ProjectFileMapper;
|
||||||
import tech.unissense.pms.business.projectFile.service.IProjectFileService;
|
import tech.unissense.pms.business.projectFile.service.IProjectFileService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import tech.unissense.pms.common.config.RuoYiConfig;
|
||||||
import tech.unissense.pms.common.utils.file.FileUtils;
|
import tech.unissense.pms.common.utils.file.FileUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -61,7 +62,7 @@ public class ProjectFileServiceImpl implements IProjectFileService {
|
||||||
public int deleteById(Integer id) {
|
public int deleteById(Integer id) {
|
||||||
ProjectFile projectFile = projectFileMapper.queryById(id);
|
ProjectFile projectFile = projectFileMapper.queryById(id);
|
||||||
try {
|
try {
|
||||||
FileUtils.deleteFile(projectFile.getFileUrl());
|
FileUtils.deleteFile(RuoYiConfig.getProfile()+projectFile.getFileUrl());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("删除文件失败,失败详情:{}", e.getStackTrace());
|
log.error("删除文件失败,失败详情:{}", e.getStackTrace());
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,10 +190,10 @@
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
<insert id="insertBatch">
|
<insert id="insertBatch">
|
||||||
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
|
values
|
||||||
<foreach collection="list" item="item" index="index" separator=",">
|
<foreach collection="list" item="item" index="index" separator=",">
|
||||||
(#{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})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue