我已经在决策表中创建了一组规则。在合并和比较GIT中的文件时,我遇到了一个问题。因此,我计划将决策表转换为CSV文件。因此,任何人都建议将电子表格转换为CSV文件的过程或文档。我很好奇语法和列是否像excel一样。我查看了下面的文档,但无法获得有关转换过程的确切图片。任何人请在示例csv模板上提供建议。
参考-
https://docs.jboss.org/drools/release/6.5.0.Final/drools-docs/html_single/http://javacodeimpl.blogspot.com/2018/03/drools-decision-table-csv-example.html
不是Drools规则引擎将决策表转换为csv文件的范围或方法。
但是Drools支持DRT,DRT是保留所有元数据并在运行时提供数据以形成所需DRL的模板。
下面的示例:
package com.package.model.rule;
public class ProductsBill {
private double total;
private double buillAmount;
private String couponCode;
private int deductionInPercentage;
public ProductsBill(double buillAmount, String couponCode) {
this.buillAmount = buillAmount;
this.couponCode = couponCode;
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public double getBuillAmount() {
return buillAmount;
}
public void setBuillAmount(double buillAmount) {
this.buillAmount = buillAmount;
}
public String getCouponCode() {
return couponCode;
}
public void setCouponCode(String couponCode) {
this.couponCode = couponCode;
}
public int getDeductionInPercentage() {
return deductionInPercentage;
}
public void setDeductionInPercentage(int deductionInPercentage) {
this.deductionInPercentage = deductionInPercentage;
}
}
DRT文件:/com/template/disount.drt
template header
couponCode
deduction
package org.drools.examples.templates;
import com.package.model.rule.ProductsBill;
global java.util.List list;
template "discount"
rule "discout_@{row.rowNumber}"
when
$data : ProductsBill(couponCode = @{couponCode})
then
modify($data) {data.setDeductionInPercentage(@{deduction})};
list.add(data)
end
end template
CSV文件:
couponCode,deduction
DC12434,20.0
FC45899,30.5
DC43589,10.0
执行规则:
InputStream template = RuleTemplateArrayDemo.class.getResourceAsStream("/com/template/disount.drt");
List<ProductsBill> dataProvider = new ObjectDataProvider(/*Code to return list of ProductsBill with the csv data*/);
DataProviderCompiler compiler = new DataProviderCompiler();
String drl = compiler.compile(dataProvider, template);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(drl.getBytes()), ResourceType.DRL);
assertFalse(kbuilder.hasErrors());
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession kSession = kbase.newStatefulKnowledgeSession();
//now create some test data
kSession.insert(new ProductsBill(46.2, "DC12434"));
kSession.insert(new ProductsBill(136.2, "DC43589"));
List<ProductsBill> list = new ArrayList<ProductsBill>();
kSession.setGlobal("list", list);
kSession.fireAllRules();
希望这会有所帮助!