断点

每天进步一点点!
posts - 174, comments - 56, trackbacks - 0, articles - 21

Drools 规则测试

Posted on 2010-03-10 23:00 断点 阅读(903) 评论(1)  编辑  收藏 所属分类: Drools

package rules;

import java.io.InputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.decisiontable.InputType;
import org.drools.decisiontable.SpreadsheetCompiler;
import org.drools.rule.Package;


public class TestPremium {
 public static final String path = "rules\\premium\\0326\\02\\030006\\rate.xls";
 
 public static void main(String[] args) throws Exception {
  try {
   RuleBase ruleBase = readDecisionTable();
   WorkingMemory workingMemory = ruleBase.newStatefulSession();
   int flag = path.indexOf("FormulaOrder");   
   ElementResultVO r = new ElementResultVO();
   PremiumHelper helper = new PremiumHelper();
   workingMemory.setGlobal("r", r);
   workingMemory.setGlobal("helper", helper);
   
   AppBaseVO base  = new AppBaseVO();
   AppVhlVO vhl = new AppVhlVO();
   AppPrmCoefVO prmCoef = new AppPrmCoefVO();
      
   base.setCAmtCur("01");
   base.setNAmt(4000000d);
   
   workingMemory.insert(base);
   workingMemory.insert(vhl);
   workingMemory.insert(prmCoef);
   
   workingMemory.fireAllRules();
   
   System.out.println("==========compile success!===========");
   
  } catch (Exception e) {
   System.out.println("==========compile failure!===========");
   e.printStackTrace();
  }
 }
 
 private static RuleBase readDecisionTable() throws Exception {
         final SpreadsheetCompiler converter = new SpreadsheetCompiler();
         InputStream is = TestPremium.class.getClassLoader().getResourceAsStream(path);
          final String drl = converter.compile( is, InputType.XLS );
          PackageBuilder builder = new PackageBuilder();
          builder.addPackageFromDrl( new StringReader( drl ) );
          Package pkg = builder.getPackage();
          RuleBase ruleBase = RuleBaseFactory.newRuleBase();
          ruleBase.addPackage( pkg );
          return ruleBase;
 }

}

++++++++++++++++++++++++++++++++++++++
执行后的一部分:
#From row number: 369
rule "_369"
  salience 65167
  activation-group "x"
 when
      vhl:AppVhlVO(CUsageCde == "374015", CVhlTyp == "365012", 
      eval(helper.getVhlYear(vhl.getCFstRegYm())>=4 && helper.getVhlYear(vhl.getCFstRegYm())<1000))
 then
      r.putCoef("rate",0.67);
      r.putField("Table.col","Cvrg.NRate");
end

Feedback

# re: Drools 规则测试  回复  更多评论   

2012-03-06 11:16 by sunjiahaoz
你好,我想问你得xls文件写些神马呢?

只有注册用户登录后才能发表评论。


网站导航: