Explorar el Código

算法库模型功能开发

zhaoyan hace 3 años
padre
commit
8b1c08e2ad

+ 4 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/mapper/AlgorithmMapper.java

@@ -24,6 +24,10 @@ public interface AlgorithmMapper {
 
     AlgorithmPO selectDetailsById(AlgorithmParameter param);
 
+    List<AlgorithmPO> selectAlgorithmName(AlgorithmParameter param);
+
+    List<AlgorithmPO> selectSharedAlgorithmName(@Param("algorithmName") String algorithmName);
+
     List<RunningProjectVO> selectRunningProject(@Param("id") String id);
 
     List<AlgorithmVO> selectSharedAlgorithmList(AlgorithmParameter param);

+ 66 - 53
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/serviceImpl/AlgorithmServiceImpl.java

@@ -35,71 +35,79 @@ public class AlgorithmServiceImpl implements AlgorithmService {
     
     @Override
     public ResponseBodyVO addOrUpdate(AlgorithmParameter param) throws IOException {
-        if(isEmpty(param.getId())){
-            //添加
-            String algorithmId = StringUtil.getRandomUUID();
-            String uploadMode = param.getUploadMode();
-            if("1".equals(uploadMode)){
-                MultipartFile file = param.getFile();
-                String fileName = file.getOriginalFilename();
-                String linuxPath = "/opt/simulation-cloud/algorithm/" + algorithmId + "/" + fileName;
-                String minioPath = "algorithm/" + algorithmId + "/" + fileName;
-                boolean uploadSuccess = uploadFile(file, linuxPath, minioPath);
-                if(uploadSuccess) {
+
+        String currentUserId = AuthUtil.getCurrentUserId();
+        param.setCreateUserId(currentUserId);
+        List<AlgorithmPO> algorithmPOS = algorithmMapper.selectAlgorithmName(param);
+        if(algorithmPOS != null && algorithmPOS.size() > 0){
+            return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,"该算法名称已存在!");
+        }else {
+            if(isEmpty(param.getId())){
+                //添加
+
+                String algorithmId = StringUtil.getRandomUUID();
+                String uploadMode = param.getUploadMode();
+                if("1".equals(uploadMode)){
+                    MultipartFile file = param.getFile();
+                    String fileName = file.getOriginalFilename();
+                    String linuxPath = "/opt/simulation-cloud/algorithm/" + algorithmId + "/" + fileName;
+                    String minioPath = "algorithm/" + algorithmId + "/" + fileName;
+                    boolean uploadSuccess = uploadFile(file, linuxPath, minioPath);
+                    if(uploadSuccess) {
+                        param.setId(algorithmId);
+                        AlgorithmPO po = setPo(param, fileName, linuxPath, minioPath, false);
+                        int add = algorithmMapper.add(po);
+                        if(add > 0){
+                            return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
+                        }else {
+                            return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"添加失败");
+                        }
+                    }else {
+                        return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"添加失败");
+                    }
+                }else {
                     param.setId(algorithmId);
-                    AlgorithmPO po = setPo(param, fileName, linuxPath, minioPath, false);
+                    AlgorithmPO po = setPo(param, "", "", "", false);
                     int add = algorithmMapper.add(po);
                     if(add > 0){
                         return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
                     }else {
                         return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"添加失败");
                     }
-                }else {
-                    return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"添加失败");
                 }
             }else {
-                param.setId(algorithmId);
-                AlgorithmPO po = setPo(param, "", "", "", false);
-                int add = algorithmMapper.add(po);
-                if(add > 0){
-                    return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
+                //编辑
+                String uploadMode = param.getUploadMode();
+                String algorithmId = param.getId();
+                if("1".equals(uploadMode)) {
+                    MultipartFile file = param.getFile();
+                    String fileName = file.getOriginalFilename();
+                    String linuxPath = "/opt/simulation-cloud/algorithm/" + algorithmId + "/" + fileName;
+                    String minioPath = "algorithm/" + algorithmId + "/" + fileName;
+
+                    boolean uploadSuccess = uploadFile(file, linuxPath, minioPath);
+                    if (uploadSuccess) {
+                        AlgorithmPO po = setPo(param, fileName, linuxPath, minioPath, true);
+                        int add = algorithmMapper.update(po);
+                        if (add > 0) {
+                            return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
+                        }else {
+                            return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "编辑失败");
+                        }
+                    } else {
+                        return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "编辑失败");
+                    }
                 }else {
-                    return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"添加失败");
-                }
-            }
-        }else {
-            //编辑
-            String uploadMode = param.getUploadMode();
-            String algorithmId = param.getId();
-            if("1".equals(uploadMode)) {
-                MultipartFile file = param.getFile();
-                String fileName = file.getOriginalFilename();
-                String linuxPath = "/opt/simulation-cloud/algorithm/" + algorithmId + "/" + fileName;
-                String minioPath = "algorithm/" + algorithmId + "/" + fileName;
-
-                boolean uploadSuccess = uploadFile(file, linuxPath, minioPath);
-                if (uploadSuccess) {
-                    AlgorithmPO po = setPo(param, fileName, linuxPath, minioPath, true);
+                    AlgorithmPO po = setPo(param, "", "", "", true);
                     int add = algorithmMapper.update(po);
                     if (add > 0) {
                         return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
                     }else {
                         return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "编辑失败");
                     }
-                } else {
-                    return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "编辑失败");
-                }
-            }else {
-                AlgorithmPO po = setPo(param, "", "", "", true);
-                int add = algorithmMapper.update(po);
-                if (add > 0) {
-                    return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
-                }else {
-                    return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "编辑失败");
                 }
             }
         }
