瀏覽代碼

feat: 模型添加优化

WANGKANG 9 月之前
父節點
當前提交
a3a8839913

+ 2 - 6
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/AlgorithmModelTrackController.java

@@ -70,12 +70,8 @@ public class AlgorithmModelTrackController extends BaseController {
     @Log(title = "算法模型配置", businessType = BusinessType.INSERT)
     @RepeatSubmit()
     @PostMapping
-    public CommonResult<Void> add(@Validated @RequestBody AlgorithmModelTrackBo algorithmModelTrackBo) {
-        boolean inserted = algorithmModelTrackService.insert(algorithmModelTrackBo);
-        if (!inserted) {
-            return CommonResult.fail("新增算法模型配置记录失败!");
-        }
-        return CommonResult.success();
+    public CommonResult<String> add(@Validated @RequestBody AlgorithmModelTrackBo algorithmModelTrackBo) {
+        return algorithmModelTrackService.insert(algorithmModelTrackBo);
     }
 
     /**

+ 1 - 1
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/bo/AlgorithmModelTrackBo.java

@@ -36,7 +36,7 @@ public class AlgorithmModelTrackBo extends BaseEntity {
     @NotBlank(message = "模型名称不能为空")
     private String modelName;
 
-    @NotNull(message = "模型文件不能为空")
+    // @NotNull(message = "模型文件不能为空")
     private Long modelInputOssId;
 
     /**

+ 3 - 2
taais-modules/taais-biz/src/main/java/com/taais/biz/listener/AlgorithmModelTrackImportListener.java

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.excel.context.AnalysisContext;
 import com.alibaba.excel.event.AnalysisEventListener;
+import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.core.exception.ServiceException;
 import com.taais.common.core.utils.SpringUtils;
 import com.taais.common.core.utils.ValidatorUtils;
@@ -51,9 +52,9 @@ public class AlgorithmModelTrackImportListener extends AnalysisEventListener<Alg
                 //不存在就新增
                 algorithmModelTrackBo.setVersion(0);
                 ValidatorUtils.validate(algorithmModelTrackBo);
-                boolean inserted = algorithmModelTrackService.insert(algorithmModelTrackBo);
+                CommonResult<String> result = algorithmModelTrackService.insert(algorithmModelTrackBo);
 
-                if (inserted) {
+                if (result.getCode() == CommonResult.SUCCESS) {
                     successNum++;
                     successMsg.append("<br/>").append(successNum).append("、算法模型配置 记录导入成功");
                     return;

+ 2 - 1
taais-modules/taais-biz/src/main/java/com/taais/biz/service/IAlgorithmModelTrackService.java

@@ -5,6 +5,7 @@ import java.util.List;
 import com.taais.biz.domain.AlgorithmModelTrack;
 import com.taais.biz.domain.vo.AlgorithmModelTrackVo;
 import com.taais.biz.domain.bo.AlgorithmModelTrackBo;
+import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.orm.core.service.IBaseService;
 import com.taais.common.core.core.page.PageResult;
 
@@ -45,7 +46,7 @@ public interface IAlgorithmModelTrackService extends IBaseService<AlgorithmModel
      * @param algorithmModelTrackBo 算法模型配置Bo
      * @return 结果:true 操作成功,false 操作失败
      */
-    boolean insert(AlgorithmModelTrackBo algorithmModelTrackBo);
+    CommonResult<String> insert(AlgorithmModelTrackBo algorithmModelTrackBo);
 
     /**
      * 修改算法模型配置

+ 29 - 11
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/AlgorithmModelTrackServiceImpl.java

@@ -5,6 +5,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 
+import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.mybatisflex.core.paginate.Page;
 import com.mybatisflex.core.query.QueryWrapper;
@@ -13,6 +14,8 @@ import com.taais.biz.domain.vo.AlgorithmConfigTrackVo;
 import com.taais.biz.mapper.AlgorithmConfigTrackMapper;
 import com.taais.common.core.config.TaaisConfig;
 import com.taais.common.core.constant.Constants;
+import com.taais.common.core.core.domain.CommonResult;
+import com.taais.common.core.utils.DateUtils;
 import com.taais.common.core.utils.MapstructUtils;
 import com.taais.common.core.utils.StringUtils;
 import com.taais.common.orm.core.page.PageQuery;
@@ -32,6 +35,7 @@ import com.taais.biz.domain.vo.AlgorithmModelTrackVo;
 import com.taais.biz.service.IAlgorithmModelTrackService;
 
 import static com.taais.biz.domain.table.AlgorithmModelTrackTableDef.ALGORITHM_MODEL_TRACK;
+import static com.taais.biz.constant.BizConstant.AlgorithmType;
 
 /**
  * 算法模型配置Service业务层处理
@@ -85,7 +89,7 @@ public class AlgorithmModelTrackServiceImpl extends BaseServiceImpl<AlgorithmMod
      */
     @Override
     public AlgorithmModelTrackVo selectById(Long id) {
-        AlgorithmModelTrackVo algorithmModelTrackVo =  this.getOneAs(query().where(ALGORITHM_MODEL_TRACK.ID.eq(id)), AlgorithmModelTrackVo.class);
+        AlgorithmModelTrackVo algorithmModelTrackVo = this.getOneAs(query().where(ALGORITHM_MODEL_TRACK.ID.eq(id)), AlgorithmModelTrackVo.class);
 
         Long algorithmId = algorithmModelTrackVo.getAlgorithmId();
 
@@ -129,23 +133,37 @@ public class AlgorithmModelTrackServiceImpl extends BaseServiceImpl<AlgorithmMod
      * @return 结果:true 操作成功,false 操作失败
      */
     @Override
-    public boolean insert(AlgorithmModelTrackBo algorithmModelTrackBo) {
-        AlgorithmModelTrack algorithmModelTrack = MapstructUtils.convert(algorithmModelTrackBo, AlgorithmModelTrack.class);
-
-        SysOssVo inputOssEntity = ossService.getById(algorithmModelTrackBo.getModelInputOssId());
+    public CommonResult<String> insert(AlgorithmModelTrackBo algorithmModelTrackBo) {
+        AlgorithmConfigTrackVo algorithmConfigTrackVo = algorithmConfigTrackService.selectById(algorithmModelTrackBo.getAlgorithmId_());
+        if (algorithmConfigTrackVo.getType().equals(AlgorithmType.REASONING) && ObjectUtil.isEmpty(algorithmModelTrackBo.getModelInputOssId())) {
+            return CommonResult.fail("预测算法必须上传模型输入文件");
+        }
 
-        String filePath = inputOssEntity.getFileName();
-        String localPath = TaaisConfig.getProfile();
-        String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
+        AlgorithmModelTrack algorithmModelTrack = MapstructUtils.convert(algorithmModelTrackBo, AlgorithmModelTrack.class);
 
+        String resourcePath = null;
+        if (algorithmModelTrackBo.getModelInputOssId() != null) {
+            SysOssVo inputOssEntity = ossService.getById(algorithmModelTrackBo.getModelInputOssId());
+
+            String filePath = inputOssEntity.getFileName();
+            String localPath = TaaisConfig.getProfile();
+            resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
+        } else {
+            String localPath = TaaisConfig.getUploadPath();
+            String path = DateUtils.datePath() + "/" + IdUtil.fastSimpleUUID();
+            ;
+            resourcePath = localPath + "/" + path + ".pt";
+        }
         algorithmModelTrack.setModelAddress(resourcePath);
 
         algorithmModelTrack.setAlgorithmId(algorithmModelTrackBo.getAlgorithmId_());
-
-        AlgorithmConfigTrackVo algorithmConfigTrackVo = algorithmConfigTrackService.selectById(algorithmModelTrackBo.getAlgorithmId_());
         algorithmModelTrack.setAlgorithmType(algorithmConfigTrackVo.getAlgorithmName());
 
-        return this.save(algorithmModelTrack); // 使用全局配置的雪花算法主键生成器生成ID值
+        boolean inserted = this.save(algorithmModelTrack); // 使用全局配置的雪花算法主键生成器生成ID值
+        if (inserted) {
+            return CommonResult.success("新增算法模型配置成功");
+        }
+        return CommonResult.fail("新增算法模型配置失败");
     }
 
     /**