|
|
@@ -0,0 +1,36 @@
|
|
|
+package cn.iocoder.yudao.module.iscs.controller.admin;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.Person;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.kie.api.runtime.KieContainer;
|
|
|
+import org.kie.api.runtime.KieSession;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@Tag(name = "管理后台 - uize------------")
|
|
|
+@RequestMapping("/rules")
|
|
|
+public class RulesController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private KieContainer kieContainer;
|
|
|
+
|
|
|
+ @Operation(summary = "规则--------")
|
|
|
+ @PostMapping("/execute")
|
|
|
+ public Person executeRule(@RequestBody Person person) {
|
|
|
+ KieSession session = null; // 声明在外部以便在 finally 块中访问
|
|
|
+ try {
|
|
|
+ session = kieContainer.newKieSession();
|
|
|
+ session.insert(person); // 插入事实对象到工作内存
|
|
|
+ session.fireAllRules(); // 触发所有匹配的规则
|
|
|
+ return person; // 返回可能已被修改的对象
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("Failed to execute rules", e);
|
|
|
+ } finally {
|
|
|
+ if (session != null) {
|
|
|
+ session.dispose(); // ✅ 显式释放资源
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|