feat():集数据

master
yuan 2024-09-08 20:09:44 +08:00
parent c2ff30ef26
commit 5785187839
7 changed files with 79 additions and 24 deletions

View File

@ -20,6 +20,8 @@ public class DataSet {
private String ruleVersionType; private String ruleVersionType;
private String ruleVersionText;
private RuleData[][] ruleData; private RuleData[][] ruleData;
} }

View File

@ -1,5 +1,6 @@
package com.muyu.constant; package com.muyu.constant;
import com.muyu.common.domain.DataValue;
import com.muyu.common.domain.RuleData; import com.muyu.common.domain.RuleData;
import com.muyu.common.domain.RuleVersion; import com.muyu.common.domain.RuleVersion;
import com.muyu.common.security.utils.SecurityUtils; import com.muyu.common.security.utils.SecurityUtils;
@ -25,7 +26,8 @@ public class GenerateConstant {
public static final String TYPE_FIELD = "DataValue"; public static final String TYPE_FIELD = "DataValue";
public static final String TYPE_RECORD = "DataRecord"; public static final String TYPE_RECORD = "DataRecord";
public static final String TYPE_SET = "DataSet"; public static final String TYPE_SET = "DataSet";
public static final String ACTION_IMPORT = "import com.muyu.common.domain."; public static final String ACTION_IMPORT_ONE = "import com.muyu.common.domain.DataValue;";
public static final String ACTION_IMPORT_TWO = "import com.muyu.common.domain.";
public static final String SCOPE_IMPORT = "import com.muyu.engine.basic.abstracts."; public static final String SCOPE_IMPORT = "import com.muyu.engine.basic.abstracts.";
public static final String PACKAGE_PATH = "package com.muyu.generate;\n"; public static final String PACKAGE_PATH = "package com.muyu.generate;\n";
@ -44,7 +46,8 @@ public class GenerateConstant {
String type = selectType(ruleData.getRuleRegion()); String type = selectType(ruleData.getRuleRegion());
String level = selectData(ruleData.getRuleRegion()); String level = selectData(ruleData.getRuleRegion());
return PACKAGE_PATH + "\n" + return PACKAGE_PATH + "\n" +
ACTION_IMPORT + type + ";\n" + ACTION_IMPORT_ONE + "\n" +
ACTION_IMPORT_TWO + type + ";\n" +
SCOPE_IMPORT + level + ";\n" + SCOPE_IMPORT + level + ";\n" +
"\n" + "\n" +
"/**\n" + "/**\n" +

View File

@ -12,14 +12,14 @@ import com.muyu.engine.basic.handler.DataEngineSetHandler;
* @Date2024/8/30 11:13 * @Date2024/8/30 11:13
* @Description: * @Description:
*/ */
public abstract class DataEngineSetActuator implements BasicEngine<DataValue> { public abstract class DataEngineSetActuator implements BasicEngine<DataValue[][]> {
public void set(DataValue dataValue){ public void set(DataValue[][] dataValue){
DataEngineSetHandler.set(dataValue); DataEngineSetHandler.set(dataValue);
} }
//获取原始值 //获取原始值
public DataValue get(){ public DataValue[][] get(){
return DataEngineSetHandler.get(); return DataEngineSetHandler.get();
} }

View File

@ -1,6 +1,7 @@
package com.muyu.engine.basic.handler; package com.muyu.engine.basic.handler;
import com.muyu.common.core.text.Convert; import com.muyu.common.core.text.Convert;
import com.muyu.common.domain.DataSet;
import com.muyu.common.domain.DataValue; import com.muyu.common.domain.DataValue;
/** /**
@ -13,24 +14,15 @@ import com.muyu.common.domain.DataValue;
*/ */
public class DataEngineSetHandler { public class DataEngineSetHandler {
public static void set(DataValue dataValue){ public static final ThreadLocal<DataValue[][]> threadLocal = new ThreadLocal<>();
DataEngineHandler.set(dataValue);
public static void set(DataValue[][] dataValue){
threadLocal.set(dataValue);
} }
public static DataValue get(){ public static DataValue[][] get(){
return DataEngineHandler.get(); return threadLocal.get();
} }
public static void remove(){
DataEngineHandler.remove();
}
public static Object getValue(){
return get().getValue();
}
public static Integer getIntegerValue(){
return Convert.toInt(getValue(),null);
}
} }

View File

@ -2,6 +2,7 @@ package com.muyu.controller;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
import com.muyu.common.domain.DataRecord; import com.muyu.common.domain.DataRecord;
import com.muyu.common.domain.DataSet;
import com.muyu.common.domain.RuleVersion; import com.muyu.common.domain.RuleVersion;
import com.muyu.common.domain.req.RuleVersionAddReq; import com.muyu.common.domain.req.RuleVersionAddReq;
import com.muyu.common.domain.req.RuleVersionUpdCodeReq; import com.muyu.common.domain.req.RuleVersionUpdCodeReq;
@ -171,4 +172,12 @@ public class RuleVersionController {
return Result.success(null,"测试成功"); return Result.success(null,"测试成功");
} }
@PostMapping("/set")
@Operation(summary = "集数据测试",description = "数据测试")
public Result<String> set(
@Validated @RequestBody DataSet dataSet){
ruleVersionService.setTest(dataSet);
return Result.success(null,"测试成功");
}
} }

View File

@ -2,6 +2,7 @@ package com.muyu.servier;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.domain.DataRecord; import com.muyu.common.domain.DataRecord;
import com.muyu.common.domain.DataSet;
import com.muyu.common.domain.RuleVersion; import com.muyu.common.domain.RuleVersion;
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;
@ -33,4 +34,6 @@ public interface RuleVersionService extends IService<RuleVersion> {
RuleVersion generatedCode(RuleVersion ruleVersion); RuleVersion generatedCode(RuleVersion ruleVersion);
void rowTest(DataRecord dataRecord); void rowTest(DataRecord dataRecord);
void setTest(DataSet dataSet);
} }

