drools规则语法(一)
- Drools
- 时间:2021-07-15 17:23
- 6344人已阅读
🔔🔔🔔好消息!好消息!🔔🔔🔔
有需要的朋友👉:联系凯哥
account : Account(balance > 100)
$account : Account($type : type)
$account : Account(balance >100)
Customer(account == $account)
Customer(name == "john")
Customer(name matches "[A-Z][a-z]+")
Account(dateCreate > "01-Feb-2009")
Transaction(isApprove == true)
Account(type == Account.Type.STUDENT)
package com.kingsun.drools.rules
import java.util.Map;
import com.kingsun.drools.service.LegacyBankService.extractData;
global ReportFactory reportFactory;
session.setGlobal("reportFactory", reportFactory);
List<Command> commands = new ArrayList<Command>();
commmands.add(CommandFactory.newSetGlobal("reportFactory", reportFactory));
session.getGlobals();
public static double calculateAccount(Account account) {
return 100 + account.balance * 1.2;
}
import com.kingsun.drools.domain.Account;
import function com.kingsun.drools.util.ValidationHelper.calculateAccount;
rule "validation account"
when
$account : Account(balance > 100)
then
Account(balance == calculateAccount($account));
end
package com.kingsun.drools.rules;
dialect "mvel"
($customer.name == "john") && (balance > 100)
$customer.address.postalCode = "123" 等同于 $customer.getAddress().setPostalCode("123")
$customer.accounts[3] 等同于 $customer.getAccounts(3)
$customerMap["123"] 等同于$customerMap.get["123"]
["001", new Account("001"), "002", new Account("002")]
["001", "002", "003"]
{"001", "002", "003"}
listOfPostCode = (postCode in (addresses in $customerS))
$customer : Customer(name == "john", age > 20)
$customer : Customer(name == "john" || age > 20)
not Account(type == Account.Type.STUDENT)
exists Account(type == Account.Type.STUDENT)
$account : Account()
; font-family: Helvetica, Tahoma, Arial, sans-serif;">
https://blog.csdn.net/caomiao2006/article/details/46417207