Browse Source

基础框架发布: 8.2.23

1) 规则引擎中, 修复指标库参数构建器未抛出违例的bug
  2)增加反射设置属性值的方法,便于脚本调用
main
wangshaoping 2 months ago
parent
commit
5c835e1805
  1. 3
      io.sc.engine.rule.core/src/main/resources/io/sc/engine/rule/core/code/java/template/impl/lib.tpl
  2. 29
      io.sc.platform.util/src/main/java/io/sc/platform/util/ReflectUtil.java

3
io.sc.engine.rule.core/src/main/resources/io/sc/engine/rule/core/code/java/template/impl/lib.tpl

@ -129,6 +129,9 @@ public class #(className(lib.code,lib.version)) {
@JsonIgnoreProperties(ignoreUnknown=true) @JsonIgnoreProperties(ignoreUnknown=true)
static class Argument { static class Argument {
#(tabs(IndicatorGenerator.generateFields(lib.indicators),2)) #(tabs(IndicatorGenerator.generateFields(lib.indicators),2))
Argument() throws Exception {}
public static Argument convertArgument(Map<String,Object> map) throws Exception { public static Argument convertArgument(Map<String,Object> map) throws Exception {
if(map!=null){ if(map!=null){
Argument arg =new Argument(); Argument arg =new Argument();

29
io.sc.platform.util/src/main/java/io/sc/platform/util/ReflectUtil.java

@ -2,6 +2,7 @@ package io.sc.platform.util;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -134,4 +135,32 @@ public class ReflectUtil {
Method method =clazz.getDeclaredMethod(methodName, innerParameterTypes); Method method =clazz.getDeclaredMethod(methodName, innerParameterTypes);
return (T)method.invoke(clazz, parameters); return (T)method.invoke(clazz, parameters);
} }
public static Object getFieldValue(Object target, String fieldName) throws IllegalAccessException {
if(target==null) { return null; }
if(!StringUtils.hasText(fieldName)) { return null; }
Field field =null;
try{
field =target.getClass().getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
return null;
}
if(field==null) { return null; }
field.setAccessible(true);
return field.get(target);
}
public static void setFieldValue(Object target, String fieldName,Object value) throws IllegalAccessException {
if(target==null) { return; }
if(!StringUtils.hasText(fieldName)) { return; }
Field field =null;
try{
field =target.getClass().getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
return;
}
if(field==null) { return; }
field.setAccessible(true);
field.set(target,value);
}
} }

Loading…
Cancel
Save