You've already forked DataMate
feat(data-management): 添加数据集文件取消上传功能
- 在OpenAPI规范中定义了取消上传的REST端点接口 - 实现了DatasetFileApplicationService中的取消上传业务逻辑 - 在FileService中添加了完整的取消上传服务方法 - 创建了DatasetUploadController控制器处理取消上传请求 - 实现了临时分片文件清理和数据库记录删除功能
This commit is contained in:
@@ -470,6 +470,23 @@ paths:
|
|||||||
'200':
|
'200':
|
||||||
description: 上传成功
|
description: 上传成功
|
||||||
|
|
||||||
|
/data-management/datasets/upload/cancel-upload/{reqId}:
|
||||||
|
put:
|
||||||
|
tags: [ DatasetFile ]
|
||||||
|
operationId: cancelUpload
|
||||||
|
summary: 取消上传
|
||||||
|
description: 取消预上传请求并清理临时分片
|
||||||
|
parameters:
|
||||||
|
- name: reqId
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
description: 预上传请求ID
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: 取消成功
|
||||||
|
|
||||||
/data-management/dataset-types:
|
/data-management/dataset-types:
|
||||||
get:
|
get:
|
||||||
operationId: getDatasetTypes
|
operationId: getDatasetTypes
|
||||||
|
|||||||
@@ -505,6 +505,14 @@ public class DatasetFileApplicationService {
|
|||||||
saveFileInfoToDb(uploadResult, datasetId);
|
saveFileInfoToDb(uploadResult, datasetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消上传
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void cancelUpload(String reqId) {
|
||||||
|
fileService.cancelUpload(reqId);
|
||||||
|
}
|
||||||
|
|
||||||
private void saveFileInfoToDb(FileUploadResult fileUploadResult, String datasetId) {
|
private void saveFileInfoToDb(FileUploadResult fileUploadResult, String datasetId) {
|
||||||
if (Objects.isNull(fileUploadResult.getSavedFile())) {
|
if (Objects.isNull(fileUploadResult.getSavedFile())) {
|
||||||
// 文件切片上传没有完成
|
// 文件切片上传没有完成
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.datamate.datamanagement.interfaces.rest;
|
||||||
|
|
||||||
|
import com.datamate.datamanagement.application.DatasetFileApplicationService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据集上传控制器
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/data-management/datasets/upload")
|
||||||
|
public class DatasetUploadController {
|
||||||
|
|
||||||
|
private final DatasetFileApplicationService datasetFileApplicationService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消上传
|
||||||
|
*
|
||||||
|
* @param reqId 预上传请求ID
|
||||||
|
*/
|
||||||
|
@PutMapping("/cancel-upload/{reqId}")
|
||||||
|
public ResponseEntity<Void> cancelUpload(@PathVariable("reqId") String reqId) {
|
||||||
|
datasetFileApplicationService.cancelUpload(reqId);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -74,6 +74,26 @@ public class FileService {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消上传
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void cancelUpload(String reqId) {
|
||||||
|
if (reqId == null || reqId.isBlank()) {
|
||||||
|
throw BusinessException.of(CommonErrorCode.PARAM_ERROR);
|
||||||
|
}
|
||||||
|
ChunkUploadPreRequest preRequest = chunkUploadRequestMapper.findById(reqId);
|
||||||
|
if (preRequest == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String uploadPath = preRequest.getUploadPath();
|
||||||
|
if (uploadPath != null && !uploadPath.isBlank()) {
|
||||||
|
File tempDir = new File(uploadPath, String.format(ChunksSaver.TEMP_DIR_NAME_FORMAT, preRequest.getId()));
|
||||||
|
ChunksSaver.deleteFolder(tempDir.getPath());
|
||||||
|
}
|
||||||
|
chunkUploadRequestMapper.deleteById(reqId);
|
||||||
|
}
|
||||||
|
|
||||||
private File uploadFile(ChunkUploadRequest fileUploadRequest, ChunkUploadPreRequest preRequest) {
|
private File uploadFile(ChunkUploadRequest fileUploadRequest, ChunkUploadPreRequest preRequest) {
|
||||||
File savedFile = ChunksSaver.saveFile(fileUploadRequest, preRequest);
|
File savedFile = ChunksSaver.saveFile(fileUploadRequest, preRequest);
|
||||||
preRequest.setTimeout(LocalDateTime.now().plusSeconds(DEFAULT_TIMEOUT));
|
preRequest.setTimeout(LocalDateTime.now().plusSeconds(DEFAULT_TIMEOUT));
|
||||||
|
|||||||
Reference in New Issue
Block a user