|
@@ -1,13 +1,15 @@
|
|
|
package com.taais.biz.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
import com.mybatisflex.core.paginate.Page;
|
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
|
-import com.taais.biz.domain.AlgorithmBizProcess;
|
|
|
-import com.taais.biz.domain.AlgorithmConfig;
|
|
|
-import com.taais.biz.domain.AlgorithmDataProcess;
|
|
|
-import com.taais.biz.domain.AlgorithmSubtask;
|
|
|
+import com.taais.biz.constant.BizConstant;
|
|
|
+import com.taais.biz.domain.*;
|
|
|
import com.taais.biz.domain.bo.AlgorithmSubtaskBo;
|
|
|
+import com.taais.biz.domain.dto.AlgorithmConfigParamDto;
|
|
|
+import com.taais.biz.domain.dto.AlgorithmRequestDto;
|
|
|
import com.taais.biz.domain.vo.AlgorithmBizProcessVo;
|
|
|
import com.taais.biz.domain.vo.AlgorithmDataProcessVo;
|
|
|
import com.taais.biz.domain.vo.AlgorithmDataSetVo;
|
|
@@ -16,6 +18,7 @@ import com.taais.biz.mapper.AlgorithmSubtaskMapper;
|
|
|
import com.taais.biz.service.*;
|
|
|
import com.taais.common.core.core.page.PageResult;
|
|
|
import com.taais.common.core.utils.MapstructUtils;
|
|
|
+import com.taais.common.core.utils.StringUtils;
|
|
|
import com.taais.common.core.utils.http.HttpUtils;
|
|
|
import com.taais.common.orm.core.page.PageQuery;
|
|
|
import com.taais.common.orm.core.service.impl.BaseServiceImpl;
|
|
@@ -25,9 +28,8 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.lang.reflect.Type;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import static com.taais.biz.domain.table.AlgorithmSubtaskTableDef.ALGORITHM_SUBTASK;
|
|
|
|
|
@@ -51,6 +53,8 @@ public class AlgorithmSubtaskServiceImpl extends BaseServiceImpl<AlgorithmSubtas
|
|
|
private IAlgorithmBizProcessService bizProcessService;
|
|
|
@Resource
|
|
|
private IAlgorithmConfigService algorithmConfigService;
|
|
|
+ @Resource
|
|
|
+ private IAlgorithmModelService modelService;
|
|
|
|
|
|
@Override
|
|
|
public QueryWrapper query() {
|
|
@@ -176,31 +180,125 @@ public class AlgorithmSubtaskServiceImpl extends BaseServiceImpl<AlgorithmSubtas
|
|
|
}
|
|
|
|
|
|
private void bizProcess(List<AlgorithmBizProcessVo> bizProcessVoList) {
|
|
|
+ Long algorithmId = null;
|
|
|
+ Long modelId = null;
|
|
|
+ String parameters = null;
|
|
|
+ String preprocessPath = null;
|
|
|
+ String resultPath = null;
|
|
|
+ String url = null;
|
|
|
+ StringJoiner errorMsg = null;
|
|
|
for (AlgorithmBizProcessVo bizProcessVo : bizProcessVoList) {
|
|
|
- Long algorithmId = bizProcessVo.getAlgorithmId();
|
|
|
- String parameters = bizProcessVo.getParameters();
|
|
|
- String preprocessPath = bizProcessVo.getPreprocessPath();
|
|
|
- String resultPath = bizProcessVo.getResultPath();
|
|
|
+ url = null;
|
|
|
+ errorMsg = new StringJoiner(System.lineSeparator());
|
|
|
+ algorithmId = bizProcessVo.getAlgorithmId();
|
|
|
+ modelId = bizProcessVo.getModelId();
|
|
|
+ parameters = bizProcessVo.getParameters();
|
|
|
+ preprocessPath = bizProcessVo.getPreprocessPath();
|
|
|
+ resultPath = bizProcessVo.getResultPath();
|
|
|
AlgorithmConfig config = algorithmConfigService.getById(algorithmId);
|
|
|
- String url = config.getAlgorithmAddress();
|
|
|
- // todo Allen send http
|
|
|
+ if (config == null) {
|
|
|
+ log.error("算法配置未找到!!!algorithmId:{}", algorithmId);
|
|
|
+ errorMsg.add("算法配置未找到!!!");
|
|
|
+ } else {
|
|
|
+ url = config.getAlgorithmAddress();
|
|
|
+ }
|
|
|
+ AlgorithmModel model = null;
|
|
|
+ if (modelId != null) {
|
|
|
+ model = modelService.getById(modelId);
|
|
|
+ }
|
|
|
+ // send http
|
|
|
+ AlgorithmRequestDto algorithmRequestDto = new AlgorithmRequestDto();
|
|
|
+ algorithmRequestDto.setSourcePath(preprocessPath);
|
|
|
+ algorithmRequestDto.setResultPath(resultPath);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ Type listType = new TypeToken<List<AlgorithmConfigParamDto>>() {}.getType();
|
|
|
+ if (StringUtils.isNotEmpty(parameters)) {
|
|
|
+ List<AlgorithmConfigParamDto> paramDtoList = gson.fromJson(parameters, listType);
|
|
|
+ Map<String, String> otherParams = new HashMap<>(paramDtoList.size());
|
|
|
+ if (model == null) {
|
|
|
+ log.error("模型配置未找到!!!modelId:{}", modelId);
|
|
|
+ errorMsg.add("模型配置未找到!!!");
|
|
|
+ } else {
|
|
|
+ otherParams.put("modelPath", model.getModelAddress());
|
|
|
+ }
|
|
|
+ for (AlgorithmConfigParamDto algorithmConfigParamDto : paramDtoList) {
|
|
|
+ otherParams.put(algorithmConfigParamDto.getName(), StringUtils.isNotEmpty(algorithmConfigParamDto.getValue()) ? algorithmConfigParamDto.getValue() : algorithmConfigParamDto.getDefaultValue())
|
|
|
+ }
|
|
|
+ algorithmRequestDto.setOtherParams(otherParams);
|
|
|
+ }
|
|
|
+ String httpResult = null;
|
|
|
+ if (StringUtils.isEmpty(url)) {
|
|
|
+ errorMsg.add("url是空!!!");
|
|
|
+ } else {
|
|
|
+ httpResult = HttpUtils.sendPost(url, gson.toJson(algorithmRequestDto));
|
|
|
+ }
|
|
|
+ // todo Allen process httpResult
|
|
|
+ log.info("httpResult:{}", httpResult);
|
|
|
+ // update AlgorithmBizProcess
|
|
|
AlgorithmBizProcess algorithmBizProcess = MapstructUtils.convert(bizProcessVo, AlgorithmBizProcess.class);
|
|
|
- algorithmBizProcess.setStartTime(new Date());
|
|
|
+ if (errorMsg.length() != 0) {
|
|
|
+ algorithmBizProcess.setStatus(BizConstant.TASK_STATUS_FAILED);
|
|
|
+ algorithmBizProcess.setLog(errorMsg.toString());
|
|
|
+ } else {
|
|
|
+ algorithmBizProcess.setStatus(BizConstant.TASK_STATUS_PROCESSING);
|
|
|
+ algorithmBizProcess.setStartTime(new Date());
|
|
|
+ }
|
|
|
bizProcessService.updateById(algorithmBizProcess);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void dateSetProcess(List<AlgorithmDataProcessVo> processVoList) {
|
|
|
+ String url;
|
|
|
+ String parameters;
|
|
|
+ String preprocessPath;
|
|
|
+ String resultPath;
|
|
|
+ StringJoiner errorMsg;
|
|
|
for (AlgorithmDataProcessVo processVo : processVoList) {
|
|
|
+ errorMsg = new StringJoiner(System.lineSeparator());
|
|
|
+ url = null;
|
|
|
Long algorithmId = processVo.getAlgorithmId();
|
|
|
- String parameters = processVo.getParameters();
|
|
|
- String preprocessPath = processVo.getPreprocessPath();
|
|
|
- String resultPath = processVo.getResultPath();
|
|
|
+ parameters = processVo.getParameters();
|
|
|
+ preprocessPath = processVo.getPreprocessPath();
|
|
|
+ resultPath = processVo.getResultPath();
|
|
|
AlgorithmConfig config = algorithmConfigService.getById(algorithmId);
|
|
|
- String url = config.getAlgorithmAddress();
|
|
|
- // todo Allen send http
|
|
|
+ if (config == null) {
|
|
|
+ log.error("算法配置未找到!!!algorithmId:{}", algorithmId);
|
|
|
+ errorMsg.add("算法配置未找到!!!");
|
|
|
+ } else {
|
|
|
+ url = config.getAlgorithmAddress();
|
|
|
+ }
|
|
|
+ // send http
|
|
|
+ AlgorithmRequestDto algorithmRequestDto = new AlgorithmRequestDto();
|
|
|
+ algorithmRequestDto.setSourcePath(preprocessPath);
|
|
|
+ algorithmRequestDto.setResultPath(resultPath);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ Type listType = new TypeToken<List<AlgorithmConfigParamDto>>() {}.getType();
|
|
|
+ if (StringUtils.isNotEmpty(parameters)) {
|
|
|
+ List<AlgorithmConfigParamDto> paramDtoList = gson.fromJson(parameters, listType);
|
|
|
+ Map<String, String> otherParams = new HashMap<>(paramDtoList.size());
|
|
|
+ for (AlgorithmConfigParamDto algorithmConfigParamDto : paramDtoList) {
|
|
|
+ otherParams.put(algorithmConfigParamDto.getName(), StringUtils.isNotEmpty(algorithmConfigParamDto.getValue()) ? algorithmConfigParamDto.getValue() : algorithmConfigParamDto.getDefaultValue())
|
|
|
+ }
|
|
|
+ algorithmRequestDto.setOtherParams(otherParams);
|
|
|
+ }
|
|
|
+ String httpResult = null;
|
|
|
+ if (StringUtils.isEmpty(url)) {
|
|
|
+ errorMsg.add("url是空!!!");
|
|
|
+ } else {
|
|
|
+ httpResult = HttpUtils.sendPost(url, gson.toJson(algorithmRequestDto));
|
|
|
+ }
|
|
|
+ // todo Allen process httpResult
|
|
|
+ log.info("httpResult:{}", httpResult);
|
|
|
+
|
|
|
+ // update AlgorithmDataProcess
|
|
|
AlgorithmDataProcess algorithmDataProcess = MapstructUtils.convert(processVo, AlgorithmDataProcess.class);
|
|
|
- algorithmDataProcess.setStartTime(new Date());
|
|
|
+ if (errorMsg.length() != 0) {
|
|
|
+ algorithmDataProcess.setStatus(BizConstant.TASK_STATUS_FAILED);
|
|
|
+ algorithmDataProcess.setLog(errorMsg.toString());
|
|
|
+ } else {
|
|
|
+ algorithmDataProcess.setStatus(BizConstant.TASK_STATUS_PROCESSING);
|
|
|
+ algorithmDataProcess.setStartTime(new Date());
|
|
|
+ }
|
|
|
dataProcessService.updateById(algorithmDataProcess);
|
|
|
}
|
|
|
}
|