| @@ -9,7 +9,9 @@ import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.springframework.core.io.InputStreamResource; | |||||
| import org.springframework.data.domain.PageRequest; | import org.springframework.data.domain.PageRequest; | ||||
| import org.springframework.http.ResponseEntity; | |||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import org.springframework.web.multipart.MultipartFile; | import org.springframework.web.multipart.MultipartFile; | ||||
| @@ -106,26 +108,22 @@ public class DatasetController { | |||||
| */ | */ | ||||
| @GetMapping("/download/{dataset_version_id}") | @GetMapping("/download/{dataset_version_id}") | ||||
| @ApiOperation(value = "下载数据集", notes = "根据数据集版本表id下载数据集文件") | @ApiOperation(value = "下载数据集", notes = "根据数据集版本表id下载数据集文件") | ||||
| public AjaxResult downloadDataset(@PathVariable("dataset_version_id") Integer dataset_version_id) { | |||||
| return AjaxResult.success(datasetService.downloadDataset(dataset_version_id)); | |||||
| public ResponseEntity<InputStreamResource> downloadDataset(@PathVariable("dataset_version_id") Integer dataset_version_id) { | |||||
| return datasetService.downloadDataset(dataset_version_id); | |||||
| } | } | ||||
| /** | /** | ||||
| * 上传数据集 | * 上传数据集 | ||||
| * | * | ||||
| * @param dataset_version_id ps:这里的id是dataset_version表的主键 | |||||
| * @param file 上传的数据集文件 | |||||
| * @param datasetId 数据集ID | |||||
| * @param files 上传的数据集文件 | |||||
| * @param version 版本文件 | |||||
| * @return 上传结果 | * @return 上传结果 | ||||
| */ | */ | ||||
| @PostMapping("/upload/{dataset_version_id}") | |||||
| @PostMapping("/upload") | |||||
| @ApiOperation(value = "上传数据集", notes = "根据数据集版本表id上传数据集文件,并将信息存入数据库。") | @ApiOperation(value = "上传数据集", notes = "根据数据集版本表id上传数据集文件,并将信息存入数据库。") | ||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "file", value = "要上传的数据集文件", required = true, dataType = "file", paramType = "form"), | |||||
| @ApiImplicitParam(name = "dataset_version_id", value = "数据集版本表id", required = true, dataType = "integer", paramType = "path") | |||||
| }) | |||||
| public AjaxResult uploadDataset(@RequestParam("file") MultipartFile file, | |||||
| @PathVariable("dataset_version_id") Integer dataset_version_id) throws Exception { | |||||
| return AjaxResult.success(this.datasetService.uploadDataset(file, dataset_version_id)); | |||||
| public AjaxResult uploadDataset(@RequestParam("files") MultipartFile[] files, @RequestParam("dataset_id") Integer datasetId, @RequestParam("version") String version) throws Exception { | |||||
| return AjaxResult.success(this.datasetService.uploadDataset(files,datasetId,version )); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -53,6 +53,20 @@ public class DatasetVersionController { | |||||
| return AjaxResult.success(this.datasetVersionService.queryById(id)); | return AjaxResult.success(this.datasetVersionService.queryById(id)); | ||||
| } | } | ||||
| /** | |||||
| * 通过数据集id和version查询版本列表 | |||||
| * | |||||
| * @param datasetId 数据集ID | |||||
| * @param version 数据集版本 | |||||
| * @return 匹配的数据集版本记录列表 | |||||
| */ | |||||
| @GetMapping("/versions") | |||||
| public AjaxResult queryByDatasetIdAndVersion(@RequestParam("dataset_id") Integer datasetId, | |||||
| @RequestParam("version") String version) { | |||||
| return AjaxResult.success(this.datasetVersionService.queryByDatasetIdAndVersion(datasetId, version)); | |||||
| } | |||||
| /** | /** | ||||
| * 新增数据 | * 新增数据 | ||||
| * | * | ||||
| @@ -52,6 +52,23 @@ public class ModelsVersionController { | |||||
| return AjaxResult.success(this.modelsVersionService.queryById(id)); | return AjaxResult.success(this.modelsVersionService.queryById(id)); | ||||
| } | } | ||||
| /** | |||||
| * 通过模型id和version查询版本列表 | |||||
| * | |||||
| * @param modelsId 模型ID | |||||
| * @param version 模型版本 | |||||
| * @return 匹配的模型版本记录列表 | |||||
| */ | |||||
| @GetMapping("/versions") | |||||
| public AjaxResult queryByModelsIdAndVersion(@RequestParam("models_id") Integer modelsId, | |||||
| @RequestParam("version") String version) { | |||||
| return AjaxResult.success(this.modelsVersionService.queryByModelsIdAndVersion(modelsId, version)); | |||||
| } | |||||
| /** | /** | ||||
| * 新增数据 | * 新增数据 | ||||
| * | * | ||||
| @@ -86,6 +86,9 @@ public interface DatasetVersionDao { | |||||
| DatasetVersion queryByDatasetVersion(DatasetVersion datasetVersion); | DatasetVersion queryByDatasetVersion(DatasetVersion datasetVersion); | ||||
| List<DatasetVersion> queryByDatasetIdAndVersion(@Param("datasetId") Integer datasetId, @Param("version") String version); | |||||
| } | } | ||||
| @@ -69,7 +69,7 @@ public interface DatasetService { | |||||
| ResponseEntity<InputStreamResource> downloadDataset(Integer id); | ResponseEntity<InputStreamResource> downloadDataset(Integer id); | ||||
| Map uploadDataset(MultipartFile file, Integer id) throws Exception; | |||||
| Map uploadDataset(MultipartFile[] files, Integer id, String version) throws Exception; | |||||
| Map uploadDatasetPipeline(DatasetVersion datasetVersion) throws Exception; | Map uploadDatasetPipeline(DatasetVersion datasetVersion) throws Exception; | ||||
| } | } | ||||
| @@ -65,4 +65,6 @@ public interface DatasetVersionService { | |||||
| DatasetVersion duplicateDatasetVersion(DatasetVersion oldDatasetVersion); | DatasetVersion duplicateDatasetVersion(DatasetVersion oldDatasetVersion); | ||||
| DatasetVersion queryByDatasetVersion(DatasetVersion datasetVersion); | DatasetVersion queryByDatasetVersion(DatasetVersion datasetVersion); | ||||
| List<DatasetVersion> queryByDatasetIdAndVersion(Integer datasetId, String version); | |||||
| } | } | ||||
| @@ -65,4 +65,6 @@ public interface ModelsVersionService { | |||||
| ModelsVersion duplicateModelsVersion(ModelsVersion oldModelsVersion); | ModelsVersion duplicateModelsVersion(ModelsVersion oldModelsVersion); | ||||
| ModelsVersion queryByModelsVersion(ModelsVersion modelsVersion); | ModelsVersion queryByModelsVersion(ModelsVersion modelsVersion); | ||||
| List<ModelsVersion> queryByModelsIdAndVersion(Integer modelsId, String version); | |||||
| } | } | ||||
| @@ -4,7 +4,8 @@ package com.ruoyi.platform.service.impl; | |||||
| import com.ruoyi.common.security.utils.SecurityUtils; | import com.ruoyi.common.security.utils.SecurityUtils; | ||||
| import com.ruoyi.platform.domain.Dataset; | import com.ruoyi.platform.domain.Dataset; | ||||
| import com.ruoyi.platform.domain.DatasetVersion; | import com.ruoyi.platform.domain.DatasetVersion; | ||||
| import com.ruoyi.platform.domain.Workflow; | |||||
| import com.ruoyi.platform.domain.Models; | |||||
| import com.ruoyi.platform.domain.ModelsVersion; | |||||
| import com.ruoyi.platform.mapper.DatasetDao; | import com.ruoyi.platform.mapper.DatasetDao; | ||||
| import com.ruoyi.platform.mapper.DatasetVersionDao; | import com.ruoyi.platform.mapper.DatasetVersionDao; | ||||
| import com.ruoyi.platform.service.DatasetService; | import com.ruoyi.platform.service.DatasetService; | ||||
| @@ -14,7 +15,6 @@ import com.ruoyi.platform.utils.MinioUtil; | |||||
| import com.ruoyi.system.api.model.LoginUser; | import com.ruoyi.system.api.model.LoginUser; | ||||
| import io.minio.MinioClient; | import io.minio.MinioClient; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.beans.BeanUtils; | |||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.core.io.InputStreamResource; | import org.springframework.core.io.InputStreamResource; | ||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||
| @@ -34,7 +34,6 @@ import java.io.InputStream; | |||||
| import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| /** | /** | ||||
| @@ -212,65 +211,56 @@ public class DatasetServiceImpl implements DatasetService { | |||||
| /** | /** | ||||
| * 上传数据集 | * 上传数据集 | ||||
| * | * | ||||
| * @param file 文件 | |||||
| * @param id 注意是dataset_version表的主键 | |||||
| * @param files 文件 | |||||
| * @param id 注意是dataset_version表的主键 | |||||
| * @param version | |||||
| * @return 是否成功 | * @return 是否成功 | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| public Map uploadDataset(MultipartFile file, Integer id) throws Exception { | |||||
| if (file.isEmpty()) { | |||||
| throw new Exception("文件为空,无法上传"); | |||||
| } | |||||
| // 获取文件大小并转换为KB | |||||
| long sizeInBytes = file.getSize(); | |||||
| double sizeInKB = sizeInBytes / 1024.0; | |||||
| // 检查并处理现有的数据集版本记录 | |||||
| DatasetVersion currentDatasetVersion = this.datasetVersionDao.queryById(id); | |||||
| if (currentDatasetVersion == null) { | |||||
| throw new Exception("未找到数据集版本记录"); | |||||
| } | |||||
| DatasetVersion datasetVersionToUse = currentDatasetVersion; | |||||
| //检查版本下是否存在URL记录 | |||||
| String url = currentDatasetVersion.getUrl(); | |||||
| if (url != null && !url.isEmpty()) { | |||||
| // 逻辑删除当前版本 | |||||
| currentDatasetVersion.setState(0); | |||||
| datasetVersionDao.update(currentDatasetVersion); | |||||
| // 创建并插入新版本 | |||||
| datasetVersionToUse = this.datasetVersionService.duplicateDatasetVersion(currentDatasetVersion); | |||||
| public Map uploadDataset(MultipartFile[] files, Integer id, String version) throws Exception { | |||||
| Map<String, Object> results = new HashMap<String, Object>(); | |||||
| } | |||||
| //查询数据集名称 | |||||
| Integer datasetID = datasetVersionToUse.getDatasetId(); | |||||
| Dataset dataset = this.datasetDao.queryById(datasetID); | |||||
| // 验证模型是否存在 | |||||
| Dataset dataset = this.datasetDao.queryById(id); | |||||
| if (dataset == null) { | if (dataset == null) { | ||||
| throw new Exception("未找到数据集记录"); | |||||
| throw new Exception("未找到模型记录"); | |||||
| } | } | ||||
| // 其余操作基于 datasetVersionToUse | |||||
| String username = SecurityUtils.getLoginUser().getUsername(); | |||||
| String version = datasetVersionToUse.getVersion(); | |||||
| Date createTime = datasetVersionToUse.getCreateTime(); | |||||
| String fileName = file.getOriginalFilename(); | |||||
| // String timestamp = new SimpleDateFormat("yyyyMMdd-HHmmss").format(createTime); | |||||
| String objectName = "datasets/" + username + "/" + dataset.getName() + "/" + version + "/" + fileName; | |||||
| // 上传文件到MinIO | |||||
| try (InputStream inputStream = file.getInputStream()) { | |||||
| minioUtil.uploadObject(bucketName, objectName, inputStream); | |||||
| datasetVersionToUse.setUrl(objectName); | |||||
| datasetVersionToUse.setFileName(fileName); | |||||
| datasetVersionToUse.setFileSize(String.valueOf(sizeInKB)); | |||||
| datasetVersionDao.update(datasetVersionToUse); | |||||
| } catch (Exception e) { | |||||
| throw new Exception("上传到数据集失败: " + e.getMessage(), e); | |||||
| for (MultipartFile file:files){ | |||||
| if (file.isEmpty()) { | |||||
| throw new Exception("文件为空,无法上传"); | |||||
| } | |||||
| // 获取文件大小并转换为KB | |||||
| long sizeInBytes = file.getSize(); | |||||
| double sizeInKB = sizeInBytes / 1024.0; | |||||
| // 其余操作基于 modelsVersionToUse | |||||
| String username = SecurityUtils.getLoginUser().getUsername(); | |||||
| String fileName = file.getOriginalFilename(); | |||||
| // String timestamp = new SimpleDateFormat("yyyyMMdd-HHmmss").format(createTime); | |||||
| String objectName = "datasets/" + username + "/" + dataset.getName() + "/" + version + "/" + 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(String.valueOf(sizeInKB)); | |||||
| datasetVersionService.insert(datasetVersion); | |||||
| } catch (Exception e) { | |||||
| throw new Exception("上传数据集失败: " + e.getMessage(), e); | |||||
| } | |||||
| Map<String, String> fileResult = new HashMap<>(); | |||||
| fileResult.put("fileName", file.getOriginalFilename()); | |||||
| fileResult.put("url", objectName); // objectName根据实际情况定义 | |||||
| results.put(file.getOriginalFilename(), fileResult); | |||||
| } | } | ||||
| Map<String, String> result = new HashMap<String, String>(); | |||||
| result.put("url",objectName); | |||||
| return result; | |||||
| return results; | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -145,4 +145,9 @@ public class DatasetVersionServiceImpl implements DatasetVersionService { | |||||
| return datasetVersionDao.queryByDatasetVersion(datasetVersion); | return datasetVersionDao.queryByDatasetVersion(datasetVersion); | ||||
| } | } | ||||
| @Override | |||||
| public List<DatasetVersion> queryByDatasetIdAndVersion(Integer datasetId, String version) { | |||||
| return this.datasetVersionDao.queryByDatasetIdAndVersion(datasetId, version); | |||||
| } | |||||
| } | } | ||||
| @@ -319,7 +319,6 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||||
| try (ZipOutputStream zos = new ZipOutputStream(baos)) { | try (ZipOutputStream zos = new ZipOutputStream(baos)) { | ||||
| //遍历每一个version数据项 | //遍历每一个version数据项 | ||||
| for (ModelsVersion modelsVersion : modelsVersionList) { | for (ModelsVersion modelsVersion : modelsVersionList) { | ||||
| String objectName = modelsVersion.getUrl(); | String objectName = modelsVersion.getUrl(); | ||||
| if (objectName != null && !objectName.isEmpty()) { | if (objectName != null && !objectName.isEmpty()) { | ||||
| @@ -150,4 +150,19 @@ public class ModelsVersionServiceImpl implements ModelsVersionService { | |||||
| return this.modelsVersionDao.queryByModelsVersion(modelsVersion); | return this.modelsVersionDao.queryByModelsVersion(modelsVersion); | ||||
| } | } | ||||
| /** | |||||
| * 复制模型版本 | |||||
| * | |||||
| * @param modelsId 模型的id | |||||
| * @param version 模型版本号 | |||||
| * @return 新的模型版本记录列表 | |||||
| */ | |||||
| @Override | |||||
| public List<ModelsVersion> queryByModelsIdAndVersion(Integer modelsId, String version) { | |||||
| return this.modelsVersionDao.queryAllByModelsVersion(modelsId, version) ; | |||||
| } | |||||
| } | } | ||||
| @@ -49,6 +49,24 @@ | |||||
| </where> | </where> | ||||
| limit 1 | limit 1 | ||||
| </select> | </select> | ||||
| <select id="queryByDatasetVersion" resultMap="DatasetVersionMap"> | |||||
| select | |||||
| id,dataset_id,version,url,file_name,file_size,available_cluster,status,create_by,create_time,update_by,update_time,state | |||||
| from dataset_version | |||||
| <where> | |||||
| state = 1 | |||||
| <if test="datasetId != null"> | |||||
| and dataset_id = #{datasetId} | |||||
| </if> | |||||
| <if test="version != null and version != ''"> | |||||
| and version = #{version} | |||||
| </if> | |||||
| </where> | |||||
| </select> | |||||
| <!--查询指定行数据--> | <!--查询指定行数据--> | ||||
| <select id="queryAllByLimit" resultMap="DatasetVersionMap"> | <select id="queryAllByLimit" resultMap="DatasetVersionMap"> | ||||
| select | select | ||||