root 2 år sedan
förälder
incheckning
4494f83f88

+ 14 - 43
api-common/src/main/java/api/common/pojo/param/algorithm/AlgorithmParameter.java

@@ -2,53 +2,24 @@ package api.common.pojo.param.algorithm;
 
 import lombok.*;
 
-
 @EqualsAndHashCode(callSuper = true)
 @Data
 @Builder
 @AllArgsConstructor
 @NoArgsConstructor
 public class AlgorithmParameter extends PageParameter {
-    //id
-    private String id;
-
-    //算法名称
-    private String algorithmName;
-
-    //算法ID
-    private String algorithmCode;
-
-    //算法描述
-    private String description;
-
-    //校验状态
-    private String validationStatus;
-
-    //上传方式
-    private String uploadMode;
-
-    //仓库地址
-    private String gitUrl;
-
-    //代码仓库访问用户名
-    private String gitUserName;
-
-    //代码仓库访问密码
-    private String gitPassword;
-
-    //代码仓库版本号
-    private String gitVersion;
-
-    //算法文件在 minio 上的位置
-    private String minioPath;
-
-    //是否删除
-    private String isDeleted;
-
-    //是否公有
-    private String share;
-
-    //创建用户ID
-    private String createUserId;
-
+    private String id;                  // id
+    private String algorithmName;       // 算法名称
+    private String algorithmCode;       // 算法ID
+    private String description;         // 算法描述
+    private String validationStatus;    // 校验状态
+    private String uploadMode;          // 上传方式
+    private String gitUrl;              // 仓库地址
+    private String gitUserName;         // 代码仓库访问用户名
+    private String gitPassword;         // 代码仓库访问密码
+    private String gitVersion;          // 代码仓库版本号
+    private String minioPath;           // 算法文件在 minio 上的位置
+    private String isDeleted;           // 是否删除
+    private String share;               // 是否公有
+    private String createUserId;        // 创建用户ID
 }

+ 1 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/controller/AlgorithmController.java

