Browse Source

update dataset version

dev-restore_mount
fanshuai 1 year ago
parent
commit
230029734c
8 changed files with 208 additions and 61 deletions
  1. +45
    -31
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java
  2. +7
    -3
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java
  3. +8
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/GitService.java
  4. +57
    -4
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java
  5. +25
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/GitServiceImpl.java
  6. +22
    -21
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java
  7. +43
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/HttpUtils.java
  8. +1
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java

+ 45
- 31
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java View File

@@ -53,6 +53,47 @@ public class NewDatasetFromGitController {


} }


@GetMapping("/queryDatasets")
@ApiOperation("数据集广场公开数据集分页查询,根据data_type,data_tag筛选,true公开false私有")
public AjaxResult queryDatasets(Dataset dataset, @RequestParam("page") int page,
@RequestParam("size") int size,
@RequestParam(value = "is_public") Boolean isPublic,
@RequestParam(value = "data_type", required = false) String dataType,
@RequestParam(value = "data_tag", required = false) String dataTag) throws Exception {
PageRequest pageRequest = PageRequest.of(page, size);
if(isPublic){
return AjaxResult.success(this.datasetService.newPubilcQueryByPage(dataset, pageRequest));
}else {
return AjaxResult.success(this.datasetService.newPersonalQueryByPage(dataset, pageRequest));
}
}

@GetMapping("/getVersionList")
@ApiOperation(value = "获取分支列表")
public AjaxResult getVersionList(@RequestParam("String") String repo,@RequestParam("owner")String owner) throws Exception {
return AjaxResult.success(this.datasetService.getVersionList(repo,owner));
}

@GetMapping("/getdatasetDetail")
@ApiOperation(value = "获取数据集详情")
public AjaxResult getDatasetVersions(@RequestParam("name") String name,@RequestParam("repo_id") Integer repoId,@RequestParam("version")String version) throws Exception {
return AjaxResult.success(this.datasetService.getNewDatasetDesc(repoId,name,version));
}

@DeleteMapping("/deleteDataset")
@ApiOperation(value = "删除数据集")
public AjaxResult deleteDataset(@RequestParam("String") String repo,@RequestParam("owner")String owner) throws Exception {
this.datasetService.deleteDatasetNew(repo,owner);
return AjaxResult.success();
}

@DeleteMapping("/deleteDatasetVersion")
@ApiOperation(value = "删除数据集版本")
public AjaxResult deleteDatasetVersion(@RequestParam("String") String repo,@RequestParam("owner")String owner,@RequestParam("version")String version) throws Exception {
this.datasetService.deleteDatasetVersionNew(repo,owner,version);
return AjaxResult.success();
}



/** /**
* 上传数据集 * 上传数据集
@@ -83,40 +124,13 @@ public class NewDatasetFromGitController {
/** /**
* 下载数据集 * 下载数据集
* *
* @param dataset_version_id ps:这里的id是dataset_version表的主键
* @param url ps:路径
* @return 单条数据 * @return 单条数据
*/ */


@GetMapping("/download/{dataset_version_id}")
@GetMapping("/downloadSinggerFile")
@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);
}

@GetMapping("/queryDatasets")
@ApiOperation("数据集广场公开数据集分页查询,根据data_type,data_tag筛选,true公开false私有")
public AjaxResult queryDatasets(Dataset dataset, @RequestParam("page") int page,
@RequestParam("size") int size,
@RequestParam(value = "is_public") Boolean isPublic,
@RequestParam(value = "data_type", required = false) String dataType,
@RequestParam(value = "data_tag", required = false) String dataTag) throws Exception {
PageRequest pageRequest = PageRequest.of(page, size);
if(isPublic){
return AjaxResult.success(this.datasetService.newPubilcQueryByPage(dataset, pageRequest));
}else {
return AjaxResult.success(this.datasetService.newPersonalQueryByPage(dataset, pageRequest));
}
}

@GetMapping("/getVersionList")
@ApiOperation(value = "获取分支列表")
public AjaxResult getVersionList(@RequestParam("name") String name,@RequestParam("repo_id") Integer repoId,@RequestParam("version")String version) throws Exception {
return AjaxResult.success(this.datasetService.getNewDatasetDesc(repoId,name,version));
}

