Browse Source

模型数据集发布个人转公共数据

dev-opt-cp
ddmte32 7 months ago
parent
commit
49dcb6032c
9 changed files with 102 additions and 15 deletions
  1. +8
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java
  2. +8
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/NewModelFromGitController.java
  3. +2
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/GitService.java
  4. +2
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ModelsService.java
  5. +2
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/NewDatasetService.java
  6. +13
    -8
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ApprovalServiceImpl.java
  7. +8
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/GitServiceImpl.java
  8. +30
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java
  9. +29
    -6
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java

+ 8
- 1
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java View File

@@ -214,6 +214,13 @@ public class NewDatasetFromGitController {
@ApiOperation(value = "发布")
public AjaxResult publish(@RequestBody NewDatasetVo datasetVo) throws Exception {
LoginUser loginUser = SecurityUtils.getLoginUser();
return AjaxResult.success(this.newDatasetService.publish(datasetVo,loginUser));
return AjaxResult.success(newDatasetService.publish(datasetVo,loginUser));
}

@PostMapping("/privateToPublic")
@ApiOperation(value = "私有库变共有库")
public AjaxResult privateToPublic(@RequestBody NewDatasetVo datasetVo) throws Exception {
newDatasetService.privateToPublic(datasetVo);
return AjaxResult.success();
}
}

+ 8
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/NewModelFromGitController.java View File

@@ -8,6 +8,7 @@ import com.ruoyi.platform.annotations.NeedApproval;
import com.ruoyi.platform.domain.ModelsVersion;
import com.ruoyi.platform.service.ModelsService;
import com.ruoyi.platform.vo.ModelsVo;
import com.ruoyi.platform.vo.NewDatasetVo;
import com.ruoyi.platform.vo.QueryModelMetricsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -174,4 +175,11 @@ public class NewModelFromGitController extends BaseController {
public AjaxResult unpraise(@PathVariable("id") Integer id) throws Exception {
return AjaxResult.success(this.modelsService.unpraise(id));
}

@PostMapping("/privateToPublic")
@ApiOperation(value = "私有库变共有库")
public AjaxResult privateToPublic(@RequestBody ModelsVo modelsVo) throws Exception {
modelsService.privateToPublic(modelsVo);
return AjaxResult.success();
}
}

+ 2
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/GitService.java View File

