测试类代码:
public class LeaveRuleTest {
@SuppressWarnings({ "rawtypes", "unchecked" , "restriction" })
@Test
public void testLeaveRule(){
LeaveRuleServiceImp crssi = new LeaveRuleServiceImp();
List<LeaveInputBOM> inputBOMList = new ArrayList<LeaveInputBOM>();
LeaveInputBOM leave=new LeaveInputBOM();
leave.setId("1101");
leave.setBanji("3");
leave.setTianshu(6);
inputBOMList.add(leave);
List<LeaveResultBOM> resultBOMList = (List)crssi.getLeaveInfo(inputBOMList);
if(resultBOMList != null && resultBOMList.size() > 0){
for(int i = 0; i < resultBOMList.size(); i++){
LeaveResultBOM resultBOM = resultBOMList.get(i);
System.out.println("核查人:" + resultBOM.getTeacher());
}
}
}
}
测试类调用的方法:
public class LeaveRuleServiceImp implements LeaveRuleService {
public List<LeaveResultBOM> getLeaveInfo(
List<LeaveInputBOM> activityInputList) {
DroolsRuleServiceImp droolsRuleServiceSpringImpl = new DroolsRuleServiceImp();
List<LeaveResultBOM> leaveResultList = new ArrayList<LeaveResultBOM>();
try{
if (activityInputList.size() > 0) {
for (int i = 0; i < activityInputList.size(); i++) {
LeaveInputBOM inputBOM = activityInputList.get(i);
LeaveResultBOM resultXOM = new LeaveResultBOM();
LeaveResultBOM returnBOM = (LeaveResultBOM) droolsRuleServiceSpringImpl
.executeRules(
"LeaveRuleFlow",
inputBOM, resultXOM,
"/com/bin/drools/drools.properties");
leaveResultList.add(returnBOM);
}
}
return leaveResultList;
}catch(Exception e){
return null;
}
}
}、
public Object executeRules(String ruleFlowName, Object inputXOM,
Object resultXOM, String propertiesFilePath) {
if (null == propertiesFilePath || "".equals(propertiesFilePath)) {
propertiesFilePath = "/drools.properties";
}
RuleAgentGen ruleAgentGen = RuleAgentGen.getRuleAgentGenInstance();
RuleAgent agent = ruleAgentGen.getRuleAgent(propertiesFilePath);
RuleBase ruleBase=agent.getRuleBase();
StatefulSession session = ruleBase.newStatefulSession();
session.setGlobal("resultXOM", resultXOM);
session.insert(inputXOM);
session.insert(resultXOM);
session.startProcess(ruleFlowName);
session.fireAllRules();
session.dispose();
return resultXOM;
}
配置文件:
newInstance=false
url=http://localhost:9080/brms/org.drools.guvnor.Guvnor/package/com.cn.bin.leaverule/LATEST
poll=30
name=LeaveRule
localCacheDir=c:/temp
enableBasicAuthentication=true
运行的时候不出结果,直接走空值。求高手告知我出错在哪里,怎么改正?谢谢大家了!!!图片没有上传成功,就这样将就着看吧!谢谢了!
RuleSet | jishu | |||||||
Import | com.bin.domain.LeaveInputBOM,com.bin.domain.LeaveResultBOM | |||||||
Variables | com.bin.domain.LeaveResultBOM resultXOM | |||||||
Notes | 活动规则 | |||||||
RuleTable jishu | ||||||||
CONDITION | CONDITION | CONDITION | ACTION | ACTION | RULEFLOW-GROUP | NO-LOOP | ||
$input:LeaveInputBOM | resultXOM | resultXOM | ||||||
id == "$param" | banji=="$param" | tianshu >="$1",tianshu<="$2" | bin("$param") | out("$1","$2","$3",$input); | ||||
奇偶 | 班级 | 请假天数 | 教师 | |||||
1101 | 1 | 3,6 | 2 | 1101,7,4 | jishu | false | ||
2 | 3,6 | 3 | 3 | jishu | false | |||
3 | 6,9 | 4 | 2 | jishu | false | |||
4 | 6,9 | 5 | 1 | jishu | false | |||