524 changed files with 68213 additions and 23 deletions
@ -0,0 +1,10 @@ |
|||
package io.sc.engine.rule.client.spring.service; |
|||
|
|||
import io.sc.engine.rule.client.Loader; |
|||
|
|||
/** |
|||
* 本地资源定义加载器接口 |
|||
*/ |
|||
public interface LocalLoader extends Loader{ |
|||
|
|||
} |
@ -0,0 +1,94 @@ |
|||
package io.sc.engine.rule.client.spring.service.impl; |
|||
|
|||
import java.lang.reflect.Method; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.context.ApplicationContext; |
|||
import org.springframework.stereotype.Service; |
|||
import io.sc.engine.rule.client.spring.service.LocalLoader; |
|||
import io.sc.engine.rule.core.classes.ResourceAbstract; |
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
|
|||
@Service("reLocalLoader") |
|||
public class LocalLoaderImpl implements LocalLoader{ |
|||
@Autowired private ApplicationContext applicationContext; |
|||
private Map<String,ResourceWrapper> cache =new ConcurrentHashMap<String,ResourceWrapper>(); |
|||
|
|||
@Override |
|||
public void cleanCache() throws Exception { |
|||
cache.clear(); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceWrapper getResourceById(String resourceId) throws Exception { |
|||
Object bean =applicationContext.getBean("reResourceService"); |
|||
if(bean!=null) { |
|||
Method method =bean.getClass().getMethod("getDefineById", String.class); |
|||
ResourceWrapper result =(ResourceWrapper)method.invoke(bean, resourceId); |
|||
return result; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public ResourceWrapper getResourceByCode(String resourceCode, Integer version) throws Exception { |
|||
if(version==null) {//未指定版本时,不缓存,加载最新的
|
|||
Object bean =applicationContext.getBean("reResourceService"); |
|||
if(bean!=null) { |
|||
Method method =bean.getClass().getMethod("getDefineByCode", String.class,Integer.class); |
|||
return (ResourceWrapper)method.invoke(bean, resourceCode,version); |
|||
} |
|||
}else {//指定版本时,缓存
|
|||
if(resourceCode!=null && !"".equals(resourceCode.trim())) { |
|||
String key =getCacheKey(resourceCode,version); |
|||
ResourceWrapper wrapper =cache.get(key); |
|||
if(wrapper!=null) { |
|||
return wrapper; |
|||
}else { |
|||
Object bean =applicationContext.getBean("reResourceService"); |
|||
if(bean!=null) { |
|||
Method method =bean.getClass().getMethod("getDefineByCode", String.class,Integer.class); |
|||
wrapper =(ResourceWrapper)method.invoke(bean, resourceCode,version); |
|||
if(wrapper!=null) { |
|||
key =getCacheKey(resourceCode,version); |
|||
if(key!=null && !"".equals(key.trim())) { |
|||
cache.put(key, wrapper); |
|||
return wrapper; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@SuppressWarnings("all") |
|||
@Override |
|||
public List<ResourceAbstract> getAllReleasableResourceAbstract() throws Exception { |
|||
Object bean =applicationContext.getBean("reResourceService"); |
|||
if(bean!=null) { |
|||
Method method =bean.getClass().getMethod("getAllReleasableResourceAbstract"); |
|||
if(method!=null) { |
|||
return (List<ResourceAbstract>)method.invoke(bean); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
private String getCacheKey(String code,Integer version) { |
|||
String result =""; |
|||
if(code!=null && !"".equals(code.trim())) { |
|||
result +=code; |
|||
} |
|||
if(version!=null) { |
|||
result +="_" + version; |
|||
} |
|||
return result; |
|||
} |
|||
} |
@ -0,0 +1 @@ |
|||
io.sc.engine.rule.client.spring.initializer.AutoCompileDeployedModelInitializer |
@ -0,0 +1,44 @@ |
|||
package io.sc.engine.rule.client; |
|||
|
|||
import io.sc.engine.rule.core.classes.ResourceAbstract; |
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
|
|||
/** |
|||
* 客户端模型定义加载器接口 |
|||
*/ |
|||
public interface Loader { |
|||
/** |
|||
* 获取资源定义 |
|||
* 说明: 通过 ID 加载资源定义时,系统不做缓存 |
|||
* @param resourceId 资源唯一标识 |
|||
* @return 资源定义 PO 对象 |
|||
* @throws Exception 违例 |
|||
*/ |
|||
public ResourceWrapper getResourceById(String resourceId) throws Exception; |
|||
|
|||
/** |
|||
* 获取资源定义 |
|||
* 说明: 通过代码和版本加载资源定义时,如果有版本,则缓存,反之,不缓存 |
|||
* @param resourceCode 资源代码 |
|||
* @param version 资源版本 |
|||
* @return 资源定义 PO 对象 |
|||
* @throws Exception 违例 |
|||
*/ |
|||
public ResourceWrapper getResourceByCode(String resourceCode,Integer version) throws Exception; |
|||
|
|||
/** |
|||
* 获取所有顶级资源摘要信息 |
|||
* @return 所有顶级资源摘要信息 |
|||
* @throws Exception 违例 |
|||
*/ |
|||
public List<ResourceAbstract> getAllReleasableResourceAbstract() throws Exception; |
|||
|
|||
/** |
|||
* 清除已经加载的模型定义缓存 |
|||
* @throws Exception 违例 |
|||
*/ |
|||
public void cleanCache() throws Exception; |
|||
} |
@ -0,0 +1,18 @@ |
|||
package io.sc.engine.rule.client.enums; |
|||
|
|||
/** |
|||
* 模型定义加载器模式 |
|||
*/ |
|||
public enum LoaderMode { |
|||
LOCAL, //本地
|
|||
REMOTE; //远程
|
|||
|
|||
public static LoaderMode parse(String str) { |
|||
if("LOCAL".equalsIgnoreCase(str)) { |
|||
return LoaderMode.LOCAL; |
|||
}else if("REMOTE".equalsIgnoreCase(str)) { |
|||
return LoaderMode.REMOTE; |
|||
} |
|||
return null; |
|||
} |
|||
} |
@ -0,0 +1,134 @@ |
|||
package io.sc.engine.rule.client.local; |
|||
|
|||
import io.sc.engine.rule.client.Executor; |
|||
import io.sc.engine.rule.client.Loader; |
|||
import io.sc.engine.rule.client.runtime.EngineRuntime; |
|||
import io.sc.engine.rule.core.code.impl.support.ResourceResult; |
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
|
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 本地执行客户端 |
|||
*/ |
|||
public class LocalExecutor implements Executor { |
|||
private Loader loader; |
|||
|
|||
public LocalExecutor() {} |
|||
|
|||
public LocalExecutor(Loader loader) { |
|||
this.loader =loader; |
|||
} |
|||
|
|||
@Override |
|||
public void compileById(String resourceId) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceById(resourceId); |
|||
EngineRuntime.getInstance().compileById(resourceId,wrapper); |
|||
} |
|||
|
|||
@Override |
|||
public void compileByCode(String resourceCode, Integer version) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceByCode(resourceCode,version); |
|||
EngineRuntime.getInstance().compileByCode(resourceCode,version,wrapper); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeById(String resourceId, String json) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceById(resourceId); |
|||
return EngineRuntime.getInstance().executeById(this,resourceId,wrapper, json); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeById(String resourceId, String subModelCode, String json) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceById(resourceId); |
|||
return EngineRuntime.getInstance().executeById(this,resourceId,wrapper,subModelCode,json); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeById(String resourceId, Map<String, Object> map) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceById(resourceId); |
|||
return EngineRuntime.getInstance().executeById(this,resourceId,wrapper, map); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeById(String resourceId, String subModelCode, Map<String, Object> map) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceById(resourceId); |
|||
return EngineRuntime.getInstance().executeById(this,resourceId,wrapper,subModelCode,map); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCode(String resourceCode, Integer version, String json) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceByCode(resourceCode, version); |
|||
return EngineRuntime.getInstance().executeByCode(this,resourceCode,version,wrapper, json); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCode(String resourceCode, Integer version, String subModelCode, String json) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceByCode(resourceCode, version); |
|||
return EngineRuntime.getInstance().executeByCode(this,resourceCode,version,wrapper,subModelCode,json); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCode(String resourceCode, Integer version, Map<String, Object> map) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceByCode(resourceCode, version); |
|||
return EngineRuntime.getInstance().executeByCode(this,resourceCode,version,wrapper, map); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCode(String resourceCode, Integer version, String subModelCode, Map<String, Object> map) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceByCode(resourceCode, version); |
|||
return EngineRuntime.getInstance().executeByCode(this,resourceCode,version,wrapper,subModelCode,map); |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public void compileByIdForTest(String resourceId) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceById(resourceId); |
|||
wrapper.setIsExecuteTestCase(true); |
|||
EngineRuntime.getInstance().compileById(resourceId,wrapper); |
|||
} |
|||
|
|||
@Override |
|||
public void compileByCodeForTest(String resourceCode, Integer version) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceByCode(resourceCode,version); |
|||
wrapper.setIsExecuteTestCase(true); |
|||
EngineRuntime.getInstance().compileByCode(resourceCode,version,wrapper); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByIdForTest(String resourceId, Map<String, Object> map) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceById(resourceId); |
|||
wrapper.setIsExecuteTestCase(true); |
|||
return EngineRuntime.getInstance().executeById(this,resourceId,wrapper, map); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByIdForTest(String resourceId, String subModelCode, Map<String, Object> map) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceById(resourceId); |
|||
wrapper.setIsExecuteTestCase(true); |
|||
return EngineRuntime.getInstance().executeById(this,resourceId,wrapper,subModelCode,map); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCodeForTest(String resourceCode, Integer version, Map<String, Object> map) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceByCode(resourceCode, version); |
|||
wrapper.setIsExecuteTestCase(true); |
|||
return EngineRuntime.getInstance().executeByCode(this,resourceCode,version,wrapper, map); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCodeForTest(String resourceCode, Integer version, String subModelCode, Map<String, Object> map) throws Exception { |
|||
ResourceWrapper wrapper =loader.getResourceByCode(resourceCode, version); |
|||
wrapper.setIsExecuteTestCase(true); |
|||
return EngineRuntime.getInstance().executeByCode(this,resourceCode,version,wrapper,subModelCode,map); |
|||
} |
|||
|
|||
public Loader getLoader() { |
|||
return loader; |
|||
} |
|||
|
|||
public void setLoader(Loader loader) { |
|||
this.loader = loader; |
|||
} |
|||
} |
@ -0,0 +1,148 @@ |
|||
package io.sc.engine.rule.client.remote; |
|||
|
|||
import java.util.Map; |
|||
|
|||
import io.sc.engine.rule.client.Executor; |
|||
import io.sc.engine.rule.client.Loader; |
|||
import io.sc.engine.rule.core.code.impl.support.ResourceResult; |
|||
import io.sc.engine.rule.core.util.HttpRequestUtil; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
/** |
|||
* 远程执行客户端 |
|||
*/ |
|||
public class RemoteExecutor implements Executor{ |
|||
private String remoteApiUrl; |
|||
private Loader loader; |
|||
|
|||
public RemoteExecutor() {} |
|||
public RemoteExecutor(String remoteApiUrl) { |
|||
this.remoteApiUrl =remoteApiUrl; |
|||
this.loader =new RemoteLoader(remoteApiUrl); |
|||
} |
|||
|
|||
@Override |
|||
public void compileById(String resourceId) throws Exception { |
|||
throw new RuntimeException("Remote Executor NOT Supported compile!"); |
|||
} |
|||
|
|||
@Override |
|||
public void compileByCode(String resourceCode, Integer version) throws Exception { |
|||
throw new RuntimeException("Remote Executor NOT Supported compile!"); |
|||
} |
|||
@Override |
|||
public ResourceResult executeById(String resourceId,String json) throws Exception { |
|||
String result =HttpRequestUtil.post(getApiUrlById(resourceId), "",json); |
|||
return JacksonObjectMapper.getDefaultObjectMapper().readValue(result, ResourceResult.class); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeById(String resourceId, String subModelCode, String json) throws Exception { |
|||
String result =HttpRequestUtil.post(getApiUrlById(resourceId,subModelCode), "",json); |
|||
return JacksonObjectMapper.getDefaultObjectMapper().readValue(result, ResourceResult.class); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeById(String resourceId, Map<String, Object> map) throws Exception { |
|||
return executeById(resourceId,JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(map)); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeById(String resourceId, String subModelCode, Map<String, Object> map) throws Exception { |
|||
return executeById(resourceId,subModelCode,JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(map)); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCode(String resourceCode, Integer version,String json) throws Exception{ |
|||
return executeByCode(resourceCode,version,null,json); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCode(String resourceCode, Integer version, String subModelCode, String json) throws Exception { |
|||
String result =HttpRequestUtil.post(getApiUrlByCode(resourceCode,version,subModelCode), "",json); |
|||
return JacksonObjectMapper.getDefaultObjectMapper().readValue(result, ResourceResult.class); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCode(String resourceCode, Integer version, Map<String, Object> map) throws Exception { |
|||
return executeByCode(resourceCode,version,JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(map)); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCode(String resourceCode, Integer version, String subModelCode, Map<String, Object> map) throws Exception { |
|||
return executeByCode(resourceCode,version,subModelCode,JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(map)); |
|||
} |
|||
|
|||
@Override |
|||
public void compileByIdForTest(String resourceId) throws Exception { |
|||
throw new RuntimeException("Remote Executor NOT Supported test mode compile!"); |
|||
} |
|||
|
|||
@Override |
|||
public void compileByCodeForTest(String resourceCode, Integer version) throws Exception { |
|||
throw new RuntimeException("Remote Executor NOT Supported test mode compile!"); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByIdForTest(String resourceId, Map<String, Object> map) throws Exception { |
|||
throw new RuntimeException("Remote Executor NOT Supported test mode execute!"); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByIdForTest(String resourceId, String subModelCode, Map<String, Object> map) throws Exception { |
|||
throw new RuntimeException("Remote Executor NOT Supported test mode execute!"); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCodeForTest(String resourceCode, Integer version, Map<String, Object> map) throws Exception { |
|||
throw new RuntimeException("Remote Executor NOT Supported test mode execute!"); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceResult executeByCodeForTest(String resourceCode, Integer version, String subModelCode, Map<String, Object> map) throws Exception { |
|||
throw new RuntimeException("Remote Executor NOT Supported test mode execute!"); |
|||
} |
|||
|
|||
public String getRemoteApiUrl() { |
|||
return remoteApiUrl; |
|||
} |
|||
public void setRemoteApiUrl(String remoteApiUrl) { |
|||
this.remoteApiUrl = remoteApiUrl; |
|||
} |
|||
|
|||
public Loader getLoader() { |
|||
return loader; |
|||
} |
|||
|
|||
public void setLoader(Loader loader) { |
|||
this.loader = loader; |
|||
} |
|||
|
|||
private String getApiUrlById(String resourceId) { |
|||
return remoteApiUrl + "/executeById?resourceId=" + resourceId; |
|||
} |
|||
|
|||
private String getApiUrlById(String resourceId,String subModelCode) { |
|||
if(subModelCode!=null && !subModelCode.trim().isEmpty()) { |
|||
return remoteApiUrl + "/executeById?resourceId=" + resourceId + "&subModelCode=" + subModelCode; |
|||
}else { |
|||
return remoteApiUrl + "/executeById?resourceId=" + resourceId; |
|||
} |
|||
} |
|||
|
|||
private String getApiUrlByCode(String resourceCode,Integer version,String subModelCode) { |
|||
if(version!=null) { |
|||
if(subModelCode!=null && !subModelCode.trim().isEmpty()) { |
|||
return remoteApiUrl + "/executeByCode?resourceCode=" + resourceCode + "&version=" + version + "&subModelCode=" + subModelCode; |
|||
}else { |
|||
return remoteApiUrl + "/executeByCode?resourceCode=" + resourceCode + "&version=" + version; |
|||
} |
|||
}else { |
|||
if(subModelCode!=null && !subModelCode.trim().isEmpty()) { |
|||
return remoteApiUrl + "/executeByCode?resourceCode=" + resourceCode + "&subModelCode=" + subModelCode; |
|||
}else { |
|||
return remoteApiUrl + "/executeByCode?resourceCode=" + resourceCode; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,112 @@ |
|||
package io.sc.engine.rule.client.remote; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
|
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import io.sc.engine.rule.client.Loader; |
|||
import io.sc.engine.rule.core.classes.ResourceAbstract; |
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
import io.sc.engine.rule.core.util.HttpRequestUtil; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.core.type.TypeReference; |
|||
|
|||
public class RemoteLoader implements Loader{ |
|||
private static final Logger log =LoggerFactory.getLogger(RemoteLoader.class); |
|||
private String remoteApiUrl; |
|||
private Map<String,ResourceWrapper> cache =new ConcurrentHashMap<String,ResourceWrapper>(); |
|||
|
|||
public RemoteLoader() {} |
|||
public RemoteLoader(String remoteApiUrl) { |
|||
this.remoteApiUrl =remoteApiUrl; |
|||
} |
|||
|
|||
@Override |
|||
public void cleanCache() throws Exception { |
|||
cache.clear(); |
|||
} |
|||
|
|||
@Override |
|||
public ResourceWrapper getResourceById(String resourceId) throws Exception { |
|||
if(resourceId!=null && !"".equals(resourceId.trim())) { |
|||
String json =HttpRequestUtil.get(getApiUrlById(resourceId)); |
|||
return JacksonObjectMapper.getDefaultObjectMapper().readValue(json, ResourceWrapper.class); |
|||
} |
|||
return null; |
|||
} |
|||
@Override |
|||
public ResourceWrapper getResourceByCode(String resourceCode, Integer version) throws Exception { |
|||
if(version==null) {//未指定版本时,不缓存,加载最新的
|
|||
String json =HttpRequestUtil.get(getApiUrlByCode(resourceCode,version)); |
|||
if(log.isDebugEnabled()) {log.debug("remote resource json:\n{}",json);} |
|||
ResourceWrapper wrapper =JacksonObjectMapper.getDefaultObjectMapper().readValue(json, ResourceWrapper.class); |
|||
if(log.isDebugEnabled()) {log.debug("resource json:\n{}",JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(wrapper));} |
|||
return wrapper; |
|||
}else {//指定版本时,缓存
|
|||
if(resourceCode!=null && !"".equals(resourceCode.trim())) { |
|||
String key =getCacheKey(resourceCode,version); |
|||
ResourceWrapper wrapper =cache.get(key); |
|||
if(wrapper!=null) { |
|||
return wrapper; |
|||
}else { |
|||
String json =HttpRequestUtil.get(getApiUrlByCode(resourceCode,version)); |
|||
wrapper =JacksonObjectMapper.getDefaultObjectMapper().readValue(json, ResourceWrapper.class); |
|||
if(wrapper!=null) { |
|||
key =getCacheKey(resourceCode,version); |
|||
if(key!=null && !"".equals(key.trim())) { |
|||
cache.put(key, wrapper); |
|||
return wrapper; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public List<ResourceAbstract> getAllReleasableResourceAbstract() throws Exception { |
|||
String json =HttpRequestUtil.get(getAllReleasableResourceAbstractApiUrl()); |
|||
if(json!=null && !"".equals(json)) { |
|||
return JacksonObjectMapper.getDefaultObjectMapper().readValue(json,new TypeReference<List<ResourceAbstract>>(){}); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public String getRemoteApiUrl() { |
|||
return remoteApiUrl; |
|||
} |
|||
public void setRemoteApiUrl(String remoteApiUrl) { |
|||
this.remoteApiUrl = remoteApiUrl; |
|||
} |
|||
|
|||
private String getApiUrlById(String modelId) { |
|||
return remoteApiUrl + "/getDefineById?id=" + modelId; |
|||
} |
|||
|
|||
private String getApiUrlByCode(String modelCode,Integer version) { |
|||
if(version!=null) { |
|||
return remoteApiUrl + "/getDefineByCode?code=" + modelCode + "&version=" + version; |
|||
}else { |
|||
return remoteApiUrl + "/getDefineByCode?code=" + modelCode; |
|||
} |
|||
} |
|||
|
|||
private String getAllReleasableResourceAbstractApiUrl() { |
|||
return remoteApiUrl + "/getAllReleasableResourceAbstract"; |
|||
} |
|||
|
|||
private String getCacheKey(String code,Integer version) { |
|||
String result =""; |
|||
if(code!=null && !"".equals(code.trim())) { |
|||
result +=code; |
|||
} |
|||
if(version!=null) { |
|||
result +="_" + version; |
|||
} |
|||
return result; |
|||
} |
|||
} |
@ -0,0 +1,79 @@ |
|||
package io.sc.engine.rule.core.classes; |
|||
|
|||
import java.util.Date; |
|||
|
|||
import io.sc.engine.rule.core.enums.DeployStatus; |
|||
|
|||
/** |
|||
* 资源摘要信息 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class ResourceAbstract { |
|||
private String id; |
|||
private String code; |
|||
private String name; |
|||
private Integer version; |
|||
protected DeployStatus status; |
|||
protected Date effectiveDate; |
|||
|
|||
public ResourceAbstract() {} |
|||
|
|||
public ResourceAbstract(String code,Integer version) { |
|||
this.code =code; |
|||
this.version =version; |
|||
} |
|||
|
|||
public ResourceAbstract(String id,String code,String name,Integer version) { |
|||
this.id =id; |
|||
this.code =code; |
|||
this.name =name; |
|||
this.version =version; |
|||
} |
|||
|
|||
public ResourceAbstract(String id,String code,String name,Integer version,DeployStatus status,Date effectiveDate) { |
|||
this.id =id; |
|||
this.code =code; |
|||
this.name =name; |
|||
this.version =version; |
|||
this.status =status; |
|||
this.effectiveDate =effectiveDate; |
|||
} |
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
public Integer getVersion() { |
|||
return version; |
|||
} |
|||
public void setVersion(Integer version) { |
|||
this.version = version; |
|||
} |
|||
public DeployStatus getStatus() { |
|||
return status; |
|||
} |
|||
public void setStatus(DeployStatus status) { |
|||
this.status = status; |
|||
} |
|||
public Date getEffectiveDate() { |
|||
return effectiveDate; |
|||
} |
|||
public void setEffectiveDate(Date effectiveDate) { |
|||
this.effectiveDate = effectiveDate; |
|||
} |
|||
} |
@ -0,0 +1,121 @@ |
|||
package io.sc.engine.rule.core.classes; |
|||
|
|||
/** |
|||
* 规则信息 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class Rule { |
|||
private boolean isTriggered; //是否触发
|
|||
private Integer level; //等级
|
|||
private String code; //代码
|
|||
private String name; //名称
|
|||
private String category; //分类
|
|||
private String value; //值
|
|||
private String message; //触发时消息
|
|||
|
|||
public Rule() {} |
|||
public Rule(boolean isTriggered,Integer level,String code,String name,String category,String value,String message) { |
|||
this.isTriggered =isTriggered; |
|||
this.level =level; |
|||
this.code =code; |
|||
this.name =name; |
|||
this.category =category; |
|||
this.value =value; |
|||
this.message =message; |
|||
} |
|||
|
|||
public boolean isTriggered() { |
|||
return isTriggered; |
|||
} |
|||
public void setTriggered(boolean isTriggered) { |
|||
this.isTriggered = isTriggered; |
|||
} |
|||
public Integer getLevel() { |
|||
return level; |
|||
} |
|||
public void setLevel(Integer level) { |
|||
this.level = level; |
|||
} |
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
public String getCategory() { |
|||
return category; |
|||
} |
|||
public void setCategory(String category) { |
|||
this.category = category; |
|||
} |
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
public void setValue(String value) { |
|||
this.value = value; |
|||
} |
|||
public String getMessage() { |
|||
return message; |
|||
} |
|||
public void setMessage(String message) { |
|||
this.message = message; |
|||
} |
|||
|
|||
@Override |
|||
public int hashCode() { |
|||
final int prime = 31; |
|||
int result = 1; |
|||
result = prime * result + ((code == null) ? 0 : code.hashCode()); |
|||
result = prime * result + (isTriggered ? 1231 : 1237); |
|||
result = prime * result + ((level == null) ? 0 : level.hashCode()); |
|||
result = prime * result + ((message == null) ? 0 : message.hashCode()); |
|||
result = prime * result + ((name == null) ? 0 : name.hashCode()); |
|||
result = prime * result + ((value == null) ? 0 : value.hashCode()); |
|||
return result; |
|||
} |
|||
@Override |
|||
public boolean equals(Object obj) { |
|||
if (this == obj) |
|||
return true; |
|||
if (obj == null) |
|||
return false; |
|||
if (getClass() != obj.getClass()) |
|||
return false; |
|||
Rule other = (Rule) obj; |
|||
if (code == null) { |
|||
if (other.code != null) |
|||
return false; |
|||
} else if (!code.equals(other.code)) |
|||
return false; |
|||
if (isTriggered != other.isTriggered) |
|||
return false; |
|||
if (level == null) { |
|||
if (other.level != null) |
|||
return false; |
|||
} else if (!level.equals(other.level)) |
|||
return false; |
|||
if (message == null) { |
|||
if (other.message != null) |
|||
return false; |
|||
} else if (!message.equals(other.message)) |
|||
return false; |
|||
if (name == null) { |
|||
if (other.name != null) |
|||
return false; |
|||
} else if (!name.equals(other.name)) |
|||
return false; |
|||
if (value == null) { |
|||
if (other.value != null) |
|||
return false; |
|||
} else if (!value.equals(other.value)) |
|||
return false; |
|||
return true; |
|||
} |
|||
} |
@ -0,0 +1,106 @@ |
|||
package io.sc.engine.rule.core.classes; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
|
|||
/** |
|||
* 规则结果值 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class RuleResult { |
|||
private boolean triggered; //是否触发
|
|||
private Integer level; //等级
|
|||
private List<Rule> rules =new ArrayList<Rule>(); //触发的规则集合
|
|||
|
|||
public void addRule(boolean isTriggered,Integer level,String code,String name,String category,String value,String message) { |
|||
Rule rule =new Rule(isTriggered,level,code,name,category,value,message); |
|||
rules.add(rule); |
|||
if(!this.triggered && isTriggered) { |
|||
this.triggered =true; |
|||
} |
|||
if(this.triggered) { |
|||
if(level!=null) { |
|||
if(this.level==null) { |
|||
this.level =level; |
|||
}else { |
|||
if(level>this.level) { |
|||
this.level =level; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
public boolean getTriggered() { |
|||
return triggered; |
|||
} |
|||
|
|||
public void setTriggered(boolean isTriggered) { |
|||
this.triggered = isTriggered; |
|||
} |
|||
|
|||
public Integer getLevel() { |
|||
return level; |
|||
} |
|||
|
|||
public void setLevel(Integer level) { |
|||
this.level = level; |
|||
} |
|||
|
|||
public List<Rule> getRules() { |
|||
return rules; |
|||
} |
|||
|
|||
public void setRules(List<Rule> rules) { |
|||
this.rules = rules; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
try { |
|||
String result =JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(this); |
|||
return result; |
|||
} catch (JsonProcessingException e) { |
|||
return "RuleResult [triggered=" + triggered + ", level=" + level + ", rules=" + rules + "]"; |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public int hashCode() { |
|||
final int prime = 31; |
|||
int result = 1; |
|||
result = prime * result + (triggered ? 1231 : 1237); |
|||
result = prime * result + ((level == null) ? 0 : level.hashCode()); |
|||
result = prime * result + ((rules == null) ? 0 : rules.hashCode()); |
|||
return result; |
|||
} |
|||
|
|||
@Override |
|||
public boolean equals(Object obj) { |
|||
if (this == obj) |
|||
return true; |
|||
if (obj == null) |
|||
return false; |
|||
if (getClass() != obj.getClass()) |
|||
return false; |
|||
RuleResult other = (RuleResult) obj; |
|||
if (triggered != other.triggered) |
|||
return false; |
|||
if (level == null) { |
|||
if (other.level != null) |
|||
return false; |
|||
} else if (!level.equals(other.level)) |
|||
return false; |
|||
if (rules == null) { |
|||
if (other.rules != null) |
|||
return false; |
|||
} else if (!rules.equals(other.rules)) |
|||
return false; |
|||
return true; |
|||
} |
|||
} |
@ -0,0 +1,70 @@ |
|||
package io.sc.engine.rule.core.classes; |
|||
|
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
|
|||
/** |
|||
* 单规则结果值 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class SingleRuleResult { |
|||
private boolean triggered; //是否触发
|
|||
private Integer level; //等级
|
|||
private String category; //分类
|
|||
private String value; //值
|
|||
private String message; //触发时消息
|
|||
|
|||
public SingleRuleResult() {} |
|||
|
|||
public SingleRuleResult(boolean isTriggered,Integer level,String category,String value,String message) { |
|||
this.triggered =isTriggered; |
|||
this.level =level; |
|||
this.category =category; |
|||
this.value =value; |
|||
this.message =message; |
|||
} |
|||
|
|||
public boolean getTriggered() { |
|||
return triggered; |
|||
} |
|||
public void setTriggered(boolean isTriggered) { |
|||
this.triggered = isTriggered; |
|||
} |
|||
public Integer getLevel() { |
|||
return level; |
|||
} |
|||
public void setLevel(Integer level) { |
|||
this.level = level; |
|||
} |
|||
public String getCategory() { |
|||
return category; |
|||
} |
|||
public void setCategory(String category) { |
|||
this.category = category; |
|||
} |
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
public void setValue(String value) { |
|||
this.value = value; |
|||
} |
|||
public String getMessage() { |
|||
return message; |
|||
} |
|||
public void setMessage(String message) { |
|||
this.message = message; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
try { |
|||
String result =JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(this); |
|||
return result; |
|||
} catch (JsonProcessingException e) { |
|||
return "SingleRuleResult [triggered=" + triggered + ", level=" + level + ", category=" + category |
|||
+ ", value=" + value + ", message=" + message + "]"; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,42 @@ |
|||
package io.sc.engine.rule.core.code; |
|||
|
|||
public class SourceCode { |
|||
private String packageName; //包名
|
|||
private String className; //类名
|
|||
private String source; //类源代码
|
|||
|
|||
public SourceCode() {} |
|||
|
|||
public SourceCode(String packageName,String className,String source) { |
|||
this.packageName =packageName; |
|||
this.className =className; |
|||
this.source =source; |
|||
} |
|||
|
|||
public String getQualifiedClassName() { |
|||
return this.packageName + "." + this.className; |
|||
} |
|||
|
|||
public String getJavaFileName() { |
|||
return this.className + ".java"; |
|||
} |
|||
|
|||
public String getPackageName() { |
|||
return packageName; |
|||
} |
|||
public void setPackageName(String packageName) { |
|||
this.packageName = packageName; |
|||
} |
|||
public String getClassName() { |
|||
return className; |
|||
} |
|||
public void setClassName(String className) { |
|||
this.className = className; |
|||
} |
|||
public String getSource() { |
|||
return source; |
|||
} |
|||
public void setSource(String source) { |
|||
this.source = source; |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
package io.sc.engine.rule.core.code.impl.support; |
|||
|
|||
/** |
|||
* 模型摘要信息 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class ModelAbstract { |
|||
private String id; |
|||
private String code; |
|||
private String name; |
|||
|
|||
public ModelAbstract() {} |
|||
|
|||
public ModelAbstract(String code) { |
|||
this.code =code; |
|||
} |
|||
|
|||
public ModelAbstract(String id,String code,String name) { |
|||
this.id =id; |
|||
this.code =code; |
|||
this.name =name; |
|||
} |
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
} |
@ -0,0 +1,146 @@ |
|||
package io.sc.engine.rule.core.code.impl.support; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.math.RoundingMode; |
|||
|
|||
import io.sc.engine.rule.core.classes.RuleResult; |
|||
import io.sc.engine.rule.core.classes.SingleRuleResult; |
|||
import io.sc.engine.rule.core.enums.ParameterType; |
|||
import io.sc.engine.rule.core.enums.ValueType; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
|
|||
/** |
|||
* 参数结果 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class ParameterResult { |
|||
private String code; //代码
|
|||
private String name; //名称
|
|||
private ParameterType type; //参数类型
|
|||
private String valueType; //参数值类型
|
|||
private Integer valueScale; //参数值精度
|
|||
private RoundingMode valueRoundingMode; //参数值四舍五入模式
|
|||
private String defaultValue; //默认值
|
|||
private String value; //结果值
|
|||
private RuleResult ruleResult; //规则结果值
|
|||
private SingleRuleResult singleRuleResult; //单规则结果值
|
|||
|
|||
public ParameterResult() {} |
|||
public ParameterResult(String code,String name,ParameterType type,String valueType,String value) { |
|||
this.code =code; |
|||
this.name =name; |
|||
this.type =type; |
|||
this.valueType =valueType; |
|||
this.value =value; |
|||
} |
|||
|
|||
public ParameterResult(String code,String name,ParameterType type,RuleResult ruleResult) { |
|||
this.code =code; |
|||
this.name =name; |
|||
this.type =type; |
|||
this.ruleResult =ruleResult; |
|||
} |
|||
|
|||
public ParameterResult(String code,String name,ParameterType type,SingleRuleResult singleRuleResult) { |
|||
this.code =code; |
|||
this.name =name; |
|||
this.type =type; |
|||
this.singleRuleResult =singleRuleResult; |
|||
} |
|||
|
|||
public ParameterResult(String code,String name,ParameterType type,String valueType,Integer valueScale,RoundingMode valueRoundingMode,String value) { |
|||
this.code =code; |
|||
this.name =name; |
|||
this.type =type; |
|||
this.valueType =valueType; |
|||
this.valueScale =valueScale; |
|||
this.valueRoundingMode =valueRoundingMode; |
|||
this.value =value; |
|||
if(ValueType.Decimal.getJavaType().equals(valueType)) { |
|||
if(value!=null && !"".equals(value.trim())) { |
|||
BigDecimal _value =new BigDecimal(value); |
|||
if(valueScale!=null && valueRoundingMode!=null) { |
|||
_value =_value.setScale(valueScale,valueRoundingMode); |
|||
this.value =String.format("%." + valueScale + "f", _value); |
|||
}else if(valueScale!=null) { |
|||
_value =_value.setScale(valueScale); |
|||
this.value =String.format("%." + valueScale + "f", _value); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
public ParameterType getType() { |
|||
return type; |
|||
} |
|||
public void setType(ParameterType type) { |
|||
this.type = type; |
|||
} |
|||
public String getValueType() { |
|||
return valueType; |
|||
} |
|||
public void setValueType(String valueType) { |
|||
this.valueType = valueType; |
|||
} |
|||
public Integer getValueScale() { |
|||
return valueScale; |
|||
} |
|||
public void setValueScale(Integer valueScale) { |
|||
this.valueScale = valueScale; |
|||
} |
|||
public RoundingMode getValueRoundingMode() { |
|||
return valueRoundingMode; |
|||
} |
|||
public void setValueRoundingMode(RoundingMode valueRoundingMode) { |
|||
this.valueRoundingMode = valueRoundingMode; |
|||
} |
|||
public String getDefaultValue() { |
|||
return defaultValue; |
|||
} |
|||
public void setDefaultValue(String defaultValue) { |
|||
this.defaultValue = defaultValue; |
|||
} |
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
public void setValue(String value) { |
|||
this.value = value; |
|||
} |
|||
public RuleResult getRuleResult() { |
|||
return ruleResult; |
|||
} |
|||
public void setRuleResult(RuleResult ruleResult) { |
|||
this.ruleResult = ruleResult; |
|||
} |
|||
public SingleRuleResult getSingleRuleResult() { |
|||
return singleRuleResult; |
|||
} |
|||
public void setSingleRuleResult(SingleRuleResult singleRuleResult) { |
|||
this.singleRuleResult = singleRuleResult; |
|||
} |
|||
@Override |
|||
public String toString() { |
|||
try { |
|||
return JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(this); |
|||
} catch (JsonProcessingException e) { |
|||
return "ParameterResult [code=" + code + ", name=" + name + ", type=" + type + ", valueType=" + valueType |
|||
+ ", valueScale=" + valueScale + ", valueRoundingMode=" + valueRoundingMode + ", defaultValue=" |
|||
+ defaultValue + ", value=" + value + "]"; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,100 @@ |
|||
package io.sc.engine.rule.core.code.impl.support; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.enums.ParameterType; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
|
|||
/** |
|||
* 模型结果 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class ResourceResult { |
|||
private int status; |
|||
private ValidateResult validateResult; |
|||
private List<ParameterResult> data =new ArrayList<ParameterResult>(); |
|||
|
|||
/** |
|||
* 添加结果参数 |
|||
* @param code 代码 |
|||
* @param name 名称 |
|||
* @param type 类型 |
|||
* @param valueType 值类型 |
|||
* @param value 值 |
|||
*/ |
|||
public void addParameterResult(String code,String name,ParameterType type,String valueType,String value) { |
|||
data.add(new ParameterResult(code,name,type,valueType,value)); |
|||
} |
|||
|
|||
/** |
|||
* 通过参数代码获取参数值 |
|||
* @param code 参数代码 |
|||
* @return 参数值 |
|||
*/ |
|||
public boolean exists(String code) { |
|||
if(code!=null && !"".equals(code.trim())) { |
|||
if(data!=null && data.size()>0) { |
|||
for(ParameterResult parameterResult : data) { |
|||
if(code.equals(parameterResult.getCode())){ |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* 通过参数代码获取参数值 |
|||
* @param code 参数代码 |
|||
* @return 参数值 |
|||
*/ |
|||
public String getValueByParameterCode(String code) { |
|||
if(code!=null && !"".equals(code.trim())) { |
|||
if(data!=null && data.size()>0) { |
|||
for(ParameterResult parameterResult : data) { |
|||
if(code.equals(parameterResult.getCode())){ |
|||
return parameterResult.getValue(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public int getStatus() { |
|||
return status; |
|||
} |
|||
public void setStatus(int status) { |
|||
this.status = status; |
|||
} |
|||
public ValidateResult getValidateResult() { |
|||
return validateResult; |
|||
} |
|||
public void setValidateResult(ValidateResult validateResult) { |
|||
this.validateResult = validateResult; |
|||
} |
|||
public List<ParameterResult> getData() { |
|||
return data; |
|||
} |
|||
public void setData(List<ParameterResult> data) { |
|||
this.data = data; |
|||
} |
|||
|
|||
public void addParameterResult(ParameterResult result) { |
|||
this.data.add(result); |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
try { |
|||
return JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(this); |
|||
} catch (JsonProcessingException e) { |
|||
return "ResourceResult [status=" + status + ", validateResult=" + validateResult + ", data=" + data + "]"; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,30 @@ |
|||
package io.sc.engine.rule.core.code.impl.support; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonSubTypes; |
|||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
|||
|
|||
|
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type",defaultImpl=ResourceWrapper4Resource.class) |
|||
@JsonSubTypes({ |
|||
@JsonSubTypes.Type(value=ResourceWrapper4Resource.class), |
|||
@JsonSubTypes.Type(value=ResourceWrapper4Lib.class) |
|||
}) |
|||
public abstract class ResourceWrapper { |
|||
protected boolean isExecuteTestCase; |
|||
|
|||
|
|||
public boolean getIsExecuteTestCase() { |
|||
return isExecuteTestCase; |
|||
} |
|||
|
|||
|
|||
public void setIsExecuteTestCase(boolean isExecuteTestCase) { |
|||
this.isExecuteTestCase = isExecuteTestCase; |
|||
} |
|||
|
|||
@JsonIgnore |
|||
public abstract String getType(); |
|||
} |
@ -0,0 +1,43 @@ |
|||
package io.sc.engine.rule.core.code.impl.support; |
|||
|
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.po.dictionary.Dictionary; |
|||
import io.sc.engine.rule.core.po.lib.Lib; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
@JsonTypeName("LIB") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class ResourceWrapper4Lib extends ResourceWrapper{ |
|||
private List<Dictionary> dictionaries; |
|||
private Lib lib; |
|||
|
|||
|
|||
@Override |
|||
@JsonIgnore |
|||
public String getType() { |
|||
return "LIB"; |
|||
} |
|||
|
|||
|
|||
public List<Dictionary> getDictionaries() { |
|||
return dictionaries; |
|||
} |
|||
|
|||
|
|||
public void setDictionaries(List<Dictionary> dictionaries) { |
|||
this.dictionaries = dictionaries; |
|||
} |
|||
|
|||
|
|||
public Lib getLib() { |
|||
return lib; |
|||
} |
|||
|
|||
public void setLib(Lib lib) { |
|||
this.lib = lib; |
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
package io.sc.engine.rule.core.code.impl.support; |
|||
|
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.po.dictionary.Dictionary; |
|||
import io.sc.engine.rule.core.po.lib.Lib; |
|||
import io.sc.engine.rule.core.po.resource.Resource; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
|
|||
@JsonTypeName("RESOURCE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class ResourceWrapper4Resource extends ResourceWrapper{ |
|||
private Resource resource; |
|||
private List<Dictionary> dictionaries; |
|||
private List<Lib> libs; |
|||
|
|||
|
|||
@Override |
|||
@JsonIgnore |
|||
public String getType() { |
|||
return "RESOURCE"; |
|||
} |
|||
|
|||
public Resource getResource() { |
|||
return resource; |
|||
} |
|||
|
|||
public void setResource(Resource resource) { |
|||
this.resource = resource; |
|||
} |
|||
|
|||
public List<Dictionary> getDictionaries() { |
|||
return dictionaries; |
|||
} |
|||
|
|||
public void setDictionaries(List<Dictionary> dictionaries) { |
|||
this.dictionaries = dictionaries; |
|||
} |
|||
|
|||
public List<Lib> getLibs() { |
|||
return libs; |
|||
} |
|||
|
|||
public void setLibs(List<Lib> libs) { |
|||
this.libs = libs; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package io.sc.engine.rule.core.code.impl.support; |
|||
|
|||
public class ValidateField { |
|||
private String fieldCode; |
|||
private String fieldName; |
|||
private String message; |
|||
|
|||
public ValidateField(String fieldCode,String fieldName,String message) { |
|||
this.fieldCode =fieldCode; |
|||
this.fieldName =fieldName; |
|||
this.message =message; |
|||
} |
|||
|
|||
public String getFieldCode() { |
|||
return fieldCode; |
|||
} |
|||
|
|||
public void setFieldCode(String fieldCode) { |
|||
this.fieldCode = fieldCode; |
|||
} |
|||
|
|||
public String getFieldName() { |
|||
return fieldName; |
|||
} |
|||
|
|||
public void setFieldName(String fieldName) { |
|||
this.fieldName = fieldName; |
|||
} |
|||
|
|||
public String getMessage() { |
|||
return message; |
|||
} |
|||
|
|||
public void setMessage(String message) { |
|||
this.message = message; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,25 @@ |
|||
package io.sc.engine.rule.core.code.impl.support; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
|
|||
public class ValidateResult { |
|||
private List<ValidateField> errorFields =new ArrayList<ValidateField>(); |
|||
|
|||
public void error(String fieldCode,String fieldName,String message) { |
|||
errorFields.add(new ValidateField(fieldCode,fieldName,message)); |
|||
} |
|||
|
|||
public boolean hasError() { |
|||
return errorFields.size()>0; |
|||
} |
|||
|
|||
public List<ValidateField> getErrorFields() { |
|||
return errorFields; |
|||
} |
|||
|
|||
public void setErrorFields(List<ValidateField> errorFields) { |
|||
this.errorFields = errorFields; |
|||
} |
|||
} |
@ -0,0 +1,54 @@ |
|||
package io.sc.engine.rule.core.code.impl.support.lib; |
|||
|
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.po.lib.Indicator; |
|||
import io.sc.engine.rule.core.po.lib.IndicatorLib; |
|||
import io.sc.engine.rule.core.po.lib.Lib; |
|||
|
|||
/** |
|||
* 库辅助类 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class LibUtil { |
|||
/** |
|||
* 查找指标 |
|||
* @param libs 库列表 |
|||
* @param libCode 被查找的指标所属库代码 |
|||
* @param libVersion 被查找的指标所属库版本 |
|||
* @param indicatorCode 被查找的指标代码 |
|||
* @return 指标对象 |
|||
*/ |
|||
public static Indicator findIndicator(List<Lib> libs,String libCode,Integer libVersion,String indicatorCode) { |
|||
if(libs==null || libs.size()==0) { |
|||
return null; |
|||
} |
|||
if(libCode==null || "".equals(libCode.trim())) { |
|||
return null; |
|||
} |
|||
if(libVersion==null) { |
|||
return null; |
|||
} |
|||
if(indicatorCode==null || "".equals(indicatorCode.trim())) { |
|||
return null; |
|||
} |
|||
|
|||
for(Lib lib : libs) { |
|||
if(lib instanceof IndicatorLib) { |
|||
IndicatorLib indicatorLib =(IndicatorLib)lib; |
|||
if(libCode.equals(indicatorLib.getCode()) && libVersion.equals(indicatorLib.getVersion())) { |
|||
List<Indicator> indicators =indicatorLib.getIndicators(); |
|||
if(indicators!=null && indicators.size()>0) { |
|||
for(Indicator indicator : indicators) { |
|||
if(indicatorCode.equals(indicator.getCode())) { |
|||
return indicator; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
} |
@ -0,0 +1,9 @@ |
|||
package io.sc.engine.rule.core.code.impl.support.parameter; |
|||
|
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
|
|||
public interface ParameterGroovyCodeContributionItem { |
|||
public String forArgumentField(ResourceWrapper wrapper); |
|||
public String forConvertArgumentFromMap(ResourceWrapper wrapper,String targetVarName); |
|||
public String forConvertArgumentFromJson(ResourceWrapper wrapper,String targetVarName); |
|||
} |
@ -0,0 +1,245 @@ |
|||
package io.sc.engine.rule.core.code.impl.support.processor; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.po.lib.Indicator; |
|||
import io.sc.engine.rule.core.po.lib.processor.NumberRangeIndicatorProcessor; |
|||
import io.sc.engine.rule.core.po.model.Parameter; |
|||
import io.sc.engine.rule.core.po.model.processor.NumberRangeParameterProcessor; |
|||
import io.sc.engine.rule.core.po.scorecard.NumberRangeScoreCardIndicatorVar; |
|||
import io.sc.engine.rule.core.po.scorecard.NumberRangeScoreCardVar; |
|||
import io.sc.engine.rule.core.po.scorecard.ScoreCardVar; |
|||
import io.sc.engine.rule.core.util.CodeReplacer; |
|||
import io.sc.engine.rule.core.util.ExpressionReplacer; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.core.type.TypeReference; |
|||
|
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class NumberRange { |
|||
private Boolean minIncluded; |
|||
private Double min; |
|||
private Double max; |
|||
private Boolean maxIncluded; |
|||
private String value; |
|||
|
|||
public static List<NumberRange> parse(String json) throws Exception{ |
|||
return JacksonObjectMapper.getDefaultObjectMapper().readValue(json, new TypeReference<List<NumberRange>>(){}); |
|||
} |
|||
|
|||
public static String generateGroovyCode(Indicator indicator,NumberRangeIndicatorProcessor processor) throws Exception{ |
|||
if(indicator==null || processor==null){ |
|||
return null; |
|||
} |
|||
try { |
|||
List<NumberRange> numberRanges =parse(processor.getNumberRange()); |
|||
List<NumberRange> _numberRanges =new ArrayList<NumberRange>(); |
|||
|
|||
//移除空行
|
|||
if(numberRanges!=null && numberRanges.size()>0) { |
|||
for(NumberRange numberRange : numberRanges) { |
|||
if(numberRange.min!=null || numberRange.max!=null || numberRange.value!=null) { |
|||
_numberRanges.add(numberRange); |
|||
} |
|||
} |
|||
} |
|||
|
|||
String parameterName =CodeReplacer.fieldName(indicator.getCode()); |
|||
String var =processor.getNumberRangeVar(); |
|||
String valueType =indicator.getValueType(); |
|||
if(_numberRanges!=null && _numberRanges.size()>0) { |
|||
if(var==null || "".equals(var.trim())) { |
|||
var =ExpressionReplacer.ARGUMENT_NAME + "." + parameterName; |
|||
} |
|||
StringBuilder sb =new StringBuilder(); |
|||
int size =_numberRanges.size(); |
|||
for(int i=0;i<size;i++) { |
|||
NumberRange numberRange =_numberRanges.get(i); |
|||
if(i==0) { |
|||
sb.append("if("); |
|||
}else { |
|||
sb.append("else if("); |
|||
} |
|||
if(numberRange.min==null && numberRange.max==null) { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("==null"); |
|||
}else if(numberRange.min!=null) { |
|||
if(numberRange.minIncluded!=null && numberRange.minIncluded) { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append(">=").append(numberRange.min); |
|||
}else { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append(">").append(numberRange.min); |
|||
} |
|||
} |
|||
if(numberRange.min!=null && numberRange.max!=null) { |
|||
sb.append(" && "); |
|||
} |
|||
if(numberRange.max!=null) { |
|||
if(numberRange.maxIncluded!=null && numberRange.maxIncluded) { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("<=").append(numberRange.max); |
|||
}else { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("<").append(numberRange.max); |
|||
} |
|||
} |
|||
sb.append(")").append("{").append("\n"); |
|||
sb.append("\t\t\t").append(ExpressionReplacer.ARGUMENT_NAME).append(".").append(parameterName).append(" =").append(ExpressionReplacer.groovy(numberRange.value, valueType)).append(";\n"); |
|||
sb.append("\t\t}"); |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
}catch(Exception e) { |
|||
throw new RuntimeException("There was a Error when generate " + indicator.getName()+ "'s NumberRange groovy source code.", e); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public static String generateGroovyCode(Parameter parameter,NumberRangeParameterProcessor processor) throws Exception{ |
|||
if(parameter==null || processor==null){ |
|||
return null; |
|||
} |
|||
try { |
|||
List<NumberRange> numberRanges =parse(processor.getNumberRange()); |
|||
List<NumberRange> _numberRanges =new ArrayList<NumberRange>(); |
|||
|
|||
//移除空行
|
|||
if(numberRanges!=null && numberRanges.size()>0) { |
|||
for(NumberRange numberRange : numberRanges) { |
|||
if(numberRange.min!=null || numberRange.max!=null || numberRange.value!=null) { |
|||
_numberRanges.add(numberRange); |
|||
} |
|||
} |
|||
} |
|||
|
|||
String parameterName =CodeReplacer.fieldName(parameter.getCode()); |
|||
String var =processor.getNumberRangeVar(); |
|||
String valueType =parameter.getValueType(); |
|||
if(_numberRanges!=null && _numberRanges.size()>0) { |
|||
if(var==null || "".equals(var.trim())) { |
|||
var =ExpressionReplacer.ARGUMENT_NAME + "." + parameterName; |
|||
} |
|||
StringBuilder sb =new StringBuilder(); |
|||
int size =_numberRanges.size(); |
|||
for(int i=0;i<size;i++) { |
|||
NumberRange numberRange =_numberRanges.get(i); |
|||
if(i==0) { |
|||
sb.append("if("); |
|||
}else { |
|||
sb.append("else if("); |
|||
} |
|||
if(numberRange.min==null && numberRange.max==null) { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("==null"); |
|||
}else if(numberRange.min!=null) { |
|||
if(numberRange.minIncluded!=null && numberRange.minIncluded) { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append(">=").append(numberRange.min); |
|||
}else { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append(">").append(numberRange.min); |
|||
} |
|||
} |
|||
if(numberRange.min!=null && numberRange.max!=null) { |
|||
sb.append(" && "); |
|||
} |
|||
if(numberRange.max!=null) { |
|||
if(numberRange.maxIncluded!=null && numberRange.maxIncluded) { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("<=").append(numberRange.max); |
|||
}else { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("<").append(numberRange.max); |
|||
} |
|||
} |
|||
sb.append(")").append("{").append("\n"); |
|||
sb.append("\t\t\t").append(ExpressionReplacer.ARGUMENT_NAME).append(".").append(parameterName).append(" =").append(ExpressionReplacer.groovy(numberRange.value, valueType)).append(";\n"); |
|||
sb.append("\t\t}"); |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
}catch(Exception e) { |
|||
throw new RuntimeException("There was a Error when generate " + parameter.getName()+ "'s NumberRange groovy source code.", e); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public static String generateGroovyCode(ScoreCardVar scoreCardVar) throws Exception{ |
|||
try { |
|||
List<NumberRange> _numberRanges =null; |
|||
if(scoreCardVar instanceof NumberRangeScoreCardVar) { |
|||
_numberRanges =parse(((NumberRangeScoreCardVar)scoreCardVar).getNumberRange()); |
|||
}else if(scoreCardVar instanceof NumberRangeScoreCardIndicatorVar) { |
|||
_numberRanges =parse(((NumberRangeScoreCardIndicatorVar)scoreCardVar).getNumberRange()); |
|||
}else { |
|||
return null; |
|||
} |
|||
|
|||
String parameterName =scoreCardVar.getCode(); |
|||
String var ="${" + parameterName + "}"; |
|||
String valueType ="java.math.BigDecimal"; |
|||
if(_numberRanges!=null && _numberRanges.size()>0) { |
|||
StringBuilder sb =new StringBuilder(); |
|||
int size =_numberRanges.size(); |
|||
for(int i=0;i<size;i++) { |
|||
NumberRange numberRange =_numberRanges.get(i); |
|||
if(i==0) { |
|||
sb.append("if("); |
|||
}else { |
|||
sb.append("else if("); |
|||
} |
|||
if(numberRange.min==null && numberRange.max==null) { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("==null"); |
|||
}else if(numberRange.min!=null) { |
|||
if(numberRange.minIncluded!=null && numberRange.minIncluded) { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append(">=").append(numberRange.min); |
|||
}else { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append(">").append(numberRange.min); |
|||
} |
|||
} |
|||
if(numberRange.min!=null && numberRange.max!=null) { |
|||
sb.append(" && "); |
|||
} |
|||
if(numberRange.max!=null) { |
|||
if(numberRange.maxIncluded!=null && numberRange.maxIncluded) { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("<=").append(numberRange.max); |
|||
}else { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("<").append(numberRange.max); |
|||
} |
|||
} |
|||
sb.append(")").append("{").append("\n"); |
|||
sb.append("\t\t\t").append(ExpressionReplacer.ARGUMENT_NAME).append(".R_").append(parameterName).append(" =").append(ExpressionReplacer.groovy(numberRange.value, valueType)).append(";\n"); |
|||
sb.append("\t\t}"); |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
}catch(Exception e) { |
|||
throw new RuntimeException("There was a Error when generate " + scoreCardVar.getName()+ "'s NumberRange groovy source code.", e); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public Boolean getMinIncluded() { |
|||
return minIncluded; |
|||
} |
|||
public void setMinIncluded(Boolean minIncluded) { |
|||
this.minIncluded = minIncluded; |
|||
} |
|||
public Double getMin() { |
|||
return min; |
|||
} |
|||
public void setMin(Double min) { |
|||
this.min = min; |
|||
} |
|||
public Double getMax() { |
|||
return max; |
|||
} |
|||
public void setMax(Double max) { |
|||
this.max = max; |
|||
} |
|||
public Boolean getMaxIncluded() { |
|||
return maxIncluded; |
|||
} |
|||
public void setMaxIncluded(Boolean maxIncluded) { |
|||
this.maxIncluded = maxIncluded; |
|||
} |
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
public void setValue(String value) { |
|||
this.value = value; |
|||
} |
|||
} |
@ -0,0 +1,104 @@ |
|||
package io.sc.engine.rule.core.code.impl.support.processor; |
|||
|
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.po.scorecard.OptionScoreCardIndicatorVar; |
|||
import io.sc.engine.rule.core.po.scorecard.OptionScoreCardVar; |
|||
import io.sc.engine.rule.core.po.scorecard.ScoreCardVar; |
|||
import io.sc.engine.rule.core.util.ExpressionReplacer; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.core.type.TypeReference; |
|||
|
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class Option { |
|||
private String uuid; |
|||
private String value; |
|||
private String title; |
|||
private String description; |
|||
private String score; |
|||
|
|||
public static List<Option> parse(String json) throws Exception{ |
|||
if(json!=null && !"".equals(json.trim())) { |
|||
return JacksonObjectMapper.getDefaultObjectMapper().readValue(json, new TypeReference<List<Option>>(){}); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public static String generateGroovyCode(ScoreCardVar scoreCardVar) throws Exception{ |
|||
try { |
|||
List<Option> _options =null; |
|||
if(scoreCardVar instanceof OptionScoreCardVar) { |
|||
_options =parse(((OptionScoreCardVar)scoreCardVar).getOption()); |
|||
}else if(scoreCardVar instanceof OptionScoreCardIndicatorVar) { |
|||
_options =parse(((OptionScoreCardIndicatorVar)scoreCardVar).getOption()); |
|||
}else { |
|||
return null; |
|||
} |
|||
String parameterName =scoreCardVar.getCode(); |
|||
String var ="${" + parameterName + "}"; |
|||
String valueType ="java.lang.String"; |
|||
String returnValueType ="java.math.BigDecimal"; |
|||
if(_options!=null && _options.size()>0) { |
|||
StringBuilder sb =new StringBuilder(); |
|||
int size =_options.size(); |
|||
for(int i=0;i<size;i++) { |
|||
Option option =_options.get(i); |
|||
if(i==0) { |
|||
sb.append("if("); |
|||
}else { |
|||
sb.append("else if("); |
|||
} |
|||
if(option.value==null) { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("==null || ").append(ExpressionReplacer.groovy(var, null)).append(".trim().isEmpty()"); |
|||
}else { |
|||
if("java.lang.String".equals(valueType)) { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("=='''").append(option.getValue()).append("'''"); |
|||
}else { |
|||
sb.append(ExpressionReplacer.groovy(var, null)).append("==").append(option.getValue()); |
|||
} |
|||
} |
|||
sb.append(")").append("{").append("\n"); |
|||
sb.append("\t\t\t").append(ExpressionReplacer.ARGUMENT_NAME).append(".R_").append(parameterName).append(" =").append(ExpressionReplacer.groovy(option.score, returnValueType)).append(";\n"); |
|||
sb.append("\t\t}"); |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
}catch(Exception e) { |
|||
throw new RuntimeException("There was a Error when generate " + scoreCardVar.getName()+ "'s Option groovy source code.", e); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public String getUuid() { |
|||
return uuid; |
|||
} |
|||
public void setUuid(String uuid) { |
|||
this.uuid = uuid; |
|||
} |
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
public void setValue(String value) { |
|||
this.value = value; |
|||
} |
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
public void setTitle(String title) { |
|||
this.title = title; |
|||
} |
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
public void setDescription(String description) { |
|||
this.description = description; |
|||
} |
|||
public String getScore() { |
|||
return score; |
|||
} |
|||
public void setScore(String score) { |
|||
this.score = score; |
|||
} |
|||
} |
@ -0,0 +1,155 @@ |
|||
package io.sc.engine.rule.core.code.impl.support.processor; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.po.model.Parameter; |
|||
import io.sc.engine.rule.core.po.model.processor.RuleParameterProcessor; |
|||
import io.sc.engine.rule.core.util.CodeReplacer; |
|||
import io.sc.engine.rule.core.util.ExpressionReplacer; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.core.type.TypeReference; |
|||
|
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class Rule { |
|||
private String uuid; |
|||
private Integer level; |
|||
private String code; |
|||
private String name; |
|||
private String category; |
|||
private String condition; |
|||
private String value; |
|||
private String message; |
|||
|
|||
public static List<Rule> parse(String json) throws Exception{ |
|||
return JacksonObjectMapper.getDefaultObjectMapper().readValue(json, new TypeReference<List<Rule>>(){}); |
|||
} |
|||
|
|||
public static String generateGroovyCode(Parameter parameter,RuleParameterProcessor processor) throws Exception{ |
|||
if(parameter==null || processor==null){ |
|||
return null; |
|||
} |
|||
try { |
|||
List<Rule> rules =parse(processor.getRule()); |
|||
List<Rule> _rules =new ArrayList<Rule>(); |
|||
|
|||
//移除没有填写条件的条件范围
|
|||
if(rules!=null && rules.size()>0) { |
|||
for(Rule rule : rules) { |
|||
if(rule.getCondition()!=null && !"".equals(rule.getCondition().trim())) { |
|||
_rules.add(rule); |
|||
} |
|||
} |
|||
} |
|||
|
|||
if(_rules!=null && _rules.size()>0) { |
|||
StringBuilder sb =new StringBuilder(); |
|||
int size =_rules.size(); |
|||
for(int i=0;i<size;i++) { |
|||
Rule rule =_rules.get(i); |
|||
sb.append("\t\tif("); |
|||
sb.append(ExpressionReplacer.groovy(rule.condition, null)); |
|||
sb.append(")").append("{").append("\n"); |
|||
sb.append("\t\t\t").append(ExpressionReplacer.ARGUMENT_NAME).append(".").append(CodeReplacer.fieldName(parameter.getCode())).append(".addRule("); |
|||
sb.append("true,"); |
|||
sb.append(rule.level).append(","); |
|||
sb.append("'''" + rule.code + "''',"); |
|||
sb.append("'''" + rule.name + "''',"); |
|||
if(rule.category!=null && !"".equals(rule.category)) { |
|||
sb.append("'''" + rule.category + "''',"); |
|||
}else { |
|||
sb.append("null,"); |
|||
} |
|||
sb.append(ExpressionReplacer.groovy(rule.value, "java.lang.String")).append(","); |
|||
sb.append(ExpressionReplacer.groovy(rule.message, "java.lang.String")); |
|||
sb.append(")").append(";\n"); |
|||
sb.append("\t\t}else{").append("\n"); |
|||
sb.append("\t\t\t").append(ExpressionReplacer.ARGUMENT_NAME).append(".").append(CodeReplacer.fieldName(parameter.getCode())).append(".addRule("); |
|||
sb.append("false,"); |
|||
sb.append(rule.level).append(","); |
|||
sb.append("'''" + rule.code + "''',"); |
|||
sb.append("'''" + rule.name + "''',"); |
|||
if(rule.category!=null && !"".equals(rule.category)) { |
|||
sb.append("'''" + rule.category + "''',"); |
|||
}else { |
|||
sb.append("null,"); |
|||
} |
|||
sb.append(ExpressionReplacer.groovy(rule.value, "java.lang.String")).append(","); |
|||
sb.append(ExpressionReplacer.groovy(rule.message, "java.lang.String")); |
|||
sb.append(")").append(";\n"); |
|||
sb.append("\t\t}\n"); |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
}catch(Exception e) { |
|||
throw new RuntimeException("There was a Error when generate " + parameter.getName()+ "'s Rule groovy source code.", e); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public String getUuid() { |
|||
return uuid; |
|||
} |
|||
|
|||
public void setUuid(String uuid) { |
|||
this.uuid = uuid; |
|||
} |
|||
|
|||
public Integer getLevel() { |
|||
return level; |
|||
} |
|||
|
|||
public void setLevel(Integer level) { |
|||
this.level = level; |
|||
} |
|||
|
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
|
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public String getCategory() { |
|||
return category; |
|||
} |
|||
|
|||
public void setCategory(String category) { |
|||
this.category = category; |
|||
} |
|||
|
|||
public String getCondition() { |
|||
return condition; |
|||
} |
|||
|
|||
public void setCondition(String condition) { |
|||
this.condition = condition; |
|||
} |
|||
|
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
|
|||
public void setValue(String value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public String getMessage() { |
|||
return message; |
|||
} |
|||
|
|||
public void setMessage(String message) { |
|||
this.message = message; |
|||
} |
|||
} |
@ -0,0 +1,127 @@ |
|||
package io.sc.engine.rule.core.code.impl.support.processor; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.po.model.Parameter; |
|||
import io.sc.engine.rule.core.po.model.processor.SingleRuleParameterProcessor; |
|||
import io.sc.engine.rule.core.util.CodeReplacer; |
|||
import io.sc.engine.rule.core.util.ExpressionReplacer; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.core.type.TypeReference; |
|||
|
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class SingleRule { |
|||
private String uuid; |
|||
private Integer level; |
|||
private String category; |
|||
private String condition; |
|||
private String value; |
|||
private String message; |
|||
|
|||
public static List<SingleRule> parse(String json) throws Exception{ |
|||
return JacksonObjectMapper.getDefaultObjectMapper().readValue(json, new TypeReference<List<SingleRule>>(){}); |
|||
} |
|||
|
|||
public static String generateGroovyCode(Parameter parameter,SingleRuleParameterProcessor processor) throws Exception{ |
|||
if(parameter==null || processor==null){ |
|||
return null; |
|||
} |
|||
try { |
|||
List<SingleRule> rules =parse(processor.getSingleRule()); |
|||
List<SingleRule> _rules =new ArrayList<SingleRule>(); |
|||
|
|||
//移除没有填写条件的条件范围
|
|||
if(rules!=null && rules.size()>0) { |
|||
for(SingleRule rule : rules) { |
|||
if(rule.getCondition()!=null && !"".equals(rule.getCondition().trim())) { |
|||
_rules.add(rule); |
|||
} |
|||
} |
|||
} |
|||
|
|||
if(_rules!=null && _rules.size()>0) { |
|||
StringBuilder sb =new StringBuilder(); |
|||
sb.append("\t\tSingleRuleResult result =new SingleRuleResult();").append("\n"); |
|||
int size =_rules.size(); |
|||
for(int i=0;i<size;i++) { |
|||
SingleRule rule =_rules.get(i); |
|||
sb.append("\t\tif("); |
|||
sb.append(ExpressionReplacer.groovy(rule.condition, null)); |
|||
sb.append(")").append("{").append("\n"); |
|||
sb.append("\t\t\t").append("SingleRuleResult temp =new SingleRuleResult("); |
|||
sb.append("true,"); |
|||
sb.append(rule.level).append(","); |
|||
if(rule.category!=null && !"".equals(rule.category)) { |
|||
sb.append("'''" + rule.category + "''',"); |
|||
}else { |
|||
sb.append("null,"); |
|||
} |
|||
sb.append(ExpressionReplacer.groovy(rule.value, "java.lang.String")).append(","); |
|||
sb.append(ExpressionReplacer.groovy(rule.message, "java.lang.String")); |
|||
sb.append(")").append(";\n"); |
|||
sb.append("\t\t\tif(!result.isTriggered() || result.getLevel()>temp.getLevel()){").append("\n"); |
|||
sb.append("\t\t\t\t").append("result =temp;").append("\n"); |
|||
sb.append("\t\t\t}").append("\n"); |
|||
sb.append("\t\t}\n"); |
|||
} |
|||
sb.append("\n"); |
|||
sb.append("\t\t").append(ExpressionReplacer.ARGUMENT_NAME).append(".").append(CodeReplacer.fieldName(parameter.getCode())).append(" =result;").append("\n"); |
|||
return sb.toString(); |
|||
} |
|||
}catch(Exception e) { |
|||
throw new RuntimeException("There was a Error when generate " + parameter.getName()+ "'s Single Rule groovy source code.", e); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public String getUuid() { |
|||
return uuid; |
|||
} |
|||
|
|||
public void setUuid(String uuid) { |
|||
this.uuid = uuid; |
|||
} |
|||
|
|||
public Integer getLevel() { |
|||
return level; |
|||
} |
|||
|
|||
public void setLevel(Integer level) { |
|||
this.level = level; |
|||
} |
|||
|
|||
public String getCategory() { |
|||
return category; |
|||
} |
|||
|
|||
public void setCategory(String category) { |
|||
this.category = category; |
|||
} |
|||
|
|||
public String getCondition() { |
|||
return condition; |
|||
} |
|||
|
|||
public void setCondition(String condition) { |
|||
this.condition = condition; |
|||
} |
|||
|
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
|
|||
public void setValue(String value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public String getMessage() { |
|||
return message; |
|||
} |
|||
|
|||
public void setMessage(String message) { |
|||
this.message = message; |
|||
} |
|||
} |
@ -0,0 +1,82 @@ |
|||
package io.sc.engine.rule.core.code.impl.support.processor; |
|||
|
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.po.lib.Indicator; |
|||
import io.sc.engine.rule.core.po.lib.processor.SqlIndicatorProcessor; |
|||
import io.sc.engine.rule.core.po.model.Parameter; |
|||
import io.sc.engine.rule.core.po.model.processor.SqlParameterProcessor; |
|||
import io.sc.engine.rule.core.util.CodeReplacer; |
|||
import io.sc.engine.rule.core.util.ExpressionReplacer; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.core.type.TypeReference; |
|||
|
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class SqlFieldMapping { |
|||
private String parameter; |
|||
private String field; |
|||
|
|||
public static List<SqlFieldMapping> parse(String json) throws Exception{ |
|||
return JacksonObjectMapper.getDefaultObjectMapper().readValue(json, new TypeReference<List<SqlFieldMapping>>(){}); |
|||
} |
|||
|
|||
public static String generateGroovyCode(Indicator indicator,SqlIndicatorProcessor processor) throws Exception{ |
|||
if(indicator==null || processor==null){ |
|||
return null; |
|||
} |
|||
try { |
|||
StringBuilder sb =new StringBuilder(); |
|||
List<SqlFieldMapping> mappings =parse(processor.getSqlFieldMapping()); |
|||
if(mappings!=null && mappings.size()>0) { |
|||
for(SqlFieldMapping mapping : mappings) { |
|||
sb.append("\t\t\t\t\t") |
|||
.append(ExpressionReplacer.groovy(CodeReplacer.fieldName(mapping.parameter), null)) |
|||
.append(" =") |
|||
.append("rs.getObject(\"").append(mapping.getField()).append("\");"); |
|||
} |
|||
} |
|||
return sb.toString(); |
|||
}catch(Exception e) { |
|||
throw new RuntimeException("There was a Error when generate " + indicator.getName()+ "'s Rule groovy source code.", e); |
|||
} |
|||
} |
|||
|
|||
public static String generateGroovyCode(Parameter parameter,SqlParameterProcessor processor) throws Exception{ |
|||
if(parameter==null || processor==null){ |
|||
return null; |
|||
} |
|||
try { |
|||
StringBuilder sb =new StringBuilder(); |
|||
List<SqlFieldMapping> mappings =parse(processor.getSqlFieldMapping()); |
|||
if(mappings!=null && mappings.size()>0) { |
|||
for(SqlFieldMapping mapping : mappings) { |
|||
sb.append("\t\t\t\t\t") |
|||
.append(ExpressionReplacer.groovy(CodeReplacer.fieldName(mapping.parameter), null)) |
|||
.append(" =") |
|||
.append("rs.getObject(\"").append(mapping.getField()).append("\");"); |
|||
} |
|||
} |
|||
return sb.toString(); |
|||
}catch(Exception e) { |
|||
throw new RuntimeException("There was a Error when generate " + parameter.getName()+ "'s Rule groovy source code.", e); |
|||
} |
|||
} |
|||
|
|||
public String getParameter() { |
|||
return parameter; |
|||
} |
|||
|
|||
public void setParameter(String parameter) { |
|||
this.parameter = parameter; |
|||
} |
|||
|
|||
public String getField() { |
|||
return field; |
|||
} |
|||
|
|||
public void setField(String field) { |
|||
this.field = field; |
|||
} |
|||
} |
@ -0,0 +1,32 @@ |
|||
package io.sc.engine.rule.core.convert.support; |
|||
|
|||
import org.springframework.core.convert.converter.Converter; |
|||
import org.springframework.core.convert.converter.ConverterFactory; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
public class JsonStringToObjectConverterFactory implements ConverterFactory<String, Object>{ |
|||
@Override |
|||
public <T extends Object> Converter<String, T> getConverter(Class<T> targetType) { |
|||
return new JsonStringToObject<>(targetType); |
|||
} |
|||
|
|||
private static final class JsonStringToObject<T extends Object> implements Converter<String, T> { |
|||
private final Class<T> targetType; |
|||
|
|||
public JsonStringToObject(Class<T> targetType) { |
|||
this.targetType = targetType; |
|||
} |
|||
|
|||
@Override |
|||
public T convert(String source) { |
|||
if (source==null || source.isEmpty()) { |
|||
return null; |
|||
} |
|||
try { |
|||
return JacksonObjectMapper.getDefaultObjectMapper().readValue(source, targetType); |
|||
} catch (Exception e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,45 @@ |
|||
package io.sc.engine.rule.core.convert.support; |
|||
|
|||
import java.util.Map; |
|||
|
|||
import org.springframework.core.convert.converter.Converter; |
|||
import org.springframework.core.convert.converter.ConverterFactory; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
|
|||
public class MapToObjectConverterFactory implements ConverterFactory<Map<String,Object>, Object>{ |
|||
@Override |
|||
public <T extends Object> Converter<Map<String,Object>, T> getConverter(Class<T> targetType) { |
|||
return new MapToObject<>(targetType); |
|||
} |
|||
|
|||
private static final class MapToObject<T extends Object> implements Converter<Map<String,Object>, T> { |
|||
private final Class<T> targetType; |
|||
|
|||
public MapToObject(Class<T> targetType) { |
|||
this.targetType = targetType; |
|||
} |
|||
|
|||
@Override |
|||
public T convert(Map<String,Object> source) { |
|||
if (source==null || source.isEmpty()) { |
|||
return null; |
|||
} |
|||
String json =null; |
|||
try { |
|||
json =JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(source); |
|||
} catch (JsonProcessingException e) { |
|||
} |
|||
if(json!=null && json.length()>0) { |
|||
T result =null; |
|||
try { |
|||
result =JacksonObjectMapper.getDefaultObjectMapper().readValue(json, targetType); |
|||
} catch (Exception e) { |
|||
} |
|||
return (T)result; |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
package io.sc.engine.rule.core.convert.support; |
|||
|
|||
import org.springframework.core.convert.TypeDescriptor; |
|||
import org.springframework.core.convert.converter.ConditionalConverter; |
|||
import org.springframework.core.convert.converter.Converter; |
|||
import org.springframework.core.convert.converter.ConverterFactory; |
|||
import org.springframework.util.NumberUtils; |
|||
|
|||
public class NumberToNumberConverterFactory implements ConverterFactory<Number, Number>, ConditionalConverter { |
|||
@Override |
|||
public <T extends Number> Converter<Number, T> getConverter(Class<T> targetType) { |
|||
return new NumberToNumber<>(targetType); |
|||
} |
|||
|
|||
@Override |
|||
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { |
|||
return !sourceType.equals(targetType); |
|||
} |
|||
|
|||
|
|||
private static final class NumberToNumber<T extends Number> implements Converter<Number, T> { |
|||
private final Class<T> targetType; |
|||
|
|||
public NumberToNumber(Class<T> targetType) { |
|||
this.targetType = targetType; |
|||
} |
|||
|
|||
@Override |
|||
public T convert(Number source) { |
|||
return NumberUtils.convertNumberToTargetClass(source, this.targetType); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
package io.sc.engine.rule.core.convert.support; |
|||
|
|||
import org.springframework.core.convert.converter.Converter; |
|||
|
|||
public class ObjectToStringConverter implements Converter<Object, String>{ |
|||
@Override |
|||
public String convert(Object source) { |
|||
return source.toString(); |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
package io.sc.engine.rule.core.convert.support; |
|||
|
|||
import java.util.HashSet; |
|||
import java.util.Set; |
|||
|
|||
import org.springframework.core.convert.converter.Converter; |
|||
|
|||
public final class StringToBooleanConverter implements Converter<String, Boolean> { |
|||
|
|||
private static final Set<String> trueValues = new HashSet<>(4); |
|||
|
|||
private static final Set<String> falseValues = new HashSet<>(4); |
|||
|
|||
static { |
|||
trueValues.add("true"); |
|||
trueValues.add("on"); |
|||
trueValues.add("yes"); |
|||
trueValues.add("1"); |
|||
|
|||
falseValues.add("false"); |
|||
falseValues.add("off"); |
|||
falseValues.add("no"); |
|||
falseValues.add("0"); |
|||
} |
|||
|
|||
@Override |
|||
public Boolean convert(String source) { |
|||
String value = source.trim(); |
|||
if ("".equals(value)) { |
|||
return null; |
|||
} |
|||
value = value.toLowerCase(); |
|||
if (trueValues.contains(value)) { |
|||
return Boolean.TRUE; |
|||
} |
|||
else if (falseValues.contains(value)) { |
|||
return Boolean.FALSE; |
|||
} |
|||
else { |
|||
throw new IllegalArgumentException("Invalid boolean value '" + source + "'"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
package io.sc.engine.rule.core.convert.support; |
|||
|
|||
import java.text.ParseException; |
|||
import java.util.Date; |
|||
|
|||
import org.springframework.core.convert.converter.Converter; |
|||
import io.sc.engine.rule.core.util.DateUtil; |
|||
|
|||
public final class StringToDateConverter implements Converter<String, Date> { |
|||
@Override |
|||
public Date convert(String source) { |
|||
if(source==null || source.trim().isEmpty()) { |
|||
return null; |
|||
} |
|||
try { |
|||
return DateUtil.tryParseDate(source); |
|||
} catch (ParseException e) { |
|||
throw new IllegalArgumentException("Invalid date value '" + source + "'"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,30 @@ |
|||
package io.sc.engine.rule.core.convert.support; |
|||
|
|||
import org.springframework.core.convert.converter.Converter; |
|||
import org.springframework.core.convert.converter.ConverterFactory; |
|||
import org.springframework.util.NumberUtils; |
|||
|
|||
public class StringToNumberConverterFactory implements ConverterFactory<String, Number>{ |
|||
@Override |
|||
public <T extends Number> Converter<String, T> getConverter(Class<T> targetType) { |
|||
return new StringToNumber<>(targetType); |
|||
} |
|||
|
|||
|
|||
private static final class StringToNumber<T extends Number> implements Converter<String, T> { |
|||
|
|||
private final Class<T> targetType; |
|||
|
|||
public StringToNumber(Class<T> targetType) { |
|||
this.targetType = targetType; |
|||
} |
|||
|
|||
@Override |
|||
public T convert(String source) { |
|||
if (source.isEmpty()) { |
|||
return null; |
|||
} |
|||
return NumberUtils.parseNumber(source, this.targetType); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
/** |
|||
* 指标类型枚举 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public enum IndicatorType { |
|||
INTERFACE, //接口
|
|||
INDICATOR //指标
|
|||
} |
@ -0,0 +1,24 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
/** |
|||
* 库类型枚举 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public enum LibType { |
|||
FOLDER, //文件夹
|
|||
INDICATOR; //指标库
|
|||
|
|||
/** |
|||
* 获取枚举类型的顺序,用于对枚举类型进行排序 |
|||
* @return 枚举类型的顺序 |
|||
*/ |
|||
public int getOrder() { |
|||
switch(this) { |
|||
case FOLDER: |
|||
return 0; |
|||
default: |
|||
return 1; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,12 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
/** |
|||
* 模型分类 |
|||
*/ |
|||
public enum ModelCategory { |
|||
QUANTITATIVE, //定量模型
|
|||
QUALITATIVE, //定性模型
|
|||
ADJUSTMENT, //调整项模型
|
|||
RULE, //规则
|
|||
OTHER //其他模型
|
|||
} |
@ -0,0 +1,17 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
/** |
|||
* 参数类型 |
|||
*/ |
|||
public enum ParameterType { |
|||
IN, //输入
|
|||
IN_OPTION, //输入(选项)
|
|||
IN_SUB_OUT, //输入(子模型输出)
|
|||
INDICATOR, //指标
|
|||
INTERMEDIATE, //中间值
|
|||
OUT, //输出
|
|||
RULE_RESULT, //规则结果值
|
|||
SINGLE_RULE_RESULT, //单规则结果值
|
|||
CONSTANT //常量
|
|||
|
|||
} |
@ -0,0 +1,26 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
/** |
|||
* 处理器类型 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public enum ProcessorType { |
|||
EMPTY, //空操作
|
|||
OPTION_VALUE, //选项值
|
|||
ARITHMETIC, //算数运算
|
|||
TERNARY, //三元操作
|
|||
WHEN_THEN, //When then 运算
|
|||
RULE, //规则
|
|||
SINGLE_RULE, //单规则
|
|||
NUMBER_RANGE, //数值分段函数
|
|||
CONDITION_RANGE, //条件分段函数
|
|||
DECISION_TABLE_2C, //简单决策表
|
|||
DECISION_TABLE, //决策表
|
|||
DECISION_TREE, //决策树
|
|||
EXECUTION_FLOW, //执行流
|
|||
PMML, //预测模型标记语言
|
|||
GROOVY_SCRIPT, //groovy脚本
|
|||
SQL, //sql
|
|||
HTTP_REQUEST //http 请求
|
|||
} |
@ -0,0 +1,19 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
/** |
|||
* 资源类型枚举 |
|||
*/ |
|||
public enum ResourceType { |
|||
FOLDER, //文件夹
|
|||
MODEL, //模型
|
|||
SCORE_CARD; //评分卡
|
|||
|
|||
public int getOrder() { |
|||
switch(this) { |
|||
case FOLDER: |
|||
return 0; |
|||
default: |
|||
return 1; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
/** |
|||
* 调用模型时,输入参数类型枚举 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public enum RuntimeInputParameterType { |
|||
MAP, //map
|
|||
JSON //json 字符串
|
|||
} |
@ -0,0 +1,15 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
/** |
|||
* 评分卡变量类型 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public enum ScoreCardVarType { |
|||
OPTION, //选项
|
|||
NUMBER_RANGE, //数值分段
|
|||
INDICATOR_OPTION, //指标选项
|
|||
INDICATOR_NUMBER_RANGE, //指标数值分段
|
|||
INDICATOR_VALUE, //指标值
|
|||
RESULT //结果值
|
|||
} |
@ -0,0 +1,13 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
/** |
|||
* 测试用例类型 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public enum TestCaseOwnerType { |
|||
LIB, //指标库
|
|||
RESOURCE, //资源
|
|||
MODEL, //模型
|
|||
SCORE_CARD //评分卡
|
|||
} |
@ -0,0 +1,12 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
/** |
|||
* 测试用例执行结果 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public enum TestResult { |
|||
PASSED, //通过
|
|||
UN_PASSED, //未通过
|
|||
ERROR; //出现错误
|
|||
} |
@ -0,0 +1,17 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
/** |
|||
* 验证器类型枚举 |
|||
*/ |
|||
public enum ValidatorType { |
|||
EMPTY, //空
|
|||
NOT_EMPTY, //非空
|
|||
TRUE, //True
|
|||
FALSE, //Fale
|
|||
INTEGER_RANGE, //整数范围
|
|||
DECIMAL_RANGE, //小数范围
|
|||
EMAIL, //邮件
|
|||
LENGTH_RANGE, //长度范围
|
|||
DATE_RANGE, //日期范围
|
|||
PATTERN //正则表达式
|
|||
} |
@ -0,0 +1,151 @@ |
|||
package io.sc.engine.rule.core.enums; |
|||
|
|||
import java.util.Date; |
|||
|
|||
import io.sc.engine.rule.core.classes.ResourceAbstract; |
|||
import io.sc.engine.rule.core.classes.RuleResult; |
|||
import io.sc.engine.rule.core.classes.SingleRuleResult; |
|||
import io.sc.engine.rule.core.util.DateUtil; |
|||
import io.sc.engine.rule.core.util.JacksonObjectMapper; |
|||
|
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
|
|||
/** |
|||
* 值类型 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public enum ValueType { |
|||
Boolean, //布尔
|
|||
Long, //整数
|
|||
Float, //浮点数
|
|||
Decimal, //小数
|
|||
String, //字符串
|
|||
Date, //日期
|
|||
RuleResult, //规则结果值
|
|||
SingleRuleResult, //单规则结果值
|
|||
ResourceAbstract; //资源摘要
|
|||
|
|||
public String getJavaType() { |
|||
switch(this) { |
|||
case Boolean: |
|||
return "java.lang.Boolean"; |
|||
case Long: |
|||
return "java.lang.Long"; |
|||
case Float: |
|||
return "java.lang.Float"; |
|||
case Decimal: |
|||
return "java.math.BigDecimal"; |
|||
case String: |
|||
return "java.lang.String"; |
|||
case Date: |
|||
return "java.util.Date"; |
|||
case RuleResult: |
|||
return "io.sc.engine.rule.core.classes.RuleResult"; |
|||
case SingleRuleResult: |
|||
return "io.sc.engine.rule.core.classes.SingleRuleResult"; |
|||
case ResourceAbstract: |
|||
return "io.sc.engine.rule.core.classes.ResourceAbstract"; |
|||
default: |
|||
return this.toString(); |
|||
} |
|||
} |
|||
|
|||
public String getSimpleJavaType() { |
|||
switch(this) { |
|||
case Boolean: |
|||
return "Boolean"; |
|||
case Long: |
|||
return "Long"; |
|||
case Float: |
|||
return "Float"; |
|||
case Decimal: |
|||
return "BigDecimal"; |
|||
case String: |
|||
return "String"; |
|||
case Date: |
|||
return "Date"; |
|||
case RuleResult: |
|||
return "RuleResult"; |
|||
case SingleRuleResult: |
|||
return "SingleRuleResult"; |
|||
case ResourceAbstract: |
|||
return "ResourceAbstract"; |
|||
default: |
|||
return this.toString(); |
|||
} |
|||
} |
|||
|
|||
public static String getSimpleJavaType(String type) { |
|||
if(Boolean.getJavaType().equals(type)) { |
|||
return Boolean.getSimpleJavaType(); |
|||
}else if(Long.getJavaType().equals(type)) { |
|||
return Long.getSimpleJavaType(); |
|||
}else if(Float.getJavaType().equals(type)) { |
|||
return Float.getSimpleJavaType(); |
|||
}else if(Decimal.getJavaType().equals(type)) { |
|||
return Decimal.getSimpleJavaType(); |
|||
}else if(String.getJavaType().equals(type)) { |
|||
return String.getSimpleJavaType(); |
|||
}else if(Date.getJavaType().equals(type)) { |
|||
return Date.getSimpleJavaType(); |
|||
}else if(RuleResult.getJavaType().equals(type)) { |
|||
return RuleResult.getSimpleJavaType(); |
|||
}else if(SingleRuleResult.getJavaType().equals(type)) { |
|||
return SingleRuleResult.getSimpleJavaType(); |
|||
}else if(ResourceAbstract.getJavaType().equals(type)) { |
|||
return ResourceAbstract.getSimpleJavaType(); |
|||
}else { |
|||
return type; |
|||
} |
|||
} |
|||
|
|||
public static boolean isBaseType(String type) { |
|||
if( |
|||
Boolean.getJavaType().equals(type) || Boolean.getSimpleJavaType().equals(type) |
|||
|| Long.getJavaType().equals(type) || Long.getSimpleJavaType().equals(type) |
|||
|| Float.getJavaType().equals(type) || Float.getSimpleJavaType().equals(type) |
|||
|| Decimal.getJavaType().equals(type) || Decimal.getSimpleJavaType().equals(type) |
|||
|| String.getJavaType().equals(type) || String.getSimpleJavaType().equals(type) |
|||
|| Date.getJavaType().equals(type)|| Date.getSimpleJavaType().equals(type) |
|||
|| RuleResult.getJavaType().equals(type)|| RuleResult.getSimpleJavaType().equals(type) |
|||
|| SingleRuleResult.getJavaType().equals(type)|| SingleRuleResult.getSimpleJavaType().equals(type) |
|||
|| ResourceAbstract.getJavaType().equals(type)|| ResourceAbstract.getSimpleJavaType().equals(type) |
|||
) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public static String generateSampleValue(String type) { |
|||
if(Boolean.getJavaType().equals(type)) { |
|||
return "true"; |
|||
}else if(Long.getJavaType().equals(type)) { |
|||
return "1"; |
|||
}else if(Float.getJavaType().equals(type)) { |
|||
return "1.0"; |
|||
}else if(Decimal.getJavaType().equals(type)) { |
|||
return "1.0"; |
|||
}else if(String.getJavaType().equals(type)) { |
|||
return "\"string\""; |
|||
}else if(Date.getJavaType().equals(type)) { |
|||
return "\"" + DateUtil.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss) + "\""; |
|||
}else if(RuleResult.getJavaType().equals(type)) { |
|||
try { |
|||
return JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(new RuleResult()); |
|||
} catch (JsonProcessingException e) { |
|||
} |
|||
}else if(SingleRuleResult.getJavaType().equals(type)) { |
|||
try { |
|||
return JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(new SingleRuleResult()); |
|||
} catch (JsonProcessingException e) { |
|||
} |
|||
}else if(ResourceAbstract.getJavaType().equals(type)) { |
|||
try { |
|||
return JacksonObjectMapper.getDefaultObjectMapper().writeValueAsString(new ResourceAbstract()); |
|||
} catch (JsonProcessingException e) { |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
} |
@ -0,0 +1,64 @@ |
|||
package io.sc.engine.rule.core.function; |
|||
|
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.UnsupportedEncodingException; |
|||
import java.util.Map; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
|
|||
import javax.xml.bind.JAXBException; |
|||
|
|||
import org.dmg.pmml.FieldName; |
|||
import org.dmg.pmml.PMML; |
|||
import org.jpmml.evaluator.Evaluator; |
|||
import org.jpmml.evaluator.EvaluatorUtil; |
|||
import org.jpmml.evaluator.ModelEvaluatorFactory; |
|||
import org.xml.sax.SAXException; |
|||
|
|||
/** |
|||
* PMML java 实现类 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class JpmmlEvaluator { |
|||
private static Map<String,Evaluator> cache =new ConcurrentHashMap<String,Evaluator>(); |
|||
/** |
|||
* 评估 pmml |
|||
* @param id pmml id |
|||
* @param xml pmml 文件内容 |
|||
* @param map 输入参数 |
|||
* @return 输出结果 |
|||
* @throws UnsupportedEncodingException 违例 |
|||
* @throws SAXException 违例 |
|||
* @throws JAXBException 违例 |
|||
*/ |
|||
public static Map<String,?> evaluate(String id,String xml,Map<String, ?> map) throws UnsupportedEncodingException, SAXException, JAXBException{ |
|||
if(xml!=null && !xml.isEmpty() && map!=null) { |
|||
//获取评估器
|
|||
Evaluator evaluator =getEvaluator(id,xml); |
|||
if(evaluator!=null) { |
|||
//调用模型
|
|||
Map<FieldName, ?> results = evaluator.evaluate(EvaluatorUtil.encodeKeys(map)); |
|||
//获取结果并转换成 Map
|
|||
return EvaluatorUtil.decodeAll(results); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
private static synchronized Evaluator getEvaluator(String id,String xml) throws UnsupportedEncodingException, SAXException, JAXBException { |
|||
if(xml!=null && !xml.isEmpty()) { |
|||
Evaluator evaluator =cache.get(id); |
|||
if(evaluator==null) { |
|||
ByteArrayInputStream ins =new ByteArrayInputStream(xml.getBytes("UTF-8")); |
|||
PMML pmml = org.jpmml.model.PMMLUtil.unmarshal(ins); |
|||
if(pmml!=null) { |
|||
ModelEvaluatorFactory modelEvaluatorFactory = ModelEvaluatorFactory.newInstance(); |
|||
evaluator = modelEvaluatorFactory.newModelEvaluator(pmml); |
|||
cache.put(id, evaluator); |
|||
} |
|||
} |
|||
return evaluator; |
|||
} |
|||
return null; |
|||
} |
|||
} |
@ -0,0 +1,19 @@ |
|||
package io.sc.engine.rule.core.function; |
|||
|
|||
import org.apache.commons.math3.distribution.NormalDistribution; |
|||
|
|||
/** |
|||
* 正态分布函数 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class NormalDistributionFunction { |
|||
public static double normalDistributioin(double x) { |
|||
NormalDistribution normalDistributioin = new NormalDistribution(0,1); |
|||
return normalDistributioin.cumulativeProbability(x); |
|||
} |
|||
public static double inverseNormalDistributioin(double x) { |
|||
NormalDistribution normalDistributioin = new NormalDistribution(0,1); |
|||
return normalDistributioin.inverseCumulativeProbability(x); |
|||
} |
|||
} |
@ -0,0 +1,29 @@ |
|||
package io.sc.engine.rule.core.function; |
|||
|
|||
/** |
|||
* 字符串函数 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class StringFunction { |
|||
/** |
|||
* 连接多个字符串 |
|||
* @param join 连接符 |
|||
* @param strings 需要连接的字符串数组 |
|||
* @return 连接后的字符串 |
|||
*/ |
|||
public static String join(String join,String...strings) { |
|||
if(join==null) { |
|||
join =""; |
|||
} |
|||
StringBuilder sb =new StringBuilder(); |
|||
if(strings!=null && strings.length>0) { |
|||
for(String s : strings) { |
|||
if(s!=null) { |
|||
sb.append(s).append(join); |
|||
} |
|||
} |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
package io.sc.engine.rule.core.mxgraph.po; |
|||
|
|||
/** |
|||
* 并行网关 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class ParallelNode extends GraphNode{ |
|||
@Override |
|||
public String toString() { |
|||
return "Parallel [id=" + id |
|||
+ ", label=" + label |
|||
+ ", outs=" + outs + "]"; |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
package io.sc.engine.rule.core.mxgraph.po; |
|||
|
|||
/** |
|||
* 模型摘要节点 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class ResourceAbstractNode extends GraphNode{ |
|||
private String code; //代码
|
|||
private String version; //版本
|
|||
|
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
|
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
|
|||
public String getVersion() { |
|||
return version; |
|||
} |
|||
|
|||
public void setVersion(String version) { |
|||
this.version = version; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return "ResourceAbstractNode [id=" + id |
|||
+ ", label=" + label |
|||
+ ", code=" + code |
|||
+ ", version=" + version |
|||
+ ", outs=" + outs + "]"; |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
package io.sc.engine.rule.core.mxgraph.po; |
|||
|
|||
/** |
|||
* 开始节点 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class StartNode extends GraphNode{ |
|||
@Override |
|||
public String toString() { |
|||
return "StartNode [id=" + id |
|||
+ ", label=" + label |
|||
+ ", outs=" + outs + "]"; |
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
package io.sc.engine.rule.core.mxgraph.po; |
|||
|
|||
/** |
|||
* 子模型摘要节点 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class SubModelAbstractNode extends GraphNode{ |
|||
private String code; //代码
|
|||
|
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
|
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return "SubModelAbstractNode [id=" + id |
|||
+ ", label=" + label |
|||
+ ", code=" + code |
|||
+ ", outs=" + outs + "]"; |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
package io.sc.engine.rule.core.po.dictionary; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
@JsonTypeName("JAVA_CLASS") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class JavaClassDictionary extends ReleasableDictionary { |
|||
private String javaClassName; |
|||
|
|||
public String getJavaClassName() { |
|||
return javaClassName; |
|||
} |
|||
|
|||
public void setJavaClassName(String javaClassName) { |
|||
this.javaClassName = javaClassName; |
|||
} |
|||
} |
@ -0,0 +1,25 @@ |
|||
package io.sc.engine.rule.core.po.dictionary; |
|||
|
|||
import io.sc.engine.rule.core.enums.DeployStatus; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
|
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public abstract class ReleasableDictionary extends Dictionary{ |
|||
protected DeployStatus status; //状态
|
|||
protected Integer version; //版本
|
|||
|
|||
|
|||
public DeployStatus getStatus() { |
|||
return status; |
|||
} |
|||
public void setStatus(DeployStatus status) { |
|||
this.status = status; |
|||
} |
|||
public Integer getVersion() { |
|||
return version; |
|||
} |
|||
public void setVersion(Integer version) { |
|||
this.version = version; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
package io.sc.engine.rule.core.po.dictionary; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
@JsonTypeName("UD_JAVA_CLASS") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class UserDefinedJavaClassDictionary extends ReleasableDictionary { |
|||
protected List<UserDefinedJavaClassField> fields =new ArrayList<UserDefinedJavaClassField>(); |
|||
|
|||
public List<UserDefinedJavaClassField> getFields() { |
|||
return fields; |
|||
} |
|||
|
|||
public void setFields(List<UserDefinedJavaClassField> fields) { |
|||
this.fields = fields; |
|||
} |
|||
} |
@ -0,0 +1,68 @@ |
|||
package io.sc.engine.rule.core.po.dictionary; |
|||
|
|||
public class UserDefinedJavaClassField { |
|||
protected String id; //Id
|
|||
protected String code; //代码
|
|||
protected String name; //名称
|
|||
protected String description; //描述
|
|||
protected String valueType; //值类型
|
|||
protected Boolean valueTypeIsList; //值是否为列表
|
|||
protected String defaultValue; //默认值
|
|||
protected String valueCalculation; //值计算逻辑
|
|||
protected Integer order; //排序
|
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
public void setDescription(String description) { |
|||
this.description = description; |
|||
} |
|||
public String getValueType() { |
|||
return valueType; |
|||
} |
|||
public void setValueType(String valueType) { |
|||
this.valueType = valueType; |
|||
} |
|||
public Boolean getValueTypeIsList() { |
|||
return valueTypeIsList; |
|||
} |
|||
public void setValueTypeIsList(Boolean valueTypeIsList) { |
|||
this.valueTypeIsList = valueTypeIsList; |
|||
} |
|||
public String getDefaultValue() { |
|||
return defaultValue; |
|||
} |
|||
public void setDefaultValue(String defaultValue) { |
|||
this.defaultValue = defaultValue; |
|||
} |
|||
public String getValueCalculation() { |
|||
return valueCalculation; |
|||
} |
|||
public void setValueCalculation(String valueCalculation) { |
|||
this.valueCalculation = valueCalculation; |
|||
} |
|||
public Integer getOrder() { |
|||
return order; |
|||
} |
|||
public void setOrder(Integer order) { |
|||
this.order = order; |
|||
} |
|||
} |
@ -0,0 +1,74 @@ |
|||
package io.sc.engine.rule.core.po.lib; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.po.testcase.LibTestCase; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonSubTypes; |
|||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
|||
|
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type",defaultImpl=FolderLib.class) |
|||
@JsonSubTypes({ |
|||
@JsonSubTypes.Type(value=FolderLib.class), |
|||
@JsonSubTypes.Type(value=IndicatorLib.class) |
|||
}) |
|||
public abstract class Lib { |
|||
protected String id; //Id
|
|||
protected String code; //代码
|
|||
protected String name; //名称
|
|||
protected String description; //描述
|
|||
protected Integer order; //排序
|
|||
private List<Lib> children =new ArrayList<Lib>();//孩子集合
|
|||
protected List<LibTestCase> testCases =new ArrayList<LibTestCase>();//测试用例
|
|||
|
|||
public Lib() {} |
|||
public Lib(String id) { |
|||
this.id =id; |
|||
} |
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
public void setDescription(String description) { |
|||
this.description = description; |
|||
} |
|||
public Integer getOrder() { |
|||
return order; |
|||
} |
|||
public void setOrder(Integer order) { |
|||
this.order = order; |
|||
} |
|||
public List<Lib> getChildren() { |
|||
return children; |
|||
} |
|||
public void setChildren(List<Lib> children) { |
|||
this.children = children; |
|||
} |
|||
public List<LibTestCase> getTestCases() { |
|||
return testCases; |
|||
} |
|||
public void setTestCases(List<LibTestCase> testCases) { |
|||
this.testCases = testCases; |
|||
} |
|||
} |
@ -0,0 +1,45 @@ |
|||
package io.sc.engine.rule.core.po.lib; |
|||
|
|||
/** |
|||
* 指标范围验证器 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public abstract class RangeIndicatorValidator extends IndicatorValidator { |
|||
protected String minValue;//最小值
|
|||
protected String maxValue;//最小值
|
|||
protected Boolean minInclude;//是否包含最小值
|
|||
protected Boolean maxInclude;//是否包含最大值
|
|||
|
|||
public String getMinValue() { |
|||
return minValue; |
|||
} |
|||
|
|||
public void setMinValue(String minValue) { |
|||
this.minValue = minValue; |
|||
} |
|||
|
|||
public String getMaxValue() { |
|||
return maxValue; |
|||
} |
|||
|
|||
public void setMaxValue(String maxValue) { |
|||
this.maxValue = maxValue; |
|||
} |
|||
|
|||
public Boolean getMinInclude() { |
|||
return minInclude; |
|||
} |
|||
|
|||
public void setMinInclude(Boolean minInclude) { |
|||
this.minInclude = minInclude; |
|||
} |
|||
|
|||
public Boolean getMaxInclude() { |
|||
return maxInclude; |
|||
} |
|||
|
|||
public void setMaxInclude(Boolean maxInclude) { |
|||
this.maxInclude = maxInclude; |
|||
} |
|||
} |
@ -0,0 +1,25 @@ |
|||
package io.sc.engine.rule.core.po.lib; |
|||
|
|||
import io.sc.engine.rule.core.enums.DeployStatus; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
|
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public abstract class ReleasableLib extends Lib{ |
|||
protected DeployStatus status; //状态
|
|||
protected Integer version; //版本
|
|||
|
|||
|
|||
public DeployStatus getStatus() { |
|||
return status; |
|||
} |
|||
public void setStatus(DeployStatus status) { |
|||
this.status = status; |
|||
} |
|||
public Integer getVersion() { |
|||
return version; |
|||
} |
|||
public void setVersion(Integer version) { |
|||
this.version = version; |
|||
} |
|||
} |
@ -0,0 +1,32 @@ |
|||
package io.sc.engine.rule.core.po.lib.indicator; |
|||
|
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
import io.sc.engine.rule.core.enums.IndicatorType; |
|||
import io.sc.engine.rule.core.po.lib.Indicator; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 指标(接口) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("INDICATOR") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class IndicatorIndicator extends Indicator { |
|||
@Override |
|||
public IndicatorType getType() { |
|||
return IndicatorType.INDICATOR; |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromMap(ResourceWrapper wrapper,String targetVarName) { |
|||
return "//skip " + this.getName(); |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromJson(ResourceWrapper wrapper,String targetVarName) { |
|||
return "//" + this.getName(); |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
package io.sc.engine.rule.core.po.lib.indicator; |
|||
|
|||
import io.sc.engine.rule.core.enums.IndicatorType; |
|||
import io.sc.engine.rule.core.po.lib.Indicator; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 指标(接口) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("INTERFACE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class InterfaceIndicator extends Indicator { |
|||
@Override |
|||
public IndicatorType getType() { |
|||
return IndicatorType.INTERFACE; |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
package io.sc.engine.rule.core.po.lib.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.lib.IndicatorProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 指标处理器(数值范围操作) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("NUMBER_RANGE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class NumberRangeIndicatorProcessor extends IndicatorProcessor { |
|||
private String numberRangeVar;//数值分段函数变量表达式
|
|||
private String numberRange;//数值分段函数
|
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.NUMBER_RANGE; |
|||
} |
|||
|
|||
public String getNumberRangeVar() { |
|||
return numberRangeVar; |
|||
} |
|||
public void setNumberRangeVar(String numberRangeVar) { |
|||
this.numberRangeVar = numberRangeVar; |
|||
} |
|||
public String getNumberRange() { |
|||
return numberRange; |
|||
} |
|||
public void setNumberRange(String numberRange) { |
|||
this.numberRange = numberRange; |
|||
} |
|||
} |
@ -0,0 +1,51 @@ |
|||
package io.sc.engine.rule.core.po.lib.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.lib.IndicatorProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 指标处理器(SQL赋值操作) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("SQL") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class SqlIndicatorProcessor extends IndicatorProcessor { |
|||
private String sqlDatasourceName; //数据源名称
|
|||
private String sql; //SQL 语句
|
|||
private String sqlParameterValues; //SQL 语句中参数的测试值
|
|||
private String sqlFieldMapping; //查询结果字段和模型参数的映射
|
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.SQL; |
|||
} |
|||
|
|||
public String getSqlDatasourceName() { |
|||
return sqlDatasourceName; |
|||
} |
|||
public void setSqlDatasourceName(String sqlDatasourceName) { |
|||
this.sqlDatasourceName = sqlDatasourceName; |
|||
} |
|||
public String getSql() { |
|||
return sql; |
|||
} |
|||
public void setSql(String sql) { |
|||
this.sql = sql; |
|||
} |
|||
public String getSqlParameterValues() { |
|||
return sqlParameterValues; |
|||
} |
|||
public void setSqlParameterValues(String sqlParameterValues) { |
|||
this.sqlParameterValues = sqlParameterValues; |
|||
} |
|||
public String getSqlFieldMapping() { |
|||
return sqlFieldMapping; |
|||
} |
|||
public void setSqlFieldMapping(String sqlFieldMapping) { |
|||
this.sqlFieldMapping = sqlFieldMapping; |
|||
} |
|||
} |
@ -0,0 +1,44 @@ |
|||
package io.sc.engine.rule.core.po.lib.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.lib.IndicatorProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 指标处理器(三元操作) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("TERNARY") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class TernaryIndicatorProcessor extends IndicatorProcessor { |
|||
private String ternaryCondition;//三元操作的条件
|
|||
private String ternaryTrue;//三元操作的条件成立时的操作
|
|||
private String ternaryFalse;//三元操作的条件不成立时的操作
|
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.TERNARY; |
|||
} |
|||
|
|||
public String getTernaryCondition() { |
|||
return ternaryCondition; |
|||
} |
|||
public void setTernaryCondition(String ternaryCondition) { |
|||
this.ternaryCondition = ternaryCondition; |
|||
} |
|||
public String getTernaryTrue() { |
|||
return ternaryTrue; |
|||
} |
|||
public void setTernaryTrue(String ternaryTrue) { |
|||
this.ternaryTrue = ternaryTrue; |
|||
} |
|||
public String getTernaryFalse() { |
|||
return ternaryFalse; |
|||
} |
|||
public void setTernaryFalse(String ternaryFalse) { |
|||
this.ternaryFalse = ternaryFalse; |
|||
} |
|||
} |
@ -0,0 +1,44 @@ |
|||
package io.sc.engine.rule.core.po.lib.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.lib.IndicatorProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 指标处理器(WhenThen操作) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("WHEN_THEN") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class WhenThenIndicatorProcessor extends IndicatorProcessor { |
|||
private String when;//When表达式
|
|||
private String then;//Then表达式
|
|||
private Boolean isWhenThenShorted;//When表达式成立时是否短路操作(当 When 条件满足时,执行完 Then 操作后,不再进行后续处理)
|
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.WHEN_THEN; |
|||
} |
|||
|
|||
public String getWhen() { |
|||
return when; |
|||
} |
|||
public void setWhen(String when) { |
|||
this.when = when; |
|||
} |
|||
public String getThen() { |
|||
return then; |
|||
} |
|||
public void setThen(String then) { |
|||
this.then = then; |
|||
} |
|||
public Boolean getIsWhenThenShorted() { |
|||
return isWhenThenShorted; |
|||
} |
|||
public void setIsWhenThenShorted(Boolean isWhenThenShorted) { |
|||
this.isWhenThenShorted = isWhenThenShorted; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
package io.sc.engine.rule.core.po.lib.validator; |
|||
|
|||
import io.sc.engine.rule.core.enums.ValidatorType; |
|||
import io.sc.engine.rule.core.po.lib.RangeIndicatorValidator; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 验证器(整数范围) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("INTEGER_RANGE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class IntegerRangeIndicatorValidator extends RangeIndicatorValidator { |
|||
@Override |
|||
public ValidatorType getType() { |
|||
return ValidatorType.INTEGER_RANGE; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
package io.sc.engine.rule.core.po.lib.validator; |
|||
|
|||
import io.sc.engine.rule.core.enums.ValidatorType; |
|||
import io.sc.engine.rule.core.po.lib.RangeIndicatorValidator; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 验证器(长度范围) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("LENGTH_RANGE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class LengthRangeIndicatorValidator extends RangeIndicatorValidator { |
|||
@Override |
|||
public ValidatorType getType() { |
|||
return ValidatorType.LENGTH_RANGE; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
package io.sc.engine.rule.core.po.lib.validator; |
|||
|
|||
import io.sc.engine.rule.core.enums.ValidatorType; |
|||
import io.sc.engine.rule.core.po.lib.IndicatorValidator; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 验证器(非空) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("NOT_EMPTY") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class NotEmptyIndicatorValidator extends IndicatorValidator { |
|||
@Override |
|||
public ValidatorType getType() { |
|||
return ValidatorType.NOT_EMPTY; |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
package io.sc.engine.rule.core.po.lib.validator; |
|||
|
|||
import io.sc.engine.rule.core.enums.ValidatorType; |
|||
import io.sc.engine.rule.core.po.lib.IndicatorValidator; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 验证器(正则表达式) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("PATTERN") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class PatternIndicatorValidator extends IndicatorValidator { |
|||
protected String pattern;//正则表达式
|
|||
|
|||
@Override |
|||
public ValidatorType getType() { |
|||
return ValidatorType.PATTERN; |
|||
} |
|||
|
|||
public String getPattern() { |
|||
return pattern; |
|||
} |
|||
|
|||
public void setPattern(String pattern) { |
|||
this.pattern = pattern; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
package io.sc.engine.rule.core.po.lib.validator; |
|||
|
|||
import io.sc.engine.rule.core.enums.ValidatorType; |
|||
import io.sc.engine.rule.core.po.lib.IndicatorValidator; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 验证器(真) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("TRUE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class TrueIndicatorValidator extends IndicatorValidator { |
|||
@Override |
|||
public ValidatorType getType() { |
|||
return ValidatorType.TRUE; |
|||
} |
|||
} |
@ -0,0 +1,168 @@ |
|||
package io.sc.engine.rule.core.po.model; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.enums.ExecuteMode; |
|||
import io.sc.engine.rule.core.enums.ModelCategory; |
|||
import io.sc.engine.rule.core.enums.ParameterType; |
|||
import io.sc.engine.rule.core.po.model.parameter.InOptionParameter; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
|
|||
public class Model { |
|||
protected String id; //Id
|
|||
protected String code; //代码
|
|||
protected String name; //名称
|
|||
protected String description; //描述
|
|||
protected Boolean enable; //是否可用
|
|||
protected Integer order; //排序
|
|||
protected ModelCategory category; //分类
|
|||
protected ExecuteMode executeMode; //执行模式
|
|||
protected List<Model> children =new ArrayList<Model>();//孩子集合
|
|||
protected List<Parameter> parameters =new ArrayList<Parameter>(); |
|||
|
|||
@JsonIgnore |
|||
protected String fullName; //全名称
|
|||
|
|||
public void buildFullName() { |
|||
buildFullName(""); |
|||
} |
|||
|
|||
public void buildFullName(String prefix) { |
|||
this.setFullName((prefix.isEmpty()?"":prefix+"/") + this.name); |
|||
List<Model> children =this.getChildren(); |
|||
if(children!=null && children.size()>0) { |
|||
for(Model child : children) { |
|||
child.buildFullName(this.getFullName()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@JsonIgnore |
|||
public List<Parameter> getAllParameters(){ |
|||
return getRecursiveParameters(this); |
|||
} |
|||
|
|||
@JsonIgnore |
|||
private List<Parameter> getRecursiveParameters(Model model){ |
|||
if(model!=null) { |
|||
List<Parameter> result =new ArrayList<Parameter>(); |
|||
|
|||
List<Model> subModels =model.getChildren(); |
|||
if(subModels!=null && subModels.size()>0) { |
|||
for(Model subModel : subModels) { |
|||
List<Parameter> subParameters =getRecursiveParameters(subModel); |
|||
if(subParameters!=null && subParameters.size()>0) { |
|||
result.addAll(subParameters); |
|||
} |
|||
} |
|||
} |
|||
List<Parameter> parameters =model.getParameters(); |
|||
if(parameters!=null && parameters.size()>0) { |
|||
result.addAll(parameters); |
|||
} |
|||
return result; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@JsonIgnore |
|||
public List<ParameterInOptionItem> getParameterOptionsByOptionParameterCode(String code){ |
|||
if(code!=null && !code.trim().isEmpty()) { |
|||
List<Parameter> parameters =this.getAllParameters(); |
|||
if(parameters!=null && parameters.size()>0) { |
|||
for(Parameter parameter : parameters) { |
|||
if(ParameterType.IN_OPTION.equals(parameter.getType()) && code.equals(parameter.getCode())) { |
|||
InOptionParameter _parameter =(InOptionParameter)parameter; |
|||
return _parameter.getOptions(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return new ArrayList<ParameterInOptionItem>(); |
|||
} |
|||
|
|||
@JsonIgnore |
|||
public Parameter getParameterByOptionParameterCode(String code){ |
|||
if(code!=null && !code.trim().isEmpty()) { |
|||
List<Parameter> parameters =this.getAllParameters(); |
|||
if(parameters!=null && parameters.size()>0) { |
|||
for(Parameter parameter : parameters) { |
|||
if(ParameterType.IN_OPTION.equals(parameter.getType()) && code.equals(parameter.getCode())) { |
|||
return parameter; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public String getFullName() { |
|||
return fullName; |
|||
} |
|||
public void setFullName(String fullName) { |
|||
this.fullName = fullName; |
|||
} |
|||
public String getId() { |
|||
return id; |
|||
} |
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
public void setDescription(String description) { |
|||
this.description = description; |
|||
} |
|||
public Boolean getEnable() { |
|||
return enable; |
|||
} |
|||
public void setEnable(Boolean enable) { |
|||
this.enable = enable; |
|||
} |
|||
public Integer getOrder() { |
|||
return order; |
|||
} |
|||
public void setOrder(Integer order) { |
|||
this.order = order; |
|||
} |
|||
public ModelCategory getCategory() { |
|||
return category; |
|||
} |
|||
public void setCategory(ModelCategory category) { |
|||
this.category = category; |
|||
} |
|||
public ExecuteMode getExecuteMode() { |
|||
return executeMode; |
|||
} |
|||
public void setExecuteMode(ExecuteMode executeMode) { |
|||
this.executeMode = executeMode; |
|||
} |
|||
public List<Model> getChildren() { |
|||
return children; |
|||
} |
|||
public void setChildren(List<Model> children) { |
|||
this.children = children; |
|||
} |
|||
public List<Parameter> getParameters() { |
|||
return parameters; |
|||
} |
|||
public void setParameters(List<Parameter> parameters) { |
|||
this.parameters = parameters; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,209 @@ |
|||
package io.sc.engine.rule.core.po.model; |
|||
|
|||
import java.math.RoundingMode; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
import io.sc.engine.rule.core.code.impl.support.parameter.ParameterGroovyCodeContributionItem; |
|||
import io.sc.engine.rule.core.enums.ParameterType; |
|||
import io.sc.engine.rule.core.enums.ValueType; |
|||
import io.sc.engine.rule.core.po.model.parameter.ConstantParameter; |
|||
import io.sc.engine.rule.core.po.model.parameter.InOptionParameter; |
|||
import io.sc.engine.rule.core.po.model.parameter.InParameter; |
|||
import io.sc.engine.rule.core.po.model.parameter.InSubOutParameter; |
|||
import io.sc.engine.rule.core.po.model.parameter.IndicatorParameter; |
|||
import io.sc.engine.rule.core.po.model.parameter.IntermediateParameter; |
|||
import io.sc.engine.rule.core.po.model.parameter.OutParameter; |
|||
import io.sc.engine.rule.core.po.model.parameter.RuleResultParameter; |
|||
import io.sc.engine.rule.core.po.model.parameter.SingleRuleResultParameter; |
|||
import io.sc.engine.rule.core.util.CodeReplacer; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonSubTypes; |
|||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
|||
|
|||
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type",defaultImpl=InParameter.class) |
|||
@JsonSubTypes({ |
|||
@JsonSubTypes.Type(value=ConstantParameter.class), //常量
|
|||
@JsonSubTypes.Type(value=IndicatorParameter.class), //指标
|
|||
@JsonSubTypes.Type(value=InParameter.class), //输入值
|
|||
@JsonSubTypes.Type(value=InOptionParameter.class), //输入选项
|
|||
@JsonSubTypes.Type(value=InSubOutParameter.class), //子模型输出
|
|||
@JsonSubTypes.Type(value=IntermediateParameter.class), //中间值
|
|||
@JsonSubTypes.Type(value=RuleResultParameter.class), //规则结果值
|
|||
@JsonSubTypes.Type(value=SingleRuleResultParameter.class), //单规则结果值
|
|||
@JsonSubTypes.Type(value=OutParameter.class) //结果值
|
|||
|
|||
}) |
|||
public abstract class Parameter implements ParameterGroovyCodeContributionItem{ |
|||
protected String id;//ID,主键
|
|||
protected String code;//代码
|
|||
protected String name;//名称
|
|||
protected String description;//描述
|
|||
protected String valueType;//参数值类型
|
|||
protected Integer valueTypeVersion;//参数值类型版本号
|
|||
protected Integer valueScale;//参数值精度
|
|||
protected RoundingMode valueRoundingMode;//参数值四舍五入模式
|
|||
protected Boolean valueTypeIsList;//参数值类型是否是列表
|
|||
protected String defaultValue;//默认值
|
|||
protected Integer order;//排序
|
|||
protected List<ParameterValidator> validators =new ArrayList<ParameterValidator>();//包含的验证器
|
|||
protected List<ParameterProcessor> processors =new ArrayList<ParameterProcessor>();//包含的处理器
|
|||
|
|||
@JsonIgnore |
|||
public abstract ParameterType getType(); |
|||
|
|||
public String getValueTypeFullName() { |
|||
String parameterValueType =this.getValueType(); |
|||
if(ValueType.isBaseType(parameterValueType)) { |
|||
parameterValueType =ValueType.getSimpleJavaType(parameterValueType); |
|||
}else { |
|||
parameterValueType =parameterValueType + (this.getValueTypeVersion()==null?"":"_V" + this.getValueTypeVersion()); |
|||
} |
|||
return parameterValueType; |
|||
} |
|||
|
|||
@Override |
|||
public String forArgumentField(ResourceWrapper wrapper) { |
|||
StringBuilder sb =new StringBuilder(""); |
|||
String parameterCode =this.getCode(); |
|||
String parameterValueType =getValueTypeFullName(); |
|||
|
|||
if("String".equals(parameterValueType)) { |
|||
if(this.getDefaultValue()!=null) { |
|||
sb.append("String ").append(CodeReplacer.fieldName(parameterCode)).append(" =\"\"\"").append(this.getDefaultValue()).append("\"\"\"").append(";"); |
|||
}else { |
|||
sb.append("String ").append(CodeReplacer.fieldName(parameterCode)).append(";"); |
|||
} |
|||
sb.append("//").append(this.getName()); |
|||
}else { |
|||
if(this.getDefaultValue()!=null) { |
|||
sb.append(parameterValueType).append(" ").append(CodeReplacer.fieldName(parameterCode)).append(" =").append(this.getDefaultValue()).append(";"); |
|||
}else { |
|||
sb.append(parameterValueType).append(" ").append(CodeReplacer.fieldName(parameterCode)).append(";"); |
|||
} |
|||
sb.append("//").append(this.getName()); |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromMap(ResourceWrapper wrapper,String targetVarName) { |
|||
StringBuilder sb =new StringBuilder(""); |
|||
String parameterCode =this.getCode(); |
|||
String parameterValueType =getValueTypeFullName(); |
|||
|
|||
if(this.getValueTypeIsList()) { |
|||
sb.append("obj =DataTypeConvertor.convert(map.get(\"").append(parameterCode).append("\"),"); |
|||
sb.append("new TypeReference<List<").append(parameterValueType).append(">>(){});\n"); |
|||
}else { |
|||
sb.append("obj =DataTypeConvertor.convert(map.get(\"").append(parameterCode).append("\"),"); |
|||
sb.append(parameterValueType).append(".class);\n"); |
|||
} |
|||
sb.append("\t\t\t"); |
|||
sb.append("if(obj!=null){"); |
|||
sb.append(targetVarName).append(".").append(CodeReplacer.fieldName(parameterCode)).append(" =obj;"); |
|||
sb.append("}"); |
|||
sb.append("//").append(this.getName()); |
|||
|
|||
if(!ValueType.isBaseType(parameterValueType)) { |
|||
sb.append("\\n\t\t\t"); |
|||
sb.append("if(").append(targetVarName).append(".").append(CodeReplacer.fieldName(parameterCode)).append("!=null){"); |
|||
sb.append(targetVarName).append(".").append(CodeReplacer.fieldName(parameterCode)).append(".init();}"); |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromJson(ResourceWrapper wrapper,String targetVarName) { |
|||
StringBuilder sb =new StringBuilder(""); |
|||
String parameterValueType =getValueTypeFullName(); |
|||
if(!ValueType.isBaseType(parameterValueType)) { |
|||
sb.append("if(").append(targetVarName).append(".").append(CodeReplacer.fieldName(this.getCode())).append("!=null){"); |
|||
sb.append(targetVarName).append(".").append(CodeReplacer.fieldName(this.getCode())).append(".init();}"); |
|||
}else { |
|||
sb.append("//skip ").append(this.getName()); |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
public void setDescription(String description) { |
|||
this.description = description; |
|||
} |
|||
public String getValueType() { |
|||
return valueType; |
|||
} |
|||
public void setValueType(String valueType) { |
|||
this.valueType = valueType; |
|||
} |
|||
public Integer getValueTypeVersion() { |
|||
return valueTypeVersion; |
|||
} |
|||
public void setValueTypeVersion(Integer valueTypeVersion) { |
|||
this.valueTypeVersion = valueTypeVersion; |
|||
} |
|||
public Integer getValueScale() { |
|||
return valueScale; |
|||
} |
|||
public void setValueScale(Integer valueScale) { |
|||
this.valueScale = valueScale; |
|||
} |
|||
public RoundingMode getValueRoundingMode() { |
|||
return valueRoundingMode; |
|||
} |
|||
public void setValueRoundingMode(RoundingMode valueRoundingMode) { |
|||
this.valueRoundingMode = valueRoundingMode; |
|||
} |
|||
public Boolean getValueTypeIsList() { |
|||
return valueTypeIsList; |
|||
} |
|||
public void setValueTypeIsList(Boolean valueTypeIsList) { |
|||
this.valueTypeIsList = valueTypeIsList; |
|||
} |
|||
public String getDefaultValue() { |
|||
return defaultValue; |
|||
} |
|||
public void setDefaultValue(String defaultValue) { |
|||
this.defaultValue = defaultValue; |
|||
} |
|||
public Integer getOrder() { |
|||
return order; |
|||
} |
|||
public void setOrder(Integer order) { |
|||
this.order = order; |
|||
} |
|||
public List<ParameterValidator> getValidators() { |
|||
return validators; |
|||
} |
|||
public void setValidators(List<ParameterValidator> validators) { |
|||
this.validators = validators; |
|||
} |
|||
public List<ParameterProcessor> getProcessors() { |
|||
return processors; |
|||
} |
|||
public void setProcessors(List<ParameterProcessor> processors) { |
|||
this.processors = processors; |
|||
} |
|||
} |
@ -0,0 +1,54 @@ |
|||
package io.sc.engine.rule.core.po.model; |
|||
|
|||
public class ParameterInOptionItem { |
|||
protected String id;//ID,主键
|
|||
protected String inputValue;//选项输入值
|
|||
protected String value;//选项值
|
|||
protected String title;//选项显示文本
|
|||
protected String description;//描述
|
|||
protected Integer order;//排序
|
|||
protected String config;//配置
|
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
public String getInputValue() { |
|||
return inputValue; |
|||
} |
|||
public void setInputValue(String inputValue) { |
|||
this.inputValue = inputValue; |
|||
} |
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
public void setValue(String value) { |
|||
this.value = value; |
|||
} |
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
public void setTitle(String title) { |
|||
this.title = title; |
|||
} |
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
public void setDescription(String description) { |
|||
this.description = description; |
|||
} |
|||
public Integer getOrder() { |
|||
return order; |
|||
} |
|||
public void setOrder(Integer order) { |
|||
this.order = order; |
|||
} |
|||
public String getConfig() { |
|||
return config; |
|||
} |
|||
public void setConfig(String config) { |
|||
this.config = config; |
|||
} |
|||
} |
@ -0,0 +1,92 @@ |
|||
package io.sc.engine.rule.core.po.model; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.model.processor.ArithmeticParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.ConditionRangeParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.DecisionTable2CParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.DecisionTableParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.DecisionTreeParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.EmptyParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.ExecutionFlowParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.GroovyScriptParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.HttpRequestParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.NumberRangeParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.OptionValueParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.PmmlParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.RuleParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.SingleRuleParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.SqlParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.TernaryParameterProcessor; |
|||
import io.sc.engine.rule.core.po.model.processor.WhenThenParameterProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonSubTypes; |
|||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
|||
|
|||
/** |
|||
* 参数处理器 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type",defaultImpl=EmptyParameterProcessor.class) |
|||
@JsonSubTypes({ |
|||
@JsonSubTypes.Type(value=OptionValueParameterProcessor.class), //选项操作处理器
|
|||
@JsonSubTypes.Type(value=ArithmeticParameterProcessor.class), //算数操作处理器
|
|||
@JsonSubTypes.Type(value=ConditionRangeParameterProcessor.class), //条件范围处理器
|
|||
@JsonSubTypes.Type(value=DecisionTable2CParameterProcessor.class), //简单决策表处理器
|
|||
@JsonSubTypes.Type(value=DecisionTableParameterProcessor.class), //决策表处理器
|
|||
@JsonSubTypes.Type(value=DecisionTreeParameterProcessor.class), //决策树处理器
|
|||
@JsonSubTypes.Type(value=EmptyParameterProcessor.class), //空处理器
|
|||
@JsonSubTypes.Type(value=ExecutionFlowParameterProcessor.class), //执行流处理器
|
|||
@JsonSubTypes.Type(value=NumberRangeParameterProcessor.class), //数值范围处理器
|
|||
@JsonSubTypes.Type(value=PmmlParameterProcessor.class), //PMML处理器
|
|||
@JsonSubTypes.Type(value=GroovyScriptParameterProcessor.class), //脚本代码处理器
|
|||
@JsonSubTypes.Type(value=TernaryParameterProcessor.class), //三元操作处理器
|
|||
@JsonSubTypes.Type(value=WhenThenParameterProcessor.class), //When-Then 操作处理器
|
|||
@JsonSubTypes.Type(value=RuleParameterProcessor.class), //规则处理器
|
|||
@JsonSubTypes.Type(value=SingleRuleParameterProcessor.class), //规则处理器
|
|||
@JsonSubTypes.Type(value=SqlParameterProcessor.class), //SQL赋值处理器
|
|||
@JsonSubTypes.Type(value=HttpRequestParameterProcessor.class) //Http请求处理器
|
|||
}) |
|||
public abstract class ParameterProcessor { |
|||
protected String id; //ID,主键
|
|||
protected String description; //描述
|
|||
protected Integer order; //排序
|
|||
protected Boolean enable; //是否可用
|
|||
|
|||
@JsonIgnore |
|||
public abstract ProcessorType getType(); |
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
|
|||
public void setDescription(String description) { |
|||
this.description = description; |
|||
} |
|||
|
|||
public Integer getOrder() { |
|||
return order; |
|||
} |
|||
|
|||
public void setOrder(Integer order) { |
|||
this.order = order; |
|||
} |
|||
|
|||
public Boolean getEnable() { |
|||
return enable; |
|||
} |
|||
|
|||
public void setEnable(Boolean enable) { |
|||
this.enable = enable; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,66 @@ |
|||
package io.sc.engine.rule.core.po.model; |
|||
|
|||
import io.sc.engine.rule.core.po.model.validator.DateRangeParameterValidator; |
|||
import io.sc.engine.rule.core.po.model.validator.DecimalRangeParameterValidator; |
|||
import io.sc.engine.rule.core.po.model.validator.EmailParameterValidator; |
|||
import io.sc.engine.rule.core.po.model.validator.EmptyParameterValidator; |
|||
import io.sc.engine.rule.core.po.model.validator.FalseParameterValidator; |
|||
import io.sc.engine.rule.core.po.model.validator.IntegerRangeParameterValidator; |
|||
import io.sc.engine.rule.core.po.model.validator.LengthRangeParameterValidator; |
|||
import io.sc.engine.rule.core.po.model.validator.NotEmptyParameterValidator; |
|||
import io.sc.engine.rule.core.po.model.validator.PatternParameterValidator; |
|||
import io.sc.engine.rule.core.po.model.validator.TrueParameterValidator; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonSubTypes; |
|||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
|||
|
|||
/** |
|||
* 模型参数验证器 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type",defaultImpl=EmptyParameterValidator.class) |
|||
@JsonSubTypes({ |
|||
@JsonSubTypes.Type(value=DateRangeParameterValidator.class), |
|||
@JsonSubTypes.Type(value=DecimalRangeParameterValidator.class), |
|||
@JsonSubTypes.Type(value=EmailParameterValidator.class), |
|||
@JsonSubTypes.Type(value=EmptyParameterValidator.class), |
|||
@JsonSubTypes.Type(value=FalseParameterValidator.class), |
|||
@JsonSubTypes.Type(value=IntegerRangeParameterValidator.class), |
|||
@JsonSubTypes.Type(value=LengthRangeParameterValidator.class), |
|||
@JsonSubTypes.Type(value=NotEmptyParameterValidator.class), |
|||
@JsonSubTypes.Type(value=PatternParameterValidator.class), |
|||
@JsonSubTypes.Type(value=TrueParameterValidator.class) |
|||
}) |
|||
public class ParameterValidator { |
|||
protected String id;//ID,主键
|
|||
protected String description;//描述
|
|||
protected Integer order;//排序
|
|||
protected String tip;//错误提示
|
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
public void setDescription(String description) { |
|||
this.description = description; |
|||
} |
|||
public Integer getOrder() { |
|||
return order; |
|||
} |
|||
public void setOrder(Integer order) { |
|||
this.order = order; |
|||
} |
|||
|
|||
public String getTip() { |
|||
return tip; |
|||
} |
|||
public void setTip(String tip) { |
|||
this.tip = tip; |
|||
} |
|||
} |
@ -0,0 +1,45 @@ |
|||
package io.sc.engine.rule.core.po.model; |
|||
|
|||
/** |
|||
* 模型参数范围验证器 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public class RangeParameterValidator extends ParameterValidator { |
|||
protected String minValue;//最小值
|
|||
protected String maxValue;//最小值
|
|||
protected Boolean minInclude;//是否包含最小值
|
|||
protected Boolean maxInclude;//是否包含最大值
|
|||
|
|||
public String getMinValue() { |
|||
return minValue; |
|||
} |
|||
|
|||
public void setMinValue(String minValue) { |
|||
this.minValue = minValue; |
|||
} |
|||
|
|||
public String getMaxValue() { |
|||
return maxValue; |
|||
} |
|||
|
|||
public void setMaxValue(String maxValue) { |
|||
this.maxValue = maxValue; |
|||
} |
|||
|
|||
public Boolean getMinInclude() { |
|||
return minInclude; |
|||
} |
|||
|
|||
public void setMinInclude(Boolean minInclude) { |
|||
this.minInclude = minInclude; |
|||
} |
|||
|
|||
public Boolean getMaxInclude() { |
|||
return maxInclude; |
|||
} |
|||
|
|||
public void setMaxInclude(Boolean maxInclude) { |
|||
this.maxInclude = maxInclude; |
|||
} |
|||
} |
@ -0,0 +1,34 @@ |
|||
package io.sc.engine.rule.core.po.model.parameter; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import io.sc.engine.rule.core.enums.ParameterType; |
|||
import io.sc.engine.rule.core.po.model.Parameter; |
|||
import io.sc.engine.rule.core.po.model.ParameterInOptionItem; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数(输入选项) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("IN_OPTION") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class InOptionParameter extends Parameter { |
|||
protected List<ParameterInOptionItem> options =new ArrayList<ParameterInOptionItem>();//选项列表
|
|||
|
|||
@Override |
|||
public ParameterType getType() { |
|||
return ParameterType.IN_OPTION; |
|||
} |
|||
|
|||
public List<ParameterInOptionItem> getOptions() { |
|||
return options; |
|||
} |
|||
public void setOptions(List<ParameterInOptionItem> options) { |
|||
this.options = options; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
package io.sc.engine.rule.core.po.model.parameter; |
|||
|
|||
import io.sc.engine.rule.core.enums.ParameterType; |
|||
import io.sc.engine.rule.core.po.model.Parameter; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数(输入值) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("IN") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class InParameter extends Parameter { |
|||
@Override |
|||
public ParameterType getType() { |
|||
return ParameterType.IN; |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
package io.sc.engine.rule.core.po.model.parameter; |
|||
|
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
import io.sc.engine.rule.core.enums.ParameterType; |
|||
import io.sc.engine.rule.core.po.model.Parameter; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数(子模型输出) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("IN_SUB_OUT") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class InSubOutParameter extends Parameter { |
|||
@Override |
|||
public ParameterType getType() { |
|||
return ParameterType.IN_SUB_OUT; |
|||
} |
|||
|
|||
@Override |
|||
public String forArgumentField(ResourceWrapper wrapper) { |
|||
return ""; |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
package io.sc.engine.rule.core.po.model.parameter; |
|||
|
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
import io.sc.engine.rule.core.code.impl.support.parameter.ParameterGroovyCodeContributionItem; |
|||
import io.sc.engine.rule.core.enums.ParameterType; |
|||
import io.sc.engine.rule.core.po.model.Parameter; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数(中间值) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("INTERMEDIATE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class IntermediateParameter extends Parameter implements ParameterGroovyCodeContributionItem{ |
|||
@Override |
|||
public ParameterType getType() { |
|||
return ParameterType.INTERMEDIATE; |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromMap(ResourceWrapper wrapper,String targetVarName) { |
|||
return "//skip " + this.getName(); |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromJson(ResourceWrapper wrapper,String targetVarName) { |
|||
return "//" + this.getName(); |
|||
} |
|||
} |
@ -0,0 +1,32 @@ |
|||
package io.sc.engine.rule.core.po.model.parameter; |
|||
|
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
import io.sc.engine.rule.core.enums.ParameterType; |
|||
import io.sc.engine.rule.core.po.model.Parameter; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数(结果值) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("OUT") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class OutParameter extends Parameter { |
|||
@Override |
|||
public ParameterType getType() { |
|||
return ParameterType.OUT; |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromMap(ResourceWrapper wrapper,String targetVarName) { |
|||
return "//skip " + this.getName(); |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromJson(ResourceWrapper wrapper,String targetVarName) { |
|||
return "//" + this.getName(); |
|||
} |
|||
} |
@ -0,0 +1,40 @@ |
|||
package io.sc.engine.rule.core.po.model.parameter; |
|||
|
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
import io.sc.engine.rule.core.enums.ParameterType; |
|||
import io.sc.engine.rule.core.util.CodeReplacer; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数(规则结果) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("RULE_RESULT") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class RuleResultParameter extends OutParameter { |
|||
@Override |
|||
public ParameterType getType() { |
|||
return ParameterType.RULE_RESULT; |
|||
} |
|||
|
|||
@Override |
|||
public String forArgumentField(ResourceWrapper wrapper) { |
|||
StringBuilder sb =new StringBuilder(""); |
|||
sb.append("RuleResult ").append(CodeReplacer.fieldName(this.getCode())).append(" =new RuleResult();"); |
|||
sb.append("//").append(this.getName()); |
|||
return sb.toString(); |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromMap(ResourceWrapper wrapper,String targetVarName) { |
|||
return "//skip " + this.getName(); |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromJson(ResourceWrapper wrapper,String targetVarName) { |
|||
return "//skip " + this.getName(); |
|||
} |
|||
} |
@ -0,0 +1,40 @@ |
|||
package io.sc.engine.rule.core.po.model.parameter; |
|||
|
|||
import io.sc.engine.rule.core.code.impl.support.ResourceWrapper; |
|||
import io.sc.engine.rule.core.enums.ParameterType; |
|||
import io.sc.engine.rule.core.util.CodeReplacer; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数(单规则结果) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("SINGLE_RULE_RESULT") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class SingleRuleResultParameter extends OutParameter { |
|||
@Override |
|||
public ParameterType getType() { |
|||
return ParameterType.SINGLE_RULE_RESULT; |
|||
} |
|||
|
|||
@Override |
|||
public String forArgumentField(ResourceWrapper wrapper) { |
|||
StringBuilder sb =new StringBuilder(""); |
|||
sb.append("SingleRuleResult ").append(CodeReplacer.fieldName(this.getCode())).append(";"); |
|||
sb.append("//").append(this.getName()); |
|||
return sb.toString(); |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromMap(ResourceWrapper wrapper,String targetVarName) { |
|||
return "//skip " + this.getName(); |
|||
} |
|||
|
|||
@Override |
|||
public String forConvertArgumentFromJson(ResourceWrapper wrapper,String targetVarName) { |
|||
return "//skip " + this.getName(); |
|||
} |
|||
} |
@ -0,0 +1,40 @@ |
|||
package io.sc.engine.rule.core.po.model.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.model.ParameterProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数处理器(数值范围操作) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("NUMBER_RANGE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class NumberRangeParameterProcessor extends ParameterProcessor { |
|||
private String numberRangeVar;//数值分段函数变量表达式
|
|||
private String numberRange;//数值分段函数
|
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.NUMBER_RANGE; |
|||
} |
|||
|
|||
public String getNumberRangeVar() { |
|||
return numberRangeVar; |
|||
} |
|||
|
|||
public void setNumberRangeVar(String numberRangeVar) { |
|||
this.numberRangeVar = numberRangeVar; |
|||
} |
|||
|
|||
public String getNumberRange() { |
|||
return numberRange; |
|||
} |
|||
|
|||
public void setNumberRange(String numberRange) { |
|||
this.numberRange = numberRange; |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
package io.sc.engine.rule.core.po.model.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.model.ParameterProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数处理器(选项值)实体类 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("OPTION_VALUE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class OptionValueParameterProcessor extends ParameterProcessor { |
|||
private String optionCode;//输入参数(选项)代码
|
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.OPTION_VALUE; |
|||
} |
|||
|
|||
public String getOptionCode() { |
|||
return optionCode; |
|||
} |
|||
|
|||
public void setOptionCode(String optionCode) { |
|||
this.optionCode = optionCode; |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
package io.sc.engine.rule.core.po.model.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.model.ParameterProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数处理器(PMML) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("PMML") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class PmmlParameterProcessor extends ParameterProcessor { |
|||
private String pmml;//PMML xml 文本
|
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.PMML; |
|||
} |
|||
|
|||
public String getPmml() { |
|||
return pmml; |
|||
} |
|||
|
|||
public void setPmml(String pmml) { |
|||
this.pmml = pmml; |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
package io.sc.engine.rule.core.po.model.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.model.ParameterProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数处理器(规则) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("RULE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class RuleParameterProcessor extends ParameterProcessor{ |
|||
private String rule; |
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.RULE; |
|||
} |
|||
|
|||
public String getRule() { |
|||
return rule; |
|||
} |
|||
|
|||
public void setRule(String rule) { |
|||
this.rule = rule; |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
package io.sc.engine.rule.core.po.model.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.model.ParameterProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数处理器(单规则) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("SINGLE_RULE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class SingleRuleParameterProcessor extends ParameterProcessor{ |
|||
private String singleRule; |
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.SINGLE_RULE; |
|||
} |
|||
|
|||
public String getSingleRule() { |
|||
return singleRule; |
|||
} |
|||
|
|||
public void setSingleRule(String singleRule) { |
|||
this.singleRule = singleRule; |
|||
} |
|||
} |
@ -0,0 +1,58 @@ |
|||
package io.sc.engine.rule.core.po.model.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.model.ParameterProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数处理器(SQL赋值操作) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("SQL") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class SqlParameterProcessor extends ParameterProcessor { |
|||
private String sqlDatasourceName; //数据源名称
|
|||
private String sql; //SQL 语句
|
|||
private String sqlParameterValues; //SQL 语句中参数的测试值
|
|||
private String sqlFieldMapping; //查询结果字段和模型参数的映射
|
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.SQL; |
|||
} |
|||
|
|||
public String getSqlDatasourceName() { |
|||
return sqlDatasourceName; |
|||
} |
|||
|
|||
public void setSqlDatasourceName(String sqlDatasourceName) { |
|||
this.sqlDatasourceName = sqlDatasourceName; |
|||
} |
|||
|
|||
public String getSql() { |
|||
return sql; |
|||
} |
|||
|
|||
public void setSql(String sql) { |
|||
this.sql = sql; |
|||
} |
|||
|
|||
public String getSqlParameterValues() { |
|||
return sqlParameterValues; |
|||
} |
|||
|
|||
public void setSqlParameterValues(String sqlParameterValues) { |
|||
this.sqlParameterValues = sqlParameterValues; |
|||
} |
|||
|
|||
public String getSqlFieldMapping() { |
|||
return sqlFieldMapping; |
|||
} |
|||
|
|||
public void setSqlFieldMapping(String sqlFieldMapping) { |
|||
this.sqlFieldMapping = sqlFieldMapping; |
|||
} |
|||
} |
@ -0,0 +1,49 @@ |
|||
package io.sc.engine.rule.core.po.model.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.model.ParameterProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数处理器(三元操作)实体类 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("TERNARY") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class TernaryParameterProcessor extends ParameterProcessor { |
|||
private String ternaryCondition;//三元操作的条件
|
|||
private String ternaryTrue;//三元操作的条件成立时的操作
|
|||
private String ternaryFalse;//三元操作的条件不成立时的操作
|
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.TERNARY; |
|||
} |
|||
|
|||
public String getTernaryCondition() { |
|||
return ternaryCondition; |
|||
} |
|||
|
|||
public void setTernaryCondition(String ternaryCondition) { |
|||
this.ternaryCondition = ternaryCondition; |
|||
} |
|||
|
|||
public String getTernaryTrue() { |
|||
return ternaryTrue; |
|||
} |
|||
|
|||
public void setTernaryTrue(String ternaryTrue) { |
|||
this.ternaryTrue = ternaryTrue; |
|||
} |
|||
|
|||
public String getTernaryFalse() { |
|||
return ternaryFalse; |
|||
} |
|||
|
|||
public void setTernaryFalse(String ternaryFalse) { |
|||
this.ternaryFalse = ternaryFalse; |
|||
} |
|||
} |
@ -0,0 +1,49 @@ |
|||
package io.sc.engine.rule.core.po.model.processor; |
|||
|
|||
import io.sc.engine.rule.core.enums.ProcessorType; |
|||
import io.sc.engine.rule.core.po.model.ParameterProcessor; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 模型参数处理器(WhenThen操作) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("WHEN_THEN") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class WhenThenParameterProcessor extends ParameterProcessor { |
|||
private String when;//When表达式
|
|||
private String then;//Then表达式
|
|||
private Boolean isWhenThenShorted;//When表达式成立时是否短路操作(当 When 条件满足时,执行完 Then 操作后,不再进行后续处理)
|
|||
|
|||
@Override |
|||
public ProcessorType getType() { |
|||
return ProcessorType.WHEN_THEN; |
|||
} |
|||
|
|||
public String getWhen() { |
|||
return when; |
|||
} |
|||
|
|||
public void setWhen(String when) { |
|||
this.when = when; |
|||
} |
|||
|
|||
public String getThen() { |
|||
return then; |
|||
} |
|||
|
|||
public void setThen(String then) { |
|||
this.then = then; |
|||
} |
|||
|
|||
public Boolean getIsWhenThenShorted() { |
|||
return isWhenThenShorted; |
|||
} |
|||
|
|||
public void setIsWhenThenShorted(Boolean isWhenThenShorted) { |
|||
this.isWhenThenShorted = isWhenThenShorted; |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
package io.sc.engine.rule.core.po.model.validator; |
|||
|
|||
import io.sc.engine.rule.core.po.model.RangeParameterValidator; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonTypeName; |
|||
|
|||
/** |
|||
* 验证器(整数范围) |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@JsonTypeName("INTEGER_RANGE") |
|||
@JsonIgnoreProperties(ignoreUnknown=true) |
|||
public class IntegerRangeParameterValidator extends RangeParameterValidator { |
|||
|
|||
} |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue