allen 11 місяців тому
батько
коміт
2bdcfdfab6

+ 1 - 1
taais-admin/src/main/resources/application-dev.yml

@@ -106,7 +106,7 @@ spring.boot.admin.client:
 powerjob:
   worker:
     # 如何开启调度中心请查看文档教程
-    enabled: true
+    enabled: false
     # 需要先在 powerjob 登录页执行应用注册后才能使用
     app-name: taais
     # 28080 端口 随着主应用端口飘逸 避免集群冲突

+ 13 - 0
taais-common/taais-common-core/src/main/java/com/taais/common/core/utils/file/FileUtils.java

@@ -315,4 +315,17 @@ public class FileUtils extends FileUtil {
         Path newPath = path.resolveSibling(newFileName);
         return newPath.toAbsolutePath().toString();
     }
+
+    public static Long getNumberOfFileByFolderPath(String folderPath) {
+
+        File folder = new File(folderPath);
+        File[] list = folder.listFiles();
+        long fileCount = 0;
+        for (File file : list) {
+            if (file.isFile()) {
+                fileCount++;
+            }
+        }
+        return fileCount;
+    }
 }

+ 1 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/constant/BizConstant.java

@@ -62,4 +62,5 @@ public class BizConstant {
     public static final String P_CURVE = "P_curve.png";
     public static final String F1_CURVE = "F1_curve.png";
     public static final String ORIGINAL_IMAGE= "原始图片";
+    public static final String DOCKER_BASE_PATH= "/workspace";
 }

+ 4 - 2
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/PublicController.java

