feat():测试
parent
ceb61b1e37
commit
92136dba5a
|
@ -0,0 +1,63 @@
|
||||||
|
package com.muyu;
|
||||||
|
|
||||||
|
import com.aliyun.oss.OSS;
|
||||||
|
import com.aliyun.oss.OSSClientBuilder;
|
||||||
|
import com.aliyun.oss.model.PutObjectRequest;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu
|
||||||
|
* @Project:cloud-rule
|
||||||
|
* @name:OSSUpload
|
||||||
|
* @Date:2024/9/3 下午3:34
|
||||||
|
*/
|
||||||
|
public class OSSUpload {
|
||||||
|
|
||||||
|
// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写
|
||||||
|
private static final String endpoint = "oss-cn-shanghai.aliyuncs.com" ;
|
||||||
|
// AccessKeyID
|
||||||
|
private static final String accessKeyId = "LTAI5tHKdDATVKeBjFH8mb8D" ;
|
||||||
|
// AccessKeySecret
|
||||||
|
private static final String accessKeySecret = "5ejb4qdgukfD1FdM181kdeAkSuURo7" ;
|
||||||
|
// Bucket名称
|
||||||
|
private static final String bucketName = "java-web-generating-class" ;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||||
|
|
||||||
|
// 上传到OSS后文件保存的目录,例如:folder/subfolder/,最后以斜杠结尾
|
||||||
|
String objectName = "build/version/rule/DataEngineRecordActuator.class";
|
||||||
|
|
||||||
|
try {
|
||||||
|
InputStream inputStream = new FileInputStream("C:\\Users\\13636\\Desktop\\test\\DataEngineRecordActuator.class");
|
||||||
|
//
|
||||||
|
// // 将内容转换为字节数组输入流
|
||||||
|
// ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
// 构造上传请求
|
||||||
|
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);
|
||||||
|
|
||||||
|
// 执行上传操作
|
||||||
|
ossClient.putObject(putObjectRequest);
|
||||||
|
|
||||||
|
System.out.println("文件"+"DataEngineRecordActuator.class"+"存储成功");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.println("文件"+"DataEngineRecordActuator.class"+"存储成功");
|
||||||
|
} finally {
|
||||||
|
// 关闭OSSClient
|
||||||
|
if (ossClient != null) {
|
||||||
|
ossClient.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.muyu.load;
|
||||||
|
|
||||||
|
import com.aliyun.oss.OSSClient;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.compile.OSSFileCompile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.load
|
||||||
|
* @Project:cloud-rule
|
||||||
|
* @name:Load
|
||||||
|
* @Date:2024/9/3 下午3:57
|
||||||
|
*/
|
||||||
|
public class Load {
|
||||||
|
|
||||||
|
// 阿里云 endpoint
|
||||||
|
private static final String endpoint = "oss-cn-shanghai.aliyuncs.com";
|
||||||
|
// 阿里云 accessKeyId
|
||||||
|
private static final String accessKeyId = "LTAI5tHKdDATVKeBjFH8mb8D";
|
||||||
|
// 阿里云 accessKeySecret
|
||||||
|
private static final String accessKeySecret = "5ejb4qdgukfD1FdM181kdeAkSuURo7";
|
||||||
|
// bucket
|
||||||
|
private static final String bucketName = "java-web-generating-class";
|
||||||
|
// OSS文件路径
|
||||||
|
private static final String filePath = "build/version/rule/";
|
||||||
|
public static Result<Object> streamingDownload(String fileName) throws IOException {
|
||||||
|
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不存在");
|
||||||
|
}
|
||||||
|
Boolean flag_file = ossClient.doesObjectExist(bucketName, filePath+fileName);
|
||||||
|
if (!flag_file) {
|
||||||
|
System.out.println("预下载文件不存在");
|
||||||
|
return Result.error("预下载文件不存在");
|
||||||
|
}
|
||||||
|
// 本地文件下载路径
|
||||||
|
String localPath = "home/lib/"+fileName;
|
||||||
|
// ObjectMetadata object = ossClient.getObject(new GetObjectRequest(bucketName, filePath + fileName), new File(localPath));
|
||||||
|
// System.out.println(object);
|
||||||
|
//
|
||||||
|
// ossClient.shutdown();
|
||||||
|
try {
|
||||||
|
// 从OSS下载文件
|
||||||
|
InputStream inputStream = ossClient.getObject(bucketName, filePath+fileName).getObjectContent();
|
||||||
|
File downloadFile = new File(localPath);
|
||||||
|
FileOutputStream outputStream = new FileOutputStream(downloadFile);
|
||||||
|
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = inputStream.read(buffer)) != -1) {
|
||||||
|
outputStream.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
outputStream.close();
|
||||||
|
inputStream.close();
|
||||||
|
|
||||||
|
System.out.println("存放路径:" + localPath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
// 关闭OSSClient
|
||||||
|
if (ossClient != null) {
|
||||||
|
ossClient.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result.success(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -46,7 +46,7 @@ public class OSSFileLoad {
|
||||||
return Result.error("预下载文件不存在");
|
return Result.error("预下载文件不存在");
|
||||||
}
|
}
|
||||||
// 本地文件下载路径
|
// 本地文件下载路径
|
||||||
String localPath = "home/"+fileName;
|
String localPath = "home/lib/"+fileName;
|
||||||
// ObjectMetadata object = ossClient.getObject(new GetObjectRequest(bucketName, filePath + fileName), new File(localPath));
|
// ObjectMetadata object = ossClient.getObject(new GetObjectRequest(bucketName, filePath + fileName), new File(localPath));
|
||||||
// System.out.println(object);
|
// System.out.println(object);
|
||||||
//
|
//
|
||||||
|
@ -76,7 +76,7 @@ public class OSSFileLoad {
|
||||||
}
|
}
|
||||||
//对路径里的.java文件进行编译
|
//对路径里的.java文件进行编译
|
||||||
System.out.println("第一步");
|
System.out.println("第一步");
|
||||||
OSSFileCompile.compile("home/"+fileName);
|
OSSFileCompile.compile("home/lib/"+fileName);
|
||||||
// SourceCodeCompiler.javaCompilerFile("home/"+fileName);
|
// SourceCodeCompiler.javaCompilerFile("home/"+fileName);
|
||||||
// System.out.println("第二步");
|
// System.out.println("第二步");
|
||||||
// File outputDir = new File("home/"); // 或者是你指定的其他输出目录
|
// File outputDir = new File("home/"); // 或者是你指定的其他输出目录
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.muyu.common.domain.req.RuleDataUpdReq;
|
||||||
import com.muyu.common.domain.req.RuleVersionAddReq;
|
import com.muyu.common.domain.req.RuleVersionAddReq;
|
||||||
import com.muyu.common.domain.req.RuleVersionUpdReq;
|
import com.muyu.common.domain.req.RuleVersionUpdReq;
|
||||||
import com.muyu.common.domain.resp.RuleVersionResp;
|
import com.muyu.common.domain.resp.RuleVersionResp;
|
||||||
|
import com.muyu.load.Load;
|
||||||
import com.muyu.load.OSSFileLoad;
|
import com.muyu.load.OSSFileLoad;
|
||||||
import com.muyu.servier.RuleVersionService;
|
import com.muyu.servier.RuleVersionService;
|
||||||
import com.muyu.upload.ALiYunUpload;
|
import com.muyu.upload.ALiYunUpload;
|
||||||
|
@ -131,6 +132,13 @@ public class RuleVersionController {
|
||||||
return Result.success(ruleVersionService.generatedCode(ruleVersion));
|
return Result.success(ruleVersionService.generatedCode(ruleVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/loadClass")
|
||||||
|
public Result<Object> OSSLoadFileClass() throws IOException {
|
||||||
|
Load.streamingDownload("DataEngineRecordActuator.class");
|
||||||
|
Load.streamingDownload("DataEngineSetActuator.class");
|
||||||
|
Load.streamingDownload("DataEngineValueActuator.class");
|
||||||
|
Load.streamingDownload("DataValue.class");
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue