提交 ea872cd8 编写于 作者: sq3536's avatar sq3536

drl

上级 d174b69d
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.extensions.util.FreeMakerHelper;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.core.lite.extensions.service.LiteModelService;
import cn.ibizlab.core.lite.extensions.util.LiteStorage;
import cn.ibizlab.core.rule.service.impl.RuleItemServiceImpl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.core.rule.domain.RuleItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -59,6 +63,9 @@ public class RuleItemExService extends RuleItemServiceImpl {
return super.modelchange(et);
}
@Autowired
private LiteModelService liteModelService;
/**
* 按照规则生成drl文件
* @param et
......@@ -105,22 +112,29 @@ public class RuleItemExService extends RuleItemServiceImpl {
strExt2field=obj.getString("ext2field");
strDimfield=obj.getString("dimfield");
strBusinesscatfield=obj.getString("businesscatfield");
strDomainsfield=StringUtils.isEmpty(strDimfield)?obj.getString("domainsfield"):strDimfield;
strDomainsfield=obj.getString("domainsfield");
}
if(StringUtils.isEmpty(strDomainsfield))
strDomainsfield=et.getModelName()+".CBDW_BM";
strDomainsfield=strDimfield;
Map param=new HashMap();
param.put("ruleid",strRuleid);
param.put("rulecode",et.getRuleCode());
param.put("rulename",strRulename);
param.put("memo",strMemo);
DataModel dataModel = liteModelService.getDataModel(et.getModelId());
synchronized(lockModel)
{
Hashtable<String,String> modelset=new Hashtable<String,String>();
param.put("datamodelname",dataModel.getDataModelName());
modelset.put("datamodelname",dataModel.getDataModelName());
param.put("rulecond",parseGroup(cfg,modelset));
param.put("releationcond",parseRelationArr(JSONObject.parseObject(strCfg),modelset));
String strCond="";
for(String key : modelset.keySet()) {
if(!StringUtils.isEmpty(strCond))
......@@ -137,7 +151,9 @@ public class RuleItemExService extends RuleItemServiceImpl {
param.put("keyvaluefield",getFieldkeyset(strKeyvaluefield,modelset));
param.put("ext2field",getFieldset(strExt2field,modelset));
param.put("domainsfield",getFieldset(strDomainsfield,modelset));
param.put("dimfield",getFieldset(strDomainsfield,modelset));
param.put("dimfield",getFieldset(strDimfield,modelset));
param.put("dimfield_d",dataModel.getDataModelName()+".$(\""+strDimfield+"\")");
param.put("keyvaluefield_d",StringUtils.isEmpty(strKeyvaluefield)?dataModel.getDataModelName()+".getRowKey()":dataModel.getDataModelName()+".$(\""+strKeyvaluefield+"\")");
if (!StringUtils.isEmpty(strBusinesscatfield)) {
hasBusinesscatField = true;
param.put("businesscatfield", getFieldset(strBusinesscatfield, modelset));
......@@ -267,7 +283,7 @@ public class RuleItemExService extends RuleItemServiceImpl {
{
if(!modelset.containsKey(arr[0]))
{
modelset.put(arr[0], "item");
modelset.put(arr[0], modelset.get("datamodelname"));
}
}
......@@ -339,10 +355,11 @@ public class RuleItemExService extends RuleItemServiceImpl {
if(!StringUtils.isEmpty(strGroupCond)){
if(relaConn.equals("exists"))
{
strRelationResult=String.format("%s:ModelObj %s from %s.getNested(\"%s\")",relaEntity,strGroupCond,relaEntity,relaEntity);
strRelationResult=String.format("%s:ModelObj %s from %s.getNested(\"%s\")",relaEntity,strGroupCond,modelset.get("datamodelname"),relaEntity);
modelset.put("EXIST",relaEntity);
}
else if(relaConn.equals("not exists")){
strRelationResult=String.format("not(exists ModelObj %s from item.getNested(\"%s\"))",strGroupCond,relaEntity);
strRelationResult=String.format("not(exists ModelObj %s from %s.getNested(\"%s\"))",strGroupCond,modelset.get("datamodelname"),relaEntity);
}
}
if(!StringUtils.isEmpty(strRelationResult))
......@@ -356,8 +373,8 @@ public class RuleItemExService extends RuleItemServiceImpl {
{
String str=this.getFieldset(fieldName, modelset);
if(str.equals("null"))
return "item.KEY";
return str+".getValue()";
return modelset.get("datamodelname")+".getRowKey()";
return str+"";
}
private String getFieldset(String fieldName,Hashtable<String,String> modelset)
......@@ -369,49 +386,14 @@ public class RuleItemExService extends RuleItemServiceImpl {
String[] arr=fieldName.split("[.]");
if(arr.length>=2)
{
if(modelset.containsKey("AJXYRHZ"))
{
String tmp=arr[0];
if(tmp.equalsIgnoreCase("TYYW_GG_XYRJBXX")||tmp.equalsIgnoreCase("TYYW_GS_XYRQK")||tmp.equalsIgnoreCase("TYYW_KG_BXFRQK")||
tmp.equalsIgnoreCase("TYYW_SHB_XYRQK")||tmp.equalsIgnoreCase("TYYW_WJ_BYXBLQK")||tmp.equalsIgnoreCase("TYYW_WJ_FZXYR")||
tmp.equalsIgnoreCase("TYYW_WJ_QTXZQK")||tmp.equalsIgnoreCase("TYYW_WJ_XYR")||tmp.equalsIgnoreCase("TYYW_WJ_XYRQK")||tmp.equalsIgnoreCase("TYYW_ZIZ_FZXYR")
||tmp.equalsIgnoreCase("TYYW_ZJ_FZXYR"))
{
return "AJXYRHZ.$(\""+ fieldName+"\")";
}
}
if(modelset.containsKey("AJWSHZ"))
{
String tmp=arr[0];
if(tmp.equalsIgnoreCase("YX_WS_SL")||tmp.equalsIgnoreCase("YX_WS_AJJZWJ"))
{
return "AJWSHZ.$(\""+ fieldName+"\")";
}
}
if(modelset.containsKey("AJDZJZMLHZ"))
{
String tmp=arr[0];
if(tmp.equalsIgnoreCase("YX_DZJZ_JZML"))
{
return "AJDZJZMLHZ.$(\""+ fieldName+"\")";
}
}
if(modelset.containsKey("AJGGQZCSQKHZ"))
{
String tmp=arr[0];
if(tmp.equalsIgnoreCase("TYYW_GG_QZCSQK"))
{
return "AJGGQZCSQKHZ.$(\""+ fieldName+"\")";
}
}
if(modelset.containsKey(arr[0]))
if(modelset.containsKey("EXIST"))
{
return modelset.get(arr[0])+".$(\""+ fieldName+"\")";
return modelset.get("EXIST")+".$(\""+ fieldName+"\")";
}
}
}
return "item.$(\""+ fieldName+"\")";
return modelset.get("datamodelname")+".$(\""+ fieldName+"\")";
}
}
......@@ -3,21 +3,20 @@ import cn.ibizlab.core.lite.extensions.ModelObj;
import cn.ibizlab.core.extensions.service.BaseEntityService;
global BaseEntityService BaseService;
rule "<#if rulecode??>${rulecode}_1</#if>"
rule "<#if ruleid??>${ruleid}_1</#if>"
salience 100
activation-group "<#if rulecode??>${rulecode}</#if>"
activation-group "<#if ruleid??>${ruleid}</#if>"
when
item:ModelObj( <#if rulecond??>${rulecond}</#if> )
${datamodelname}:ModelObj( <#if rulecond??>${rulecond}</#if> )
<#if (releationcond??)>${releationcond}</#if>
then
BaseService.saveResult(item,"<#if rulecode??>${rulecode}</#if>","<#if rulename??>${rulename}</#if>","<#if memo??>${memo}</#if>",<#if businesscat??><#if hasbusinesscatfield>${businesscatfield}<#else>"${businesscat}"</#if></#if>,1,${keyvaluefield},${domainsfield},${dimfield},${metricfield},${timefield},${ext1field},${ext2field});
BaseService.saveResult(${datamodelname},"<#if rulecode??>${rulecode}</#if>","<#if rulename??>${rulename}</#if>","<#if memo??>${memo}</#if>",<#if hasbusinesscatfield>${businesscatfield}<#else>"${businesscat}"</#if>,1,${keyvaluefield},${domainsfield},${dimfield},${metricfield},${timefield},${ext1field},${ext2field});
end
rule "<#if rulecode??>${rulecode}_d</#if>"
rule "<#if ruleid??>${ruleid}_d</#if>"
salience 0
activation-group "<#if rulecode??>${rulecode}</#if>"
activation-group "<#if ruleid??>${ruleid}</#if>"
when
item:ModelObj( )
<#if (releationcond??)>${releationcond}</#if>
${datamodelname}:ModelObj( )
then
BaseService.saveResult(item,"<#if rulecode??>${rulecode}</#if>",null, null,null,0,${keyvaluefield},${domainsfield},${dimfield},${metricfield},${timefield},null,null);
BaseService.saveResult(${datamodelname},"<#if rulecode??>${rulecode}</#if>",null,null,null,0,${keyvaluefield_d},null,${dimfield_d},0,null,null,null);
end
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册