feat():行数据测试
parent
f29abfb9eb
commit
d6aca9b11b
|
@ -20,6 +20,8 @@ public class DataRecord {
|
|||
|
||||
private String ruleVersionType;
|
||||
|
||||
private RuleData[] ruleData;
|
||||
private String ruleVersionTest;
|
||||
|
||||
private DataValue[] dataValues;
|
||||
|
||||
}
|
||||
|
|
|
@ -46,12 +46,12 @@ public class FilesCompilerLoad {
|
|||
System.out.println("编译失败");
|
||||
}
|
||||
|
||||
ALiYunUpload.uploadClassFiles(fileName,"/home/lib/com/muyu/generate/"+fileName+ MethodSuffix.CLASSSUFFIX);
|
||||
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
public static Result<Object> classLoad(String fileName){
|
||||
public static Result<Class<?>> classLoad(String fileName){
|
||||
|
||||
Class<?> clazz ;
|
||||
|
||||
|
@ -78,27 +78,8 @@ public class FilesCompilerLoad {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
return Result.success(clazz);
|
||||
|
||||
engineMap.put(fileName, (BasicEngine<DataValue>) instance);
|
||||
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
DataValue dataValue = DataValue.builder()
|
||||
.type("String")
|
||||
.label("姓名")
|
||||
.key("name")
|
||||
.value("张三")
|
||||
.build();
|
||||
|
||||
BasicEngine<DataValue> engine = engineMap.get(fileName);
|
||||
engine.set(dataValue);
|
||||
engine.execution();
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.engine.basic;
|
||||
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.handler.DataEngineRecordHandler;
|
||||
import com.muyu.engine.basic.handler.DataEngineValueHandler;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine.basic
|
||||
* @Project:cloud-rule
|
||||
* @name:BasicEngin
|
||||
* @Date:2024/8/29 下午3:13
|
||||
* @Description: 规则引擎基准
|
||||
*/
|
||||
public interface BasicRecordEngine<V> {
|
||||
|
||||
public void set(DataValue[] dataValue);
|
||||
|
||||
//获取原始值
|
||||
public V get();
|
||||
|
||||
public default void remove(){
|
||||
DataEngineRecordHandler.remove();
|
||||
}
|
||||
|
||||
public void execution();
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.muyu.engine.basic.abstracts;
|
|||
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.BasicEngine;
|
||||
import com.muyu.engine.basic.BasicRecordEngine;
|
||||
import com.muyu.engine.basic.handler.DataEngineRecordHandler;
|
||||
|
||||
/**
|
||||
|
@ -12,7 +13,7 @@ import com.muyu.engine.basic.handler.DataEngineRecordHandler;
|
|||
* @Date:2024/8/30 上午11:13
|
||||
* @Description: 记录
|
||||
*/
|
||||
public abstract class DataEngineRecordActuator implements BasicEngine<DataValue[]> {
|
||||
public abstract class DataEngineRecordActuator implements BasicRecordEngine<DataValue[]> {
|
||||
|
||||
public void set(DataValue[] dataValue){
|
||||
DataEngineRecordHandler.set(dataValue);
|
||||
|
|
|
@ -13,6 +13,9 @@ import com.muyu.common.domain.DataValue;
|
|||
*/
|
||||
public class DataEngineRecordHandler {
|
||||
|
||||
private static final ThreadLocal<DataValue[]> dataEngineRecordHandler = new ThreadLocal<>();
|
||||
|
||||
|
||||
public static void set(DataValue[] dataValue){
|
||||
DataEngineHandler.set(dataValue);
|
||||
}
|
||||
|
@ -29,8 +32,4 @@ public class DataEngineRecordHandler {
|
|||
return get().getClass();
|
||||
}
|
||||
|
||||
public static Integer getIntegerValue(){
|
||||
return Convert.toInt(getValue(),null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.generate;
|
||||
|
||||
import com.muyu.common.domain.DataRecord;
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.abstracts.DataEngineRecordActuator;
|
||||
|
||||
/**
|
||||
* @Author: admin
|
||||
* @date: 2024/09/07 20:14:51
|
||||
* @Description: 行测试1.0_QWEQWE
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class GenerateRecordQWEQWE extends DataEngineRecordActuator {
|
||||
@Override
|
||||
public void run() {
|
||||
DataValue[] record = get();
|
||||
for (DataValue dataValue : record) {
|
||||
if (dataValue.getKey()!=null && dataValue.getValue()!=null && dataValue.getType() != null && dataValue.getLabel() != null) {
|
||||
System.out.println("数据正常:" + dataValue);
|
||||
} else {
|
||||
System.out.println("数据异常" + dataValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ public class OSSFileLoad {
|
|||
private static final String fileClassPath = "build/version/class/";
|
||||
private static final Logger log = LoggerFactory.getLogger(OSSFileLoad.class);
|
||||
|
||||
public static Result<Object> streamingDownload(String fileName) throws IOException {
|
||||
public static Result<Object> streamingJavaDownload(String fileName) throws IOException {
|
||||
String source = null;
|
||||
// 创建 OSSClient 实例
|
||||
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
|
@ -73,8 +73,6 @@ public class OSSFileLoad {
|
|||
}
|
||||
}
|
||||
//对路径里的.java文件进行编译
|
||||
System.out.println("执行编译");
|
||||
FilesCompilerLoad.javaCompiler(fileName);
|
||||
// SourceCodeCompiler.javaCompilerPath("home/");
|
||||
// System.out.println("第二步");
|
||||
// File outputDir = new File("home/"); // 或者是你指定的其他输出目录
|
||||
|
@ -136,9 +134,7 @@ public class OSSFileLoad {
|
|||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
//对路径里的.class文件进行编译
|
||||
log.info("执行编译class:[{}]",fileName);
|
||||
FilesCompilerLoad.classLoad(fileName);
|
||||
|
||||
return Result.success(source);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,8 +82,7 @@ public class ALiYunUpload {
|
|||
ossClient.putObject(bucketName, objectName, new File(filePath));
|
||||
|
||||
log.info("文件[{}]存储成功",fileName+ MethodSuffix.CLASSSUFFIX);
|
||||
log.info("开始拉取....");
|
||||
OSSFileLoad.streamingClassDownload(fileName);
|
||||
|
||||
return Result.success(null,"文件"+fileName+".class"+"存储成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.domain.DataRecord;
|
||||
import com.muyu.common.domain.RuleVersion;
|
||||
import com.muyu.common.domain.req.RuleVersionAddReq;
|
||||
import com.muyu.common.domain.req.RuleVersionUpdCodeReq;
|
||||
|
@ -158,13 +159,15 @@ public class RuleVersionController {
|
|||
) throws IOException {
|
||||
Result<Object> objectResult = ALiYunUpload.uploadJavaFiles(ruleVersionAddReq.getRuleVersionText(), ruleVersionAddReq.getRuleVersionType());
|
||||
System.out.println(objectResult.getMsg());
|
||||
OSSFileLoad.streamingDownload(ruleVersionAddReq.getRuleVersionType());
|
||||
OSSFileLoad.streamingJavaDownload(ruleVersionAddReq.getRuleVersionType());
|
||||
return Result.success(null,"测试成功");
|
||||
}
|
||||
|
||||
public Result<String> test(
|
||||
|
||||
){
|
||||
@PostMapping("/row")
|
||||
@Operation(summary = "行数据测试",description = "行数据测试")
|
||||
public Result<String> row(
|
||||
@Validated @RequestBody DataRecord dataRecord){
|
||||
ruleVersionService.rowTest(dataRecord);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.servier;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.domain.DataRecord;
|
||||
import com.muyu.common.domain.RuleVersion;
|
||||
import com.muyu.common.domain.req.RuleVersionUpdReq;
|
||||
import com.muyu.common.domain.resp.RuleVersionResp;
|
||||
|
@ -30,4 +31,6 @@ public interface RuleVersionService extends IService<RuleVersion> {
|
|||
public void settingVersionActivate(Long ruleVersionId, String activate);
|
||||
|
||||
RuleVersion generatedCode(RuleVersion ruleVersion);
|
||||
|
||||
void rowTest(DataRecord dataRecord);
|
||||
}
|
||||
|
|
|
@ -3,21 +3,33 @@ package com.muyu.servier.impl;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.enums.SysRuleActivate;
|
||||
import com.muyu.common.core.exception.ServiceException;
|
||||
import com.muyu.common.domain.DataRecord;
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.common.domain.RuleData;
|
||||
import com.muyu.common.domain.RuleVersion;
|
||||
import com.muyu.common.domain.req.RuleVersionUpdReq;
|
||||
import com.muyu.common.domain.resp.RuleVersionResp;
|
||||
import com.muyu.compile.FilesCompilerLoad;
|
||||
import com.muyu.constant.GenerateConstant;
|
||||
import com.muyu.constant.MethodSuffix;
|
||||
import com.muyu.engine.basic.BasicEngine;
|
||||
import com.muyu.load.OSSFileLoad;
|
||||
import com.muyu.mapper.RuleVersionMapper;
|
||||
import com.muyu.servier.RuleDataService;
|
||||
import com.muyu.servier.RuleVersionService;
|
||||
import com.muyu.upload.ALiYunUpload;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
|
@ -26,6 +38,7 @@ import java.util.List;
|
|||
* @name:RuleVersionServiceImpl
|
||||
* @Date:2024/8/27 上午11:47
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class RuleVersionServiceImpl
|
||||
extends ServiceImpl<RuleVersionMapper, RuleVersion>
|
||||
|
@ -34,6 +47,11 @@ public class RuleVersionServiceImpl
|
|||
@Autowired private RuleVersionMapper ruleVersionMapper;
|
||||
@Autowired private RuleDataService ruleDataService;
|
||||
|
||||
public static final String ClassPath = "/home/lib/com/muyu/generate/";
|
||||
|
||||
static Map<String , BasicEngine<DataValue>> engineValueMap = new ConcurrentHashMap<>();
|
||||
static Map<String , BasicEngine<DataRecord>> engineRecordMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public List<RuleVersionResp> selectList(Long ruleId) {
|
||||
List<RuleVersionResp> ruleVersion = ruleVersionMapper.selectByIdList(ruleId);
|
||||
|
@ -80,6 +98,72 @@ public class RuleVersionServiceImpl
|
|||
return ruleVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rowTest(DataRecord dataRecord) {
|
||||
|
||||
//上传java文件
|
||||
ALiYunUpload.uploadJavaFiles(dataRecord.getRuleVersionTest(),dataRecord.getRuleVersionType());
|
||||
|
||||
try {
|
||||
System.out.println("执行编译");
|
||||
OSSFileLoad.streamingJavaDownload(dataRecord.getRuleVersionType());
|
||||
} catch (IOException e) {
|
||||
log.info(e.getMessage());
|
||||
}
|
||||
|
||||
//编译class
|
||||
FilesCompilerLoad.javaCompiler(dataRecord.getRuleVersionType());
|
||||
|
||||
//上传class
|
||||
ALiYunUpload.uploadClassFiles(
|
||||
dataRecord.getRuleVersionType(),
|
||||
ClassPath+dataRecord.getRuleVersionType()+ MethodSuffix.CLASSSUFFIX);
|
||||
log.info("开始拉取....");
|
||||
|
||||
//下载class
|
||||
try {
|
||||
OSSFileLoad.streamingClassDownload(dataRecord.getRuleVersionType());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
//对路径里的.class文件进行编译
|
||||
log.info("执行加载class:[{}]",dataRecord.getRuleVersionType());
|
||||
Result<Class<?>> classResult = FilesCompilerLoad.classLoad(dataRecord.getRuleVersionType());
|
||||
Class<?> clazz = classResult.getData();
|
||||
|
||||
try {
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
|
||||
engineRecordMap.put(dataRecord.getRuleVersionType(), (BasicEngine<DataRecord>) instance);
|
||||
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
DataValue[] dataValues = new DataValue[3];
|
||||
dataValues[0].setKey("id");
|
||||
dataValues[0].setType("bigint");
|
||||
dataValues[0].setLabel("主键ID");
|
||||
dataValues[0].setValue("1");
|
||||
dataValues[1].setKey("name");
|
||||
dataValues[1].setType("string");
|
||||
dataValues[1].setLabel("名字");
|
||||
dataValues[1].setValue("张三");
|
||||
dataValues[2].setKey("age");
|
||||
dataValues[2].setType("int");
|
||||
dataValues[2].setLabel("年龄");
|
||||
dataValues[2].setValue("20");
|
||||
|
||||
dataRecord.setDataValues(dataValues);
|
||||
|
||||
BasicEngine<DataRecord> engine = engineRecordMap.get(dataRecord.getRuleVersionType());
|
||||
engine.set(dataRecord.getDataValues()[3]);
|
||||
engine.execution();
|
||||
|
||||
}
|
||||
|
||||
public static String getClassName(String versionCode){
|
||||
String[] splits = versionCode.split("_");
|
||||
String className="";
|
||||
|
|
Loading…
Reference in New Issue