mirror of
https://gitee.com/jamen/slife.git
synced 2026-11-22 16:33:38 +00:00
加入规则引擎和代码生成模块
This commit is contained in:
@@ -186,7 +186,7 @@
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
Copyright 2017 SLife
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
+24563
-25273
File diff suppressed because one or more lines are too long
@@ -33,6 +33,7 @@
|
||||
<fastjson.version>1.2.36</fastjson.version>
|
||||
<sitemesh.version>3.0.1</sitemesh.version>
|
||||
<mybatisplus-spring-boot-starter.version>1.0.4</mybatisplus-spring-boot-starter.version>
|
||||
<drools.version>7.5.0.Final</drools.version>
|
||||
|
||||
</properties>
|
||||
|
||||
@@ -46,6 +47,8 @@
|
||||
<module>slife-log</module>
|
||||
<!-- <module>slife-test</module>-->
|
||||
<module>slife-blog</module>
|
||||
<module>slife-drools</module>
|
||||
<module>slife-code</module>
|
||||
</modules>
|
||||
|
||||
<!--全局依赖-->
|
||||
@@ -232,6 +235,12 @@
|
||||
<version>${slife.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.slife</groupId>
|
||||
<artifactId>slife-code</artifactId>
|
||||
<version>${slife.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.slife</groupId>
|
||||
<artifactId>slife-wx-applet</artifactId>
|
||||
@@ -249,7 +258,11 @@
|
||||
<artifactId>slife-activiti</artifactId>
|
||||
<version>${slife.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.slife</groupId>
|
||||
<artifactId>slife-drools</artifactId>
|
||||
<version>${slife.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.activiti</groupId>
|
||||
<artifactId>activiti-spring-boot-starter-basic</artifactId>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>slife</artifactId>
|
||||
<groupId>com.slife</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>slife-code</artifactId>
|
||||
<name>slife-code</name>
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>slife</artifactId>
|
||||
<groupId>com.slife</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>slife-drools</artifactId>
|
||||
|
||||
<name>slife-drools</name>
|
||||
<description>Drools project for Spring Boot</description>
|
||||
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.kie</groupId>
|
||||
<artifactId>kie-spring</artifactId>
|
||||
<version>${drools.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.drools</groupId>
|
||||
<artifactId>drools-compiler</artifactId>
|
||||
<version>${drools.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.kie</groupId>
|
||||
<artifactId>kie-maven-plugin</artifactId>
|
||||
<version>${drools.version}</version>
|
||||
<extensions>true</extensions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.slife.config;
|
||||
|
||||
import org.kie.api.KieBase;
|
||||
import org.kie.api.KieServices;
|
||||
import org.kie.api.builder.*;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.kie.internal.io.ResourceFactory;
|
||||
import org.kie.spring.KModuleBeanFactoryPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chen
|
||||
* @date 2017/12/21
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe: 通过KieServices对象得到一个KieContainer,利用kieContainer对象创建一个新的KieSession,
|
||||
*/
|
||||
@Configuration
|
||||
public class DroolsAutoConfiguration {
|
||||
private static final String RULES_PATH = "rules/";
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(KieFileSystem.class)
|
||||
public KieFileSystem kieFileSystem() throws IOException {
|
||||
KieFileSystem kieFileSystem = getKieServices().newKieFileSystem();
|
||||
for (Resource file : getRuleFiles()) {
|
||||
kieFileSystem.write(ResourceFactory.newClassPathResource(RULES_PATH + file.getFilename(), "UTF-8"));
|
||||
}
|
||||
return kieFileSystem;
|
||||
}
|
||||
|
||||
private Resource[] getRuleFiles() throws IOException {
|
||||
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
|
||||
return resourcePatternResolver.getResources("classpath*:" + RULES_PATH + "**/*.*");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(KieContainer.class)
|
||||
public KieContainer kieContainer() throws IOException {
|
||||
final KieRepository kieRepository = getKieServices().getRepository();
|
||||
|
||||
kieRepository.addKieModule(new KieModule() {
|
||||
@Override
|
||||
public ReleaseId getReleaseId() {
|
||||
return kieRepository.getDefaultReleaseId();
|
||||
}
|
||||
});
|
||||
|
||||
KieBuilder kieBuilder = getKieServices().newKieBuilder(kieFileSystem());
|
||||
kieBuilder.buildAll();
|
||||
|
||||
return getKieServices().newKieContainer(kieRepository.getDefaultReleaseId());
|
||||
}
|
||||
|
||||
private KieServices getKieServices() {
|
||||
return KieServices.Factory.get();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(KieBase.class)
|
||||
public KieBase kieBase() throws IOException {
|
||||
return kieContainer().getKieBase();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(KieSession.class)
|
||||
public KieSession kieSession() throws IOException {
|
||||
return kieContainer().newKieSession();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(KModuleBeanFactoryPostProcessor.class)
|
||||
public KModuleBeanFactoryPostProcessor kiePostProcessor() {
|
||||
return new KModuleBeanFactoryPostProcessor();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.slife.controller;
|
||||
|
||||
import com.slife.fact.User;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* Created by chen on 2017/12/21.
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
*/
|
||||
@RestController
|
||||
public class RuleTestController {
|
||||
@Resource
|
||||
private KieSession kieSession;
|
||||
|
||||
@GetMapping("/address")
|
||||
public void test(){
|
||||
User user = new User();
|
||||
user.setUserId(1L);
|
||||
user.setUserName("admin");
|
||||
|
||||
kieSession.insert(user);
|
||||
|
||||
int ruleFiredCount = kieSession.fireAllRules();
|
||||
System.out.println("触发了" + ruleFiredCount + "条规则");
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.slife.fact;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chen
|
||||
* @date 2017/12/21
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
*/
|
||||
public class User {
|
||||
private Long userId;
|
||||
private String userName;
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package plausibcheck.adress
|
||||
|
||||
rule qw
|
||||
no-loop true
|
||||
when
|
||||
|
||||
then
|
||||
System.out.println("=========================");
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
package plausibcheck.adress
|
||||
import com.slife.fact.User
|
||||
rule "sf"
|
||||
when
|
||||
User(getUserName().equals("d"))
|
||||
then
|
||||
System.out.println("cccccc");
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.slife;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SlifeDroolsApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.slife.dao;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.slife.base.dao.CrudDao;
|
||||
import com.slife.entity.SysUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -32,7 +33,9 @@ public interface SysUserDao extends CrudDao<SysUser> {
|
||||
* @return
|
||||
*/
|
||||
|
||||
List<SysUser> selectSysUserBySysOfficeId(@Param("sysOfficeId") String sysOfficeId, @Param("delFlag") String delFlag);
|
||||
List<SysUser> selectSysUserBySysOfficeId(@Param("sysOfficeId") String sysOfficeId, @Param("delFlag")
|
||||
String
|
||||
delFlag);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,6 +47,11 @@
|
||||
<artifactId>slife-activiti</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.slife</groupId>
|
||||
<artifactId>slife-code</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.slife</groupId>
|
||||
<artifactId>slife-blog</artifactId>
|
||||
@@ -74,6 +79,10 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.slife</groupId>
|
||||
<artifactId>slife-drools</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user