|
@@ -1,23 +1,20 @@
|
|
|
package com.taais.biz.service.impl;
|
|
|
-import java.util.Date;
|
|
|
|
|
|
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.DataAmplificationTaskVo;
|
|
|
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;
|
|
@@ -37,7 +34,6 @@ import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -52,9 +48,7 @@ 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.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.taais.biz.domain.table.DataTableDef.DATA;
|
|
@@ -73,17 +67,14 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
private static final String ZIP = ".zip";
|
|
|
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:11001/augment";
|
|
|
+ private static final String[] VALID_EXTENSIONS = {".jpg", ".jpeg", ".png", ".bmp"};
|
|
|
+ private static final String PYTHON_DATA_AMPLIFY_API = "http://127.0.0.1:9096/api/data/amplify";
|
|
|
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);
|
|
@@ -257,13 +248,18 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
countSize.getAndIncrement();
|
|
|
});
|
|
|
//是否选择已标注,如果已标注则需要检测所有图片是否标注
|
|
|
- if (!labeledList.isEmpty() && labeled) {
|
|
|
+ if (!labeledList.isEmpty()) {
|
|
|
// 已标注数量
|
|
|
long unmarkedCount = labeledList.stream().filter(Boolean.FALSE::equals).count();
|
|
|
// 未标注数量
|
|
|
long markedCount = labeledList.stream().filter(Boolean.TRUE::equals).count();
|
|
|
// 如果存在未标注的数据,则返回错误信息
|
|
|
- if (unmarkedCount > 0) {
|
|
|
+ if (unmarkedCount > 0 && labeled) {
|
|
|
+ String format = String.format("错误: 已标注文件 %d 个,未标注文件 %d 个", markedCount, unmarkedCount);
|
|
|
+ return CommonResult.fail(format);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (markedCount > 0 && !labeled) {
|
|
|
String format = String.format("错误: 已标注文件 %d 个,未标注文件 %d 个", markedCount, unmarkedCount);
|
|
|
return CommonResult.fail(format);
|
|
|
}
|
|
@@ -280,16 +276,58 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public CommonResult<Boolean> dataAmplify(DataAmplifyDto dataAmplifyDto) {
|
|
|
- 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());
|
|
|
+ //根据批次号获取该批次的所有文件数据
|
|
|
+ QueryWrapper query = query();
|
|
|
+ query.eq(Data::getBatchNum, dataAmplifyDto.getBatchNum());
|
|
|
+ List<Data> dataList = dataMapper.selectListByQuery(query);
|
|
|
+ if (dataList.isEmpty()) {
|
|
|
+ return CommonResult.fail("该批次下没有文件数据,请重新选择批次!");
|
|
|
+ }
|
|
|
+ //TODO: 此处需要定义任务开始,把相关任务信息添加上(任务名称、任务开始时间、任务类型),然后再处理文件。
|
|
|
+
|
|
|
+ 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;
|
|
|
+ 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)) {
|
|
|
+ throw new RuntimeException("调用Python接口返回扩增失败");
|
|
|
+ }
|
|
|
+ //处理当前目录文件,并进行入库
|
|
|
+ saveDataInfo(outputImagePath, dataInfo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return CommonResult.fail("该批次下没有文件数据,请重新选择批次!");
|
|
|
}
|
|
|
|
|
|
private void initFileInfo(String dest, List<File> extractedImagesFileList, boolean directory, String fileName) {
|
|
@@ -361,8 +399,6 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
public boolean update(DataBo dataBo) {
|
|
|
Data data = MapstructUtils.convert(dataBo, Data.class);
|
|
|
if (ObjectUtil.isNotNull(data) && ObjectUtil.isNotNull(data.getId())) {
|
|
|
- // 不更新采集时间
|
|
|
- data.setGatherTime(null);
|
|
|
boolean updated = this.updateById(data);
|
|
|
//新增之后清除缓存
|
|
|
deleteFormSelectKey();
|
|
@@ -405,143 +441,6 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
return cacheList;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public CommonResult<Boolean> amplifyForData(String id) {
|
|
|
- DataAmplificationTaskVo taskVo = dataAmplificationTaskService.selectById(Long.valueOf(id));
|
|
|
- DataAmplifyDto dataAmplifyDto = new DataAmplifyDto();
|
|
|
- dataAmplifyDto.setId(taskVo.getId().toString());
|
|
|
- dataAmplifyDto.setAugmentationType(taskVo.getAugmentationType());
|
|
|
- List<Map<String, String>> maps = JsonUtils.parseArray(taskVo.getParameters(), Map.class);
|
|
|
- dataAmplifyDto.setOtherParams(maps);
|
|
|
- dataAmplifyDto.setBatchNum(taskVo.getDataBatchNums());
|
|
|
- return this.doAmplify(dataAmplifyDto);
|
|
|
- }
|
|
|
-
|
|
|
- @Value("${taais.profile}")
|
|
|
- private String profile;
|
|
|
-
|
|
|
- private CommonResult<Boolean> doAmplify(DataAmplifyDto dataAmplifyDto) {
|
|
|
- this.updateEmp(Long.valueOf(dataAmplifyDto.getId()));
|
|
|
- String[] split = dataAmplifyDto.getBatchNum().split(",");
|
|
|
- for (String batchNum : split) {
|
|
|
- QueryWrapper query = query();
|
|
|
- query.eq(Data::getBatchNum, batchNum);
|
|
|
- List<Data> dataList = dataMapper.selectListByQuery(query);
|
|
|
- if (dataList.isEmpty()) {
|
|
|
- this.updateFail(Long.valueOf(dataAmplifyDto.getId()));
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- List<Data> dataListInfo = dataList.stream().filter(data -> !StringUtils.isEmpty(data.getUrl())).toList();
|
|
|
- if (dataListInfo.isEmpty()) {
|
|
|
- this.updateFail(Long.valueOf(dataAmplifyDto.getId()));
|
|
|
- continue;
|
|
|
- }
|
|
|
- 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;
|
|
|
- Map<String, String> otherParams = new HashMap<>();
|
|
|
- for (Map<String, String> param : dataAmplifyDto.getOtherParams()) {
|
|
|
- otherParams.put(param.get("agName"), param.get("defaultValue"));
|
|
|
- }
|
|
|
- Map<String, String> param = dataAmplifyDto.getOtherParams()
|
|
|
- .stream().collect(Collectors.toMap(item -> item.get("agName"), item -> item.get("defaultValue")));
|
|
|
- dataListInfo.forEach(dataInfo -> {
|
|
|
- try {
|
|
|
- boolean success = true;
|
|
|
- String message = "";
|
|
|
- Date startTime = new Date();
|
|
|
-
|
|
|
- //循环调用Python扩增接口
|
|
|
- Map<String, Object> bodyJson = new HashMap<>();
|
|
|
- bodyJson.put("bizType", "数据扩增");
|
|
|
- bodyJson.put("bizId", dataAmplifyDto.getId());
|
|
|
- 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", otherParams);
|
|
|
- String logPath = profile + "/task/log/" + dataAmplifyDto.getId() + "_log.log";
|
|
|
- System.out.println("logPath===>" + logPath);
|
|
|
- bodyJson.put("logPath", logPath);
|
|
|
- //实际请求接口,接口未提供,暂且注释
|
|
|
- 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 = false;
|
|
|
- }
|
|
|
- message = rootNode.path("msg").asText();
|
|
|
- //处理当前目录文件,并进行入库
|
|
|
- saveDataInfo(outputImagePath, dataInfo);
|
|
|
-
|
|
|
- DataAmplificationTaskVo taskVo = dataAmplificationTaskService.selectById(Long.valueOf(dataAmplifyDto.getId()));
|
|
|
- Date endTime = new Date();
|
|
|
- DataAmplificationTaskBo update = new DataAmplificationTaskBo();
|
|
|
- if (taskVo.getInputImagePath() != null) {
|
|
|
- update.setInputImagePath(taskVo.getInputImagePath()+"|" + dataInfo.getUrl());
|
|
|
- } else {
|
|
|
- update.setInputImagePath(dataInfo.getUrl());
|
|
|
- }
|
|
|
- if (taskVo.getOutputImagePath() != null) {
|
|
|
- update.setOutputImagePath(taskVo.getOutputImagePath()+"|" + outputImagePath);
|
|
|
- } else {
|
|
|
- update.setOutputImagePath(outputImagePath);
|
|
|
- }
|
|
|
- update.setId(Long.valueOf(dataAmplifyDto.getId()));
|
|
|
- update.setStartTime(startTime);
|
|
|
- update.setEndTime(endTime);
|
|
|
- update.setCostSecond((int) (endTime.getTime() - startTime.getTime()));
|
|
|
- update.setStatus(success ? BizConstant.TASK_STATUS_SUCCEED : BizConstant.TASK_STATUS_FAILED);
|
|
|
- update.setLog(taskVo.getLog() + "|" + message);
|
|
|
- update.setVersion(taskVo.getVersion());
|
|
|
- update.setRemarks(taskVo.getRemarks() + "|" + (int) (endTime.getTime() - startTime.getTime()));
|
|
|
- dataAmplificationTaskService.update(update);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- //根据批次号获取该批次的所有文件数据
|
|
|
- return CommonResult.success();
|
|
|
- }
|
|
|
-
|
|
|
- private void updateEmp(Long id) {
|
|
|
- DataAmplificationTaskVo taskVo = dataAmplificationTaskService.selectById(id);
|
|
|
- DataAmplificationTaskBo update = new DataAmplificationTaskBo();
|
|
|
- update.setOutputImagePath("");
|
|
|
- update.setInputImagePath("");
|
|
|
- update.setId(id);
|
|
|
- update.setLog("");
|
|
|
- update.setVersion(taskVo.getVersion());
|
|
|
- update.setRemarks("");
|
|
|
- dataAmplificationTaskService.update(update);
|
|
|
- }
|
|
|
-
|
|
|
- private void updateFail(Long id) {
|
|
|
- DataAmplificationTaskVo taskVo = dataAmplificationTaskService.selectById(id);
|
|
|
- DataAmplificationTaskBo update = new DataAmplificationTaskBo();
|
|
|
- update.setId(taskVo.getId());
|
|
|
- update.setStatus(BizConstant.TASK_STATUS_FAILED);
|
|
|
- update.setLog(taskVo.getLog() + "|" + "该批次下没有文件数据,请重新选择批次!");
|
|
|
- update.setVersion(taskVo.getVersion());
|
|
|
- dataAmplificationTaskService.update(update);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 解析目标目录所有文件,进行文件更名并入库
|