@@ -35,7 +35,7 @@ public class AlgorithmController {
      * 新增/修改算法
      */
     @RequestMapping("addOrUpdate")
-    public ResponseBodyVO addOrUpdate(@RequestBody AlgorithmParameter param) throws IOException {
+    public ResponseBodyVO<Void> addOrUpdate(@RequestBody AlgorithmParameter param) throws IOException {
         return algorithmService.addOrUpdate(param);
     }
 

+ 8 - 12
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/mapper/AlgorithmMapper.java

@@ -1,18 +1,16 @@
 package com.css.simulation.resource.algorithm.mapper;
 
+import api.common.pojo.param.algorithm.AlgorithmParameter;
 import api.common.pojo.po.algorithm.AlgorithmPO;
+import api.common.pojo.vo.algorithm.AlgorithmVO;
 import api.common.pojo.vo.algorithm.RunningProjectVO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
-import org.springframework.stereotype.Repository;
-import api.common.pojo.vo.algorithm.AlgorithmVO;
-import api.common.pojo.param.algorithm.AlgorithmParameter;
 
 import java.util.List;
 
 @Mapper
-@Repository
 public interface AlgorithmMapper {
 
     List<AlgorithmVO> selectAlgorithmList(AlgorithmParameter param);
@@ -25,15 +23,15 @@ public interface AlgorithmMapper {
 
     AlgorithmPO selectDetailsById(@Param("algorithmId") String algorithmId);
 
-    @Select("        select a.is_deleted\n" +
-            "        from `algorithm` a \n" +
-            "        where a.id = #{algorithmId,jdbcType=VARCHAR}")
+    @Select("        select is_deleted\n" +
+            "        from algorithm\n" +
+            "        where id = #{algorithmId}")
     String selectIsDeletedById(@Param("algorithmId") String algorithmId);
 
-    @Select("select a.algorithm_name \n" +
-            "from `algorithm` a \n" +
+    @Select("select algorithm_name\n" +
+            "from algorithm\n" +
             "where is_deleted = '1'\n" +
-            " and a.id = #{algorithmId,jdbcType=VARCHAR}")
+            " and id = #{algorithmId}")
     String selectDeletedById(@Param("algorithmId") String algorithmId);
 
     List<AlgorithmPO> selectAlgorithmName(AlgorithmParameter param);
@@ -46,8 +44,6 @@ public interface AlgorithmMapper {
 
     List<RunningProjectVO> selectAutoProjectIdByAlgorithmId(@Param("algorithmId") String algorithmId);
 
-
-
     List<AlgorithmVO> selectSharedAlgorithmList(AlgorithmParameter param);
 
     int  selectDetailsBySy(AlgorithmParameter param);

+ 1 - 2
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/service/AlgorithmService.java

@@ -3,13 +3,12 @@ package com.css.simulation.resource.algorithm.service;
 import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.param.algorithm.AlgorithmParameter;
 
-import java.io.IOException;
 import java.util.Map;
 
 
 public interface AlgorithmService {
 
-    ResponseBodyVO addOrUpdate(AlgorithmParameter param) throws IOException;
+    ResponseBodyVO<Void> addOrUpdate(AlgorithmParameter param);
 
     ResponseBodyVO selectAlgorithmList(AlgorithmParameter param);
 

+ 16 - 16
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/service/impl/AlgorithmServiceImpl.java

@@ -29,10 +29,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 @Slf4j
 @Service
@@ -69,35 +66,38 @@ public class AlgorithmServiceImpl implements AlgorithmService {
 
     @Override
     @SneakyThrows
-    public ResponseBodyVO<String> addOrUpdate(AlgorithmParameter param) {
-
+    public ResponseBodyVO<Void> addOrUpdate(AlgorithmParameter param) {
         String currentUserId = AuthUtil.getCurrentUserId();
         param.setCreateUserId(currentUserId);
+        // 公有另存为私有,设置 share 为 0
+        if (Objects.equals(DictConstants.IS_SHARED, param.getShare())) {
+            param.setShare(DictConstants.IS_NOT_SHARED);
+        }
         List<AlgorithmPO> algorithmPOS = algorithmMapper.selectAlgorithmName(param);
         if (algorithmPOS != null && algorithmPOS.size() > 0) {
-            return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "该算法名称已存在!");
+            return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "该算法名称已存在");
         } else {
             String uploadMode = param.getUploadMode();
             if (DictConstants.FILE.equals(uploadMode)) {
                 String minioPath = param.getMinioPath();
                 ResponseBodyVO<String> checkRes = schedulerService.check(minioPath);
                 if (ObjectUtil.isNull(checkRes)) {
-                    return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "算法校验服务异常,请联系管理人员");
+                    return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "算法校验服务异常,请联系管理人员");
                 }
                 if (!checkRes.isStatus()) {//校验失败
                     MinioParameter minioParameter = new MinioParameter();
                     minioParameter.setObjectName(minioPath);
                     fileDownService.remove(minioParameter);
-                    return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "该算法经校验不可用,无法保存");
+                    return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "该算法经校验不可用,无法保存");
                 }
             }
             return doAddOrUpdate(param);
         }
     }
 
-    private ResponseBodyVO doAddOrUpdate(AlgorithmParameter param) {
+    private ResponseBodyVO<Void> doAddOrUpdate(AlgorithmParameter param) {
         if (isEmpty(param.getId())) {
-            //添加
+            // 添加
             String algorithmId = StringUtil.getRandomUUID();
             param.setId(algorithmId);
             String algorithmCode = StringUtil.getRandomCode();
@@ -106,19 +106,19 @@ public class AlgorithmServiceImpl implements AlgorithmService {
             int add = algorithmMapper.add(po);
             if (add > 0) {
                 LogUtil.insert();
-                return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
+                return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
             } else {
-                return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "添加失败");
+                return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "添加失败");
             }
         } else {
-            //编辑
+            // 编辑
             AlgorithmPO po = setPo(param, true);
             int add = algorithmMapper.update(po);
             if (add > 0) {
                 LogUtil.update();
-                return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
+                return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
             } else {
-                return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "编辑失败");
+                return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "编辑失败");
             }
         }