| @@ -63,6 +63,13 @@ public class DatasetController { | |||||
| return AjaxResult.success(this.datasetService.queryById(id)); | return AjaxResult.success(this.datasetService.queryById(id)); | ||||
| } | } | ||||
| @GetMapping("/versions/{datasetId}") | |||||
| @ApiOperation(value = "获取数据集的所有版本", notes = "根据数据集ID获取该数据集的所有版本信息。") | |||||
| public AjaxResult getDatasetVersions(@PathVariable("datasetId") Integer datasetId) throws Exception { | |||||
| return AjaxResult.success(this.datasetService.getDatasetVersions(datasetId)); | |||||
| } | |||||
| /** | /** | ||||
| * 新增数据 | * 新增数据 | ||||
| * | * | ||||
| @@ -55,9 +55,16 @@ public class ModelsController { | |||||
| @GetMapping("{id}") | @GetMapping("{id}") | ||||
| @ApiOperation("根据id查询") | @ApiOperation("根据id查询") | ||||
| public AjaxResult queryById(@PathVariable("id") Integer id) { | public AjaxResult queryById(@PathVariable("id") Integer id) { | ||||
| return AjaxResult.success(this.modelsService.queryById(id)); | |||||
| return AjaxResult.success(this.modelsService.queryById(id)); | |||||
| } | } | ||||
| @GetMapping("/versions/{modelId}") | |||||
| @ApiOperation(value = "获取模型的所有版本", notes = "根据模型ID获取该模型的所有版本信息。") | |||||
| public AjaxResult getModelVersions(@PathVariable("modelId") Integer modelId) throws Exception { | |||||
| return AjaxResult.success(this.modelsService.getModelVersions(modelId)); | |||||
| } | |||||
| /** | /** | ||||
| * 新增数据 | * 新增数据 | ||||
| * | * | ||||
| @@ -72,4 +72,6 @@ public interface DatasetService { | |||||
| Map uploadDataset(MultipartFile[] files, Integer id, String version) throws Exception; | Map uploadDataset(MultipartFile[] files, Integer id, String version) throws Exception; | ||||
| Map uploadDatasetPipeline(DatasetVersion datasetVersion) throws Exception; | Map uploadDatasetPipeline(DatasetVersion datasetVersion) throws Exception; | ||||
| Map getDatasetVersions(Integer datasetId) throws Exception; | |||||
| } | } | ||||
| @@ -73,4 +73,5 @@ public interface ModelsService { | |||||
| Map uploadModelsPipeline(ModelsVersion modelsVersion) throws Exception; | Map uploadModelsPipeline(ModelsVersion modelsVersion) throws Exception; | ||||
| ResponseEntity<InputStreamResource> downloadAllModelFiles(Integer modelsId, String version); | ResponseEntity<InputStreamResource> downloadAllModelFiles(Integer modelsId, String version); | ||||
| Map getModelVersions(Integer modelId) throws Exception; | |||||
| } | } | ||||
| @@ -34,7 +34,9 @@ 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; | ||||
| import java.util.stream.Collectors; | |||||
| /** | /** | ||||
| * (Dataset)表服务实现类 | * (Dataset)表服务实现类 | ||||
| @@ -218,7 +220,7 @@ public class DatasetServiceImpl implements DatasetService { | |||||
| */ | */ | ||||
| @Override | @Override | ||||
| public Map uploadDataset(MultipartFile[] files, Integer id, String version) throws Exception { | public Map uploadDataset(MultipartFile[] files, Integer id, String version) throws Exception { | ||||
| Map<String, Object> results = new HashMap<String, Object>(); | |||||
| Map<Integer, Object> results = new HashMap<Integer, Object>(); | |||||
| // 验证模型是否存在 | // 验证模型是否存在 | ||||
| Dataset dataset = this.datasetDao.queryById(id); | Dataset dataset = this.datasetDao.queryById(id); | ||||
| @@ -249,15 +251,16 @@ public class DatasetServiceImpl implements DatasetService { | |||||
| datasetVersion.setUrl(objectName); | datasetVersion.setUrl(objectName); | ||||
| datasetVersion.setFileName(fileName); | datasetVersion.setFileName(fileName); | ||||
| datasetVersion.setFileSize(String.valueOf(sizeInKB)); | datasetVersion.setFileSize(String.valueOf(sizeInKB)); | ||||
| datasetVersionService.insert(datasetVersion); | |||||
| //返回插入结果 | |||||
| DatasetVersion insertedDatasetversion = datasetVersionService.insert(datasetVersion); | |||||
| Map<String, String> fileResult = new HashMap<>(); | |||||
| fileResult.put("fileName", file.getOriginalFilename()); | |||||
| fileResult.put("url", objectName); // objectName根据实际情况定义 | |||||
| results.put(insertedDatasetversion.getId(), fileResult); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| throw new Exception("上传数据集失败: " + e.getMessage(), 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); | |||||
| } | } | ||||
| return results; | return results; | ||||
| @@ -300,6 +303,18 @@ public class DatasetServiceImpl implements DatasetService { | |||||
| return result; | return result; | ||||
| } | } | ||||
| @Override | |||||
| public Map<String, List<DatasetVersion>> getDatasetVersions(Integer datasetId) throws Exception { | |||||
| // 获取所有相同模型ID的记录 | |||||
| List<DatasetVersion> versions = datasetVersionDao.queryByDatasetId(datasetId); | |||||
| if (versions.isEmpty()) { | |||||
| throw new Exception("未找到相关数据集版本记录"); | |||||
| } | |||||
| // 将结果按照版本分类 | |||||
| return versions.stream().collect(Collectors.groupingBy(DatasetVersion::getVersion)); | |||||
| } | |||||
| private String extractFileName(String urlStr) { | private String extractFileName(String urlStr) { | ||||
| return urlStr.substring(urlStr.lastIndexOf('/') + 1); | return urlStr.substring(urlStr.lastIndexOf('/') + 1); | ||||
| @@ -149,6 +149,7 @@ public class DatasetVersionServiceImpl implements DatasetVersionService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public List<DatasetVersion> queryByDatasetIdAndVersion(Integer datasetId, String version) { | public List<DatasetVersion> queryByDatasetIdAndVersion(Integer datasetId, String version) { | ||||
| return this.datasetVersionDao.queryAllByDatasetVersion(datasetId, version); | return this.datasetVersionDao.queryAllByDatasetVersion(datasetId, version); | ||||
| } | } | ||||
| @@ -32,6 +32,7 @@ import java.util.Date; | |||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.stream.Collectors; | |||||
| import java.util.zip.ZipEntry; | import java.util.zip.ZipEntry; | ||||
| import java.util.zip.ZipOutputStream; | import java.util.zip.ZipOutputStream; | ||||
| @@ -212,7 +213,7 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| @Override | @Override | ||||
| public Map uploadModels(MultipartFile[] files, Integer id, String version) throws Exception { | public Map uploadModels(MultipartFile[] files, Integer id, String version) throws Exception { | ||||
| Map<String, Object> results = new HashMap<String, Object>(); | |||||
| Map<Integer, Object> results = new HashMap<Integer, Object>(); | |||||
| // 验证模型是否存在 | // 验证模型是否存在 | ||||
| Models models = this.modelsDao.queryById(id); | Models models = this.modelsDao.queryById(id); | ||||
| @@ -243,15 +244,15 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| modelsVersion.setUrl(objectName); | modelsVersion.setUrl(objectName); | ||||
| modelsVersion.setFileName(fileName); | modelsVersion.setFileName(fileName); | ||||
| modelsVersion.setFileSize(String.valueOf(sizeInKB)); | modelsVersion.setFileSize(String.valueOf(sizeInKB)); | ||||
| modelsVersionService.insert(modelsVersion); | |||||
| //返回插入结果 | |||||
| ModelsVersion insertedModelsVersion = modelsVersionService.insert(modelsVersion); | |||||
| Map<String, String> fileResult = new HashMap<>(); | |||||
| fileResult.put("fileName", file.getOriginalFilename()); | |||||
| fileResult.put("url", objectName); // objectName根据实际情况定义 | |||||
| results.put(insertedModelsVersion.getId(), fileResult); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| throw new Exception("上传到模型失败: " + e.getMessage(), 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); | |||||
| } | } | ||||
| return results; | return results; | ||||
| } | } | ||||
| @@ -348,6 +349,18 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| } | } | ||||
| @Override | |||||
| public Map<String, List<ModelsVersion>> getModelVersions(Integer modelId) throws Exception { | |||||
| // 获取所有相同模型ID的记录 | |||||
| List<ModelsVersion> versions = modelsVersionDao.queryByModelsId(modelId); | |||||
| if (versions.isEmpty()) { | |||||
| throw new Exception("未找到相关模型版本记录"); | |||||
| } | |||||
| // 将结果按照版本分类 | |||||
| return versions.stream().collect(Collectors.groupingBy(ModelsVersion::getVersion)); | |||||
| } | |||||
| private String extractFileName(String urlStr) { | private String extractFileName(String urlStr) { | ||||
| return urlStr.substring(urlStr.lastIndexOf('/') + 1); | return urlStr.substring(urlStr.lastIndexOf('/') + 1); | ||||
| } | } | ||||