| @@ -160,15 +160,28 @@ public class DatasetController { | |||
| */ | |||
| @GetMapping("/download/{dataset_version_id}") | |||
| @ApiOperation(value = "下载数据集", notes = "根据数据集版本表id下载数据集文件") | |||
| @ApiOperation(value = "下载单个数据集文件", notes = "根据数据集版本表id下载单个数据集文件") | |||
| public ResponseEntity<InputStreamResource> downloadDataset(@PathVariable("dataset_version_id") Integer dataset_version_id) throws Exception { | |||
| return datasetService.downloadDataset(dataset_version_id); | |||
| } | |||
| /** | |||
| * 数据集打包下载 | |||
| * | |||
| * @param datasetId 数据集id | |||
| * @param version 数据集版本 | |||
| * @return 单条数据 | |||
| */ | |||
| @GetMapping("/downloadAllFiles") | |||
| @ApiOperation(value = "下载同一版本下所有数据集,并打包", notes = "根据数据集ID和版本下载所有数据集文件,并打包。") | |||
| public ResponseEntity<InputStreamResource> downloadAllDatasetFiles(@RequestParam("dataset_id") Integer datasetId, @RequestParam("version") String version) throws Exception { | |||
| return datasetService.downloadAllDatasetFiles(datasetId, version); | |||
| } | |||
| /** | |||
| * 上传数据集 | |||
| * | |||
| * @param datasetId 数据集ID | |||
| // * @param datasetId 数据集ID | |||
| * @param files 上传的数据集文件 | |||
| * | |||
| * @return 上传结果 | |||
| @@ -204,7 +204,7 @@ public class ModelsController { | |||
| */ | |||
| @GetMapping("/downloadAllFiles") | |||
| @ApiOperation(value = "下载模型压缩包", notes = "根据模型ID和版本下载所有模型文件,并打包。") | |||
| public ResponseEntity<InputStreamResource> downloadAllModelFiles(@RequestParam("models_id") Integer modelsId, @RequestParam("version") String version) { | |||
| public ResponseEntity<InputStreamResource> downloadAllModelFiles(@RequestParam("models_id") Integer modelsId, @RequestParam("version") String version) throws Exception { | |||
| return modelsService.downloadAllModelFiles(modelsId, version); | |||
| } | |||
| @@ -85,7 +85,7 @@ public class ModelsVersionController { | |||
| * @return 新增结果 | |||
| */ | |||
| @PostMapping("/addModelVersions") | |||
| @ApiOperation("添加模型版本") | |||
| @ApiOperation("批量添加模型版本,传数组") | |||
| public AjaxResult addModelVersions(@RequestBody List<ModelsVersion> modelsVersions) throws Exception { | |||
| return AjaxResult.success(this.modelsVersionService.addModelVersions(modelsVersions)); | |||
| } | |||
| @@ -80,4 +80,6 @@ DatasetService { | |||
| String insertDatasetAndVersion(DatasetVo datasetVo) throws Exception; | |||
| public void checkDeclaredName(Dataset insert) throws Exception; | |||
| ResponseEntity<InputStreamResource> downloadAllDatasetFiles(Integer datasetId, String version) throws Exception; | |||
| } | |||
| @@ -74,7 +74,7 @@ public interface ModelsService { | |||
| Map uploadModelsPipeline(ModelsVersion modelsVersion) throws Exception; | |||
| ResponseEntity<InputStreamResource> downloadAllModelFiles(Integer modelsId, String version); | |||
| ResponseEntity<InputStreamResource> downloadAllModelFiles(Integer modelsId, String version) throws Exception; | |||
| List<String> getModelVersions(Integer modelId) throws Exception; | |||
| String insertModelAndVersion(ModelsVo modelsVo) throws Exception; | |||
| @@ -5,6 +5,8 @@ import com.ruoyi.common.security.utils.SecurityUtils; | |||
| import com.ruoyi.platform.annotations.CheckDuplicate; | |||
| import com.ruoyi.platform.domain.Dataset; | |||
| import com.ruoyi.platform.domain.DatasetVersion; | |||
| import com.ruoyi.platform.domain.Models; | |||
| import com.ruoyi.platform.domain.ModelsVersion; | |||
| import com.ruoyi.platform.mapper.DatasetDao; | |||
| import com.ruoyi.platform.mapper.DatasetVersionDao; | |||
| import com.ruoyi.platform.service.DatasetService; | |||
| @@ -38,6 +40,8 @@ import java.lang.reflect.Field; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| import java.util.zip.ZipEntry; | |||
| import java.util.zip.ZipOutputStream; | |||
| /** | |||
| * (Dataset)表服务实现类 | |||
| @@ -386,4 +390,47 @@ public class DatasetServiceImpl implements DatasetService { | |||
| } | |||
| } | |||
| @Override | |||
| public ResponseEntity<InputStreamResource> downloadAllDatasetFiles(Integer datasetId, String version) throws Exception { | |||
| // 根据数据集id查数据名 | |||
| Dataset dataset = this.datasetDao.queryById(datasetId); | |||
| String datasetName = dataset.getName(); | |||
| // 查询特定模型和版本对应的所有文件 | |||
| List<DatasetVersion> datasetVersionList = this.datasetVersionDao.queryAllByDatasetVersion(datasetId, version); | |||
| if (datasetVersionList == null || datasetVersionList.isEmpty()) { | |||
| throw new Exception("数据集文件记录不存在!"); | |||
| } | |||
| // 创建ZIP文件,准备打包下载 | |||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
| try (ZipOutputStream zos = new ZipOutputStream(baos)) { | |||
| //遍历每一个version数据项 | |||
| for (DatasetVersion datasetVersion : datasetVersionList) { | |||
| String objectName = datasetVersion.getUrl(); | |||
| if (objectName != null && !objectName.isEmpty()) { | |||
| // 使用ByteArrayOutputStream来捕获MinIO中的文件 | |||
| ByteArrayOutputStream fileOutputStream = new ByteArrayOutputStream(); | |||
| minioUtil.downloadObject(bucketName, objectName, fileOutputStream); | |||
| // 添加到ZIP文件 | |||
| zos.putNextEntry(new ZipEntry(extractFileName(objectName))); | |||
| fileOutputStream.writeTo(zos); | |||
| zos.closeEntry(); | |||
| } | |||
| } | |||
| // 转换为输入流 | |||
| ByteArrayInputStream inputStream = new ByteArrayInputStream(baos.toByteArray()); | |||
| InputStreamResource resource = new InputStreamResource(inputStream); | |||
| // 设置响应 | |||
| return ResponseEntity.ok() | |||
| .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + datasetName + "_" + version + ".zip\"") | |||
| .contentType(MediaType.APPLICATION_OCTET_STREAM) | |||
| .body(resource); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); | |||
| } | |||
| } | |||
| } | |||
| @@ -32,6 +32,7 @@ import javax.annotation.Resource; | |||
| 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; | |||
| @@ -179,7 +180,7 @@ public class ModelsServiceImpl implements ModelsService { | |||
| public ResponseEntity<InputStreamResource> downloadModels(Integer id) throws Exception { | |||
| ModelsVersion modelsVersion = this.modelsVersionDao.queryById(id); | |||
| if (modelsVersion == null) { | |||
| throw new Exception("未找到该版本模型"); | |||
| throw new Exception("未找到该模型下版本记录"); | |||
| } | |||
| // 从数据库中获取存储路径(即MinIO中的对象名称) | |||
| String objectName = modelsVersion.getUrl(); | |||
| @@ -194,8 +195,9 @@ public class ModelsServiceImpl implements ModelsService { | |||
| ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); | |||
| InputStreamResource resource = new InputStreamResource(inputStream); | |||
| return ResponseEntity.ok() | |||
| .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + extractFileName(objectName) + "\"") | |||
| .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + URLEncoder.encode(extractFileName(objectName),"UTF-8") + "\"") | |||
| .contentType(MediaType.APPLICATION_OCTET_STREAM) | |||
| .body(resource); | |||
| } catch (Exception e) { | |||
| @@ -303,14 +305,14 @@ public class ModelsServiceImpl implements ModelsService { | |||
| * @return 文件内容 | |||
| */ | |||
| @Override | |||
| public ResponseEntity<InputStreamResource> downloadAllModelFiles(Integer modelsId, String version) { | |||
| public ResponseEntity<InputStreamResource> downloadAllModelFiles(Integer modelsId, String version) throws Exception { | |||
| // 根据模型id查模型名 | |||
| Models model = this.modelsDao.queryById(modelsId); | |||
| String modelName = model.getName(); | |||
| // 查询特定模型和版本对应的所有文件 | |||
| List<ModelsVersion> modelsVersionList = this.modelsVersionDao.queryAllByModelsVersion(modelsId, version); | |||
| if (modelsVersionList == null || modelsVersionList.isEmpty()) { | |||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); | |||
| throw new Exception("模型文件记录不存在,请检查模型id"); | |||
| } | |||
| // 创建ZIP文件,准备打包下载 | |||
| @@ -341,7 +343,7 @@ public class ModelsServiceImpl implements ModelsService { | |||
| .body(resource); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); | |||
| throw new Exception("模型文件打包下载失败"); | |||
| } | |||
| } | |||
| @@ -166,23 +166,37 @@ | |||
| <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true"> | |||
| insert into models_version(models_id,version,url,file_name,file_size,status,create_by,create_time,update_by,update_time,state) | |||
| insert into models_version | |||
| (models_id, version, url, file_name, file_size, status, create_by, create_time, update_by, update_time, state) | |||
| values | |||
| <foreach collection="entities" item="entity" separator=","> | |||
| (#{entity.modelsId}#{entity.version}#{entity.url}#{entity.fileName}#{entity.fileSize}#{entity.status}#{entity.createBy}#{entity.createTime}#{entity.updateBy}#{entity.updateTime}#{entity.state}) | |||
| (#{entity.modelsId}, #{entity.version}, #{entity.url}, #{entity.fileName}, #{entity.fileSize}, #{entity.status}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime}, #{entity.state}) | |||
| </foreach> | |||
| </insert> | |||
| <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true"> | |||
| insert into models_version(models_id,version,url,file_name,file_size,status,create_by,create_time,update_by,update_time,state) | |||
| insert into models_version | |||
| (models_id, version, url, file_name, file_size, status, create_by, create_time, update_by, update_time, state) | |||
| values | |||
| <foreach collection="entities" item="entity" separator=","> | |||
| (#{entity.modelsId}#{entity.version}#{entity.url}#{entity.fileName}#{entity.fileSize}#{entity.status}#{entity.createBy}#{entity.createTime}#{entity.updateBy}#{entity.updateTime}#{entity.state}) | |||
| (#{entity.modelsId}, #{entity.version}, #{entity.url}, #{entity.fileName}, #{entity.fileSize}, #{entity.status}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime}, #{entity.state}) | |||
| </foreach> | |||
| on duplicate key update | |||
| models_id = values(models_id)version = values(version)url = values(url)file_name = values(file_name)file_size = values(file_size)status = values(status)create_by = values(create_by)create_time = values(create_time)update_by = values(update_by)update_time = values(update_time)state = values(state) | |||
| models_id = values(models_id), | |||
| version = values(version), | |||
| url = values(url), | |||
| file_name = values(file_name), | |||
| file_size = values(file_size), | |||
| status = values(status), | |||
| create_by = values(create_by), | |||
| create_time = values(create_time), | |||
| update_by = values(update_by), | |||
| update_time = values(update_time), | |||
| state = values(state) | |||
| </insert> | |||
| <!--通过主键修改数据--> | |||
| <update id="update"> | |||
| update models_version | |||