| @@ -52,13 +52,13 @@ public class DatasetController { | |||
| @ApiOperation("数据集广场公开数据集分页查询,根据data_type筛选,1公开0私有") | |||
| public AjaxResult queryByPage(Dataset dataset, @RequestParam("page") int page, | |||
| @RequestParam("size") int size, | |||
| //@RequestParam("available_range") int availableRange , | |||
| @RequestParam(value = "available_range") int availableRange , | |||
| @RequestParam(value = "data_type", required = false) String dataType) { | |||
| if (dataType != null) { // 仅当dataType有值时设置 | |||
| dataset.setDataType(dataType); | |||
| } | |||
| dataset.setAvailableRange(1); | |||
| dataset.setAvailableRange(availableRange); | |||
| PageRequest pageRequest = PageRequest.of(page, size); | |||
| return AjaxResult.success(this.datasetService.queryByPage(dataset, pageRequest)); | |||
| } | |||
| @@ -182,16 +182,15 @@ public class DatasetController { | |||
| /** | |||
| * 上传数据集 | |||
| * | |||
| // * @param datasetId 数据集ID | |||
| * @param files 上传的数据集文件 | |||
| * | |||
| * @param uuid 上传唯一标识,构建url | |||
| * @return 上传结果 | |||
| */ | |||
| @CrossOrigin(origins = "*", allowedHeaders = "*") | |||
| @PostMapping("/upload") | |||
| @ApiOperation(value = "上传数据集", notes = "根据数据集版本表id上传数据集文件,并将信息存入数据库。") | |||
| public AjaxResult uploadDataset(@RequestParam("file") MultipartFile[] files) throws Exception { | |||
| return AjaxResult.success(this.datasetService.uploadDataset(files)); | |||
| public AjaxResult uploadDataset(@RequestParam("file") MultipartFile[] files, @RequestParam("uuid") String uuid) throws Exception { | |||
| return AjaxResult.success(this.datasetService.uploadDataset(files,uuid)); | |||
| } | |||
| @@ -176,8 +176,8 @@ public class ModelsController extends BaseController { | |||
| @CrossOrigin(origins = "*", allowedHeaders = "*") | |||
| @PostMapping("/upload") | |||
| @ApiOperation(value = "上传模型", notes = "根据模型id上传模型文件,并将信息存入数据库。") | |||
| public GenericsAjaxResult<List<Map<String, String>>> uploadModels(@RequestParam("file") MultipartFile[] files) throws Exception { | |||
| return genericsSuccess(this.modelsService.uploadModels(files)); | |||
| public GenericsAjaxResult<List<Map<String, String>>> uploadModels(@RequestParam("file") MultipartFile[] files , @RequestParam("uuid") String uuid) throws Exception { | |||
| return genericsSuccess(this.modelsService.uploadModels(files,uuid)); | |||
| } | |||
| @@ -72,7 +72,7 @@ DatasetService { | |||
| ResponseEntity<InputStreamResource> downloadDataset(Integer id) throws Exception; | |||
| List<Map<String, String>> uploadDataset(MultipartFile[] files) throws Exception; | |||
| List<Map<String, String>> uploadDataset(MultipartFile[] files, String uuid) throws Exception; | |||
| Map uploadDatasetPipeline(DatasetVersion datasetVersion) throws Exception; | |||
| @@ -70,7 +70,7 @@ public interface ModelsService { | |||
| List<Map<String, String>> uploadModels(MultipartFile[] files) throws Exception; | |||
| List<Map<String, String>> uploadModels(MultipartFile[] files, String uuid) throws Exception; | |||
| Map uploadModelsPipeline(ModelsVersion modelsVersion) throws Exception; | |||
| @@ -12,7 +12,7 @@ import com.ruoyi.platform.service.DatasetVersionService; | |||
| import com.ruoyi.platform.utils.BeansUtils; | |||
| import com.ruoyi.platform.utils.FileUtil; | |||
| import com.ruoyi.platform.utils.MinioUtil; | |||
| import com.ruoyi.platform.vo.DatasetVersionVo; | |||
| import com.ruoyi.platform.vo.VersionVo; | |||
| import com.ruoyi.platform.vo.DatasetVo; | |||
| import com.ruoyi.system.api.model.LoginUser; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| @@ -203,16 +203,16 @@ public class DatasetServiceImpl implements DatasetService { | |||
| /** | |||
| * 上传数据集 | |||
| * | |||
| * @param files 文件 | |||
| * @param files 文件 | |||
| * @param uuid | |||
| * @return 是否成功 | |||
| */ | |||
| @Override | |||
| public List<Map<String, String>> uploadDataset(MultipartFile[] files) throws Exception { | |||
| public List<Map<String, String>> uploadDataset(MultipartFile[] files, String uuid) throws Exception { | |||
| List<Map<String, String>> results = new ArrayList<>(); | |||
| //时间戳统一定在外面,一次上传就定好 | |||
| Date createTime = new Date(); | |||
| String timestamp = new SimpleDateFormat("yyyyMMdd-HHmmss").format(createTime); | |||
| // //时间戳统一定在外面,一次上传就定好 | |||
| // Date createTime = new Date(); | |||
| // String timestamp = new SimpleDateFormat("yyyyMMdd-HHmmss").format(createTime); | |||
| for (MultipartFile file:files){ | |||
| if (file.isEmpty()) { | |||
| @@ -225,20 +225,12 @@ public class DatasetServiceImpl implements DatasetService { | |||
| // 其余操作基于 modelsVersionToUse | |||
| String username = SecurityUtils.getLoginUser().getUsername(); | |||
| String fileName = file.getOriginalFilename(); | |||
| String objectName = "datasets/" + username + "/" + timestamp + "/" + fileName; | |||
| String objectName = "datasets/" + username + "/" + uuid + "/" + fileName; | |||
| // 上传文件到MinIO并将记录新增到数据库中 | |||
| try (InputStream inputStream = file.getInputStream()) { | |||
| minioUtil.uploadObject(bucketName, objectName, inputStream); | |||
| // DatasetVersion datasetVersion = new DatasetVersion(); | |||
| // datasetVersion.setDatasetId(id); | |||
| // datasetVersion.setVersion(version); | |||
| // datasetVersion.setUrl(objectName); | |||
| // datasetVersion.setFileName(fileName); | |||
| // datasetVersion.setFileSize(formattedSize); | |||
| // | |||
| // //返回插入结果 | |||
| // DatasetVersion insertedDatasetversion = datasetVersionService.insert(datasetVersion); | |||
| Map<String, String> fileResult = new HashMap<>(); | |||
| fileResult.put("fileName", file.getOriginalFilename()); | |||
| fileResult.put("url", objectName); // objectName根据实际情况定义 | |||
| @@ -313,8 +305,8 @@ public class DatasetServiceImpl implements DatasetService { | |||
| @Override | |||
| @Transactional | |||
| public String insertDatasetAndVersion(DatasetVo datasetVo) throws Exception { | |||
| List<DatasetVersionVo> datasetVersionVos = datasetVo.getDatasetVersionVos(); | |||
| if (datasetVersionVos==null||datasetVersionVos.size()==0){ | |||
| List<VersionVo> datasetVersionVos = datasetVo.getDatasetVersionVos(); | |||
| if (datasetVersionVos==null || datasetVersionVos.isEmpty()){ | |||
| throw new Exception("数据集版本信息错误"); | |||
| } | |||
| @@ -329,7 +321,7 @@ public class DatasetServiceImpl implements DatasetService { | |||
| throw new Exception("新增数据集失败"); | |||
| } | |||
| for (DatasetVersionVo datasetVersionVo :datasetVersionVos){ | |||
| for (VersionVo datasetVersionVo :datasetVersionVos){ | |||
| DatasetVersion datasetVersion = new DatasetVersion(); | |||
| datasetVersion.setDatasetId(datasetInsert.getId()); | |||
| datasetVersion.setVersion(datasetVo.getVersion()); | |||
| @@ -138,9 +138,10 @@ public class DatasetVersionServiceImpl implements DatasetVersionService { | |||
| Map<String, Object> response = new HashMap<>(); | |||
| List<DatasetVersion> datasetVersionList = this.datasetVersionDao.queryAllByDatasetVersion(datasetId, version); | |||
| datasetVersionList.stream(). | |||
| findFirst(). | |||
| ifPresent(datasetVersion -> { | |||
| datasetVersionList.stream() | |||
| .filter(datasetVersion -> datasetVersion.getUrl() != null && !datasetVersion.getUrl().isEmpty()) | |||
| .findFirst() | |||
| .ifPresent(datasetVersion -> { | |||
| String url = datasetVersion.getUrl(); | |||
| String path = bucketName + '/' + url.substring(0, url.lastIndexOf('/')); | |||
| response.put("path", path); | |||
| @@ -1,7 +1,6 @@ | |||
| package com.ruoyi.platform.service.impl; | |||
| import com.ruoyi.common.security.utils.SecurityUtils; | |||
| import com.ruoyi.platform.domain.DatasetVersion; | |||
| import com.ruoyi.platform.domain.Models; | |||
| import com.ruoyi.platform.domain.ModelsVersion; | |||
| import com.ruoyi.platform.mapper.ModelsDao; | |||
| @@ -12,16 +11,15 @@ import com.ruoyi.platform.utils.BeansUtils; | |||
| import com.ruoyi.platform.utils.FileUtil; | |||
| import com.ruoyi.platform.utils.MinioUtil; | |||
| import com.ruoyi.platform.vo.ModelsVo; | |||
| import com.ruoyi.platform.vo.VersionVo; | |||
| import com.ruoyi.system.api.model.LoginUser; | |||
| import io.minio.MinioClient; | |||
| import io.netty.util.Version; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.core.io.InputStreamResource; | |||
| 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.HttpStatus; | |||
| import org.springframework.http.MediaType; | |||
| import org.springframework.http.ResponseEntity; | |||
| import org.springframework.stereotype.Service; | |||
| @@ -33,7 +31,6 @@ import java.io.ByteArrayInputStream; | |||
| import java.io.ByteArrayOutputStream; | |||
| import java.io.InputStream; | |||
| import java.net.URLEncoder; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| import java.util.zip.ZipEntry; | |||
| @@ -169,6 +166,7 @@ public class ModelsServiceImpl implements ModelsService { | |||
| ModelsVersion modelsVersion = this.modelsVersionDao.queryById(id); | |||
| if (modelsVersion == null) { | |||
| throw new Exception("未找到该模型下版本记录"); | |||
| } | |||
| // 从数据库中获取存储路径(即MinIO中的对象名称) | |||
| String objectName = modelsVersion.getUrl(); | |||
| @@ -199,15 +197,16 @@ public class ModelsServiceImpl implements ModelsService { | |||
| * 上传模型 | |||
| * | |||
| * @param files 文件 | |||
| * @param uuid | |||
| * @return 是否成功 | |||
| */ | |||
| @Override | |||
| public List<Map<String, String>> uploadModels(MultipartFile[] files) throws Exception { | |||
| public List<Map<String, String>> uploadModels(MultipartFile[] files, String uuid) throws Exception { | |||
| List<Map<String, String>> results = new ArrayList<>(); | |||
| //时间戳统一定在外面,一次上传就定好 | |||
| Date createTime = new Date(); | |||
| String timestamp = new SimpleDateFormat("yyyyMMdd-HHmmss").format(createTime); | |||
| // //时间戳统一定在外面,一次上传就定好 | |||
| // Date createTime = new Date(); | |||
| // String timestamp = new SimpleDateFormat("yyyyMMdd-HHmmss").format(createTime); | |||
| for (MultipartFile file:files){ | |||
| if (file.isEmpty()) { | |||
| @@ -217,22 +216,18 @@ public class ModelsServiceImpl implements ModelsService { | |||
| long sizeInBytes = file.getSize(); | |||
| String formattedSize = FileUtil.formatFileSize(sizeInBytes); // 格式化文件大小 | |||
| // 其余操作基于 modelsVersionToUse | |||
| String username = SecurityUtils.getLoginUser().getUsername(); | |||
| String fileName = file.getOriginalFilename(); | |||
| String objectName = "models/" + username + "/" + timestamp + "/" + fileName; | |||
| String objectName = "models/" + username + "/" + uuid + "/" + fileName; | |||
| // 上传文件到MinIO并将记录新增到数据库中 | |||
| try (InputStream inputStream = file.getInputStream()) { | |||
| minioUtil.uploadObject(bucketName, objectName, inputStream); | |||
| // ModelsVersion modelsVersion = new ModelsVersion(); | |||
| // modelsVersion.setModelsId(id); | |||
| // modelsVersion.setVersion(version); | |||
| // modelsVersion.setUrl(objectName); | |||
| // modelsVersion.setFileName(fileName); | |||
| // modelsVersion.setFileSize(formattedSize); | |||
| // //返回插入结果 | |||
| // ModelsVersion insertedModelsVersion = modelsVersionService.insert(modelsVersion); | |||
| // | |||
| Map<String, String> fileResult = new HashMap<>(); | |||
| fileResult.put("fileName", file.getOriginalFilename()); | |||
| fileResult.put("url", objectName); // objectName根据实际情况定义 | |||
| @@ -361,6 +356,11 @@ public class ModelsServiceImpl implements ModelsService { | |||
| @Override | |||
| @Transactional | |||
| public String insertModelAndVersion(ModelsVo modelsVo) throws Exception { | |||
| List<VersionVo> modelsVersionVos = modelsVo.getModelsVersionVos(); | |||
| if (modelsVersionVos==null || modelsVersionVos.isEmpty()){ | |||
| throw new Exception("模型版本信息错误"); | |||
| } | |||
| Models models = new Models(); | |||
| models.setName(modelsVo.getName()); | |||
| models.setDescription(modelsVo.getDescription()); | |||
| @@ -371,16 +371,20 @@ public class ModelsServiceImpl implements ModelsService { | |||
| if (modelsInsert == null){ | |||
| throw new Exception("新增模型失败"); | |||
| } | |||
| ModelsVersion modelsVersion = new ModelsVersion(); | |||
| modelsVersion.setModelsId(modelsInsert.getId()); | |||
| modelsVersion.setVersion(modelsVo.getVersion()); | |||
| modelsVersion.setUrl(modelsVo.getUrl()); | |||
| modelsVersion.setFileName(modelsVo.getFileName()); | |||
| modelsVersion.setFileSize(modelsVo.getFileSize()); | |||
| ModelsVersion modelsVersionInsert = this.modelsVersionService.insert(modelsVersion); | |||
| if (modelsVersionInsert == null) { | |||
| throw new Exception("新增模型失败"); | |||
| //遍历版本信息列表,把文件信息插入数据库 | |||
| for(VersionVo modelsVersionVo : modelsVersionVos){ | |||
| ModelsVersion modelsVersion = new ModelsVersion(); | |||
| modelsVersion.setModelsId(modelsInsert.getId()); | |||
| modelsVersion.setVersion(modelsVo.getVersion()); | |||
| modelsVersion.setUrl(modelsVersionVo.getUrl()); | |||
| modelsVersion.setFileName(modelsVersionVo.getFileName()); | |||
| modelsVersion.setFileSize(modelsVersionVo.getFileSize()); | |||
| ModelsVersion modelsVersionInsert = this.modelsVersionService.insert(modelsVersion); | |||
| if (modelsVersionInsert == null) { | |||
| throw new Exception("新增模型版本失败"); | |||
| } | |||
| } | |||
| return "新增模型成功"; | |||
| } | |||
| @@ -166,9 +166,10 @@ public class ModelsVersionServiceImpl implements ModelsVersionService { | |||
| Map<String,Object> response = new HashMap<>(); | |||
| List<ModelsVersion> modelsVersionList = this.modelsVersionDao.queryAllByModelsVersion(modelsId, version); | |||
| modelsVersionList.stream(). | |||
| findFirst(). | |||
| ifPresent(modelsVersion -> { | |||
| modelsVersionList.stream() | |||
| .filter(modelsVersion -> modelsVersion.getUrl() != null && !modelsVersion.getUrl().isEmpty()) | |||
| .findFirst() | |||
| .ifPresent(modelsVersion -> { | |||
| String url = modelsVersion.getUrl(); | |||
| String path = bucketName + '/' + url.substring(0, url.lastIndexOf('/')); | |||
| response.put("path", path); | |||
| @@ -30,7 +30,9 @@ public class DatasetVo implements Serializable { | |||
| */ | |||
| @ApiModelProperty(name = "version") | |||
| private String version; | |||
| private List<DatasetVersionVo> datasetVersionVos; | |||
| @ApiModelProperty(name = "dataset_version_vos") | |||
| private List<VersionVo> datasetVersionVos; | |||
| /** | |||
| * 可用集群 | |||
| */ | |||
| @@ -85,11 +87,11 @@ public class DatasetVo implements Serializable { | |||
| this.version = version; | |||
| } | |||
| public List<DatasetVersionVo> getDatasetVersionVos() { | |||
| public List<VersionVo> getDatasetVersionVos() { | |||
| return datasetVersionVos; | |||
| } | |||
| public void setDatasetVersionVos(List<DatasetVersionVo> datasetVersionVos) { | |||
| public void setDatasetVersionVos(List<VersionVo> datasetVersionVos) { | |||
| this.datasetVersionVos = datasetVersionVos; | |||
| } | |||
| @@ -2,9 +2,11 @@ package com.ruoyi.platform.vo; | |||
| import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | |||
| import com.ruoyi.platform.domain.ModelsVersion; | |||
| import io.swagger.annotations.ApiModelProperty; | |||
| import java.io.Serializable; | |||
| import java.util.List; | |||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | |||
| public class ModelsVo implements Serializable { | |||
| @@ -36,27 +38,16 @@ public class ModelsVo implements Serializable { | |||
| */ | |||
| @ApiModelProperty(name = "version") | |||
| private String version; | |||
| /** | |||
| * 模型存储地址 | |||
| */ | |||
| @ApiModelProperty(name = "url") | |||
| private String url; | |||
| /** | |||
| * 文件名 | |||
| */ | |||
| @ApiModelProperty(name = "file_name") | |||
| private String fileName; | |||
| /** | |||
| * 文件大小 | |||
| */ | |||
| @ApiModelProperty(name = "file_size") | |||
| private String fileSize; | |||
| /** | |||
| * 状态 | |||
| */ | |||
| @ApiModelProperty(name = "status") | |||
| private Integer status; | |||
| @ApiModelProperty(name = "models_version_vos") | |||
| private List<VersionVo> modelsVersionVos; | |||
| public String getName() { | |||
| return name; | |||
| @@ -107,35 +98,21 @@ public class ModelsVo implements Serializable { | |||
| this.version = version; | |||
| } | |||
| public String getUrl() { | |||
| return url; | |||
| } | |||
| public void setUrl(String url) { | |||
| this.url = url; | |||
| } | |||
| public String getFileName() { | |||
| return fileName; | |||
| public Integer getStatus() { | |||
| return status; | |||
| } | |||
| public void setFileName(String fileName) { | |||
| this.fileName = fileName; | |||
| public void setStatus(Integer status) { | |||
| this.status = status; | |||
| } | |||
| public String getFileSize() { | |||
| return fileSize; | |||
| public List<VersionVo> getModelsVersionVos() { | |||
| return modelsVersionVos; | |||
| } | |||
| public void setFileSize(String fileSize) { | |||
| this.fileSize = fileSize; | |||
| public void setModelsVersionVos(List<VersionVo> modelsVersionVos) { | |||
| this.modelsVersionVos = modelsVersionVos; | |||
| } | |||
| public Integer getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(Integer status) { | |||
| this.status = status; | |||
| } | |||
| } | |||
| @@ -7,7 +7,7 @@ import io.swagger.annotations.ApiModelProperty; | |||
| import java.io.Serializable; | |||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | |||
| public class DatasetVersionVo implements Serializable { | |||
| public class VersionVo implements Serializable { | |||
| /** | |||
| * 数据集存储地址 | |||