@@ -36,8 +36,10 @@ public class PublicController extends BaseController {
     private IAlgorithmTaskService algorithmTaskService;
     @PostMapping("/taskResult")
     public CommonResult<Void> taskResult(@RequestBody TaskResultDTO resultDTO) {
+        log.info("taskResult start,params:{}",resultDTO);
         String errorMsg = checkDTO(resultDTO);
         if(StringUtils.isNotEmpty(errorMsg)){
+            log.error("taskResult error,{}",errorMsg);
             return CommonResult.fail(errorMsg);
         }
         String bizType = resultDTO.getBizType();
@@ -58,8 +60,8 @@ public class PublicController extends BaseController {
 
     private String checkDTO(TaskResultDTO resultDTO) {
         Integer status = resultDTO.getStatus();
-        if(status != 1 && status != 0){
-            return "status 只能是0或1";
+        if(status != 200 && status != 500){
+            return "status 只能是200或500";
         }
         Long bizId = resultDTO.getBizId();
         if(bizId == null){

+ 1 - 1
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/dto/AlgorithmRequestDto.java

@@ -14,5 +14,5 @@ public class AlgorithmRequestDto {
     private String sourcePath;
     private String resultPath;
     private String logPath;
-    private Map<String,String> otherParams;
+    private Map<String,Object> otherParams;
 }

+ 2 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/mapper/AlgorithmModelMapper.java

@@ -3,6 +3,7 @@ package com.taais.biz.mapper;
 import com.mybatisflex.core.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
 import com.taais.biz.domain.AlgorithmModel;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 算法模型配置Mapper接口
@@ -13,4 +14,5 @@ import com.taais.biz.domain.AlgorithmModel;
 @Mapper
 public interface AlgorithmModelMapper extends BaseMapper<AlgorithmModel> {
 
+    String getModelNameBySubtaskId(@Param("subtaskId") Long subTaskId, @Param("algorithmId") Long algorithmId);
 }

+ 3 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/service/IAlgorithmModelService.java

@@ -2,6 +2,7 @@ package com.taais.biz.service;
 
 import java.util.List;
 
+import com.taais.biz.domain.AlgorithmBizProcess;
 import com.taais.biz.domain.AlgorithmModel;
 import com.taais.biz.domain.vo.AlgorithmModelVo;
 import com.taais.biz.domain.bo.AlgorithmModelBo;
@@ -63,4 +64,6 @@ public interface IAlgorithmModelService extends IBaseService<AlgorithmModel> {
      */
     boolean deleteByIds(Long[] ids);
 
+    void createModelByBizProcess(AlgorithmBizProcess algorithmBizProcess);
+
 }

+ 15 - 12
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/AlgorithmBizProcessServiceImpl.java

@@ -13,6 +13,7 @@ import com.taais.biz.domain.dto.TaskResultDTO;
 import com.taais.biz.domain.dto.task.TestResultDto;
 import com.taais.biz.domain.dto.task.TranResultDto;
 import com.taais.biz.service.IAlgorithmConfigService;
+import com.taais.biz.service.IAlgorithmModelService;
 import com.taais.common.core.config.TaaisConfig;
 import com.taais.common.core.utils.DateUtils;
 import com.taais.common.core.utils.MapstructUtils;
@@ -48,6 +49,8 @@ public class AlgorithmBizProcessServiceImpl extends BaseServiceImpl<AlgorithmBiz
     private AlgorithmBizProcessMapper algorithmBizProcessMapper;
     @Resource
     private IAlgorithmConfigService algorithmConfigService;
+    @Resource
+    private IAlgorithmModelService algorithmModelService;
 
     @Override
     public QueryWrapper query() {
@@ -156,27 +159,27 @@ public class AlgorithmBizProcessServiceImpl extends BaseServiceImpl<AlgorithmBiz
     @Override
     public String taskResult(TaskResultDTO resultDTO) {
         Long bizId = resultDTO.getBizId();
-        AlgorithmBizProcessVo bizProcessVo = this.selectById(bizId);
-        if(bizProcessVo == null){
+        AlgorithmBizProcess bizProcess = this.getById(bizId);
+        if(bizProcess == null){
             log.error("任务数据没有找到,resultDTO:{}",resultDTO);
             return "任务数据没有找到,resultDTO:"+ resultDTO;
         }
-        AlgorithmBizProcessBo algorithmBizProcess = MapstructUtils.convert(bizProcessVo, AlgorithmBizProcessBo.class);
-        if (resultDTO.getStatus() == 1) {
-            algorithmBizProcess.setStatus(BizConstant.TASK_STATUS_SUCCEED);
-        } else if (resultDTO.getStatus() == 0) {
-            algorithmBizProcess.setStatus(BizConstant.TASK_STATUS_FAILED);
+        if (resultDTO.getStatus() == 200) {
+            bizProcess.setStatus(BizConstant.TASK_STATUS_SUCCEED);
+        } else if (resultDTO.getStatus() == 500) {
+            bizProcess.setStatus(BizConstant.TASK_STATUS_FAILED);
         } else {
             log.error("不可能的分支");
         }
-        algorithmBizProcess.setLog(resultDTO.getMsg());
+//        bizProcess.setLog(resultDTO.getMsg());
         Date now = new Date();
-        Date startTime = algorithmBizProcess.getStartTime();
-        algorithmBizProcess.setEndTime(now);
+        Date startTime = bizProcess.getStartTime();
+        bizProcess.setEndTime(now);
         if (startTime != null) {
-            algorithmBizProcess.setCostSecond(DateUtils.differentSecondByDate(now, startTime));
+            bizProcess.setCostSecond(DateUtils.differentSecondByDate(startTime, now));
         }
-        this.update(algorithmBizProcess);
+        this.updateById(bizProcess);
+        algorithmModelService.createModelByBizProcess(bizProcess);
         algorithmBizProcessMapper.updateTaskAndSubtask(resultDTO.getBizId(),resultDTO.getBizType());
         return null;
     }

+ 18 - 1
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/AlgorithmModelServiceImpl.java

@@ -6,8 +6,11 @@ import java.util.List;
 import cn.hutool.core.util.ObjectUtil;
 import com.mybatisflex.core.paginate.Page;
 import com.mybatisflex.core.query.QueryWrapper;
+import com.taais.biz.constant.BizConstant;
+import com.taais.biz.domain.AlgorithmBizProcess;
+import com.taais.common.core.config.TaaisConfig;
 import com.taais.common.core.utils.MapstructUtils;
-import com.taais.common.core.utils.StringUtils;
+import com.taais.common.core.utils.file.FileUtils;
 import com.taais.common.orm.core.page.PageQuery;
 import com.taais.common.core.core.page.PageResult;
 import com.taais.common.orm.core.service.impl.BaseServiceImpl;
@@ -131,4 +134,18 @@ public class AlgorithmModelServiceImpl extends BaseServiceImpl<AlgorithmModelMap
         return this.removeByIds(Arrays.asList(ids));
     }
 
+    @Override
+    public void createModelByBizProcess(AlgorithmBizProcess algorithmBizProcess) {
+        AlgorithmModel algorithmModel = new AlgorithmModel();
+        algorithmModel.setAlgorithmId(algorithmBizProcess.getAlgorithmId());
+        // 获取算法任务名称和算法名称
+        String modelName = mapper.getModelNameBySubtaskId(algorithmBizProcess.getSubTaskId(), algorithmBizProcess.getAlgorithmId());
+        algorithmModel.setModelName(modelName);
+        // todo allen 待添加模型地址
+        algorithmModel.setModelAddress("");
+        String preprocessPath = algorithmBizProcess.getPreprocessPath();
+        Long numberOfFileByFolderPath = FileUtils.getNumberOfFileByFolderPath(TaaisConfig.getProfile() + preprocessPath + BizConstant.IMAGE);
+        algorithmModel.setSampleNumber(numberOfFileByFolderPath);
+        mapper.insert(algorithmModel);
+    }
 }

+ 19 - 8
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/AlgorithmSubtaskServiceImpl.java

@@ -22,6 +22,7 @@ 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;
 import jakarta.annotation.Resource;
+import org.apache.commons.lang3.math.NumberUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -218,14 +219,14 @@ public class AlgorithmSubtaskServiceImpl extends BaseServiceImpl<AlgorithmSubtas
             AlgorithmRequestDto algorithmRequestDto = new AlgorithmRequestDto();
             algorithmRequestDto.setBizType(BizConstant.TYPE_DATA_BIZ_PROCESS);
             algorithmRequestDto.setBizId(bizProcessVo.getId());
-            algorithmRequestDto.setSourcePath(preprocessPath);
-            algorithmRequestDto.setResultPath(resultPath);
+            algorithmRequestDto.setSourcePath(BizConstant.DOCKER_BASE_PATH + preprocessPath);
+            algorithmRequestDto.setResultPath(BizConstant.DOCKER_BASE_PATH + resultPath);
             algorithmRequestDto.setLogPath(bizProcessVo.getLog());
             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());
+                Map<String, Object> otherParams = new HashMap<>(paramDtoList.size());
                 // todo allen 模型没加载进去
                 if (model == null) {
                     log.error("模型配置未找到!!!modelId:{}", modelId);
@@ -234,7 +235,12 @@ public class AlgorithmSubtaskServiceImpl extends BaseServiceImpl<AlgorithmSubtas
                     otherParams.put("pretrained_model", model.getModelAddress());
                 }
                 for (AlgorithmConfigParamDto algorithmConfigParamDto : paramDtoList) {
-                    otherParams.put(algorithmConfigParamDto.getAgName(), StringUtils.isNotEmpty(algorithmConfigParamDto.getValue()) ? algorithmConfigParamDto.getValue() : algorithmConfigParamDto.getDefaultValue());
+                    String value = StringUtils.isNotEmpty(algorithmConfigParamDto.getValue()) ? algorithmConfigParamDto.getValue() : algorithmConfigParamDto.getDefaultValue();
+                    if(NumberUtils.isDigits(value)){
+                        otherParams.put(algorithmConfigParamDto.getAgName(), NumberUtils.createFloat(value));
+                    } else {
+                        otherParams.put(algorithmConfigParamDto.getAgName(), value);
+                    }
                 }
                 algorithmRequestDto.setOtherParams(otherParams);
             }
@@ -283,16 +289,21 @@ public class AlgorithmSubtaskServiceImpl extends BaseServiceImpl<AlgorithmSubtas
             AlgorithmRequestDto algorithmRequestDto = new AlgorithmRequestDto();
             algorithmRequestDto.setBizType(BizConstant.TYPE_DATA_BIZ_PROCESS);
             algorithmRequestDto.setBizId(processVo.getId());
-            algorithmRequestDto.setSourcePath(preprocessPath);
-            algorithmRequestDto.setResultPath(resultPath);
+            algorithmRequestDto.setSourcePath(BizConstant.DOCKER_BASE_PATH + preprocessPath);
+            algorithmRequestDto.setResultPath(BizConstant.DOCKER_BASE_PATH + resultPath);
             algorithmRequestDto.setLogPath(processVo.getLog());
             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());
+                Map<String, Object> otherParams = new HashMap<>(paramDtoList.size());
                 for (AlgorithmConfigParamDto algorithmConfigParamDto : paramDtoList) {
-                    otherParams.put(algorithmConfigParamDto.getName(), StringUtils.isNotEmpty(algorithmConfigParamDto.getValue()) ? algorithmConfigParamDto.getValue() : algorithmConfigParamDto.getDefaultValue());
+                    String value = StringUtils.isNotEmpty(algorithmConfigParamDto.getValue()) ? algorithmConfigParamDto.getValue() : algorithmConfigParamDto.getDefaultValue();
+                    if(NumberUtils.isDigits(value)){
+                        otherParams.put(algorithmConfigParamDto.getAgName(), NumberUtils.createFloat(value));
+                    } else {
+                        otherParams.put(algorithmConfigParamDto.getAgName(), value);
+                    }
                 }
                 algorithmRequestDto.setOtherParams(otherParams);
             }

+ 6 - 0
taais-modules/taais-biz/src/main/resources/mapper/ag/AlgorithmModelMapper.xml

@@ -4,4 +4,10 @@
     "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.taais.biz.mapper.AlgorithmModelMapper">
 
+    <select id="getModelNameBySubtaskId" parameterType="Long" resultType="String">
+        select
+        (select att.name as taskName from algorithm_task att left join algorithm_subtask ast on att.id = ast.task_id where ast.id = ${subtaskId} limit 1)
+        || '-' ||
+        (select ac.algorithm_name from algorithm_config ac where ac.id = #{algorithmId} limit 1)
+    </select>
 </mapper>

+ 2 - 2
taais-modules/taais-biz/src/main/resources/mapper/task/AlgorithmBizProcessMapper.xml

@@ -16,7 +16,7 @@
         <result property="index" column="index" />
         <result property="startTime" column="start_time" />
         <result property="endTime" column="end_time" />
-        <result property="cost_second" column="cost_second" />
+        <result property="costSecond" column="cost_second" />
         <result property="log" column="log" />
         <result property="createBy" column="create_by" />
         <result property="createTime" column="create_time" />
@@ -26,7 +26,7 @@
     </resultMap>
 
     <select id="updateTaskAndSubtask" statementType="CALLABLE">
-        {call update_task_and_subtask(#{bizId,jdbcType=INTEGER,mode=IN}, #{bizType,jdbcType=VARCHAR,mode=IN}, #{status,jdbcType=VARCHAR,mode=IN})}
+        call update_task_and_subtask(#{bizId,jdbcType=INTEGER,mode=IN}, #{bizType,jdbcType=VARCHAR,mode=IN})
     </select>
 
     <select id="getProcessBySubtaskId" resultMap="AlgorithmBizProcessResultMap">

+ 1 - 1
taais-modules/taais-biz/src/main/resources/mapper/task/AlgorithmDataProcessMapper.xml

@@ -16,7 +16,7 @@
         <result property="index" column="index" />
         <result property="startTime" column="start_time" />
         <result property="endTime" column="end_time" />
-        <result property="cost_second" column="cost_second" />
+        <result property="costSecond" column="cost_second" />
         <result property="log" column="log" />
         <result property="createBy" column="create_by" />
         <result property="createTime" column="create_time" />