|
@@ -2,19 +2,20 @@ package com.taais.biz.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
-import cn.hutool.http.HttpUtil;
|
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.mybatisflex.core.paginate.Page;
|
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
|
+import com.taais.biz.constant.BizConstant;
|
|
|
import com.taais.biz.domain.Data;
|
|
|
+import com.taais.biz.domain.bo.DataAmplificationTaskBo;
|
|
|
import com.taais.biz.domain.bo.DataBo;
|
|
|
import com.taais.biz.domain.vo.BatchDataResult;
|
|
|
import com.taais.biz.domain.dto.DataAmplifyDto;
|
|
|
import com.taais.biz.domain.vo.DataSelectVo;
|
|
|
import com.taais.biz.domain.vo.DataVo;
|
|
|
import com.taais.biz.mapper.DataMapper;
|
|
|
+import com.taais.biz.service.IDataAmplificationTaskService;
|
|
|
import com.taais.biz.service.IDataService;
|
|
|
import com.taais.common.core.config.TaaisConfig;
|
|
|
import com.taais.common.core.core.domain.CommonResult;
|
|
@@ -36,7 +37,6 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
@@ -49,8 +49,9 @@ import java.time.Instant;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
import static com.taais.biz.domain.table.DataTableDef.DATA;
|
|
|
|
|
@@ -69,13 +70,16 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
private static final String RAR = ".rar";
|
|
|
private static final String TXT = ".txt";
|
|
|
private static final String[] VALID_EXTENSIONS = {".jpg", ".jpeg", ".png"};
|
|
|
- private static final String PYTHON_DATA_AMPLIFY_API = "http://127.0.0.1:9096/api/data/amplify";
|
|
|
+ private static final String PYTHON_DATA_AMPLIFY_API = "http://127.0.0.1:11001/augment";
|
|
|
private static final String RESULT_CODE = "status";
|
|
|
private static final String RESULT_STATUS = "200";
|
|
|
private static final String AMPLIFY = "/AMPLIFY/";
|
|
|
@Resource
|
|
|
private DataMapper dataMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private IDataAmplificationTaskService dataAmplificationTaskService;
|
|
|
+
|
|
|
@Override
|
|
|
public QueryWrapper query() {
|
|
|
return super.query().from(DATA);
|
|
@@ -279,7 +283,6 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
if (dataList.isEmpty()) {
|
|
|
return CommonResult.fail("该批次下没有文件数据,请重新选择批次!");
|
|
|
}
|
|
|
- //TODO: 此处需要定义任务开始,把相关任务信息添加上(任务名称、任务开始时间、任务类型),然后再处理文件。
|
|
|
|
|
|
List<Data> dataListInfo = dataList.stream().filter(data -> !StringUtils.isEmpty(data.getUrl())).toList();
|
|
|
if (dataListInfo.isEmpty()) {
|
|
@@ -292,7 +295,10 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
String formattedDate = currentDate.format(formatter);
|
|
|
filePath = filePath + File.separator + formattedDate;
|
|
|
String finalFilePath = filePath;
|
|
|
- dataListInfo.forEach(dataInfo -> {
|
|
|
+ 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<>();
|
|
@@ -306,23 +312,33 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
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\":\"扩增成功\"}";
|
|
|
+ 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)) {
|
|
|
- throw new RuntimeException("调用Python接口返回扩增失败");
|
|
|
+ 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("该批次下没有文件数据,请重新选择批次!");
|
|
|
}
|
|
|
|