提交 51b6ea28 编写于 作者: C Captain.B 提交者: BugKing

fix(项目文件更新): 修复项目文件更新时不能上传同名文件

上级 f7e0c650
......@@ -91,9 +91,9 @@ public class ProjectController {
return projectService.uploadFiles(projectId, files);
}
@PostMapping(value = "/update/file/{projectId}/{fileId}", consumes = {"multipart/form-data"})
public FileMetadata updateFile(@PathVariable String projectId, @PathVariable String fileId, @RequestPart(value = "file") MultipartFile file) {
return projectService.updateFile(projectId, fileId, file);
@PostMapping(value = "/update/file/{fileId}", consumes = {"multipart/form-data"})
public FileMetadata updateFile(@PathVariable String fileId, @RequestPart(value = "file") MultipartFile file) {
return projectService.updateFile(fileId, file);
}
@GetMapping(value = "delete/file/{fileId}")
......
......@@ -43,6 +43,13 @@ public class FileService {
return fileContentMapper.selectByPrimaryKey(fileId);
}
public void setFileContent(String fileId, byte[] content) {
FileContent record = new FileContent();
record .setFile(content);
record.setFileId(fileId);
fileContentMapper.updateByPrimaryKeySelective(record);
}
public void deleteFileByIds(List<String> ids) {
if (CollectionUtils.isEmpty(ids)) {
return;
......
......@@ -28,6 +28,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
......@@ -186,16 +187,21 @@ public class ProjectService {
return result;
}
public FileMetadata updateFile(String projectId, String fileId, MultipartFile file) {
public FileMetadata updateFile( String fileId, MultipartFile file) {
QueryProjectFileRequest request = new QueryProjectFileRequest();
request.setName(file.getOriginalFilename());
if (CollectionUtils.isEmpty(fileService.getProjectFiles(projectId, request))) {
fileService.deleteFileById(fileId);
return fileService.saveFile(file, projectId);
} else {
MSException.throwException(Translator.get("project_file_already_exists"));
FileMetadata fileMetadata = fileService.getFileMetadataById(fileId);
if (fileMetadata != null) {
fileMetadata.setSize(file.getSize());
fileMetadata.setUpdateTime(System.currentTimeMillis());
fileService.updateFileMetadata(fileMetadata);
try {
fileService.setFileContent(fileId, file.getBytes());
} catch (IOException e) {
MSException.throwException(e);
}
}
return null;
return fileMetadata;
}
public void deleteFile(String fileId) {
......
......@@ -167,7 +167,7 @@ export default {
}
let formData = new FormData();
let url = '/project/update/file/' + this.projectId + '/' + this.currentRow.id
let url = '/project/update/file/' + '/' + this.currentRow.id
formData.append("file", file);
let options = {
method: 'POST',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册