@GetMapping("/getdatasetDetail")
@ApiOperation(value = "获取数据集详情")
public AjaxResult getDatasetVersions(@RequestParam("name") String name,@RequestParam("repo_id") Integer repoId,@RequestParam("version")String version) throws Exception {
return AjaxResult.success(this.datasetService.getNewDatasetDesc(repoId,name,version));
public ResponseEntity<InputStreamResource> downloadDataset(@RequestParam("url") String url) throws Exception {
return datasetService.downloadDatasetlocal(url);
} }
} }

+ 7
- 3
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java View File

@@ -95,13 +95,17 @@ DatasetService {
CompletableFuture<String> newCreateDataset(NewDatasetVo datasetVo) throws Exception; CompletableFuture<String> newCreateDataset(NewDatasetVo datasetVo) throws Exception;
CompletableFuture<String> newCreateVersion(NewDatasetVo datasetVo); CompletableFuture<String> newCreateVersion(NewDatasetVo datasetVo);




List<Map<String, String>> uploadDatasetlocal(MultipartFile[] files, String uuid) throws Exception; List<Map<String, String>> uploadDatasetlocal(MultipartFile[] files, String uuid) throws Exception;
ResponseEntity<InputStreamResource> downloadDatasetlocal(String filePath) throws Exception;
ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String repositoryName, String version) throws IOException, Exception; ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String repositoryName, String version) throws IOException, Exception;
Page<NewDatasetVo> newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception; Page<NewDatasetVo> newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception;
Page<NewDatasetVo> newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception; Page<NewDatasetVo> newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception;


NewDatasetVo getNewDatasetDesc(Integer repoId,String RepositoryName, String version); NewDatasetVo getNewDatasetDesc(Integer repoId,String RepositoryName, String version);

List<Map<String, Object>> getVersionList(String repo, String owner) throws Exception;

void deleteDatasetNew(String repo, String owner) throws Exception;

void deleteDatasetVersionNew(String repo, String owner, String version) throws Exception;
} }

+ 8
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/GitService.java View File

@@ -2,6 +2,8 @@ package com.ruoyi.platform.service;


import com.ruoyi.platform.vo.GitProjectVo; import com.ruoyi.platform.vo.GitProjectVo;


import java.io.IOException;
import java.util.List;
import java.util.Map; import java.util.Map;