View File

@ -6,10 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
import com.muyu.common.core.enums.SysRuleActivate; import com.muyu.common.core.enums.SysRuleActivate;
import com.muyu.common.core.exception.ServiceException; import com.muyu.common.core.exception.ServiceException;
import com.muyu.common.domain.DataRecord; import com.muyu.common.domain.*;
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.req.RuleVersionUpdReq;
import com.muyu.common.domain.resp.RuleVersionResp; import com.muyu.common.domain.resp.RuleVersionResp;
import com.muyu.compile.FilesCompilerLoad; import com.muyu.compile.FilesCompilerLoad;
@ -51,6 +48,7 @@ public class RuleVersionServiceImpl
static Map<String , BasicEngine<DataValue>> engineValueMap = new ConcurrentHashMap<>(); static Map<String , BasicEngine<DataValue>> engineValueMap = new ConcurrentHashMap<>();
static Map<String , BasicEngine<DataValue[]>> engineRecordMap = new ConcurrentHashMap<>(); static Map<String , BasicEngine<DataValue[]>> engineRecordMap = new ConcurrentHashMap<>();
static Map<String , BasicEngine<DataValue[][]>> engineSetMap = new ConcurrentHashMap<>();
@Override @Override
public List<RuleVersionResp> selectList(Long ruleId) { public List<RuleVersionResp> selectList(Long ruleId) {
@ -174,6 +172,54 @@ public class RuleVersionServiceImpl
} }
@Override
public void setTest(DataSet dataSet) {
//上传java文件
log.info("上传OSS:java文件");
Result<Object> objectResult = ALiYunUpload.uploadJavaFiles(dataSet.getRuleVersionText(), dataSet.getRuleVersionType());
log.info(objectResult.getData());
try {
OSSFileLoad.streamingJavaDownload(dataSet.getRuleVersionType());
} catch (IOException e) {
log.info(e.getMessage());
}
//编译class
System.out.println("执行编译");
FilesCompilerLoad.javaCompiler(dataSet.getRuleVersionType());
//上传class
log.info("上传OSS:class文件");
ALiYunUpload.uploadClassFiles(
dataSet.getRuleVersionType(),
ClassPath+dataSet.getRuleVersionType()+ MethodSuffix.CLASSSUFFIX);
log.info("开始拉取....");
//下载class
try {
OSSFileLoad.streamingClassDownload(dataSet.getRuleVersionType());
} catch (IOException e) {
throw new RuntimeException(e);
}
//对路径里的.class文件进行编译
log.info("执行加载class:[{}]",dataSet.getRuleVersionType());
Result<Class<?>> classResult = FilesCompilerLoad.classLoad(dataSet.getRuleVersionType());
Class<?> clazz = classResult.getData();
try {
Object instance = clazz.getDeclaredConstructor().newInstance();
engineSetMap.put(dataSet.getRuleVersionType(), (BasicEngine<DataValue[][]>) instance);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
public static String getClassName(String versionCode){ public static String getClassName(String versionCode){
String[] splits = versionCode.split("_"); String[] splits = versionCode.split("_");
String className=""; String className="";