1.rulesWithDSL.drl文件的定义:
package com.mip.biz.operatebill.rules;
import com.mip.biz.operatebill.objects.ValueBean;
import org.apache.commons.lang.StringUtils;
import com.mip.core.utils.Log;
global com.mip.biz.operatebill.services.RulesService operateRulesService;
expander rules.dsl;
/** *//**
* 判断操作项目内容中是否存在相应的标记字符串
*/
function boolean itemContains(String content,String flag){
boolean res = StringUtils.contains(content,flag);
return res;
}
/** *//**
* 判断操作项目内容中是否存在相应的标记字符串
*/
function boolean judge(String content,String action,String dev){
//判断指定的设备是否存在
Log.debug("content:"+content);
String[] splitDevname = dev.split("或");
boolean exitsDevname = false;
for(int i=0;i<splitDevname.length;i++){
String oneDevname = splitDevname[i];
//Log.debug("oneDevname:"+oneDevname);
exitsDevname = StringUtils.contains(content,oneDevname);
if(exitsDevname) break;
}
Log.debug("exitsDevName:"+exitsDevname);
String[] splitAction = action.split("或");
boolean exitsAction = false;
for(int i=0;i<splitAction.length;i++){
String oneAction = splitAction[i];
//Log.debug("oneAction:"+oneAction);
exitsAction = StringUtils.contains(content,oneAction);
if(exitsAction) break;
}
Log.debug("exitsAction:"+exitsAction);
return exitsAction && exitsDevname;
}
rule "拉闸操作时设置“操作标志”为RULES_IS_OPEN_SWITCH(2)"
when
"本次操作如果" "拉或拉开或断开" "某某" "刀闸或开关"
then
"设置标记为:"2
end
rule "合闸操作时设置“操作标志”为RULES_IS_CLOSE_SWITCH(3)"
when
"本次操作如果" "合或合上" "某某" "刀闸或开关"
then
"设置标记为:"3
end
rule "拉或拉开##地刀操作设置“操作标志”为RULES_IS_OPEN_SWITCH_FLOOR(4)"
when
"本次操作如果" "拉或拉开或断开" "某某" "地刀"
then
"设置标记为:"4
end
rule "合或合上##地刀操作设置“操作标志”为RULES_IS_CLOSE_SWITCH_FLOOR(5)"
when
"本次操作如果" "合或合上" "某某" "地刀"
then
"设置标记为:"5
end
rule "安装地线操作时设置“操作标志”为RULES_IS_FIX_FLOOR_LINE(6)"
when
"本次操作如果" "安装" "某某" "地线"
then
"设置标记为:"6
end
rule "拆除地线操作时设置“操作标志”为RULES_IS_UNFIX_FLOOR_LINE(7)"
when
"本次操作如果" "拆除" "某某" "地线"
then
"设置标记为:"7
end 2.rules.dsl文件的定义
[when]"本次操作如果" {action} "某某" {dev}=vb:ValueBean(itemc:content->(judge(itemc,{action},{dev})))
[then]"设置标记为:"{level}=operateRulesService.setResult(vb,new Long({level}));
3.RulesServiceImpl类
package com.mip.biz.operatebill.services.imp;
import org.drools.WorkingMemory;
import com.mip.biz.operatebill.objects.ValueBean;
import com.mip.biz.operatebill.services.RulesService;
import com.mip.core.jbossrules.DroolsTemplate;
/** *//**
* <p>
* 处理操作票中的一引起逻辑规则
* </p>
* @author Libin
* @date Mar 17, 2007
* @version 4.0
*
* @see AnotherClass
*/
public class RulesServiceImpl implements RulesService {
/** *//** Drools的封装便利函数,返回WorkingMemory */
private DroolsTemplate operateReluesTemplate;
/** *//**
* A judge function
* <p> 运行规则 </p>
* @param valueBean
*/
public void runRules(ValueBean valueBean){
WorkingMemory wm = operateReluesTemplate.getWorkingMemory(valueBean);
//注入本类,提供各种简便函数供规则中使用
if(wm.getGlobal(OPERATE_RULES_SERVICE_NAME)==null){
wm.setGlobal(OPERATE_RULES_SERVICE_NAME, this);
}
wm.fireAllRules();
}
/**//* (非 Javadoc)
* @see com.mip.biz.operatebill.services.RulesService#setResult(com.mip.biz.operatebill.objects.ValueBean, java.lang.Long)
*/
public void setResult(ValueBean valueBean, Long result) {
// TODO Auto-generated method stub
switch(result.intValue()){
//拉闸操作
case RULES_IS_OPEN_SWITCH:
valueBean.setOpenSwitch(new Boolean(true));
valueBean.setStress(new Boolean(true));
break;
//合闸操作
case RULES_IS_CLOSE_SWITCH:
valueBean.setCloseSwitch(new Boolean(true));
valueBean.setStress(new Boolean(true));
break;
//拉地刀闸操作
case RULES_IS_OPEN_SWITCH_FLOOR:
valueBean.setOpenSwitchFloor(new Boolean(true));
valueBean.setStress(new Boolean(true));
break;
//合地刀闸操作
case RULES_IS_CLOSE_SWITCH_FLOOR:
valueBean.setCloseSwitchFloor(new Boolean(true));
valueBean.setStress(new Boolean(true));
break;
//装地线操作
case RULES_IS_FIX_FLOOR_LINE:
valueBean.setFixFloorLine(new Boolean(true));
valueBean.setStress(new Boolean(true));
break;
//拆地线操作
case RULES_IS_UNFIX_FLOOR_LINE:
valueBean.setUnfixFloorLine(new Boolean(true));
valueBean.setStress(new Boolean(true));
break;
}
valueBean.setResult(result);
}
/**//* (非 Javadoc)
* @see com.mip.biz.operatebill.services.RulesService#isStress(com.mip.biz.operatebill.objects.ValueBean)
*/
public boolean isStress(ValueBean valueBean) {
// TODO Auto-generated method stub
return valueBean.getStress();
}
/**//* (非 Javadoc)
* @see com.mip.biz.operatebill.services.RulesService#isCloseSwith(com.mip.biz.operatebill.objects.ValueBean)
*/
public boolean isCloseSwitch(ValueBean valueBean) {
// TODO Auto-generated method stub
return valueBean.getCloseSwitch();
}
public boolean isCloseSwitchFloor(ValueBean valueBean) {
// TODO Auto-generated method stub
return valueBean.getCloseSwitchFloor();
}
public boolean isOpenSwitchFloor(ValueBean valueBean) {
// TODO Auto-generated method stub
return valueBean.getOpenSwitchFloor();
}
/**//* (非 Javadoc)
* @see com.mip.biz.operatebill.services.RulesService#isOpenSwitch(com.mip.biz.operatebill.objects.ValueBean)
*/
public boolean isOpenSwitch(ValueBean valueBean) {
// TODO Auto-generated method stub
return valueBean.getOpenSwitch();
}
public void setOperateReluesTemplate(DroolsTemplate operateReluesTemplate) {
this.operateReluesTemplate = operateReluesTemplate;
}
public boolean isFixFloorLine(ValueBean valueBean) {
// TODO Auto-generated method stub
return valueBean.getFixFloorLine();
}
public boolean isUnfixFloorLine(ValueBean valueBean) {
// TODO Auto-generated method stub
return valueBean.getUnfixFloorLine();
}
}
posted on 2007-03-19 19:41
Lib 阅读(1470)
评论(2) 编辑 收藏 所属分类:
开源框架