|
@@ -0,0 +1,58 @@
|
|
|
+package com.alvin;
|
|
|
+
|
|
|
+import com.alvin.entity.Customer;
|
|
|
+import com.alvin.entity.Res;
|
|
|
+import com.bstek.urule.Utils;
|
|
|
+import com.bstek.urule.runtime.KnowledgePackage;
|
|
|
+import com.bstek.urule.runtime.KnowledgeSession;
|
|
|
+import com.bstek.urule.runtime.KnowledgeSessionFactory;
|
|
|
+import com.bstek.urule.runtime.service.KnowledgeService;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+@RestController
|
|
|
+public class TestController {
|
|
|
+ @GetMapping("/test")
|
|
|
+ public Customer test(int age) throws IOException {
|
|
|
+ KnowledgeService service = (KnowledgeService) Utils.getApplicationContext().getBean(KnowledgeService.BEAN_ID);
|
|
|
+ KnowledgePackage knowledgePackage = service.getKnowledge("测试/level2");
|
|
|
+ KnowledgeSession session = KnowledgeSessionFactory.newKnowledgeSession(knowledgePackage);
|
|
|
+
|
|
|
+ Customer customer = new Customer();
|
|
|
+ customer.setAge(age);
|
|
|
+ customer.setMarried(true);
|
|
|
+ customer.setHouse(true);
|
|
|
+
|
|
|
+ session.insert(customer);
|
|
|
+
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("result", "1222");
|
|
|
+ session.startProcess("testFlow", map);
|
|
|
+ System.out.println(session.getParameters());
|
|
|
+
|
|
|
+ return customer;
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/test2")
|
|
|
+ public Res test2() throws IOException {
|
|
|
+ KnowledgeService service = (KnowledgeService) Utils.getApplicationContext().getBean(KnowledgeService.BEAN_ID);
|
|
|
+ KnowledgePackage knowledgePackage = service.getKnowledge("测试/test2");
|
|
|
+ KnowledgeSession session = KnowledgeSessionFactory.newKnowledgeSession(knowledgePackage);
|
|
|
+
|
|
|
+ Customer customer = new Customer();
|
|
|
+ customer.setName("{\"prob\": \"0.1330860691083673\", \"score\": \"556\"}");
|
|
|
+ customer.setAge(1);
|
|
|
+
|
|
|
+ session.insert(customer);
|
|
|
+ Res res = new Res();
|
|
|
+ session.insert(res);
|
|
|
+
|
|
|
+ session.startProcess("flow");
|
|
|
+
|
|
|
+ System.out.println(res);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+}
|