Explorar o código

算法库模型功能开发

zhaoyan %!s(int64=3) %!d(string=hai) anos
pai
achega
dd590380fd

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

@@ -28,8 +28,8 @@ public class AlgorithmParameter extends PageParameter {
     //代码仓库访问令牌
     private String gitToken;
 
-    //算法文件
-    private MultipartFile file;
+    //算法文件在 minio 上的位置
+    private String minioPath;
 
     //是否删除
     private String isDeleted;

+ 0 - 3
api-common/src/main/java/api/common/pojo/po/algorithm/AlgorithmPO.java

@@ -34,9 +34,6 @@ public class AlgorithmPO extends BasePo {
     //算法文件在 minio 上的位置
     private String minioPath;
 
-    //算法文件的 linux 备份路径
-    private String linuxPath;
-
     //是否公有
     private String share;
 

+ 5 - 4
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/ctrl/AlgorithmCtrl.java

@@ -5,10 +5,10 @@ import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.param.algorithm.AlgorithmParameter;
 import com.css.simulation.resource.algorithm.service.AlgorithmService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 
@@ -30,10 +30,11 @@ public class AlgorithmCtrl {
      */
     @RequestMapping("addOrUpdate")
     @ResponseBody
-    public ResponseBodyVO addOrUpdate(AlgorithmParameter param) throws IOException {
+    public ResponseBodyVO addOrUpdate(@RequestBody AlgorithmParameter param) throws IOException {
         return service.addOrUpdate(param);
     }
 
+
     /**
      * 查询算法列表-私有导入和私有仓库页面
      * @param param

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

@@ -2,6 +2,7 @@ package com.css.simulation.resource.algorithm.service;
 
 import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.param.algorithm.AlgorithmParameter;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 

+ 57 - 123
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/serviceImpl/AlgorithmServiceImpl.java

@@ -1,110 +1,67 @@
 package com.css.simulation.resource.algorithm.serviceImpl;
-import api.common.pojo.common.PageVO;
 import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.param.algorithm.AlgorithmParameter;
+import api.common.pojo.param.system.DictParam;
 import api.common.pojo.po.algorithm.AlgorithmPO;
-import api.common.pojo.vo.algorithm.PageInfoVo;
 import api.common.pojo.constants.DictConstants;
 import api.common.util.StringUtil;
 import api.common.util.FileUtil;
 import api.common.pojo.vo.algorithm.AlgorithmVO;
 import api.common.pojo.vo.algorithm.RunningProjectVO;
+import api.common.util.TimeUtil;
 import com.css.simulation.resource.common.utils.AuthUtil;
 import com.css.simulation.resource.common.utils.PageUtil;
 import com.css.simulation.resource.algorithm.mapper.AlgorithmMapper;
 import com.css.simulation.resource.algorithm.service.AlgorithmService;
 import com.css.simulation.resource.feign.FileDownService;
+import com.css.simulation.resource.system.service.DictService;
 import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
-
 import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 @Service
 public class AlgorithmServiceImpl implements AlgorithmService {
 
     @Autowired
     private AlgorithmMapper algorithmMapper;
+
+    @Autowired
+    DictService dictService;
     
     @Autowired
     FileDownService fileDownService;
     
     @Override
-    public ResponseBodyVO addOrUpdate(AlgorithmParameter param) throws IOException {
+    public ResponseBodyVO addOrUpdate(AlgorithmParameter param) {
 
         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,"该算法名称已存在!");
+            return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"该算法名称已存在!");
         }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,"添加失败");
-                    }
+                param.setId(algorithmId);
+                AlgorithmPO po = setPo(param, false);
+                int add = algorithmMapper.add(po);
+                if(add > 0){
+                    return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
                 }else {
-                    param.setId(algorithmId);
-                    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,"添加失败");
-                    }
+                    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);
-                        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, "编辑失败");
-                    }
+                AlgorithmPO po = setPo(param, true);
+                int add = algorithmMapper.update(po);
+                if (add > 0) {
+                    return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
                 }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, "编辑失败");
-                    }
+                    return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "编辑失败");
                 }
             }
         }
@@ -114,29 +71,23 @@ public class AlgorithmServiceImpl implements AlgorithmService {
     public ResponseBodyVO selectAlgorithmList(AlgorithmParameter param) {
         param.setIsDeleted("0");
         param.setCreateUserId(AuthUtil.getCurrentUserId());
-        setPage(param.getPageNum()==null?1:param.getPageNum(), param.getPageSize()==null?10:param.getPageSize());
+        PageUtil.setPageInfo(param);
         List<AlgorithmVO> vos = algorithmMapper.selectAlgorithmList(param);
-        PageInfo<AlgorithmVO> pageInfo = new PageInfo<>(vos);
-        PageInfoVo<AlgorithmVO> result = new PageInfoVo<>();
-
-        result.setInfo(vos);
-        result.setTotal(pageInfo.getTotal());
-
-        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,result);
+        for (AlgorithmVO vo:vos){
+            vo.setValidationStatus(getDictName(DictConstants.VALIDATION_STATUS, vo.getValidationStatus()));
+        }
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,new PageInfo<>(vos));
     }
 
     @Override
     public ResponseBodyVO selectSharedAlgorithmList(AlgorithmParameter param) {
         param.setShare("1");
-        setPage(param.getPageNum()==null?1:param.getPageNum(), param.getPageSize()==null?10:param.getPageSize());
+        PageUtil.setPageInfo(param);
         List<AlgorithmVO> vos = algorithmMapper.selectSharedAlgorithmList(param);
-        PageInfo<AlgorithmVO> pageInfo = new PageInfo<>(vos);
-        PageInfoVo<AlgorithmVO> result = new PageInfoVo<>();
-
-        result.setInfo(vos);
-        result.setTotal(pageInfo.getTotal());
-
-        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,result);
+        for (AlgorithmVO vo:vos){
+            vo.setValidationStatus(getDictName(DictConstants.VALIDATION_STATUS, vo.getValidationStatus()));
+        }
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,new PageInfo<>(vos));
     }
 
     @Override
@@ -147,7 +98,7 @@ public class AlgorithmServiceImpl implements AlgorithmService {
             AlgorithmPO po = algorithmMapper.selectDetailsById(param);
             List<AlgorithmPO> algorithmPOS = algorithmMapper.selectSharedAlgorithmName(po.getAlgorithmName());
             if(algorithmPOS != null && algorithmPOS.size() > 0){
-                return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,"该算法名称已存在, 无法分享!");
+                return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"该算法名称已存在, 无法分享!");
             }else {
                 po.setShare("1");
                 po.setId(StringUtil.getRandomUUID());
@@ -209,6 +160,7 @@ public class AlgorithmServiceImpl implements AlgorithmService {
             return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
         }else {
             AlgorithmPO po = algorithmMapper.selectDetailsById(param);
+            po.setValidationStatus(getDictName(DictConstants.VALIDATION_STATUS, po.getValidationStatus()));
             return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,po);
         }
 
@@ -226,69 +178,51 @@ public class AlgorithmServiceImpl implements AlgorithmService {
         return false;
     }
 
-    private void setPage(Integer pageNum, Integer pageSize){
-        PageVO pageVO = new PageVO();
-        pageVO.setCurrentPage(pageNum);
-        pageVO.setPageSize(pageSize);
-        PageUtil.setPageInfo(pageVO);
-    }
-
 
-    public boolean uploadFile(MultipartFile file, String linuxPath, String minioPath){
-
-        boolean uploadSuccess = false;
-        try {
-            //linux备份
-            InputStream inputStream = file.getInputStream();
-            FileUtil.writeInputStreamToLocalFile(inputStream, linuxPath);
-            uploadSuccess = true;
-            //minio保存
-            ResponseBodyVO<String> upload = fileDownService.upload(file, minioPath);
-            if(upload.getCode() != 200){
-                uploadSuccess = false;
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return uploadSuccess;
-
-    }
+    private AlgorithmPO setPo(AlgorithmParameter param,  Boolean isEdit) {
 
-
-    private AlgorithmPO setPo(AlgorithmParameter param, String fileName, String linuxPath, String minioPath, Boolean isEdit) throws IOException {
-
-        String algorithmId = param.getId();
         AlgorithmPO po = new AlgorithmPO();
         //设置po信息
-        String gitUrl = "";
-        String gitToken = "";
         if("2".equals(param.getUploadMode())){ //使用仓库地址上传
-            gitUrl = param.getGitUrl();
-            gitToken = param.getGitToken();
+            String gitUrl = param.getGitUrl();
+            String gitToken = param.getGitToken();
+            po.setGitUrl(gitUrl);
+            po.setGitToken(gitToken);
+        }else {
+            String minioPath = param.getMinioPath();
+            String[] splits = minioPath.split("/");
+            String fileName = splits[splits.length-1];
+            po.setMinioPath(param.getMinioPath());
+            po.setFileName(fileName);
         }
         po.setAlgorithmName(param.getAlgorithmName());
         po.setDescription(param.getDescription());
         po.setUploadMode(param.getUploadMode());
-        po.setGitUrl(gitUrl);
-        po.setGitToken(gitToken);
-        po.setFileName(fileName);
         po.setValidationStatus(DictConstants.SUCCESS);
         po.setShare("0");
-        po.setLinuxPath(linuxPath);
-        po.setMinioPath(minioPath);
-        po.setId(algorithmId);
+        po.setId(param.getId());
 
-        Date date = new Date();
         if(isEdit){
-            po.setModifyTime(date);
+            po.setModifyTime(TimeUtil.getNowForMysql());
             po.setCreateUserId(AuthUtil.getCurrentUserId());
         }else {
             po.setIsDeleted("0");
-            po.setCreateTime(date);
+            po.setCreateTime(TimeUtil.getNowForMysql());
             po.setCreateUserId(AuthUtil.getCurrentUserId());
         }
         return po;
 
     }
 
+    private String getDictName(String type, String code) {
+        DictParam dictParam = new DictParam();
+        dictParam.setDictTypes(type);
+        Map<String, Map<String, String>> dictMapsByTypes = dictService.getDictMapsByTypes(dictParam);
+        Map<String, String> stringStringMap = dictMapsByTypes.get(type);
+        if(stringStringMap != null && stringStringMap.size() > 0){
+            return stringStringMap.get(code);
+        }
+        return "";
+    }
+
 }

+ 2 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/scene/ctrl/FileController.java

@@ -48,6 +48,8 @@ public class FileController {
                 fileName="交通事故场景/"+nowTime+"/"+objectPath+"/"+multipartFile.getOriginalFilename();
             }else if(type.equals(DictConstants.SCENE_GENERAL)){
                 fileName="泛化场景/"+nowTime+"/"+objectPath+"/"+multipartFile.getOriginalFilename();
+            }else if(type.equals(DictConstants.ALGORITHM_FILE)){
+                fileName="algorithm/"+ nowTime +"/" + multipartFile.getOriginalFilename();
             }else{
                 fileName=multipartFile.getOriginalFilename();
             }

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

@@ -16,7 +16,6 @@
         git_token,
         file_name,
         minio_path,
-        linux_path,
         share,
         create_time,
         create_user_id,
@@ -35,7 +34,6 @@
         #{gitToken,jdbcType=VARCHAR},
         #{fileName,jdbcType=VARCHAR},
         #{minioPath,jdbcType=VARCHAR},
-        #{linuxPath,jdbcType=VARCHAR},
         #{share,jdbcType=VARCHAR},
         #{createTime,jdbcType=TIMESTAMP},
         #{createUserId,jdbcType=VARCHAR},
@@ -56,7 +54,7 @@
     <select id="selectAlgorithmList" 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
         <where>
-            is_deleted = '0'
+            is_deleted = '0' and share = '0'
         </where>
         <if test="id != null and id != ''">
             and id like CONCAT('%',#{id,jdbcType=VARCHAR},'%')