public interface GitService { public interface GitService {
@@ -14,4 +16,10 @@ public interface GitService {
void createBranch(String token,String owner, String projectName, String branchName, String oldBranchName) throws Exception; void createBranch(String token,String owner, String projectName, String branchName, String oldBranchName) throws Exception;


void createTopic(String token, Integer id, String topicName) throws Exception; void createTopic(String token, Integer id, String topicName) throws Exception;

List<Map<String, Object>> getBrancheList(String token, String owner, String projectName) throws Exception;

void deleteProject(String token, String owner, String projectName) throws Exception;

void deleteBranch(String token, String owner,String projectName ,String branchName) throws Exception;
} }

+ 57
- 4
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java View File

@@ -506,7 +506,7 @@ public class DatasetServiceImpl implements DatasetService {
DVCUtils.moveFiles(sourcePath, localPath); DVCUtils.moveFiles(sourcePath, localPath);
//拼接生产的元数据后写入yaml文件 //拼接生产的元数据后写入yaml文件
datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String)userInfo.get("nickname"))? userInfo.get("nickname") : userInfo.get("login"))); datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String)userInfo.get("nickname"))? userInfo.get("nickname") : userInfo.get("login")));
datasetVo.setUpdateTime(DateUtils.getTime());
datasetVo.setUpdateTime(DateUtils.getNowDate());
datasetVo.setVersionDesc(datasetVo.getDescription()); datasetVo.setVersionDesc(datasetVo.getDescription());
datasetVo.setUsage("```bash\n" + datasetVo.setUsage("```bash\n" +
"# 克隆数据集配置文件与存储参数到本地\n" + "# 克隆数据集配置文件与存储参数到本地\n" +
@@ -564,7 +564,7 @@ public class DatasetServiceImpl implements DatasetService {
String sourcePath = url.substring(0, url.lastIndexOf("/")); String sourcePath = url.substring(0, url.lastIndexOf("/"));
// 命令行操作 git clone 项目地址 // 命令行操作 git clone 项目地址
if(FileUtil.checkDirectoryExists(localPath)){ if(FileUtil.checkDirectoryExists(localPath)){
DVCUtils.gitFetch(localPath);
DVCUtils.gitFetch(localPath,gitLinkUsername, gitLinkPassword);
DVCUtils.gitCheckoutBranch(localPath,branchName); DVCUtils.gitCheckoutBranch(localPath,branchName);
}else { }else {
DVCUtils.gitClone(localPath, projectUrl, branchName, gitLinkUsername, gitLinkPassword); DVCUtils.gitClone(localPath, projectUrl, branchName, gitLinkUsername, gitLinkPassword);
@@ -575,7 +575,7 @@ public class DatasetServiceImpl implements DatasetService {
DVCUtils.moveFiles(sourcePath, localPath); DVCUtils.moveFiles(sourcePath, localPath);
//拼接生产的元数据后写入yaml文件 //拼接生产的元数据后写入yaml文件
datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String)userInfo.get("nickname"))? userInfo.get("nickname") : userInfo.get("login"))); datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String)userInfo.get("nickname"))? userInfo.get("nickname") : userInfo.get("login")));
datasetVo.setUpdateTime(DateUtils.getTime());
datasetVo.setUpdateTime(DateUtils.getNowDate());
datasetVo.setVersionDesc(datasetVo.getDescription()); datasetVo.setVersionDesc(datasetVo.getDescription());
datasetVo.setUsage("```bash\n" + datasetVo.setUsage("```bash\n" +
"# 克隆数据集配置文件与存储参数到本地\n" + "# 克隆数据集配置文件与存储参数到本地\n" +
@@ -661,8 +661,11 @@ public class DatasetServiceImpl implements DatasetService {


@Override @Override
public NewDatasetVo getNewDatasetDesc(Integer repoId,String repositoryName, String version) { public NewDatasetVo getNewDatasetDesc(Integer repoId,String repositoryName, String version) {
LoginUser loginUser = SecurityUtils.getLoginUser();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
// cd到 localPathlocal/repoId/下面还有一个文件夹,然后做git pull操作,然后读取里面的文件列表,列出每个文件的大小和名称,封装成MAP // cd到 localPathlocal/repoId/下面还有一个文件夹,然后做git pull操作,然后读取里面的文件列表,列出每个文件的大小和名称,封装成MAP
List<Map<String, Object>> fileDetailsAfterGitPull = DVCUtils.getFileDetailsAfterGitPull(localPathlocal+repoId, repositoryName, version);
List<Map<String, Object>> fileDetailsAfterGitPull = DVCUtils.getFileDetailsAfterGitPull(localPathlocal+repoId, repositoryName, version,gitLinkUsername, gitLinkPassword);
//在localPathlocal+repoId+"/"+repositoryName目录下的dataset.yaml中取到元数据 //在localPathlocal+repoId+"/"+repositoryName目录下的dataset.yaml中取到元数据
Map<String, Object> stringObjectMap = YamlUtils.loadYamlFile(localPathlocal + repoId + "/" + repositoryName + "/dataset.yaml"); Map<String, Object> stringObjectMap = YamlUtils.loadYamlFile(localPathlocal + repoId + "/" + repositoryName + "/dataset.yaml");
NewDatasetVo newDatasetVo = ConvertUtil.convertMapToObject(stringObjectMap, NewDatasetVo.class); NewDatasetVo newDatasetVo = ConvertUtil.convertMapToObject(stringObjectMap, NewDatasetVo.class);
@@ -681,6 +684,34 @@ public class DatasetServiceImpl implements DatasetService {
return newDatasetVo; return newDatasetVo;
} }


@Override
public List<Map<String, Object>> getVersionList(String repo, String owner) throws Exception {
LoginUser loginUser = SecurityUtils.getLoginUser();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
String token = gitService.login(gitLinkUsername, gitLinkPassword);
List<Map<String, Object>> brancheList = gitService.getBrancheList(token, owner, repo);
return brancheList;
}

@Override
public void deleteDatasetNew(String repo, String owner) throws Exception {
LoginUser loginUser = SecurityUtils.getLoginUser();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
String token = gitService.login(gitLinkUsername, gitLinkPassword);
gitService.deleteProject(token, owner, repo);
}

@Override
public void deleteDatasetVersionNew(String repo, String owner, String version) throws Exception {
LoginUser loginUser = SecurityUtils.getLoginUser();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
String token = gitService.login(gitLinkUsername, gitLinkPassword);
gitService.deleteBranch(token, owner, repo, version);
}

@Override @Override
public List<Map<String, String>> uploadDatasetlocal(MultipartFile[] files, String uuid) throws Exception { public List<Map<String, String>> uploadDatasetlocal(MultipartFile[] files, String uuid) throws Exception {
List<Map<String, String>> results = new ArrayList<>(); List<Map<String, String>> results = new ArrayList<>();
@@ -708,6 +739,28 @@ public class DatasetServiceImpl implements DatasetService {
return results; return results;
} }


@Override
public ResponseEntity<InputStreamResource> downloadDatasetlocal(String filePath) throws Exception {
File file = new File(filePath);

if (!file.exists()) {
throw new FileNotFoundException("File not found: " + filePath);
}

InputStreamResource resource = new InputStreamResource(new FileInputStream(file));

HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName());
headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length()));
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);

return ResponseEntity.ok()
.headers(headers)
.contentLength(file.length())
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(resource);
}

@Override @Override
public ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String repositoryName, String version) throws Exception { public ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String repositoryName, String version) throws Exception {
// 命令行操作 git clone 项目地址 // 命令行操作 git clone 项目地址


+ 25
- 1
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/GitServiceImpl.java View File

@@ -1,9 +1,9 @@
package com.ruoyi.platform.service.impl; package com.ruoyi.platform.service.impl;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.platform.service.GitService; import com.ruoyi.platform.service.GitService;
import com.ruoyi.platform.utils.HttpUtils; import com.ruoyi.platform.utils.HttpUtils;
import com.ruoyi.platform.utils.JacksonUtil;
import com.ruoyi.platform.utils.JsonUtils; import com.ruoyi.platform.utils.JsonUtils;
import com.ruoyi.platform.vo.GitProjectVo; import com.ruoyi.platform.vo.GitProjectVo;
import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.model.LoginUser;
@@ -14,7 +14,9 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;


import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;


@Service @Service
@@ -95,4 +97,26 @@ public class GitServiceImpl implements GitService {
String req = HttpUtils.sendPostWithToken("https://www.gitlink.org.cn/api/v1/project_topics.json",JsonUtils.objectToJson(resMap),token); String req = HttpUtils.sendPostWithToken("https://www.gitlink.org.cn/api/v1/project_topics.json",JsonUtils.objectToJson(resMap),token);
System.out.println(req); System.out.println(req);
} }

