Changes
parent
84cbaffed2
commit
0e3489c7ca
|
@ -55,4 +55,9 @@ public class Rule {
|
|||
@Excel(name = "规则描述")
|
||||
private String ruleCode;
|
||||
|
||||
/**
|
||||
* 作用域
|
||||
*/
|
||||
private String ruleScope;
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.rule.controller;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.rule.service.RuleEditionService;
|
||||
import com.muyu.rule.test.OSSFileDownload;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -59,7 +60,7 @@ public class RuleEditionController {
|
|||
|
||||
//java OSS
|
||||
UploadOss.uploadFiles(ruleEdition.getRuleEngine(), ruleEdition.getRuleKind());
|
||||
|
||||
OSSFileDownload.streamingDownload(ruleEdition.getRuleKind());
|
||||
return Result.success(ruleEditionService.save(ruleEdition));
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
package com.muyu.rule.test;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.model.GetObjectRequest;
|
||||
import com.aliyun.oss.model.OSSObject;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class OSSFileDownload {
|
||||
|
||||
// // 阿里云 endpoint
|
||||
// private static final String endpoint = "oss-cn-shanghai.aliyuncs.com";
|
||||
// // 阿里云 accessKeyId
|
||||
// private static final String accessKeyId = "LTAI5t6ytyyHWWB693bMEo53";
|
||||
// // 阿里云 accessKeySecret
|
||||
// private static final String accessKeySecret = "CSubcq72LLVttBlo2XO1JEMEmw894z";
|
||||
// // bucket
|
||||
// private static final String bucketName = "oss-tai";
|
||||
// // 文件路径
|
||||
// private static final String fileNamePath = "oss/";
|
||||
// // 本地文件下载路径
|
||||
//// private static final String localpath = "D:\\oss\\邮箱_SDFGHJ.java";
|
||||
// private static final String localpath = "D:\\oss\\";
|
||||
//
|
||||
// public static Result<Object> streamingDownload(String fileName) {
|
||||
// String source = null;
|
||||
// // 创建 OSSClient 实例
|
||||
// OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
// // 判断 bucket 是否存在
|
||||
// Boolean flag_bucket = ossClient.doesBucketExist(bucketName);
|
||||
// if (!flag_bucket) {
|
||||
// System.out.println("bucket不存在");
|
||||
// return Result.error("bucket不存在");
|
||||
// }
|
||||
// String objectName = fileName + ".java";
|
||||
// Boolean flag_file = ossClient.doesObjectExist(bucketName, localpath + objectName);
|
||||
// if (!flag_file) {
|
||||
// System.out.println("预下载文件不存在");
|
||||
// return Result.error("预下载文件不存在");
|
||||
// }
|
||||
// // 本地文件下载路径
|
||||
// String localPath = "home/" + objectName;
|
||||
// ObjectMetadata object = ossClient.getObject(new GetObjectRequest(bucketName, localpath + objectName), new File(localPath));
|
||||
// System.out.println(object);
|
||||
// ossClient.shutdown();
|
||||
// return Result.success(source);
|
||||
// }
|
||||
|
||||
// 阿里云 endpoint
|
||||
private static final String endpoint = "oss-cn-shanghai.aliyuncs.com";
|
||||
// 阿里云 accessKeyId
|
||||
private static final String accessKeyId = "LTAI5t6ytyyHWWB693bMEo53";
|
||||
// 阿里云 accessKeySecret
|
||||
private static final String accessKeySecret = "CSubcq72LLVttBlo2XO1JEMEmw894z";
|
||||
// bucket
|
||||
private static final String bucketName = "oss-tai";
|
||||
// OSS文件路径
|
||||
private static final String filePath = "oss/";
|
||||
|
||||
public static Result<Object> streamingDownload(String fileName) {
|
||||
String source = null;
|
||||
// 创建 OSSClient 实例
|
||||
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
// 判断 bucket 是否存在
|
||||
Boolean flag_bucket = ossClient.doesBucketExist(bucketName);
|
||||
if (!flag_bucket) {
|
||||
System.out.println("bucket不存在");
|
||||
return Result.error("bucket不存在");
|
||||
}
|
||||
String objectName = fileName + ".java";
|
||||
Boolean flag_file = ossClient.doesObjectExist(bucketName, filePath+objectName);
|
||||
if (!flag_file) {
|
||||
System.out.println("预下载文件不存在");
|
||||
return Result.error("预下载文件不存在");
|
||||
}
|
||||
// 本地文件下载路径
|
||||
String localPath = "home/"+objectName;
|
||||
ObjectMetadata object = ossClient.getObject(new GetObjectRequest(bucketName, filePath + objectName), new File(localPath));
|
||||
System.out.println(object);
|
||||
ossClient.shutdown();
|
||||
return Result.success(source);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue