feat():测试
parent
4823fb68e3
commit
cfb1982f75
|
@ -1,77 +0,0 @@
|
|||
package com.muyu.load;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -26,6 +26,7 @@ public class OSSFileLoad {
|
|||
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 实例
|
||||
|
@ -43,10 +44,7 @@ public class OSSFileLoad {
|
|||
}
|
||||
// 本地文件下载路径
|
||||
String localPath = "home/" + fileName + MethodSuffix.JAVASUFFIX;
|
||||
// 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 + MethodSuffix.JAVASUFFIX).getObjectContent();
|
||||
|
@ -71,7 +69,7 @@ public class OSSFileLoad {
|
|||
}
|
||||
}
|
||||
//对路径里的.java文件进行编译
|
||||
System.out.println("第一步");
|
||||
System.out.println("执行编译");
|
||||
JavaFileCompile.compile(fileName);
|
||||
// SourceCodeCompiler.javaCompilerPath("home/");
|
||||
// System.out.println("第二步");
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
package com.muyu.upload;
|
||||
|
||||
import com.aliyun.oss.ClientException;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.OSSException;
|
||||
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
|
||||
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import com.aliyun.oss.model.PutObjectResult;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import com.muyu.constant.MethodSuffix;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
|
@ -34,22 +27,20 @@ public class ALiYunUpload {
|
|||
// Bucket名称
|
||||
private static final String bucketName = "java-web-generating-class" ;
|
||||
|
||||
public static Result<Object> uploadFiles(String content, String fileName) {
|
||||
public static Result<Object> uploadJavaFiles(String JavaContent, String fileName) {
|
||||
|
||||
|
||||
System.out.println(content);
|
||||
System.out.println(JavaContent);
|
||||
|
||||
System.out.println(fileName);
|
||||
|
||||
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
|
||||
// 上传到OSS后文件保存的目录,例如:folder/subfolder/,最后以斜杠结尾
|
||||
String objectName = "build/version/rule/"+fileName+".java";
|
||||
String objectName = "build/version/java/" + fileName + MethodSuffix.JAVASUFFIX;
|
||||
|
||||
try {
|
||||
// 将内容转换为字节数组输入流
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(JavaContent.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// 构造上传请求
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);
|
||||
|
@ -72,4 +63,40 @@ public class ALiYunUpload {
|
|||
|
||||
}
|
||||
|
||||
public static Result<Object> uploadClassFiles(String classContent, String fileName) {
|
||||
|
||||
System.out.println(classContent);
|
||||
|
||||
System.out.println(fileName);
|
||||
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
|
||||
// 上传到OSS后文件保存的目录,例如:folder/subfolder/,最后以斜杠结尾
|
||||
String objectName = "build/version/class/"+fileName+MethodSuffix.CLASSSUFFIX;
|
||||
|
||||
try {
|
||||
// 将内容转换为字节数组输入流
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(classContent.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// 构造上传请求
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);
|
||||
|
||||
// 执行上传操作
|
||||
ossClient.putObject(putObjectRequest);
|
||||
|
||||
return Result.success(null,"文件"+fileName+".class"+"存储成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
return Result.error(null,"文件"+fileName+".class"+"存储失败");
|
||||
} finally {
|
||||
// 关闭OSSClient
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package com.muyu.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.domain.RuleData;
|
||||
import com.muyu.common.domain.RuleVersion;
|
||||
import com.muyu.common.domain.req.RuleDataAddReq;
|
||||
import com.muyu.common.domain.req.RuleDataUpdReq;
|
||||
import com.muyu.common.domain.req.RuleVersionAddReq;
|
||||
import com.muyu.common.domain.req.RuleVersionUpdReq;
|
||||
import com.muyu.common.domain.resp.RuleVersionResp;
|
||||
import com.muyu.load.Load;
|
||||
import com.muyu.load.OSSFileLoad;
|
||||
import com.muyu.servier.RuleVersionService;
|
||||
import com.muyu.upload.ALiYunUpload;
|
||||
|
@ -60,11 +56,8 @@ public class RuleVersionController {
|
|||
@Operation(summary = "规则版本接口添加",description = "根据客户需求创建对应规则版本")
|
||||
public Result<String> add(
|
||||
@Validated @RequestBody RuleVersionAddReq ruleVersionAddReq
|
||||
) throws IOException {
|
||||
){
|
||||
ruleVersionService.save(RuleVersion.addBuild(ruleVersionAddReq));
|
||||
Result<Object> objectResult = ALiYunUpload.uploadFiles(ruleVersionAddReq.getRuleVersionText(), ruleVersionAddReq.getRuleVersionType());
|
||||
System.out.println(objectResult.getMsg());
|
||||
OSSFileLoad.streamingDownload(ruleVersionAddReq.getRuleVersionType());
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
|
@ -132,21 +125,6 @@ public class RuleVersionController {
|
|||
return Result.success(ruleVersionService.generatedCode(ruleVersion));
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载class文件
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/loadClass")
|
||||
@Operation(summary = "加载class文件",description = "在进行编译java类时需先加载class文件")
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ID修改版本代码
|
||||
* @param ruleVersionId
|
||||
|
@ -163,6 +141,21 @@ public class RuleVersionController {
|
|||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 版本测试
|
||||
* @param ruleVersionAddReq
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/compileLoad")
|
||||
@Operation(summary = "版本测试",description = "版本测试")
|
||||
public Result<String> compileLoad(
|
||||
@Validated @RequestBody RuleVersionAddReq ruleVersionAddReq
|
||||
) throws IOException {
|
||||
Result<Object> objectResult = ALiYunUpload.uploadJavaFiles(ruleVersionAddReq.getRuleVersionText(), ruleVersionAddReq.getRuleVersionType());
|
||||
System.out.println(objectResult.getMsg());
|
||||
OSSFileLoad.streamingDownload(ruleVersionAddReq.getRuleVersionType());
|
||||
return Result.success(null,"测试成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue