|
@@ -1,110 +1,67 @@
|
|
package com.css.simulation.resource.algorithm.serviceImpl;
|
|
package com.css.simulation.resource.algorithm.serviceImpl;
|
|
-import api.common.pojo.common.PageVO;
|
|
|
|
import api.common.pojo.common.ResponseBodyVO;
|
|
import api.common.pojo.common.ResponseBodyVO;
|
|
import api.common.pojo.param.algorithm.AlgorithmParameter;
|
|
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.po.algorithm.AlgorithmPO;
|
|
-import api.common.pojo.vo.algorithm.PageInfoVo;
|
|
|
|
import api.common.pojo.constants.DictConstants;
|
|
import api.common.pojo.constants.DictConstants;
|
|
import api.common.util.StringUtil;
|
|
import api.common.util.StringUtil;
|
|
import api.common.util.FileUtil;
|
|
import api.common.util.FileUtil;
|
|
import api.common.pojo.vo.algorithm.AlgorithmVO;
|
|
import api.common.pojo.vo.algorithm.AlgorithmVO;
|
|
import api.common.pojo.vo.algorithm.RunningProjectVO;
|
|
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.AuthUtil;
|
|
import com.css.simulation.resource.common.utils.PageUtil;
|
|
import com.css.simulation.resource.common.utils.PageUtil;
|
|
import com.css.simulation.resource.algorithm.mapper.AlgorithmMapper;
|
|
import com.css.simulation.resource.algorithm.mapper.AlgorithmMapper;
|
|
import com.css.simulation.resource.algorithm.service.AlgorithmService;
|
|
import com.css.simulation.resource.algorithm.service.AlgorithmService;
|
|
import com.css.simulation.resource.feign.FileDownService;
|
|
import com.css.simulation.resource.feign.FileDownService;
|
|
|
|
+import com.css.simulation.resource.system.service.DictService;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
|
-
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.io.InputStream;
|
|
|
|
-import java.util.Date;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class AlgorithmServiceImpl implements AlgorithmService {
|
|
public class AlgorithmServiceImpl implements AlgorithmService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private AlgorithmMapper algorithmMapper;
|
|
private AlgorithmMapper algorithmMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ DictService dictService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
FileDownService fileDownService;
|
|
FileDownService fileDownService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public ResponseBodyVO addOrUpdate(AlgorithmParameter param) throws IOException {
|
|
|
|
|
|
+ public ResponseBodyVO addOrUpdate(AlgorithmParameter param) {
|
|
|
|
|
|
String currentUserId = AuthUtil.getCurrentUserId();
|
|
String currentUserId = AuthUtil.getCurrentUserId();
|
|
param.setCreateUserId(currentUserId);
|
|
param.setCreateUserId(currentUserId);
|
|
List<AlgorithmPO> algorithmPOS = algorithmMapper.selectAlgorithmName(param);
|
|
List<AlgorithmPO> algorithmPOS = algorithmMapper.selectAlgorithmName(param);
|
|
if(algorithmPOS != null && algorithmPOS.size() > 0){
|
|
if(algorithmPOS != null && algorithmPOS.size() > 0){
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,"该算法名称已存在!");
|
|
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"该算法名称已存在!");
|
|
}else {
|
|
}else {
|
|
if(isEmpty(param.getId())){
|
|
if(isEmpty(param.getId())){
|
|
//添加
|
|
//添加
|
|
-
|
|
|
|
String algorithmId = StringUtil.getRandomUUID();
|
|
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 {
|
|
}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 {
|
|
}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 {
|
|
}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) {
|
|
public ResponseBodyVO selectAlgorithmList(AlgorithmParameter param) {
|
|
param.setIsDeleted("0");
|
|
param.setIsDeleted("0");
|
|
param.setCreateUserId(AuthUtil.getCurrentUserId());
|
|
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);
|
|
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
|
|
@Override
|
|
public ResponseBodyVO selectSharedAlgorithmList(AlgorithmParameter param) {
|
|
public ResponseBodyVO selectSharedAlgorithmList(AlgorithmParameter param) {
|
|
param.setShare("1");
|
|
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);
|
|
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
|
|
@Override
|
|
@@ -147,7 +98,7 @@ public class AlgorithmServiceImpl implements AlgorithmService {
|
|
AlgorithmPO po = algorithmMapper.selectDetailsById(param);
|
|
AlgorithmPO po = algorithmMapper.selectDetailsById(param);
|
|
List<AlgorithmPO> algorithmPOS = algorithmMapper.selectSharedAlgorithmName(po.getAlgorithmName());
|
|
List<AlgorithmPO> algorithmPOS = algorithmMapper.selectSharedAlgorithmName(po.getAlgorithmName());
|
|
if(algorithmPOS != null && algorithmPOS.size() > 0){
|
|
if(algorithmPOS != null && algorithmPOS.size() > 0){
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,"该算法名称已存在, 无法分享!");
|
|
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"该算法名称已存在, 无法分享!");
|
|
}else {
|
|
}else {
|
|
po.setShare("1");
|
|
po.setShare("1");
|
|
po.setId(StringUtil.getRandomUUID());
|
|
po.setId(StringUtil.getRandomUUID());
|
|
@@ -209,6 +160,7 @@ public class AlgorithmServiceImpl implements AlgorithmService {
|
|
return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
}else {
|
|
}else {
|
|
AlgorithmPO po = algorithmMapper.selectDetailsById(param);
|
|
AlgorithmPO po = algorithmMapper.selectDetailsById(param);
|
|
|
|
+ po.setValidationStatus(getDictName(DictConstants.VALIDATION_STATUS, po.getValidationStatus()));
|
|
return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,po);
|
|
return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,po);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -226,69 +178,51 @@ public class AlgorithmServiceImpl implements AlgorithmService {
|
|
return false;
|
|
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();
|
|
AlgorithmPO po = new AlgorithmPO();
|
|
//设置po信息
|
|
//设置po信息
|
|
- String gitUrl = "";
|
|
|
|
- String gitToken = "";
|
|
|
|
if("2".equals(param.getUploadMode())){ //使用仓库地址上传
|
|
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.setAlgorithmName(param.getAlgorithmName());
|
|
po.setDescription(param.getDescription());
|
|
po.setDescription(param.getDescription());
|
|
po.setUploadMode(param.getUploadMode());
|
|
po.setUploadMode(param.getUploadMode());
|
|
- po.setGitUrl(gitUrl);
|
|
|
|
- po.setGitToken(gitToken);
|
|
|
|
- po.setFileName(fileName);
|
|
|
|
po.setValidationStatus(DictConstants.SUCCESS);
|
|
po.setValidationStatus(DictConstants.SUCCESS);
|
|
po.setShare("0");
|
|
po.setShare("0");
|
|
- po.setLinuxPath(linuxPath);
|
|
|
|
- po.setMinioPath(minioPath);
|
|
|
|
- po.setId(algorithmId);
|
|
|
|
|
|
+ po.setId(param.getId());
|
|
|
|
|
|
- Date date = new Date();
|
|
|
|
if(isEdit){
|
|
if(isEdit){
|
|
- po.setModifyTime(date);
|
|
|
|
|
|
+ po.setModifyTime(TimeUtil.getNowForMysql());
|
|
po.setCreateUserId(AuthUtil.getCurrentUserId());
|
|
po.setCreateUserId(AuthUtil.getCurrentUserId());
|
|
}else {
|
|
}else {
|
|
po.setIsDeleted("0");
|
|
po.setIsDeleted("0");
|
|
- po.setCreateTime(date);
|
|
|
|
|
|
+ po.setCreateTime(TimeUtil.getNowForMysql());
|
|
po.setCreateUserId(AuthUtil.getCurrentUserId());
|
|
po.setCreateUserId(AuthUtil.getCurrentUserId());
|
|
}
|
|
}
|
|
return po;
|
|
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 "";
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|