feat():增加策略
parent
e51c667d94
commit
3763f0b9ad
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.common.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.common.domain
|
||||
* @Project:cloud-rule
|
||||
* @name:DataValue
|
||||
* @Date:2024/8/29 下午4:03
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DataValue {
|
||||
|
||||
private String label;
|
||||
|
||||
private String key;
|
||||
|
||||
private Object value;
|
||||
|
||||
private String type;
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.common.enums;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.common.domain
|
||||
* @Project:cloud-rule
|
||||
* @name:DataType
|
||||
* @Date:2024/8/29 下午4:07
|
||||
*/
|
||||
public enum DataType {
|
||||
VERCHAR("verchar",String.class);
|
||||
|
||||
private final String sourceType;
|
||||
|
||||
private final Class<?> targetType;
|
||||
|
||||
DataType(String sourceType, Class<?> targetType) {
|
||||
this.sourceType = sourceType;
|
||||
this.targetType = targetType;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.muyu.engine;
|
||||
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.BasicEngine;
|
||||
import com.muyu.servier.ENGINE_VALUE_JDIES732842_V1;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine
|
||||
* @Project:cloud-rule
|
||||
* @name:Main
|
||||
* @Date:2024/8/29 下午3:12
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
static Map<String , BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<?> aClass = Class.forName("com.muyu.servier.ENGINE_VALUE_JDIES732842_V1");
|
||||
try {
|
||||
engineMap.put("ENGINE_VALUE_JDIES732842_V1",(BasicEngine<DataValue>) aClass.newInstance());
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
DataValue dataValue = DataValue.builder()
|
||||
.type("String")
|
||||
.label("姓名")
|
||||
.key("name")
|
||||
.value(null)
|
||||
.build();
|
||||
BasicEngine<DataValue> engine = engineMap.get("ENGINE_VALUE_JDIES732842_V1");
|
||||
engine.set(dataValue);
|
||||
engine.execution();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.engine.basic;
|
||||
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.handler.DataEngineValueHandler;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine.basic
|
||||
* @Project:cloud-rule
|
||||
* @name:BasicEngin
|
||||
* @Date:2024/8/29 下午3:13
|
||||
*/
|
||||
public interface BasicEngine<V> {
|
||||
|
||||
public void set(DataValue dataValue);
|
||||
|
||||
//获取原始值
|
||||
public V get();
|
||||
|
||||
public default void remove(){
|
||||
DataEngineValueHandler.remove();
|
||||
}
|
||||
|
||||
public void execution();
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.engine.basic.abstracts;
|
||||
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.BasicEngine;
|
||||
import com.muyu.engine.basic.handler.DataEngineRowHandler;
|
||||
import com.muyu.engine.basic.handler.DataEngineValueHandler;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine.basic.handler
|
||||
* @Project:cloud-rule
|
||||
* @name:DataEngineValueActuator
|
||||
* @Date:2024/8/29 下午4:21
|
||||
* @Description: 数据值处理对象
|
||||
*/
|
||||
public abstract class DataEngineRowActuator implements BasicEngine<DataValue[]> {
|
||||
|
||||
public void set(DataValue[] dataValue){
|
||||
DataEngineRowHandler.set(dataValue);
|
||||
}
|
||||
|
||||
//获取原始值
|
||||
public DataValue[] get(){
|
||||
return DataEngineRowHandler.get();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.engine.basic.abstracts;
|
||||
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.BasicEngine;
|
||||
import com.muyu.engine.basic.handler.DataEngineValueHandler;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine.basic.handler
|
||||
* @Project:cloud-rule
|
||||
* @name:DataEngineValueActuator
|
||||
* @Date:2024/8/29 下午4:21
|
||||
* @Description: 数据值处理对象
|
||||
*/
|
||||
public abstract class DataEngineValueActuator implements BasicEngine<DataValue> {
|
||||
|
||||
public void set(DataValue dataValue){
|
||||
DataEngineValueHandler.set(dataValue);
|
||||
}
|
||||
|
||||
//获取原始值
|
||||
public DataValue get(){
|
||||
return DataEngineValueHandler.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execution() {
|
||||
this.run();
|
||||
this.remove();
|
||||
}
|
||||
|
||||
public abstract void run();
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.engine.basic.handler;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine.basic.handler
|
||||
* @Project:cloud-rule
|
||||
* @name:DataEngineHandler
|
||||
* @Date:2024/8/29 下午3:15
|
||||
* @Description: 规则引擎作用域
|
||||
*/
|
||||
public class DataEngineHandler {
|
||||
|
||||
private static final ThreadLocal<Object> dataEngineHandler = new ThreadLocal<>();
|
||||
|
||||
public static void set(final Object handler) {
|
||||
dataEngineHandler.set(handler);
|
||||
}
|
||||
|
||||
public static <T> T get() {
|
||||
return (T) dataEngineHandler.get();
|
||||
}
|
||||
|
||||
public static void remove(){
|
||||
dataEngineHandler.remove();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.engine.basic.handler;
|
||||
|
||||
import com.muyu.common.core.text.Convert;
|
||||
import com.muyu.common.domain.DataValue;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine.basic.handler
|
||||
* @Project:cloud-rule
|
||||
* @name:DataEngineValueHandler
|
||||
* @Date:2024/8/29 下午3:21
|
||||
* @Description: 数据记录/行作用域
|
||||
*/
|
||||
public class DataEngineRowHandler {
|
||||
|
||||
public static void set(DataValue[] dataValue){
|
||||
DataEngineHandler.set(dataValue);
|
||||
}
|
||||
|
||||
public static DataValue[] get(){
|
||||
return DataEngineHandler.get();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.engine.basic.handler;
|
||||
|
||||
import com.muyu.common.core.text.Convert;
|
||||
import com.muyu.common.domain.DataValue;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine.basic.handler
|
||||
* @Project:cloud-rule
|
||||
* @name:DataEngineValueHandler
|
||||
* @Date:2024/8/29 下午3:21
|
||||
* @Description: 数据自作用域
|
||||
*/
|
||||
public class DataEngineValueHandler {
|
||||
|
||||
public static void set(DataValue dataValue){
|
||||
DataEngineHandler.set(dataValue);
|
||||
}
|
||||
|
||||
public static DataValue get(){
|
||||
return DataEngineHandler.get();
|
||||
}
|
||||
|
||||
public static void remove(){
|
||||
DataEngineHandler.remove();
|
||||
}
|
||||
|
||||
public static Object getValue(){
|
||||
return get().getValue();
|
||||
}
|
||||
|
||||
public static Integer getIntegerValue(){
|
||||
return Convert.toInt(getValue(),null);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.servier;
|
||||
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.abstracts.DataEngineValueActuator;
|
||||
import com.muyu.engine.basic.handler.DataEngineValueHandler;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.servier
|
||||
* @Project:cloud-rule
|
||||
* @name:ENGINE_VALUE_JDIES732842_V1
|
||||
* @Date:2024/8/29 下午4:54
|
||||
*/
|
||||
public class ENGINE_VALUE_JDIES732842_V1 extends DataEngineValueActuator {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
DataValue dataValue = get();
|
||||
if (dataValue == null){
|
||||
System.out.println("数据为空,需要丢弃。");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue