|
@@ -1,4 +1,5 @@
|
|
|
package com.taais.biz.service.impl;
|
|
|
+import java.util.Date;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
@@ -279,70 +280,16 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public CommonResult<Boolean> dataAmplify(DataAmplifyDto dataAmplifyDto) {
|
|
|
- //根据批次号获取该批次的所有文件数据
|
|
|
- QueryWrapper query = query();
|
|
|
- query.eq(Data::getBatchNum, dataAmplifyDto.getBatchNum());
|
|
|
- List<Data> dataList = dataMapper.selectListByQuery(query);
|
|
|
- if (dataList.isEmpty()) {
|
|
|
- return CommonResult.fail("该批次下没有文件数据,请重新选择批次!");
|
|
|
- }
|
|
|
-
|
|
|
- List<Data> dataListInfo = dataList.stream().filter(data -> !StringUtils.isEmpty(data.getUrl())).toList();
|
|
|
- if (dataListInfo.isEmpty()) {
|
|
|
- return CommonResult.fail("该批次下没有文件数据,请重新选择批次!");
|
|
|
- }
|
|
|
- String filePath = TaaisConfig.getUploadPath();
|
|
|
- LocalDate currentDate = LocalDate.now();
|
|
|
- // 定义日期格式器
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
|
|
|
- String formattedDate = currentDate.format(formatter);
|
|
|
- filePath = filePath + File.separator + formattedDate;
|
|
|
- String finalFilePath = filePath;
|
|
|
- Date startTime = new Date();
|
|
|
- AtomicBoolean success = new AtomicBoolean(true);
|
|
|
- AtomicReference<String> message = new AtomicReference<>("");
|
|
|
- dataListInfo.forEach(dataInfo -> {
|
|
|
- try {
|
|
|
- //循环调用Python扩增接口
|
|
|
- Map<String, Object> bodyJson = new HashMap<>();
|
|
|
- bodyJson.put("augmentationType", dataAmplifyDto.getAugmentationType());
|
|
|
- bodyJson.put("inputImagePath", dataInfo.getUrl());
|
|
|
- String outputImagePath = finalFilePath + AMPLIFY + System.currentTimeMillis();
|
|
|
- File desc = new File(outputImagePath);
|
|
|
- if (!desc.exists()) {
|
|
|
- log.info("创建文件目录: {}", desc.mkdirs());
|
|
|
- }
|
|
|
- bodyJson.put("outputImagePath", outputImagePath);
|
|
|
- bodyJson.put("otherParams", dataAmplifyDto.getOtherParams());
|
|
|
- //实际请求接口,接口未提供,暂且注释
|
|
|
- String response = HttpRequest.post(PYTHON_DATA_AMPLIFY_API)
|
|
|
- .body(JsonUtils.toJsonString(bodyJson))
|
|
|
- .execute().body();
|
|
|
-// String response = "{\"status\":200,\"msg\":\"扩增成功\"}";
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- JsonNode rootNode = objectMapper.readTree(response);
|
|
|
- String resultCode = rootNode.path(RESULT_CODE).asText();
|
|
|
- //判断接口是否响应成功
|
|
|
- if (!RESULT_STATUS.equals(resultCode)) {
|
|
|
- success.set(true);
|
|
|
- }
|
|
|
- message.set(rootNode.path("msg").asText());
|
|
|
- //处理当前目录文件,并进行入库
|
|
|
- saveDataInfo(outputImagePath, dataInfo);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- });
|
|
|
- Date endTime = new Date();
|
|
|
- DataAmplificationTaskBo update = new DataAmplificationTaskBo();
|
|
|
- update.setId(Long.valueOf(dataAmplifyDto.getId()));
|
|
|
- update.setStartTime(startTime);
|
|
|
- update.setEndTime(endTime);
|
|
|
- update.setCostSecond((int) (endTime.getTime() - startTime.getTime()));
|
|
|
- update.setStatus(success.get() ? BizConstant.TASK_STATUS_SUCCEED : BizConstant.TASK_STATUS_FAILED);
|
|
|
- update.setLog(message.get());
|
|
|
- dataAmplificationTaskService.update(update);
|
|
|
- return CommonResult.fail("该批次下没有文件数据,请重新选择批次!");
|
|
|
+ DataAmplifyDto amplifyDto = new DataAmplifyDto();
|
|
|
+ DataAmplificationTaskBo dataAmplificationTaskBo = new DataAmplificationTaskBo();
|
|
|
+ dataAmplificationTaskBo.setName(amplifyDto.getTaskName());
|
|
|
+ dataAmplificationTaskBo.setStatus(BizConstant.TASK_STATUS_PENDING);
|
|
|
+ dataAmplificationTaskBo.setDataBatchNums(amplifyDto.getBatchNum());
|
|
|
+ dataAmplificationTaskBo.setAugmentationType(amplifyDto.getAugmentationType());
|
|
|
+ dataAmplificationTaskBo.setParameters(JsonUtils.toJsonString(amplifyDto.getOtherParams()));
|
|
|
+ dataAmplificationTaskBo.setDelFlag(0);
|
|
|
+ dataAmplificationTaskService.insert(dataAmplificationTaskBo);
|
|
|
+ return this.amplifyForData(dataAmplificationTaskBo.getId().toString());
|
|
|
}
|
|
|
|
|
|
private void initFileInfo(String dest, List<File> extractedImagesFileList, boolean directory, String fileName) {
|