|
|
|
@@ -4,6 +4,7 @@ package com.ruoyi.platform.service.impl; |
|
|
|
import com.ruoyi.common.security.utils.SecurityUtils; |
|
|
|
import com.ruoyi.platform.domain.Dataset; |
|
|
|
import com.ruoyi.platform.domain.DatasetVersion; |
|
|
|
import com.ruoyi.platform.domain.Workflow; |
|
|
|
import com.ruoyi.platform.mapper.DatasetDao; |
|
|
|
import com.ruoyi.platform.mapper.DatasetVersionDao; |
|
|
|
import com.ruoyi.platform.service.DatasetService; |
|
|
|
@@ -156,7 +157,7 @@ public class DatasetServiceImpl implements DatasetService { |
|
|
|
String username = loginUser.getUsername(); |
|
|
|
String createdBy = dataset.getCreateBy(); |
|
|
|
if (!(StringUtils.equals(username,"admin") || StringUtils.equals(username,createdBy))){ |
|
|
|
return "无权限删除该数据集"; |
|
|
|
return "无权限删除该数据集版本"; |
|
|
|
} |
|
|
|
if (datasetVersionService.queryByDatasetId(id).size()>0){ |
|
|
|
return "请先删除该数据集的版本文件"; |
|
|
|
@@ -213,50 +214,61 @@ public class DatasetServiceImpl implements DatasetService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String uploadDataset(MultipartFile file, Integer id) throws Exception { |
|
|
|
if(file.isEmpty()){ |
|
|
|
if (file.isEmpty()) { |
|
|
|
throw new Exception("文件为空,无法上传"); |
|
|
|
} |
|
|
|
// 获取文件大小并转换为KB |
|
|
|
long sizeInBytes = file.getSize(); |
|
|
|
double sizeInKB = sizeInBytes / 1024.0; |
|
|
|
|
|
|
|
//拿到dataset表的id去查数据集名字 |
|
|
|
DatasetVersion datasetVersion = this.datasetVersionDao.queryById(id); |
|
|
|
if (datasetVersion == null) { |
|
|
|
// 检查并处理现有的数据集版本记录 |
|
|
|
DatasetVersion currentDatasetVersion = this.datasetVersionDao.queryById(id); |
|
|
|
if (currentDatasetVersion == null) { |
|
|
|
throw new Exception("未找到数据集版本记录"); |
|
|
|
} |
|
|
|
Integer datasetID = datasetVersion.getDatasetId(); |
|
|
|
|
|
|
|
DatasetVersion datasetVersionToUse = currentDatasetVersion; |
|
|
|
//检查是否存在URL记录 |
|
|
|
if (!currentDatasetVersion.getUrl().isEmpty()) { |
|
|
|
// 逻辑删除当前版本 |
|
|
|
currentDatasetVersion.setState(0); |
|
|
|
datasetVersionDao.update(currentDatasetVersion); |
|
|
|
|
|
|
|
// 创建并插入新版本 |
|
|
|
datasetVersionToUse = this.datasetVersionService.duplicateDatasetVersion(currentDatasetVersion); |
|
|
|
datasetVersionDao.insert(datasetVersionToUse); |
|
|
|
} |
|
|
|
|
|
|
|
//查询数据集名称 |
|
|
|
Integer datasetID = datasetVersionToUse.getDatasetId(); |
|
|
|
Dataset dataset = this.datasetDao.queryById(datasetID); |
|
|
|
if (dataset == null) { |
|
|
|
throw new Exception("未找到数据集记录"); |
|
|
|
} |
|
|
|
|
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser(); |
|
|
|
//拼接objectName |
|
|
|
String username = loginUser.getUsername(); |
|
|
|
String version = datasetVersion.getVersion(); |
|
|
|
Date createTime = datasetVersion.getCreateTime(); |
|
|
|
// 其余操作基于 datasetVersionToUse |
|
|
|
String username = SecurityUtils.getLoginUser().getUsername(); |
|
|
|
String version = datasetVersionToUse.getVersion(); |
|
|
|
Date createTime = datasetVersionToUse.getCreateTime(); |
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
//格式化日期为时间戳字符串 |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss"); |
|
|
|
String timestamp = sdf.format(createTime); |
|
|
|
|
|
|
|
String objectName = "datasets/" + username + "/" + dataset.getName() + "-" + timestamp + "/" + version + "/" + fileName; |
|
|
|
String timestamp = new SimpleDateFormat("yyyyMMdd-HHmmss").format(createTime); |
|
|
|
String objectName = "datasets/" + username + "/" + dataset.getName() + "-" + timestamp + "/" + version + "/" + fileName; |
|
|
|
|
|
|
|
// 上传文件到MinIO |
|
|
|
try (InputStream inputStream = file.getInputStream()) { |
|
|
|
minioUtil.uploadObject(bucketName, objectName, inputStream); |
|
|
|
// 更新数据库中dataset_version表url记录 |
|
|
|
datasetVersion.setUrl(objectName); |
|
|
|
datasetVersion.setFileName(fileName); |
|
|
|
datasetVersion.setFileSize(String.valueOf(sizeInKB)); |
|
|
|
datasetVersionDao.update(datasetVersion); |
|
|
|
datasetVersionToUse.setUrl(objectName); |
|
|
|
datasetVersionToUse.setFileName(fileName); |
|
|
|
datasetVersionToUse.setFileSize(String.valueOf(sizeInKB)); |
|
|
|
datasetVersionDao.update(datasetVersionToUse); |
|
|
|
return "数据集成功上传到: " + objectName; |
|
|
|
} catch (Exception e) { |
|
|
|
throw new Exception("上传到MinIO失败: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String extractFileName(String urlStr) { |
|
|
|
return urlStr.substring(urlStr.lastIndexOf('/') + 1); |
|
|
|
} |
|
|
|
|