mirror of
https://github.com/abcv7/sfbx-cloud.git
synced 2026-08-16 19:49:49 +00:00
first commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>sfbx-rule</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>rule-client</artifactId>
|
||||
<name>rule-client</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>framework-rule-base</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.itheima.sfbx.framework.rule.config;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.runtime.service.KnowledgeService;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* SpringApplicationAware
|
||||
*
|
||||
* @author: wgl
|
||||
* @describe: 上下文增强器
|
||||
* @date: 2022/12/28 10:10
|
||||
*/
|
||||
@Component
|
||||
@Configuration
|
||||
public class SpringApplicationAware implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext ctx;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
ctx = applicationContext;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取上下文中的内容
|
||||
* @return
|
||||
*/
|
||||
public static ApplicationContext getApplicationContext(){
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.itheima.sfbx.framework.rule.config;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.KnowledgePackageReceiverServlet;
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Component
|
||||
public class URuleServletRegistration {
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean registerURuleServlet(){
|
||||
return new ServletRegistrationBean(new KnowledgePackageReceiverServlet(),"/knowledgepackagereceiver");
|
||||
}
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.itheima.sfbx.framework.rule.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
|
||||
/**
|
||||
* UruleBeanInit
|
||||
*
|
||||
* @author: wgl
|
||||
* @describe: Urule配置类加载
|
||||
* @date: 2022/12/28 10:10
|
||||
*/
|
||||
@Configuration
|
||||
@ImportResource({"classpath:urule-core-context.xml"})
|
||||
@PropertySource(value = {"classpath:urule-core-context.properties"})
|
||||
public class UruleBeanInit {
|
||||
@Bean
|
||||
public PropertySourcesPlaceholderConfigurer propertySourceLoader() {
|
||||
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
|
||||
configurer.setIgnoreUnresolvablePlaceholders(true);
|
||||
configurer.setOrder(1);
|
||||
return configurer;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.itheima.sfbx.framework.rule.dto;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.model.Label;
|
||||
|
||||
/**
|
||||
* RuleParams
|
||||
*
|
||||
* @author: wgl
|
||||
* @describe: 规则参数
|
||||
* @date: 2022/12/28 10:10
|
||||
*/
|
||||
public class ScoreParams {
|
||||
|
||||
@Label("得分")
|
||||
private String score;
|
||||
|
||||
|
||||
public ScoreParams() {
|
||||
}
|
||||
|
||||
public ScoreParams(String score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
|
||||
public String getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(String score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScoreParams{" +
|
||||
"score='" + score + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package com.itheima.sfbx.framework.rule.template;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.Utils;
|
||||
import com.itheima.sfbx.framework.rule.config.SpringApplicationAware;
|
||||
import com.itheima.sfbx.framework.rule.runtime.KnowledgePackage;
|
||||
import com.itheima.sfbx.framework.rule.runtime.KnowledgeSession;
|
||||
import com.itheima.sfbx.framework.rule.runtime.KnowledgeSessionFactory;
|
||||
import com.itheima.sfbx.framework.rule.runtime.service.KnowledgeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* RuleTemplate
|
||||
*
|
||||
* @author: wgl
|
||||
* @describe: 规则调用模板
|
||||
* @date: 2022/12/28 10:10
|
||||
*/
|
||||
@Service
|
||||
public class RuleTemplate {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取知识库里的包
|
||||
*
|
||||
* @param serverName
|
||||
* @param packageId
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public KnowledgePackage getPackage(String serverName, String packageId) throws IOException {
|
||||
//创建一个KnowledgeSession对象
|
||||
KnowledgeService knowledgeService = (KnowledgeService) SpringApplicationAware.getApplicationContext().getBean(KnowledgeService.BEAN_ID);
|
||||
KnowledgePackage knowledgePackage = knowledgeService.getKnowledge(serverName + "/" + packageId);
|
||||
return knowledgePackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取urule的session连接
|
||||
*
|
||||
* @param serverName
|
||||
* @param packageId
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public KnowledgeSession getSession(String serverName, String packageId) throws IOException {
|
||||
KnowledgeService knowledgeService = (KnowledgeService) SpringApplicationAware.getApplicationContext().getBean(KnowledgeService.BEAN_ID);
|
||||
KnowledgePackage knowledgePackage = knowledgeService.getKnowledge(serverName + "/" + packageId);
|
||||
KnowledgeSession session = KnowledgeSessionFactory.newKnowledgeSession(knowledgePackage);
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取urule的session连接
|
||||
*
|
||||
* @param serverName
|
||||
* @param packageId
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public void fireRules(Map data, String serverName, String packageId) throws IOException {
|
||||
Object knowledgeService = Utils.getApplicationContext().getBean(KnowledgeService.BEAN_ID);
|
||||
KnowledgePackage knowledgePackage = ((KnowledgeService)knowledgeService).getKnowledge(serverName + "/" + packageId);
|
||||
KnowledgeSession session = KnowledgeSessionFactory.newKnowledgeSession(knowledgePackage);
|
||||
session.fireRules(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.itheima.sfbx.framework.rule.config.SpringApplicationAware,\
|
||||
com.itheima.sfbx.framework.rule.config.URuleServletRegistration,\
|
||||
com.itheima.sfbx.framework.rule.template.RuleTemplate
|
||||
Reference in New Issue
Block a user