|
@@ -0,0 +1,281 @@
|
|
|
|
+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.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 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.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;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class AlgorithmServiceImpl implements AlgorithmService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private AlgorithmMapper algorithmMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ FileDownService fileDownService;
|
|
|
|
+
|
|
|
|
+ @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) {
|
|
|
|
+ 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, "", "", "", false);
|
|
|
|
+ int add = algorithmMapper.add(po);
|
|
|
|
+ if(add > 0){
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
|
|
|
|
+ }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);
|
|
|
|
+ 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
|
|
|
|
+ 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());
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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);
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseBodyVO shareAlgorithm(AlgorithmParameter param) {
|
|
|
|
+ if(isEmpty(param.getId())){
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"分享失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseBodyVO testConnection(AlgorithmParameter param) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseBodyVO isAlgorithmRunning(AlgorithmParameter param)
|
|
|
|
+ {
|
|
|
|
+ if(isEmpty(param.getId())){
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
|
|
+ }else {
|
|
|
|
+ String algorithmId = param.getId();
|
|
|
|
+ List<RunningProjectVO> runningProjectVos = algorithmMapper.selectRunningProject(algorithmId);
|
|
|
|
+ if(runningProjectVos != null && runningProjectVos.size() > 0){
|
|
|
|
+ StringBuffer stringBuffer = new StringBuffer("");
|
|
|
|
+ for (RunningProjectVO vo:runningProjectVos){
|
|
|
|
+ String projectId = vo.getProjectId();
|
|
|
|
+ stringBuffer.append(projectId+",");
|
|
|
|
+ }
|
|
|
|
+ String substring = stringBuffer.substring(0, stringBuffer.lastIndexOf(","));
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,"已被工作ID:"+ substring +" 应用,无法删除");
|
|
|
|
+ }else {
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseBodyVO deleteByid(AlgorithmParameter param) {
|
|
|
|
+ if(isEmpty(param.getId())){
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
|
|
+ }else {
|
|
|
|
+ int i = algorithmMapper.deleteByid(param);
|
|
|
|
+ if(i > 0){
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"删除失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseBodyVO selectDetailsById(AlgorithmParameter param) {
|
|
|
|
+ if(isEmpty(param.getId())){
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
|
|
+ }else {
|
|
|
|
+ AlgorithmPO po = algorithmMapper.selectDetailsById(param);
|
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,po);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private boolean isEmpty(String value){
|
|
|
|
+ if(value == null){
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ value = value.trim();
|
|
|
|
+ if(value.length() == 0){
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ 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, 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();
|
|
|
|
+ }
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ if(isEdit){
|
|
|
|
+ po.setModifyTime(date);
|
|
|
|
+ po.setCreateUserId(AuthUtil.getCurrentUserId());
|
|
|
|
+ }else {
|
|
|
|
+ po.setIsDeleted("0");
|
|
|
|
+ po.setCreateTime(date);
|
|
|
|
+ po.setCreateUserId(AuthUtil.getCurrentUserId());
|
|
|
|
+ }
|
|
|
|
+ return po;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|