| @@ -61,6 +61,7 @@ public class DatasetVersionController { | |||
| * @return 匹配的数据集版本记录列表 | |||
| */ | |||
| @GetMapping("/versions") | |||
| @ApiOperation("通过数据集id和version查询版本列表") | |||
| public AjaxResult queryByDatasetIdAndVersion(@RequestParam("dataset_id") Integer datasetId, | |||
| @RequestParam("version") String version) { | |||
| return AjaxResult.success(this.datasetVersionService.queryByDatasetIdAndVersion(datasetId, version)); | |||
| @@ -4,6 +4,8 @@ import com.ruoyi.common.core.web.domain.AjaxResult; | |||
| import com.ruoyi.platform.domain.Image; | |||
| import com.ruoyi.platform.domain.Models; | |||
| import com.ruoyi.platform.service.ImageService; | |||
| import com.ruoyi.platform.vo.DatasetVo; | |||
| import com.ruoyi.platform.vo.ImageVo; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.springframework.data.domain.Page; | |||
| @@ -79,6 +81,19 @@ public class ImageController { | |||
| return AjaxResult.success(this.imageService.insert(image)); | |||
| } | |||
| /** | |||
| * 新增镜像和版本 | |||
| * | |||
| * @param datasetVo 实体 | |||
| * @return 新增结果 | |||
| */ | |||
| @PostMapping("/addImageAndVersion") | |||
| @ApiOperation("添加镜像和版本") | |||
| public AjaxResult addImageAndVersion(@RequestBody ImageVo imageVo) throws Exception { | |||
| return AjaxResult.success(this.imageService.insertImageAndVersion(imageVo)); | |||
| } | |||
| /** | |||
| * 编辑数据 | |||
| * | |||
| @@ -168,9 +168,19 @@ public class ModelsController { | |||
| public ResponseEntity<InputStreamResource> downloadAllModelFiles(@RequestParam("models_id") Integer modelsId, @RequestParam("version") String version) { | |||
| return modelsService.downloadAllModelFiles(modelsId, version); | |||
| } | |||
| @GetMapping("/readme") | |||
| @ApiOperation(value = "读取README文件", notes = "读取README文件并返回String类型。") | |||
| public AjaxResult readFileContent(@RequestParam("models_id") Integer modelsId, @RequestParam("version") String version) throws Exception { | |||
| return AjaxResult.success(this.modelsService.readFileContent(modelsId,version)); | |||
| } | |||
| } | |||
| @@ -2,6 +2,7 @@ package com.ruoyi.platform.service; | |||
| import com.ruoyi.platform.domain.Image; | |||
| import com.ruoyi.platform.domain.Workflow; | |||
| import com.ruoyi.platform.vo.ImageVo; | |||
| import org.springframework.data.domain.Page; | |||
| import org.springframework.data.domain.PageRequest; | |||
| @@ -61,4 +62,6 @@ public interface ImageService { | |||
| String removeById(Integer id); | |||
| Page<Image> queryByName(String name); | |||
| String insertImageAndVersion(ImageVo imageVo) throws Exception; | |||
| } | |||
| @@ -77,4 +77,6 @@ public interface ModelsService { | |||
| Map getModelVersions(Integer modelId) throws Exception; | |||
| String insertModelAndVersion(ModelsVo modelsVo) throws Exception; | |||
| String readFileContent(Integer modelsId, String version) throws Exception; | |||
| } | |||
| @@ -1,14 +1,12 @@ | |||
| package com.ruoyi.platform.service.impl; | |||
| import com.ruoyi.common.security.utils.SecurityUtils; | |||
| import com.ruoyi.platform.domain.Image; | |||
| import com.ruoyi.platform.domain.ImageVersion; | |||
| import com.ruoyi.platform.domain.Models; | |||
| import com.ruoyi.platform.domain.Workflow; | |||
| import com.ruoyi.platform.domain.*; | |||
| import com.ruoyi.platform.mapper.ImageDao; | |||
| import com.ruoyi.platform.mapper.ImageVersionDao; | |||
| import com.ruoyi.platform.service.ImageService; | |||
| import com.ruoyi.platform.service.ImageVersionService; | |||
| import com.ruoyi.platform.vo.ImageVo; | |||
| import com.ruoyi.system.api.model.LoginUser; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.stereotype.Service; | |||
| @@ -142,4 +140,29 @@ public class ImageServiceImpl implements ImageService { | |||
| public Page<Image> queryByName(String name) { | |||
| return new PageImpl<>(this.imageDao.queryByName(name)); | |||
| } | |||
| @Override | |||
| public String insertImageAndVersion(ImageVo imageVo) throws Exception { | |||
| Image image = new Image(); | |||
| image.setName(imageVo.getName()); | |||
| image.setDescription(imageVo.getDescription()); | |||
| image.setImageType(imageVo.getImageType()); | |||
| Image imageInsert = this.insert(image); | |||
| if (imageInsert == null){ | |||
| throw new Exception("新增镜像失败"); | |||
| } | |||
| ImageVersion imageVersion = new ImageVersion(); | |||
| imageVersion.setImageId(imageInsert.getId()); | |||
| imageVersion.setVersion(imageVo.getVersion()); | |||
| imageVersion.setUrl(imageVo.getUrl()); | |||
| imageVersion.setTagName(imageVo.getTagName()); | |||
| //imageVersion.setFileSize(datasetVo.getFileSize()); | |||
| ImageVersion imageVersionInsert = this.imageVersionService.insert(imageVersion); | |||
| if (imageVersionInsert == null) { | |||
| throw new Exception("新增镜像失败"); | |||
| } | |||
| return "新增镜像成功"; | |||
| } | |||
| } | |||
| @@ -392,6 +392,49 @@ public class ModelsServiceImpl implements ModelsService { | |||
| } | |||
| /** | |||
| * 根据模型id和版本读取文件内容 | |||
| * | |||
| * @param modelsId 模型ID | |||
| * @param version 模型版本号 | |||
| * @return 文件内容 | |||
| */ | |||
| @Override | |||
| public String readFileContent(Integer modelsId, String version) throws Exception { | |||
| // 根据模型id查模型名 | |||
| Models model = this.modelsDao.queryById(modelsId); | |||
| if (model == null) { | |||
| throw new Exception("模型不存在"); | |||
| } | |||
| String modelName = model.getName(); | |||
| String objectName = ""; | |||
| // 查询特定模型和版本对应的所有文件 | |||
| List<ModelsVersion> modelsVersionList = this.modelsVersionDao.queryAllByModelsVersion(modelsId, version); | |||
| if (modelsVersionList == null || modelsVersionList.isEmpty()) { | |||
| throw new Exception("对应模型版本不存在"); | |||
| } | |||
| //遍历文件列表 | |||
| for(ModelsVersion modelsVersion : modelsVersionList){ | |||
| String fileName = modelsVersion.getFileName(); | |||
| if("readme.md".equalsIgnoreCase(fileName)){ | |||
| //如果存在readme文件,读取minio中的url | |||
| objectName = modelsVersion.getUrl(); | |||
| // 读取MinIO中的对象为字符串 | |||
| try { | |||
| return minioUtil.readObjectAsString(bucketName, objectName); | |||
| } catch (Exception e) { | |||
| throw new Exception("读取README.md文件失败", e); | |||
| } | |||
| } | |||
| } | |||
| // 如果没有找到README.md文件,返回null或者抛出一个异常 | |||
| throw new Exception("未找到README.md文件"); | |||
| } | |||
| private String extractFileName(String urlStr) { | |||
| return urlStr.substring(urlStr.lastIndexOf('/') + 1); | |||
| } | |||
| @@ -0,0 +1,132 @@ | |||
| package com.ruoyi.platform.vo; | |||
| import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | |||
| import io.swagger.annotations.ApiModelProperty; | |||
| import java.io.Serializable; | |||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | |||
| public class ImageVo implements Serializable { | |||
| /** | |||
| * 主键 | |||
| */ | |||
| private Integer id; | |||
| /** | |||
| * 镜像名称 | |||
| */ | |||
| @ApiModelProperty(name = "name") | |||
| private String name; | |||
| /** | |||
| * 镜像描述 | |||
| */ | |||
| @ApiModelProperty(name = "description") | |||
| private String description; | |||
| /** | |||
| * 镜像类型 | |||
| */ | |||
| @ApiModelProperty(name = "image_type") | |||
| private Integer imageType; | |||
| /** | |||
| * 镜像版本 | |||
| */ | |||
| @ApiModelProperty(name = "version") | |||
| private String version; | |||
| /** | |||
| * 镜像推送地址 | |||
| */ | |||
| @ApiModelProperty(name = "url") | |||
| private String url; | |||
| /** | |||
| * 镜像tag名称 | |||
| */ | |||
| @ApiModelProperty(name = "tag_name") | |||
| private String tagName; | |||
| /** | |||
| * 镜像文件大小 | |||
| */ | |||
| @ApiModelProperty(name = "file_size") | |||
| private String fileSize; | |||
| /** | |||
| * 镜像构建状态 | |||
| */ | |||
| @ApiModelProperty(name = "status") | |||
| private String status; | |||
| public Integer getId() { | |||
| return id; | |||
| } | |||
| public void setId(Integer id) { | |||
| this.id = id; | |||
| } | |||
| public String getName() { | |||
| return name; | |||
| } | |||
| public void setName(String name) { | |||
| this.name = name; | |||
| } | |||
| public String getDescription() { | |||
| return description; | |||
| } | |||
| public void setDescription(String description) { | |||
| this.description = description; | |||
| } | |||
| public Integer getImageType() { | |||
| return imageType; | |||
| } | |||
| public void setImageType(Integer imageType) { | |||
| this.imageType = imageType; | |||
| } | |||
| public String getVersion() { | |||
| return version; | |||
| } | |||
| public void setVersion(String version) { | |||
| this.version = version; | |||
| } | |||
| public String getUrl() { | |||
| return url; | |||
| } | |||
| public void setUrl(String url) { | |||
| this.url = url; | |||
| } | |||
| public String getTagName() { | |||
| return tagName; | |||
| } | |||
| public void setTagName(String tagName) { | |||
| this.tagName = tagName; | |||
| } | |||
| public String getFileSize() { | |||
| return fileSize; | |||
| } | |||
| public void setFileSize(String fileSize) { | |||
| this.fileSize = fileSize; | |||
| } | |||
| public String getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(String status) { | |||
| this.status = status; | |||
| } | |||
| } | |||
| @@ -27,6 +27,8 @@ public class ModelsVo implements Serializable { | |||
| // private String url; | |||
| @ApiModelProperty(name = "model_type") | |||
| private Integer modelType; | |||
| @ApiModelProperty(name = "model_tag") | |||
| private Integer modelTag; | |||
| /** | |||