拆分文件接口代码提交
This commit is contained in:
parent
4cf558b4c2
commit
df7cb15775
@ -815,4 +815,27 @@ public class TsFilesController {
|
||||
}
|
||||
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 拆分文件接口
|
||||
* 参数说明 id 要拆分的文件id
|
||||
* 参数说明 taskId 任务ID
|
||||
* 返回值说明: com.yfd.platform.config.ResponseResult
|
||||
***********************************/
|
||||
@Log(module = "实验数据管理", value = "拆分文件接口!")
|
||||
@PostMapping("/splitFile")
|
||||
@ApiOperation("解压缩接口")
|
||||
public ResponseResult splitFile(String id,String taskId) {
|
||||
try {
|
||||
if (StrUtil.isBlank(id) ) {
|
||||
return ResponseResult.error("参数为空");
|
||||
}
|
||||
Map<String, TsFiles> mapTsfiles = tsFilesService.splitFile(id,taskId);
|
||||
return ResponseResult.successData(mapTsfiles);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.print("拆分文件异常原因" + e);
|
||||
return ResponseResult.error("拆分文件失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -272,4 +273,5 @@ public interface ITsFilesService extends IService<TsFiles> {
|
||||
*/
|
||||
List<TsFiles> getByTaskId(String taskId);
|
||||
|
||||
Map<String, TsFiles> splitFile(String id, String taskId) throws Exception;
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.opencsv.CSVReader;
|
||||
import com.opencsv.CSVWriter;
|
||||
import com.opencsv.exceptions.CsvValidationException;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import com.yfd.platform.component.ExtractTaskStatus;
|
||||
import com.yfd.platform.component.ServerSendEventServer;
|
||||
import com.yfd.platform.component.TaskStatusHolder;
|
||||
@ -45,6 +46,7 @@ import com.yfd.platform.modules.experimentalData.mapper.TsFilesMapper;
|
||||
import com.yfd.platform.modules.experimentalData.mapper.TsTaskMapper;
|
||||
import com.yfd.platform.modules.experimentalData.service.ITsFilesService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yfd.platform.modules.experimentalData.service.InsFileConvertService;
|
||||
import com.yfd.platform.modules.storage.context.StorageSourceContext;
|
||||
import com.yfd.platform.modules.storage.mapper.StorageSourceConfigMapper;
|
||||
import com.yfd.platform.modules.storage.mapper.StorageSourceMapper;
|
||||
@ -138,6 +140,9 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
@Autowired
|
||||
private ExtractTaskStatus extractTaskStatus;
|
||||
|
||||
@Autowired
|
||||
private InsFileConvertService insFileConvertService;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
private TaskMessage taskMessage;
|
||||
@ -6289,6 +6294,70 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拆分文件接口
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public Map<String, TsFiles> splitFile(String id,String taskId) throws Exception {
|
||||
//1:动态表名 以及通过ID查询tsfiles 然后根据id path taskId nodeid 等等条件查询所欲的集合
|
||||
TsTask tsTask = tsTaskMapper.selectById(taskId);
|
||||
TableNameContextHolder.setTaskCode(tsTask.getTaskCode());
|
||||
StorageSource storageSource = getStorageConfig(tsTask.getLocalStorageId());
|
||||
TsFiles tsFile = tsFilesMapper.selectById(id);
|
||||
if (tsFile == null) {
|
||||
throw new RuntimeException("文件不存在: " + id);
|
||||
}
|
||||
StorageSourceConfig config = getStorageSourceConfig("filePath", "local", tsTask.getLocalStorageId());
|
||||
|
||||
|
||||
// 2. 构建源文件路径
|
||||
Path sourcePath = Paths.get(config.getValue(), tsFile.getWorkPath(), tsFile.getFileName()).normalize();
|
||||
File sourceFile = sourcePath.toFile();
|
||||
if (!sourceFile.exists()) {
|
||||
throw new FileNotFoundException("文件不存在: " + sourcePath);
|
||||
}
|
||||
|
||||
// 3. 根据规则拆分文件
|
||||
Map<String, String> outputPaths = insFileConvertService.convertByTemplate(sourceFile);
|
||||
|
||||
// 3. 生成两个 TsFiles 对象
|
||||
Map<String, TsFiles> resultMap = new HashMap<>();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// VINS 文件
|
||||
File vinsFile = new File(outputPaths.get("vins"));
|
||||
TsFiles vinsTs = new TsFiles();
|
||||
vinsTs.setNodeId(tsFile.getNodeId());
|
||||
vinsTs.setTaskId(tsFile.getTaskId());
|
||||
vinsTs.setIsFile("FILE");
|
||||
vinsTs.setParentId(tsFile.getParentId());
|
||||
vinsTs.setFileName(vinsFile.getName());
|
||||
vinsTs.setFileSize(String.valueOf(vinsFile.length() / (1024.0 * 1024.0))); // 转 M
|
||||
vinsTs.setWorkPath(tsFile.getWorkPath());
|
||||
|
||||
|
||||
this.addTsFiles(vinsTs);
|
||||
resultMap.put("vins", vinsTs);
|
||||
|
||||
// FVNS 文件
|
||||
File fvnsFile = new File(outputPaths.get("fvns"));
|
||||
TsFiles fvnsTs = new TsFiles();
|
||||
fvnsTs.setNodeId(tsFile.getNodeId());
|
||||
fvnsTs.setTaskId(tsFile.getTaskId());
|
||||
fvnsTs.setIsFile("FILE");
|
||||
fvnsTs.setParentId(tsFile.getParentId());
|
||||
fvnsTs.setFileName(fvnsFile.getName());
|
||||
fvnsTs.setFileSize(String.valueOf(fvnsFile.length() / (1024.0 * 1024.0)));
|
||||
fvnsTs.setWorkPath(tsFile.getWorkPath());
|
||||
|
||||
this.addTsFiles(fvnsTs);
|
||||
resultMap.put("fvns", fvnsTs);
|
||||
|
||||
return resultMap;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user