tianyun 3 년 전
부모
커밋
94f0fc66b5

+ 24 - 0
springboot-main/pom.xml

@@ -17,9 +17,29 @@
     </properties>
 
     <dependencies>
+        <dependency>
+            <groupId>com.bstek.urule</groupId>
+            <artifactId>urule-console-pro</artifactId>
+            <version>3.0.2</version>
+        </dependency>
+        <!--<dependency>-->
+        <!--    <groupId>javax.servlet</groupId>-->
+        <!--    <artifactId>servlet-api</artifactId>-->
+        <!--    <version>2.5</version>-->
+        <!--    <scope>provided</scope>-->
+        <!--</dependency>-->
+
+
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-starter-logging</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>com.google.code.gson</groupId>
@@ -49,6 +69,10 @@
             <artifactId>commons-pool2</artifactId>
             <version>2.11.1</version>
         </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

+ 7 - 26
springboot-main/src/main/java/com/alvin/Application.java

@@ -1,33 +1,14 @@
 package com.alvin;
 
 
-import redis.clients.jedis.*;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ImportResource;
 
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-public class Application {
+@SpringBootApplication
+@ImportResource({"classpath:context.xml"})
+public class Application{
     public static void main(String[] args) throws Exception {
-
-        Set<String> hosts = new HashSet<>();
-        hosts.add("127.0.0.1:26379");
-        //hosts.add("127.0.0.1:36379"); 配置多个哨兵
-
-        JedisSentinelPool pool = new JedisSentinelPool("mymaster", hosts);
-        pool.setMaxTotal(10);
-        Jedis jedis = null;
-
-        for (int i = 0; i < 20; i++) {
-            Thread.sleep(2000);
-            try {
-                jedis = pool.getResource();
-                String v = "hi" + i;
-                jedis.set("hello", v);
-                System.out.println(v + "-->" + jedis.get("hello").equals(v));
-            } catch (Exception e) {
-                System.out.println(" [ exception happened]" + e);
-            }
-        }
+        SpringApplication.run(Application.class);
     }
 }

+ 31 - 0
springboot-main/src/main/java/com/alvin/CustomAction.java

@@ -0,0 +1,31 @@
+package com.alvin;
+
+import com.alvin.entity.Res;
+import com.alvin.util.JsonUtil;
+import com.bstek.urule.model.library.action.annotation.ActionBean;
+import com.bstek.urule.model.library.action.annotation.ActionMethod;
+import com.bstek.urule.model.library.action.annotation.ActionMethodParameter;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+@Component
+@ActionBean(name = "json解析")
+public class CustomAction {
+    @ActionMethod(name = "json2Map")
+    @ActionMethodParameter(names = {"json字符串"})
+    public Map<String, Object> json2Map(String jsonStr) {
+        return JsonUtil.getMap(jsonStr);
+    }
+
+    @ActionMethod(name = "json2Res")
+    @ActionMethodParameter(names = {"json字符串"})
+    public Res json2Res(String jsonStr) {
+        return JsonUtil.getObject(jsonStr, Res.class);
+    }
+
+    public static void main(String[] args) {
+        Map<String, Object> stringObjectMap = new CustomAction().json2Map("{\"prob\": \"0.1330860691083673\", \"score\": \"556\"}");
+        System.out.println(stringObjectMap);
+    }
+}

+ 58 - 0
springboot-main/src/main/java/com/alvin/TestController.java

@@ -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;
+    }
+}

+ 14 - 0
springboot-main/src/main/java/com/alvin/URuleServletRegistration.java

@@ -0,0 +1,14 @@
+package com.alvin;
+
+import com.bstek.urule.console.servlet.URuleServlet;
+import org.springframework.boot.web.servlet.ServletRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.stereotype.Component;
+
+@Component
+public class URuleServletRegistration {
+    @Bean
+    public ServletRegistrationBean registerURuleServlet(){
+        return new ServletRegistrationBean(new URuleServlet(),"/urule/*");
+    }
+}

+ 28 - 0
springboot-main/src/main/java/com/alvin/entity/Customer.java

@@ -0,0 +1,28 @@
+package com.alvin.entity;
+
+import com.bstek.urule.model.Label;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class Customer {
+    @Label("名称")
+    private String name;
+    @Label("年龄")
+    private int age;
+    @Label("出生日期")
+    private Date birthday;
+    @Label("等级")
+    private int level;
+    @Label("手机号")
+    private String mobile;
+    @Label("性别")
+    private boolean gender;
+    @Label("是否有车")
+    private boolean car;
+    @Label("婚否")
+    private boolean married;
+    @Label("是否有房")
+    private boolean house;
+}

+ 17 - 0
springboot-main/src/main/java/com/alvin/entity/Res.java

@@ -0,0 +1,17 @@
+package com.alvin.entity;
+
+import com.bstek.urule.model.Label;
+import lombok.Data;
+
+@Data
+public class Res {
+    @Label("prob")
+    private String prob;
+    @Label("score")
+    private String score;
+    @Label("relativ_pos")
+    private String relativ_pos;
+    @Label("bad_ratio")
+    private String bad_ratio;
+
+}

+ 1 - 0
springboot-main/src/main/resources/configure.properties

@@ -0,0 +1 @@
+urule.repository.dir=C:/Users/root/urule_repo1

+ 13 - 0
springboot-main/src/main/resources/context.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
+	">
+    <import resource="classpath:urule-console-context.xml"/>
+    <context:property-placeholder ignore-unresolvable="true" order="2" location="classpath:configure.properties"/>
+
+    <!--<bean id="urule.scoreAction" class="com.alvin.CustomAction">-->
+
+    <!--</bean>-->
+</beans>