-
     }
 
     @Override
@@ -119,7 +127,6 @@ public class AlgorithmServiceImpl implements AlgorithmService {
 
     @Override
     public ResponseBodyVO selectSharedAlgorithmList(AlgorithmParameter param) {
-        param.setIsDeleted("0");
         param.setShare("1");
         setPage(param.getPageNum()==null?1:param.getPageNum(), param.getPageSize()==null?10:param.getPageSize());
         List<AlgorithmVO> vos = algorithmMapper.selectSharedAlgorithmList(param);
@@ -138,13 +145,19 @@ public class AlgorithmServiceImpl implements AlgorithmService {
             return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
         }else {
             AlgorithmPO po = algorithmMapper.selectDetailsById(param);
-            po.setShare("1");
-            po.setId(StringUtil.getRandomUUID());
-            int add = algorithmMapper.add(po);
-            if(add > 0){
-                return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
+            List<AlgorithmPO> algorithmPOS = algorithmMapper.selectSharedAlgorithmName(po.getAlgorithmName());
+            if(algorithmPOS != null && algorithmPOS.size() > 0){
+                return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,"该算法名称已存在, 无法分享!");
+            }else {
+                po.setShare("1");
+                po.setId(StringUtil.getRandomUUID());
+                int add = algorithmMapper.add(po);
+                if(add > 0){
+                    return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,"分享成功");
+                }
+                return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"分享失败");
+
             }
-            return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"分享失败");
         }
     }
 

+ 26 - 1
simulation-resource-server/src/main/resources/mapper/algorithm/AlgorithmMapper.xml

@@ -88,6 +88,22 @@
         </if>
     </select>
 
+    <!--查询算法名称是否已存在-当前用户-->
+    <select id="selectAlgorithmName"  parameterType="api.common.pojo.param.algorithm.AlgorithmParameter" resultType="api.common.pojo.po.algorithm.AlgorithmPO">
+        select id  from algorithm
+        where is_deleted = '0'
+        <if test="algorithmName != null and algorithmName != ''">
+            and  algorithm_name = #{algorithmName,jdbcType=VARCHAR}
+        </if>
+        <if test="createUserId != null and createUserId != ''">
+            and create_user_id = #{createUserId,jdbcType=VARCHAR}
+        </if>
+        <if test="id != null and id != ''">
+            and id != #{id,jdbcType=VARCHAR}
+        </if>
+    </select>
+
+
     <!--查询算法列表—公有-->
     <select id="selectSharedAlgorithmList" parameterType="api.common.pojo.param.algorithm.AlgorithmParameter" resultType="api.common.pojo.vo.algorithm.AlgorithmVO">
         select id, algorithm_name, description, validation_status, upload_mode from algorithm
@@ -112,6 +128,15 @@
         order by modify_time desc, create_time desc
     </select>
 
+    <!--查询算法名称是否已存在-公有-->
+    <select id="selectSharedAlgorithmName" resultType="api.common.pojo.po.algorithm.AlgorithmPO">
+        select id  from algorithm
+        where is_deleted = '0' and share = '1'
+        <if test="algorithmName != null and algorithmName != ''">
+            and  algorithm_name = #{algorithmName,jdbcType=VARCHAR}
+        </if>
+    </select>
+
     <!--删除-->
     <update id="deleteByid">
         update algorithm
@@ -131,7 +156,7 @@
         minio_path=#{minioPath,jdbcType=VARCHAR},
         linux_path=#{linuxPath,jdbcType=VARCHAR},
         modify_time=#{modifyTime,jdbcType=VARCHAR},
-        modify_user_id=#{modifyUserId,jdbcType=VARCHAR},
+        modify_user_id=#{modifyUserId,jdbcType=VARCHAR}
         where id=#{id,jdbcType=VARCHAR}
     </update>