@Override
public List<Map<String, Object>> getBrancheList(String token, String owner, String projectName) throws Exception {
String req = HttpUtils.sendGetWithToken("https://www.gitlink.org.cn/api/v1/"+owner+"/"+projectName+"/branches/all.json",null, token);
// 解析响应JSON
if (StringUtils.isEmpty(req)) {
throw new RuntimeException("终止响应内容为空。");
}
// 将响应的JSON字符串转换为List<Map>对象
List<Map<String, Object>> mapList = JacksonUtil.parseJSONStr2MapList(req);
return mapList;
}

@Override
public void deleteProject(String token, String owner, String projectName) throws Exception {
HttpUtils.sendDeleteRequest("https://www.gitlink.org.cn/api/"+owner+"/"+projectName+".json", token);
}

@Override
public void deleteBranch(String token, String owner, String projectName, String branchName) throws Exception {
HttpUtils.sendDeleteRequest("https://www.gitlink.org.cn/api/v1/"+owner+"/"+projectName+"/branches/"+branchName+".json", token);
}
} }

+ 22
- 21
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java View File

@@ -6,6 +6,8 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.io.*; import java.io.*;
import java.nio.file.*; import java.nio.file.*;
@@ -16,6 +18,8 @@ import java.util.Map;


public class DVCUtils { public class DVCUtils {


private static final Logger log = LoggerFactory.getLogger(DVCUtils.class);

private static void runCommand(String command, String workingDir) throws Exception { private static void runCommand(String command, String workingDir) throws Exception {
ProcessBuilder processBuilder = new ProcessBuilder(command.split(" ")); ProcessBuilder processBuilder = new ProcessBuilder(command.split(" "));
processBuilder.directory(new File(workingDir)); processBuilder.directory(new File(workingDir));
@@ -99,14 +103,17 @@ public class DVCUtils {
} }
} }


public static void gitFetch(String localPath) {
try {
ProcessBuilder pb = new ProcessBuilder("git", "fetch");
pb.directory(new File(localPath));
Process process = pb.start();
process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
public static void gitFetch(String localPath, String username, String password) throws IOException, GitAPIException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(localPath, ".git"))
.readEnvironment()
.findGitDir()
.build();

try (Git git = new Git(repository)) {
CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);
FetchCommand fetchCommand = git.fetch();
fetchCommand.setCredentialsProvider(credentialsProvider).call();
} }
} }
public static void gitCheckoutBranch(String localPath, String branchName) throws IOException, GitAPIException { public static void gitCheckoutBranch(String localPath, String branchName) throws IOException, GitAPIException {
@@ -186,25 +193,19 @@ public class DVCUtils {
* @param branch 分支名称 * @param branch 分支名称
* @return 包含文件路径、名称和大小的List<Map<String, Object>> * @return 包含文件路径、名称和大小的List<Map<String, Object>>
*/ */
public static List<Map<String, Object>> getFileDetailsAfterGitPull(String localPath, String repoFolder, String branch) {
public static List<Map<String, Object>> getFileDetailsAfterGitPull(String localPath, String repoFolder, String branch,String username, String password) {
List<Map<String, Object>> fileInfoList = new ArrayList<>(); List<Map<String, Object>> fileInfoList = new ArrayList<>();


try { try {
// 切换到指定目录 // 切换到指定目录
Path repoPath = Paths.get(localPath, repoFolder); Path repoPath = Paths.get(localPath, repoFolder);


//刷新
gitFetch(localPath, username, password);
// 切换到指定分支 // 切换到指定分支
ProcessBuilder pb = new ProcessBuilder("git", "checkout", branch);
pb.directory(repoPath.toFile());
Process process = pb.start();
process.waitFor();

gitCheckoutBranch(localPath, branch);
// 执行git pull // 执行git pull
pb = new ProcessBuilder("git", "pull");
pb.directory(repoPath.toFile());
process = pb.start();
process.waitFor();

gitPull(localPath, username, password);
// 读取data文件夹中的文件列表 // 读取data文件夹中的文件列表
Path dataPath = Paths.get(repoPath.toString(), "data"); Path dataPath = Paths.get(repoPath.toString(), "data");
File[] files = dataPath.toFile().listFiles(); File[] files = dataPath.toFile().listFiles();
@@ -226,8 +227,8 @@ public class DVCUtils {
} }
} }


} catch (IOException | InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
log.error("Error occurred while getting file details after git pull", e);
} }


return fileInfoList; return fileInfoList;


+ 43
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/HttpUtils.java View File

@@ -9,6 +9,7 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder; import org.apache.http.client.utils.URIBuilder;
@@ -622,4 +623,46 @@ public class HttpUtils {
} }
return resultStr; return resultStr;
} }



