| @@ -4,7 +4,7 @@ import com.ruoyi.common.core.web.controller.BaseController; | |||||
| import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | ||||
| import com.ruoyi.platform.domain.DatasetVersion; | import com.ruoyi.platform.domain.DatasetVersion; | ||||
| import com.ruoyi.platform.service.DatasetVersionService; | import com.ruoyi.platform.service.DatasetVersionService; | ||||
| import com.ruoyi.platform.vo.LabelDatasetVersion; | |||||
| import com.ruoyi.platform.vo.LabelDatasetVersionVo; | |||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageRequest; | import org.springframework.data.domain.PageRequest; | ||||
| @@ -138,8 +138,10 @@ public class DatasetVersionController extends BaseController { | |||||
| @PostMapping("/addDatasetVersionsFromLabel") | @PostMapping("/addDatasetVersionsFromLabel") | ||||
| @ApiOperation("从数据标注添加数据集版本") | @ApiOperation("从数据标注添加数据集版本") | ||||
| public GenericsAjaxResult<Boolean> addDatasetVersionsFromLabel(@RequestBody LabelDatasetVersion labelDatasetVersion) throws Exception { | |||||
| return genericsSuccess(true); | |||||
| public GenericsAjaxResult<?> addDatasetVersionsFromLabel(@RequestBody LabelDatasetVersionVo labelDatasetVersionVo) throws Exception { | |||||
| datasetVersionService.addDatasetVersionsFromLabel(labelDatasetVersionVo); | |||||
| return GenericsAjaxResult.success(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,11 +1,8 @@ | |||||
| package com.ruoyi.platform.service; | package com.ruoyi.platform.service; | ||||
| import com.ruoyi.platform.domain.Dataset; | |||||
| import com.ruoyi.platform.domain.DatasetVersion; | import com.ruoyi.platform.domain.DatasetVersion; | ||||
| import com.ruoyi.platform.vo.LabelDatasetVersion; | |||||
| import com.ruoyi.platform.vo.LabelDatasetVersionVo; | |||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageRequest; | import org.springframework.data.domain.PageRequest; | ||||
| @@ -75,5 +72,6 @@ public interface DatasetVersionService { | |||||
| String addDatasetVersions(List<DatasetVersion> datasetVersions) throws Exception; | String addDatasetVersions(List<DatasetVersion> datasetVersions) throws Exception; | ||||
| void addDatasetVersionsFromLabel(LabelDatasetVersion labelDatasetVersion) throws Exception; | |||||
| void | |||||
| addDatasetVersionsFromLabel(LabelDatasetVersionVo labelDatasetVersionVo) throws Exception; | |||||
| } | } | ||||
| @@ -4,6 +4,7 @@ import org.springframework.core.io.InputStreamResource; | |||||
| import org.springframework.http.ResponseEntity; | import org.springframework.http.ResponseEntity; | ||||
| import org.springframework.web.multipart.MultipartFile; | import org.springframework.web.multipart.MultipartFile; | ||||
| import java.io.InputStream; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| @@ -11,5 +12,5 @@ public interface MinioService { | |||||
| ResponseEntity<InputStreamResource> downloadZipFile(String bucketName , String path); | ResponseEntity<InputStreamResource> downloadZipFile(String bucketName , String path); | ||||
| Map<String, String> uploadFile(String bucketName, String objectName, MultipartFile file ) throws Exception; | Map<String, String> uploadFile(String bucketName, String objectName, MultipartFile file ) throws Exception; | ||||
| void uploaInputStream(String bucketName, String objectName, InputStream inputStream ) throws Exception; | |||||
| } | } | ||||
| @@ -18,6 +18,7 @@ import com.ruoyi.platform.vo.DatasetVo; | |||||
| import com.ruoyi.system.api.model.LoginUser; | import com.ruoyi.system.api.model.LoginUser; | ||||
| import io.minio.messages.Item; | import io.minio.messages.Item; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| 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; | ||||
| import org.springframework.data.domain.PageImpl; | import org.springframework.data.domain.PageImpl; | ||||
| @@ -62,7 +63,8 @@ public class DatasetServiceImpl implements DatasetService { | |||||
| private MinioService minioService; | private MinioService minioService; | ||||
| // 固定存储桶名 | // 固定存储桶名 | ||||
| private final String bucketName = "platform-data"; | |||||
| @Value("${minio.dataReleaseBucketName}") | |||||
| private String bucketName; | |||||
| @Resource | @Resource | ||||
| private MinioUtil minioUtil; | private MinioUtil minioUtil; | ||||
| @@ -1,17 +1,20 @@ | |||||
| package com.ruoyi.platform.service.impl; | package com.ruoyi.platform.service.impl; | ||||
| import com.ruoyi.common.core.utils.DateUtils; | |||||
| import com.ruoyi.common.security.utils.SecurityUtils; | import com.ruoyi.common.security.utils.SecurityUtils; | ||||
| import com.ruoyi.platform.annotations.CheckDuplicate; | import com.ruoyi.platform.annotations.CheckDuplicate; | ||||
| 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.ModelsVersion; | |||||
| import com.ruoyi.platform.domain.Workflow; | |||||
| import com.ruoyi.platform.mapper.DatasetDao; | |||||
| import com.ruoyi.platform.mapper.DatasetVersionDao; | import com.ruoyi.platform.mapper.DatasetVersionDao; | ||||
| import com.ruoyi.platform.service.DatasetVersionService; | import com.ruoyi.platform.service.DatasetVersionService; | ||||
| import com.ruoyi.platform.service.MinioService; | |||||
| import com.ruoyi.platform.utils.FileUtil; | |||||
| import com.ruoyi.platform.utils.HttpUtils; | import com.ruoyi.platform.utils.HttpUtils; | ||||
| import com.ruoyi.platform.vo.LabelDatasetVersion; | |||||
| import com.ruoyi.platform.vo.LabelDatasetVersionVo; | |||||
| import com.ruoyi.system.api.model.LoginUser; | import com.ruoyi.system.api.model.LoginUser; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.beans.factory.annotation.Value; | |||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageImpl; | import org.springframework.data.domain.PageImpl; | ||||
| import org.springframework.data.domain.PageRequest; | import org.springframework.data.domain.PageRequest; | ||||
| @@ -35,9 +38,13 @@ import java.util.Map; | |||||
| public class DatasetVersionServiceImpl implements DatasetVersionService { | public class DatasetVersionServiceImpl implements DatasetVersionService { | ||||
| @Resource | @Resource | ||||
| private DatasetVersionDao datasetVersionDao; | private DatasetVersionDao datasetVersionDao; | ||||
| @Resource | |||||
| private DatasetDao datasetDao; | |||||
| // 固定存储桶名 | // 固定存储桶名 | ||||
| private final String bucketName = "platform-data"; | |||||
| @Value("${minio.dataReleaseBucketName}") | |||||
| private String bucketName; | |||||
| @Resource | |||||
| private MinioService minioService; | |||||
| /** | /** | ||||
| * 通过ID查询单条数据 | * 通过ID查询单条数据 | ||||
| * | * | ||||
| @@ -198,12 +205,31 @@ public class DatasetVersionServiceImpl implements DatasetVersionService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void addDatasetVersionsFromLabel(LabelDatasetVersion labelDatasetVersion) throws Exception{ | |||||
| public void addDatasetVersionsFromLabel(LabelDatasetVersionVo labelDatasetVersionVo) throws Exception{ | |||||
| Dataset dataset = datasetDao.queryById(labelDatasetVersionVo.getDataset_id()); | |||||
| if (dataset == null){ | |||||
| throw new Exception("数据集不存在"); | |||||
| } | |||||
| // 获取label-studio数据流 | // 获取label-studio数据流 | ||||
| InputStream inputStream = HttpUtils.getInputStream("http://127.0.0.1:8080/api/projects/"+labelDatasetVersion.getProject_id()+"/export?exportType="+labelDatasetVersion.getExportType(), labelDatasetVersion.getToken()); | |||||
| // 上传镜像至minio | |||||
| Map<String, String> headers = new HashMap<String, String>(); | |||||
| headers.put("Authorization","Token "+labelDatasetVersionVo.getToken()); | |||||
| InputStream inputStream = HttpUtils.getIntputStream("http://127.0.0.1:8080/api/projects/"+labelDatasetVersionVo.getProject_id()+"/export?exportType="+labelDatasetVersionVo.getExportType(), headers); | |||||
| // 构建objectName | |||||
| String username = SecurityUtils.getLoginUser().getUsername(); | |||||
| String url = username + "/" + DateUtils.dateTimeNow() + "/" + dataset.getName()+"_"+labelDatasetVersionVo.getVersion()+"."+labelDatasetVersionVo.getExportType(); | |||||
| String objectName = "datasets/" + url; | |||||
| String formattedSize = FileUtil.formatFileSize(inputStream.available()); | |||||
| minioService.uploaInputStream(bucketName,objectName,inputStream); | |||||
| //保存DatasetVersion | //保存DatasetVersion | ||||
| DatasetVersion datasetVersion = new DatasetVersion(); | |||||
| datasetVersion.setVersion(labelDatasetVersionVo.getVersion()); | |||||
| datasetVersion.setDatasetId(labelDatasetVersionVo.getDataset_id()); | |||||
| datasetVersion.setFileName(dataset.getName()+"_"+labelDatasetVersionVo.getVersion()+"."+labelDatasetVersionVo.getExportType()); | |||||
| datasetVersion.setFileSize(formattedSize); | |||||
| datasetVersion.setUrl(url); | |||||
| datasetVersion.setDescription(labelDatasetVersionVo.getDesc()); | |||||
| this.insert(datasetVersion); | |||||
| } | } | ||||
| private void insertPrepare(DatasetVersion datasetVersion) throws Exception { | private void insertPrepare(DatasetVersion datasetVersion) throws Exception { | ||||
| @@ -69,4 +69,9 @@ public class MinioServiceImpl implements MinioService { | |||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| @Override | |||||
| public void uploaInputStream(String bucketName, String objectName, InputStream inputStream ) throws Exception { | |||||
| minioUtil.uploadObject(bucketName, objectName, inputStream); | |||||
| } | |||||
| } | } | ||||
| @@ -17,6 +17,7 @@ import com.ruoyi.system.api.model.LoginUser; | |||||
| import io.minio.messages.Item; | import io.minio.messages.Item; | ||||
| import io.netty.util.Version; | import io.netty.util.Version; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| 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; | ||||
| import org.springframework.data.domain.PageImpl; | import org.springframework.data.domain.PageImpl; | ||||
| @@ -59,7 +60,8 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| // 固定存储桶名 | // 固定存储桶名 | ||||
| private final String bucketName = "platform-data"; | |||||
| @Value("${minio.dataReleaseBucketName}") | |||||
| private String bucketName; | |||||
| @Resource | @Resource | ||||
| private MinioUtil minioUtil; | private MinioUtil minioUtil; | ||||
| @@ -8,6 +8,7 @@ import com.ruoyi.platform.mapper.ModelsVersionDao; | |||||
| import com.ruoyi.platform.service.ModelsVersionService; | import com.ruoyi.platform.service.ModelsVersionService; | ||||
| import com.ruoyi.system.api.model.LoginUser; | import com.ruoyi.system.api.model.LoginUser; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.beans.factory.annotation.Value; | |||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageImpl; | import org.springframework.data.domain.PageImpl; | ||||
| import org.springframework.data.domain.PageRequest; | import org.springframework.data.domain.PageRequest; | ||||
| @@ -35,7 +36,8 @@ public class ModelsVersionServiceImpl implements ModelsVersionService { | |||||
| private ModelsDao modelsDao; | private ModelsDao modelsDao; | ||||
| // 固定存储桶名 | // 固定存储桶名 | ||||
| private final String bucketName = "platform-data"; | |||||
| @Value("${minio.dataReleaseBucketName}") | |||||
| private String bucketName; | |||||
| /** | /** | ||||
| * 通过ID查询单条数据 | * 通过ID查询单条数据 | ||||
| @@ -375,25 +375,54 @@ public class HttpUtils { | |||||
| } | } | ||||
| /** | /** | ||||
| * 发送 HTTP 请求并返回二进制数据流(InputStream)。 | |||||
| * 发送 HTTP 请求并返回二进制数据流(OutputStream)。 | |||||
| * | * | ||||
| * @param url 请求的 URL 地址。 | * @param url 请求的 URL 地址。 | ||||
| * @param token 要携带的 Token。 | |||||
| * @return 服务器响应的二进制数据流(InputStream)。 | |||||
| * @param headers 头节点。 | |||||
| * @return 服务器响应的二进制数据流(OutputStream)。 | |||||
| * @throws IOException 如果请求失败或发生其他 I/O 错误。 | * @throws IOException 如果请求失败或发生其他 I/O 错误。 | ||||
| */ | */ | ||||
| public static InputStream getInputStream(String url, String token) throws IOException { | |||||
| public static InputStream getIntputStream(String url, Map<String, String> headers) throws IOException { | |||||
| URL requestUrl = new URL(url); | URL requestUrl = new URL(url); | ||||
| HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection(); | HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection(); | ||||
| // Set request headers | |||||
| for (Map.Entry<String, String> entry : headers.entrySet()) { | |||||
| connection.setRequestProperty(entry.getKey(), entry.getValue()); | |||||
| } | |||||
| // Set other connection properties (e.g., timeouts, request method, etc.) | |||||
| connection.setRequestMethod("GET"); | connection.setRequestMethod("GET"); | ||||
| connection.setRequestProperty("Authorization", "Bearer " + token); // 添加 Authorization 头部,携带 Token | |||||
| connection.setConnectTimeout(5000); | |||||
| connection.setReadTimeout(5000); | |||||
| // Connect and get the response code | |||||
| connection.connect(); | |||||
| int responseCode = connection.getResponseCode(); | int responseCode = connection.getResponseCode(); | ||||
| if (responseCode == HttpURLConnection.HTTP_OK) { | if (responseCode == HttpURLConnection.HTTP_OK) { | ||||
| return connection.getInputStream(); // 获取响应的输入流 | |||||
| // Get the response InputStream | |||||
| InputStream inputStream = connection.getInputStream(); | |||||
| // // Create a ByteArrayOutputStream to store the response data | |||||
| // ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | |||||
| // | |||||
| // // Read data from the InputStream and write it to the ByteArrayOutputStream | |||||
| // byte[] buffer = new byte[1024]; | |||||
| // int bytesRead; | |||||
| // while ((bytesRead = inputStream.read(buffer)) != -1) { | |||||
| // outputStream.write(buffer, 0, bytesRead); | |||||
| // } | |||||
| // | |||||
| // // Close the InputStream | |||||
| // inputStream.close(); | |||||
| // Return the ByteArrayOutputStream as an OutputStream | |||||
| return inputStream; | |||||
| } else { | } else { | ||||
| throw new IOException("HTTP 请求失败,状态码:" + responseCode); | |||||
| throw new IOException("HTTP request failed with response code: " + responseCode); | |||||
| } | } | ||||
| } | } | ||||
| @@ -6,10 +6,10 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; | |||||
| import java.io.Serializable; | import java.io.Serializable; | ||||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||||
| public class LabelDatasetVersion implements Serializable { | |||||
| public class LabelDatasetVersionVo implements Serializable { | |||||
| private String token; | private String token; | ||||
| private String project_id; | private String project_id; | ||||
| private String dataset_id; | |||||
| private Integer dataset_id; | |||||
| private String version; | private String version; | ||||
| private String desc; | private String desc; | ||||
| private String exportType; | private String exportType; | ||||
| @@ -29,11 +29,11 @@ public class LabelDatasetVersion implements Serializable { | |||||
| this.project_id = project_id; | this.project_id = project_id; | ||||
| } | } | ||||
| public String getDataset_id() { | |||||
| public Integer getDataset_id() { | |||||
| return dataset_id; | return dataset_id; | ||||
| } | } | ||||
| public void setDataset_id(String dataset_id) { | |||||
| public void setDataset_id(Integer dataset_id) { | |||||
| this.dataset_id = dataset_id; | this.dataset_id = dataset_id; | ||||
| } | } | ||||