|
@@ -12,10 +12,12 @@ 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.common.utils.PoUtil;
|
|
import com.css.simulation.resource.feign.AlgoPlatformService;
|
|
import com.css.simulation.resource.feign.AlgoPlatformService;
|
|
import com.css.simulation.resource.feign.FileDownService;
|
|
import com.css.simulation.resource.feign.FileDownService;
|
|
import com.css.simulation.resource.feign.SchedulerService;
|
|
import com.css.simulation.resource.feign.SchedulerService;
|
|
import com.css.simulation.resource.system.service.DictService;
|
|
import com.css.simulation.resource.system.service.DictService;
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
import feign.Response;
|
|
import feign.Response;
|
|
import org.eclipse.jgit.lib.Ref;
|
|
import org.eclipse.jgit.lib.Ref;
|
|
@@ -59,44 +61,53 @@ public class AlgorithmServiceImpl implements AlgorithmService {
|
|
if(algorithmPOS != null && algorithmPOS.size() > 0){
|
|
if(algorithmPOS != null && algorithmPOS.size() > 0){
|
|
return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"该算法名称已存在!");
|
|
return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"该算法名称已存在!");
|
|
}else {
|
|
}else {
|
|
- String minioPath = param.getMinioPath();
|
|
|
|
- ResponseBodyVO<String> checkRes = schedulerService.check(minioPath);
|
|
|
|
- if(checkRes.isStatus()){
|
|
|
|
- if(isEmpty(param.getId())){
|
|
|
|
- //添加
|
|
|
|
- String algorithmId = StringUtil.getRandomUUID();
|
|
|
|
- param.setId(algorithmId);
|
|
|
|
- String algorithmCode = StringUtil.getRandomCode();
|
|
|
|
- param.setAlgorithmCode(algorithmCode);
|
|
|
|
- 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,"添加失败");
|
|
|
|
- }
|
|
|
|
|
|
+ String uploadMode = param.getUploadMode();
|
|
|
|
+ if(DictConstants.FILE.equals(uploadMode)){
|
|
|
|
+ String minioPath = param.getMinioPath();
|
|
|
|
+ ResponseBodyVO<String> checkRes = schedulerService.check(minioPath);
|
|
|
|
+ if(checkRes.isStatus()){
|
|
|
|
+ return doAddOrUpdate(param);
|
|
}else {
|
|
}else {
|
|
- //编辑
|
|
|
|
- AlgorithmPO po = setPo(param, true);
|
|
|
|
- int add = algorithmMapper.update(po);
|
|
|
|
- if (add > 0) {
|
|
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
|
|
|
|
|
|
+ MinioParameter minioParameter = new MinioParameter();
|
|
|
|
+ minioParameter.setObjectName(minioPath);
|
|
|
|
+ Response remove =fileDownService.remove(minioParameter);
|
|
|
|
+ if(remove.status() == 200){
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"该算法经校验不可用,无法保存,算法文件已删除!");
|
|
}else {
|
|
}else {
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "编辑失败");
|
|
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"该算法经校验不可用,无法保存,算法文件删除失败!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}else {
|
|
}else {
|
|
- MinioParameter minioParameter = new MinioParameter();
|
|
|
|
- minioParameter.setObjectName(minioPath);
|
|
|
|
- Response remove =fileDownService.remove(minioParameter);
|
|
|
|
- if(remove.status() == 200){
|
|
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"该算法经校验不可用,无法保存,算法文件已删除!");
|
|
|
|
- }else {
|
|
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"该算法经校验不可用,无法保存,算法文件删除失败!");
|
|
|
|
- }
|
|
|
|
|
|
+ return doAddOrUpdate(param);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ private ResponseBodyVO doAddOrUpdate(AlgorithmParameter param) {
|
|
|
|
+ if(isEmpty(param.getId())){
|
|
|
|
+ //添加
|
|
|
|
+ String algorithmId = StringUtil.getRandomUUID();
|
|
|
|
+ param.setId(algorithmId);
|
|
|
|
+ String algorithmCode = StringUtil.getRandomCode();
|
|
|
|
+ param.setAlgorithmCode(algorithmCode);
|
|
|
|
+ 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 {
|
|
|
|
+ //编辑
|
|
|
|
+ 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
|
|
@Override
|
|
@@ -179,7 +190,8 @@ public class AlgorithmServiceImpl implements AlgorithmService {
|
|
if(isEmpty(param.getId())){
|
|
if(isEmpty(param.getId())){
|
|
return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
}else {
|
|
}else {
|
|
- AlgorithmPO po = algorithmMapper.selectDetailsById(param);
|
|
|
|
|
|
+ String algorithmId = param.getId();
|
|
|
|
+ AlgorithmPO po = algorithmMapper.selectDetailsById(algorithmId);
|
|
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.SERVER_FAILURE,"该算法名称已存在, 无法分享!");
|
|
return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"该算法名称已存在, 无法分享!");
|
|
@@ -208,31 +220,34 @@ public class AlgorithmServiceImpl implements AlgorithmService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public ResponseBodyVO getGitVersion(AlgorithmParameter param) throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
|
|
|
-
|
|
|
|
- AlgorithmPO po = algorithmMapper.selectDetailsById(param);
|
|
|
|
|
|
+ public String getGitVersion(String algorithmId) {
|
|
|
|
+ AlgorithmPO po = algorithmMapper.selectDetailsById(algorithmId);
|
|
String gitUrl = po.getGitUrl();
|
|
String gitUrl = po.getGitUrl();
|
|
if(StringUtil.isEmpty(gitUrl)){
|
|
if(StringUtil.isEmpty(gitUrl)){
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
|
|
|
|
+ return "";
|
|
}
|
|
}
|
|
//拼接get请求地址
|
|
//拼接get请求地址
|
|
String prefix = "https://api.github.com/repos/";
|
|
String prefix = "https://api.github.com/repos/";
|
|
String suffix = "/commits?page=1&per_page=1";
|
|
String suffix = "/commits?page=1&per_page=1";
|
|
String gitInfo = gitUrl.substring(19, gitUrl.length()-4);
|
|
String gitInfo = gitUrl.substring(19, gitUrl.length()-4);
|
|
String requestUrl = prefix + gitInfo + suffix;
|
|
String requestUrl = prefix + gitInfo + suffix;
|
|
- String result = HttpUtil.get(HttpUtil.getHttpClient(), HttpUtil.getRequestConfig(), requestUrl);
|
|
|
|
- List<HashMap> hashMaps = JsonUtil.jsonToList(result, HashMap.class);
|
|
|
|
- String sha = "";
|
|
|
|
- if(hashMaps.size() > 0){
|
|
|
|
- HashMap hashMap = hashMaps.get(0);
|
|
|
|
- sha = hashMap.get("sha").toString();
|
|
|
|
|
|
+ try {
|
|
|
|
+ String result = HttpUtil.get(HttpUtil.getHttpClient(), HttpUtil.getRequestConfig(), requestUrl);
|
|
|
|
+ List<HashMap> hashMaps = JsonUtil.jsonToList(result, HashMap.class);
|
|
|
|
+ if(hashMaps.size() > 0){
|
|
|
|
+ HashMap hashMap = hashMaps.get(0);
|
|
|
|
+ String version = hashMap.get("sha").toString();
|
|
|
|
+ return version;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,"请求成功", sha);
|
|
|
|
|
|
+ return StringUtil.getRandomCode();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public ResponseBodyVO isAlgorithmRunning(AlgorithmParameter param)
|
|
|
|
- {
|
|
|
|
|
|
+ public ResponseBodyVO deleteByid(AlgorithmParameter param) {
|
|
if(isEmpty(param.getId())){
|
|
if(isEmpty(param.getId())){
|
|
return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
}else {
|
|
}else {
|
|
@@ -245,34 +260,24 @@ public class AlgorithmServiceImpl implements AlgorithmService {
|
|
stringBuffer.append(projectId+",");
|
|
stringBuffer.append(projectId+",");
|
|
}
|
|
}
|
|
String substring = stringBuffer.substring(0, stringBuffer.lastIndexOf(","));
|
|
String substring = stringBuffer.substring(0, stringBuffer.lastIndexOf(","));
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,"已被工作ID:"+ substring +" 应用,无法删除");
|
|
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"已被工作ID:"+ substring +" 应用,无法删除!");
|
|
}else {
|
|
}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);
|
|
|
|
|
|
+ int i = algorithmMapper.deleteByid(param);
|
|
|
|
+ if(i > 0){
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"删除失败");
|
|
}
|
|
}
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"删除失败");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public ResponseBodyVO selectDetailsById(AlgorithmParameter param) {
|
|
|
|
- if(isEmpty(param.getId())){
|
|
|
|
|
|
+ public ResponseBodyVO selectDetailsById(String algorithmId) {
|
|
|
|
+ if(isEmpty(algorithmId)){
|
|
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(algorithmId);
|
|
po.setValidationStatus(getDictName(DictConstants.VALIDATION_STATUS, po.getValidationStatus()));
|
|
po.setValidationStatus(getDictName(DictConstants.VALIDATION_STATUS, po.getValidationStatus()));
|
|
return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,po);
|
|
return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,po);
|
|
}
|
|
}
|
|
@@ -296,7 +301,7 @@ public class AlgorithmServiceImpl implements AlgorithmService {
|
|
|
|
|
|
AlgorithmPO po = new AlgorithmPO();
|
|
AlgorithmPO po = new AlgorithmPO();
|
|
//设置po信息
|
|
//设置po信息
|
|
- if("2".equals(param.getUploadMode())){ //使用仓库地址上传
|
|
|
|
|
|
+ if(DictConstants.GIT.equals(param.getUploadMode())){ //使用仓库地址上传
|
|
String gitUrl = param.getGitUrl();
|
|
String gitUrl = param.getGitUrl();
|
|
String gitUserName = param.getGitUserName();
|
|
String gitUserName = param.getGitUserName();
|
|
String gitPassword = param.getGitPassword();
|
|
String gitPassword = param.getGitPassword();
|
|
@@ -315,18 +320,13 @@ public class AlgorithmServiceImpl implements AlgorithmService {
|
|
po.setDescription(param.getDescription());
|
|
po.setDescription(param.getDescription());
|
|
po.setUploadMode(param.getUploadMode());
|
|
po.setUploadMode(param.getUploadMode());
|
|
po.setValidationStatus(DictConstants.SUCCESS);
|
|
po.setValidationStatus(DictConstants.SUCCESS);
|
|
- po.setShare("0");
|
|
|
|
|
|
+ po.setShare(DictConstants.NO);
|
|
po.setId(param.getId());
|
|
po.setId(param.getId());
|
|
|
|
|
|
if(isEdit){
|
|
if(isEdit){
|
|
- po.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
|
- po.setModifyUserId(AuthUtil.getCurrentUserId());
|
|
|
|
|
|
+ PoUtil.initUpdatePo(po);
|
|
}else {
|
|
}else {
|
|
- po.setIsDeleted("0");
|
|
|
|
- po.setCreateTime(TimeUtil.getNowForMysql());
|
|
|
|
- po.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
|
- po.setCreateUserId(AuthUtil.getCurrentUserId());
|
|
|
|
- po.setModifyUserId(AuthUtil.getCurrentUserId());
|
|
|
|
|
|
+ PoUtil.initAddPo(po);
|
|
}
|
|
}
|
|
return po;
|
|
return po;
|
|
|
|
|