// 其他方法保持不变

/**
* 向指定 URL 发送带 token 的 DELETE 方法的请求
*
* @param url 发送请求的 URL
* @param token 认证 token,作为请求头的一部分。
* @return 所代表远程资源的响应结果
* @throws IOException 如果请求失败或发生其他 I/O 错误。
*/
public static String sendDeleteRequest(String url, String token) throws IOException {
String result = "";
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpDelete httpDelete = new HttpDelete(url);

// 设置请求头
httpDelete.setHeader("Authorization", "Bearer " + token);
httpDelete.setHeader("Content-Type", "application/json");

// 创建请求配置
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(15000) // 连接服务区主机超时时间
.setConnectionRequestTimeout(60000) // 连接请求超时时间
.setSocketTimeout(60000) // 设置读取响应数据超时时间
.build();
httpDelete.setConfig(requestConfig);

// 执行请求
try (CloseableHttpResponse response = httpClient.execute(httpDelete)) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 200) {
result = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
} else {
throw new IOException("HTTP request failed with response code: " + statusCode);
}
}
}
return result;
}
} }

+ 1
- 1
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java View File

@@ -53,7 +53,7 @@ public class NewDatasetVo implements Serializable {
@ApiModelProperty(name = "usage",value = "使用示例") @ApiModelProperty(name = "usage",value = "使用示例")
private String usage; private String usage;
@ApiModelProperty(name = "update_time",value = "更新时间") @ApiModelProperty(name = "update_time",value = "更新时间")
private String updateTime;
private Date updateTime;
@ApiModelProperty(name = "processing_code",value = "处理代码") @ApiModelProperty(name = "processing_code",value = "处理代码")
private String processingCode; private String processingCode;




Loading…
Cancel
Save