您好,这里是我的用例,需要实现。我有不同类型的设备。根据设备类型,需要执行一些操作。但是对于实现的一个操作(考虑调用4个Java类)中的特定设备类型,其中一个Java类返回一个值,因此取决于该值(让它作为布尔值)是否为真(比所有4个都正确)在操作中需要调用类),或者如果该值为false,则仅需要调用2个类。因此,基本上存在设备检查,这是主要条件,而根据子条件,根据子类之一的输出需要执行不同的操作。这是基本场景...我正在尝试通过复合规则来实施,但随后我无法弄清楚如何检查多个条件,而且我实施的复合规则也无法正常工作。请让我知道我需要如何进行和实施
[
{
"name": "Movie id rule",
"compositeRuleType": "UnitRuleGroup",
"priority": 1,
"composingRules": [
{
"name": "Time is evening",
"description": "If it's later than 7pm",
"priority": 1,
"condition": "type == 'TCU'",
"actions": [
"System.out.println(\"device is tcu\");"
]
},
{
"name": "Movie is rated R",
"description": "If the movie is rated R",
"priority": 1,
"condition": "type == 'TBOX'",
"actions": [
"System.out.println(\"device is tbox\");"
]
}
]
},
{
"name": "weather rule",
"description": "when it rains, then take an umbrella",
"priority": 1,
"condition": "type == 'EPID'",
"actions": [
"System.out.println(\"It rains, take an umbrella!\");"
]
}
]
这是order-rule.json
这是主要课程
public class Launcher {
public static String device;
public static void main(String[] args) throws Exception {
Scanner myObj = new Scanner(System.in); // Create a Scanner object
System.out.println("Enter device type");
device = myObj.nextLine(); // Read user input
//System.out.println("Device Type is: " + device);
DeviceType type = new DeviceType();
type.setDeviceType(device);
Facts facts = new Facts();
facts.put("type", device);
facts.put("aRestAdapter", new ARestAdapter());
facts.put("bRestAdapter", new BRestAdapter());
facts.put("cRestAdapter", new CRestAdapater());
facts.put("dRestAdapter", new DRestAdapter());
MVELRuleFactory factory = new MVELRuleFactory(new JsonRuleDefinitionReader());
Rules orderRule = factory.createRules(new FileReader("C:\\Users\\PALURI1\\Downloads\\easy-rules-easy-rules-3.3.0\\easy-rules-easy-rules-3.3.0\\easy-rules-tutorials\\src\\main\\java\\org\\jeasy\\rules\\tutorials\\device\\order-rule.json"));
RulesEngine rulesEngine = new DefaultRulesEngine();
rulesEngine.fire(orderRule, facts);
}
}
因此,如果设备是TCU或TBOX,则在我运行时未执行操作。
,但是当设备为EPID时,将按预期实施操作。在实施复合规则时需要帮助