fix(项目文件更新): 修复项目文件更新时不能上传同名文件
This commit is contained in:
parent
f7e0c65074
commit
51b6ea2850
|
@ -91,9 +91,9 @@ public class ProjectController {
|
||||||
return projectService.uploadFiles(projectId, files);
|
return projectService.uploadFiles(projectId, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/update/file/{projectId}/{fileId}", consumes = {"multipart/form-data"})
|
@PostMapping(value = "/update/file/{fileId}", consumes = {"multipart/form-data"})
|
||||||
public FileMetadata updateFile(@PathVariable String projectId, @PathVariable String fileId, @RequestPart(value = "file") MultipartFile file) {
|
public FileMetadata updateFile(@PathVariable String fileId, @RequestPart(value = "file") MultipartFile file) {
|
||||||
return projectService.updateFile(projectId, fileId, file);
|
return projectService.updateFile(fileId, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "delete/file/{fileId}")
|
@GetMapping(value = "delete/file/{fileId}")
|
||||||
|
|
|
@ -43,6 +43,13 @@ public class FileService {
|
||||||
return fileContentMapper.selectByPrimaryKey(fileId);
|
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) {
|
public void deleteFileByIds(List<String> ids) {
|
||||||
if (CollectionUtils.isEmpty(ids)) {
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -186,16 +187,21 @@ public class ProjectService {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileMetadata updateFile(String projectId, String fileId, MultipartFile file) {
|
public FileMetadata updateFile( String fileId, MultipartFile file) {
|
||||||
QueryProjectFileRequest request = new QueryProjectFileRequest();
|
QueryProjectFileRequest request = new QueryProjectFileRequest();
|
||||||
request.setName(file.getOriginalFilename());
|
request.setName(file.getOriginalFilename());
|
||||||
if (CollectionUtils.isEmpty(fileService.getProjectFiles(projectId, request))) {
|
FileMetadata fileMetadata = fileService.getFileMetadataById(fileId);
|
||||||
fileService.deleteFileById(fileId);
|
if (fileMetadata != null) {
|
||||||
return fileService.saveFile(file, projectId);
|
fileMetadata.setSize(file.getSize());
|
||||||
} else {
|
fileMetadata.setUpdateTime(System.currentTimeMillis());
|
||||||
MSException.throwException(Translator.get("project_file_already_exists"));
|
fileService.updateFileMetadata(fileMetadata);
|
||||||
|
try {
|
||||||
|
fileService.setFileContent(fileId, file.getBytes());
|
||||||
|
} catch (IOException e) {
|
||||||
|
MSException.throwException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return fileMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteFile(String fileId) {
|
public void deleteFile(String fileId) {
|
||||||
|
|
|
@ -167,7 +167,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
let formData = new FormData();
|
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);
|
formData.append("file", file);
|
||||||
let options = {
|
let options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
Loading…
Reference in New Issue