@@ -29,6 +29,8 @@ public interface GitService {

Map getProjectDetail(String owner, String identifier, String token) throws Exception;

void updateProjectDetail(Map<String,Object> body,String owner, String identifier,String token) throws Exception;

void createUser(SysUser sysUser) throws Exception;

void resetPwd(SysUser sysUser) throws Exception;


+ 2
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ModelsService.java View File

@@ -126,4 +126,6 @@ public interface ModelsService {
List<ModelsVo> convert(List<Map<String, Object>> lst, String modelTopic, String modelTagName, String modelTypeName);

String getNextVersion(ModelsVersion modelsVersion) throws Exception;

void privateToPublic(ModelsVo modelsVo) throws Exception;
}

+ 2
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/NewDatasetService.java View File

@@ -52,4 +52,6 @@ public interface NewDatasetService {
String getNextVersion(NewDatasetVo datasetVo) throws Exception;

String publish(NewDatasetVo datasetVo, LoginUser loginUser) throws Exception;

void privateToPublic(NewDatasetVo newDatasetVo) throws Exception;
}

+ 13
- 8
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ApprovalServiceImpl.java View File

@@ -9,6 +9,7 @@ import com.ruoyi.platform.mapper.ApprovalInfoMapper;
import com.ruoyi.platform.service.ApprovalService;
import com.ruoyi.platform.service.ModelsService;
import com.ruoyi.platform.service.NewDatasetService;
import com.ruoyi.platform.vo.ModelsVo;
import com.ruoyi.platform.vo.NewDatasetVo;
import com.ruoyi.system.api.RemoteInfoPublishService;
import com.ruoyi.system.api.domain.NewSysNotificationParamsVo;
@@ -24,11 +25,11 @@ import java.util.List;
public class ApprovalServiceImpl implements ApprovalService {
private static final Logger logger = LoggerFactory.getLogger(ApprovalServiceImpl.class);

// @Resource
// private NewDatasetService newDatasetService;
//
// @Resource
// private ModelsService modelsService;
@Resource
private NewDatasetService newDatasetService;
@Resource
private ModelsService modelsService;

@Resource
private ApprovalInfoMapper approvalInfoMapper;
@@ -154,14 +155,18 @@ public class ApprovalServiceImpl implements ApprovalService {
case "DATASET":
NewDatasetVo dataset = BeanUtil.toBean(content, NewDatasetVo.class);
try {
// newDatasetService.updateVersionDesc(dataset);
newDatasetService.privateToPublic(dataset);
} catch (Exception e) {
logger.error(e.getMessage());
}
break;
case "MODEL":
Models models = BeanUtil.toBean(content, Models.class);
// modelsService.update(models);
ModelsVo models = BeanUtil.toBean(content, ModelsVo.class);
try {
modelsService.privateToPublic(models);
} catch (Exception e) {
logger.error(e.getMessage());
}
break;
}
}


+ 8
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/GitServiceImpl.java View File

@@ -183,6 +183,14 @@ public class GitServiceImpl implements GitService {
return runResMap;
}

@Override
public void updateProjectDetail(Map<String,Object> body,String owner, String identifier,String token) throws Exception {
String userReq = httpUtils.sendPatchWithToken(gitendpoint + "/api/" + owner + "/" + identifier + "/detail.json", null, token, JsonUtils.mapToJson(body));
if (StringUtils.isEmpty(userReq)) {
throw new RuntimeException();
}
}

@Override
public void createUser(SysUser sysUser) throws Exception {
String token = checkoutToken();


+ 30
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java View File

@@ -1355,6 +1355,36 @@ public class ModelsServiceImpl implements ModelsService {
return incrementVersion(versionList);
}

@Override
public void privateToPublic(ModelsVo modelsVo) throws Exception {
//获取版本列表信息,每一个版本的配置文件都要更改
String token = gitService.checkoutToken();
List<Map<String, Object>> brancheList = gitService.getBrancheList(token, modelsVo.getOwner(), modelsVo.getIdentifier());
for (Map<String, Object> branch : brancheList) {
if (branch.get("name").equals("master")) {
continue;
}
//获取每个版本的配置信息
Map<String, Object> branchConfig = YamlUtils.loadYamlFile(localPath + modelsVo.getOwner() + "/model/" + modelsVo.getId() + "/" + modelsVo.getIdentifier() + "/" + branch.get("name") + "/metadata/metadata.yaml");
branchConfig.put("is_public", "true");

//更新每个版本的配置信息
LoginUser loginUser = SecurityUtils.getLoginUser();
String ci4sUsername = loginUser.getUsername();
String repositoryName = modelsVo.getIdentifier();
String branchName = modelsVo.getVersion();
String relatePath = ci4sUsername + "/model/" + modelsVo.getId() + "/" + repositoryName + "/" + branchName;
String rootPath = localPath + relatePath;
String metaPath = rootPath + "/metadata";
YamlUtils.generateYamlFile(JsonUtils.objectToMap(branchConfig), metaPath, "metadata");
}
Map projectDetail = gitService.getProjectDetail(modelsVo.getOwner(), modelsVo.getIdentifier(), token);
Map<String, Object> param = new HashMap<>();
param.put("id", projectDetail.get("project_id"));
param.put("is_public", true);
gitService.updateProjectDetail(param,modelsVo.getOwner(),modelsVo.getIdentifier(),token);
}

/**
* 从Map列表中提取"v+数字"格式的版本号并升级
*


+ 29
- 6
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java View File

@@ -1,11 +1,6 @@
package com.ruoyi.platform.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
@@ -31,7 +26,6 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@@ -754,6 +748,35 @@ public class NewDatasetServiceImpl implements NewDatasetService {
return "发布成功";
}

@Override
public void privateToPublic(NewDatasetVo newDatasetVo) throws Exception {
//获取版本列表信息,每一个版本的配置文件都要更改
String token = gitService.checkoutToken();
List<Map<String, Object>> brancheList = gitService.getBrancheList(token, newDatasetVo.getOwner(), newDatasetVo.getIdentifier());
for (Map<String, Object> branch : brancheList) {
if (branch.get("name").equals("master")) {
continue;
}
//获取每个版本的配置信息
Map<String, Object> branchConfig = YamlUtils.loadYamlFile(localPathlocal + newDatasetVo.getOwner() + "/datasets/" + newDatasetVo.getId() + "/" + newDatasetVo.getIdentifier() + "/" + branch.get("name") + "/dataset.yaml");
branchConfig.put("is_public", "true");

//更新每个版本的配置信息
LoginUser loginUser = SecurityUtils.getLoginUser();
String ci4sUsername = loginUser.getUsername();
String repositoryName = newDatasetVo.getIdentifier();
String branchName = newDatasetVo.getVersion();
String relatePath = ci4sUsername + "/datasets/" + newDatasetVo.getId() + "/" + repositoryName + "/" + branchName;
String localPath = localPathlocal + relatePath;
YamlUtils.generateYamlFile(JsonUtils.objectToMap(branchConfig), localPath, "dataset");
}
Map projectDetail = gitService.getProjectDetail(newDatasetVo.getOwner(), newDatasetVo.getIdentifier(), token);
Map<String, Object> param = new HashMap<>();
param.put("id", projectDetail.get("project_id"));
param.put("is_public", true);
gitService.updateProjectDetail(param,newDatasetVo.getOwner(),newDatasetVo.getIdentifier(),token);
}

/**
* 从Map列表中提取"v+数字"格式的版本号并升级
*


Loading…
Cancel
Save