新增统一配置config,修复工作流问题,通用平台多数据源新增yml配置,是否开启多数据源

This commit is contained in:
lhc
2021-02-23 13:34:11 +08:00
parent f43cb56dac
commit 389fb6c082
18 changed files with 457 additions and 17 deletions

View File

@@ -1,22 +1,30 @@
package com.hcframe.activiti;
import com.hcframe.base.module.datasource.config.DataSourceConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.FilterType;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import tk.mybatis.spring.annotation.MapperScan;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@SpringBootApplication(exclude = {
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class,
org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration.class,
})
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableSwagger2
@ServletComponentScan
@EnableCaching
//@EnableDiscoveryClient
//@EnableFeignClients
@ComponentScan(basePackages = {"com.hcframe.**"})
@MapperScan(basePackages = "com.hcframe.**.dao")
@ComponentScan(basePackages = {"com.hcframe.**"},excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {DataSourceConfiguration.class}))
public class ActivitiApplication {
public static void main(String[] args) {

View File

@@ -100,6 +100,16 @@ swagger:
# 密码
password: admin
# Druid连接配置
# 框架配置
frame:
# 是否开启redis 用户登录若开启此项需要配置redis节点及相关配置若不开启需要注释掉redis相关配置信息
isRedisLogin: true
# 用户登陆超时设置单位为小时此值不能为0
loginTimeout: 4
# 是否开启controller日志监控
showControllerLog: true
# 是否开启多数据源
multi-data-source: false
druid:
# Druid用户名
username: test

View File

@@ -11,4 +11,5 @@ public class FrameConfig {
private Boolean isRedisLogin = false;
private Integer loginTimeout = 4;
private Boolean showControllerLog = true;
private Boolean MultiDataSource = true;
}

View File

@@ -1,6 +1,6 @@
package com.hcframe.base.common.utils;
import java.util.Random;
import java.util.UUID;
/**
* 生成Token的工具类
@@ -21,7 +21,7 @@ public class TokenProccessor {
* @return
*/
public String makeToken() {
String token = (System.currentTimeMillis() + new Random().nextInt(999999999)) + "";
String token = System.currentTimeMillis() + UUID.randomUUID().toString();
EncryptUtil encryptUtil = EncryptUtil.getInstance();
String str = encryptUtil.MD5(token);
str = str.replaceAll("/", "");

View File

@@ -1,5 +1,7 @@
package com.hcframe.base.module.datasource.aop;
import com.hcframe.base.common.config.FrameConfig;
import com.hcframe.base.common.utils.RedisUtil;
import com.hcframe.base.module.datasource.dao.DatasourceConfigDao;
import com.hcframe.base.module.datasource.dynamic.DBContextHolder;
import com.hcframe.base.module.datasource.utils.DataUnit;
@@ -29,6 +31,14 @@ import javax.servlet.http.HttpServletRequest;
@Component
public class DataSourceAop {
public static boolean isMulti;
// 通过yml文件获取host
@Autowired
public void setHost(FrameConfig config) {
DataSourceAop.isMulti = config.getMultiDataSource();
}
@Autowired
DatasourceConfigDao datasourceConfigDao;
@@ -44,17 +54,21 @@ public class DataSourceAop {
public void doBefore(JoinPoint joinPoint) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
String key = request.getParameter("datasourceKey");
if (StringUtils.isBlank(key)) {
DBContextHolder.setDataSource(DataUnit.MASTER);
} else {
DBContextHolder.setDataSource(key);
if (isMulti) {
String key = request.getParameter("datasourceKey");
if (StringUtils.isBlank(key)) {
DBContextHolder.setDataSource(DataUnit.MASTER);
} else {
DBContextHolder.setDataSource(key);
}
}
}
@After("log()")
public void doAfter() {
DBContextHolder.clearDataSource();
if (isMulti) {
DBContextHolder.clearDataSource();
}
}
}

View File

@@ -0,0 +1,39 @@
<?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>parent</artifactId>
<groupId>com.hcframe</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hcframe-config</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.hcframe</groupId>
<artifactId>hcframe-base</artifactId>
<version>1.2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.hcframe</groupId>
<artifactId>hcframe-starter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,24 @@
package com.hcframe.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableSwagger2
@ServletComponentScan
@EnableCaching
//@EnableDiscoveryClient
//@EnableFeignClients
@ComponentScan(basePackages = {"com.hcframe.**"})
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}

View File

@@ -0,0 +1,36 @@
package com.hcframe.config.common.config;
import com.hcframe.base.module.cache.CacheService;
import com.hcframe.base.module.datasource.utils.DataSourceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author lhc
* @date 2020-10-09
* @description springboot启动执行配置类
*/
@Component
public class CommandLineRunnerImpl implements CommandLineRunner {
private static final Logger logger = LoggerFactory.getLogger(CommandLineRunnerImpl.class);
@Autowired
List<CacheService> cacheServices;
@Override
public void run(String... args) {
DataSourceUtil.initDataSource();
// 初始化缓存
// for (CacheService cacheService : cacheServices) {
// cacheService.initTableCache();
// }
logger.info("start success");
}
}

View File

@@ -0,0 +1,80 @@
package com.hcframe.config.common.config;
import com.hcframe.base.module.auth.dao.FtUserDao;
import com.hcframe.base.module.auth.entity.FtUser;
import com.hcframe.base.module.shiro.service.ShiroType;
import com.hcframe.base.module.shiro.service.SystemRealm;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
/**
* @author lhc
* @date 2021-02-05
* @decription shiro 配置类
*/
@Component
public class ShiroRealmConfig implements SystemRealm {
final
FtUserDao ftUserDao;
public ShiroRealmConfig(FtUserDao ftUserDao) {
this.ftUserDao = ftUserDao;
}
/**
* 根据用户信息注入权限
* @param user 用户信息
* @return 权限信息
*/
@Override
public SimpleAuthorizationInfo setAuthoriztion(Object user) {
return new SimpleAuthorizationInfo();
}
/**
* 根据用户Id查询用户信息并注入到shiro框架中
* @param userId 用户id
* @return 用户信息
*/
@Override
public Object findByUserId(String userId) {
return ftUserDao.selectOne(FtUser.builder().userId(Integer.parseInt(userId)).build());
}
/**
* 配置拦截及放行路径
* @return 返回拦截及放行路径Map
*/
@Override
public LinkedHashMap<String, String> setShiroUrl() {
LinkedHashMap<String, String> map = new LinkedHashMap<>();
// 用户登陆
map.put("/ftUser/login", ShiroType.ANON);
// Vue静态资源
map.put("/img/**", ShiroType.ANON);
map.put("/static/**", ShiroType.ANON);
map.put("/tinymce/**", ShiroType.ANON);
map.put("/favicon.ico", ShiroType.ANON);
map.put("/manifest.json", ShiroType.ANON);
map.put("/robots.txt", ShiroType.ANON);
map.put("/precache*", ShiroType.ANON);
map.put("/service-worker.js", ShiroType.ANON);
// swagger UI 静态资源
map.put("/swagger-ui.html",ShiroType.ANON);
map.put("/doc.html",ShiroType.ANON);
map.put("/swagger-resources/**",ShiroType.ANON);
map.put("/webjars/**",ShiroType.ANON);
map.put("/v2/api-docs",ShiroType.ANON);
map.put("/v2/api-docs-ext",ShiroType.ANON);
map.put("/swagger/**",ShiroType.ANON);
// druid 资源路径
map.put("/druid/**",ShiroType.ANON);
// 其余路径均拦截
map.put("/**", ShiroType.ANON);
return map;
}
}

View File

@@ -0,0 +1,131 @@
server:
port: 8080
servlet:
context-path: /config
pagehelper:
auto-runtime-dialect: true
spring:
application:
name: cloud-config
# 缓存设置
cache:
# redis缓存
# type: redis
# redis:
# time-to-live: 1d
# use-key-prefix: true
# cache-null-values: true
# key-prefix: cache.
# ehcache缓存
type: ehcache
ehcache:
config: classpath:ehcache.xml
redis:
database: 0
host: 192.168.4.119
port: 6379
password:
lettuce:
pool:
# 连接池中的最大空闲连接 默认8
max-idle: 8
# 连接池中的最小空闲连接 默认0
min-idle: 0
# 连接池最大连接数 默认8 ,负数表示没有限制
max-active: 8
# 连接池最大阻塞等待时间(使用负值表示没有限制) 默认-1
max-wait: -1
timeout: 30000
mvc:
view:
prefix: classpath*:/templates/
suffix: .html
static-path-pattern: classpath*:/static/**
datasource:
druid:
# 配置sqlite文件路径需要填写绝对路径推荐将sqlite文件放入到服务器上而非程序jar包或war包中
driver-class-name: org.sqlite.JDBC
url: jdbc:sqlite:/Volumes/DATA/ideaProject/common-frame/hcframe/hcframe-parent/hcframe-config/src/main/resources/datasource.db
username:
password:
#使用Druid数据源
initialSize: 5
# 初始化大小,最小,最大
minIdle: 5
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: select 1
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 配置监控统计拦截的filters去掉后监控界面sql无法统计'wall'用于防火墙
filters: stat,slf4j
# 通过connectProperties属性来打开mergeSql功能慢SQL记录
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
mybatis:
mapper-locations: classpath*:mapping/**/*.xml
type-aliases-package: com.hcframe.**.entity
configuration:
# 开启Sql日志记录
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 框架配置
frame:
# 是否开启redis 用户登录若开启此项需要配置redis节点及相关配置若不开启需要注释掉redis相关配置信息
isRedisLogin: true
# 用户登陆超时设置单位为小时此值不能为0
loginTimeout: 4
# 是否开启controller日志监控
showControllerLog: true
# swagger配置
swagger:
# 配置controller包路径
path: com.hcframe.module.**.controller
# 是否开启权限
enableAuth: false
# 用户名
username: admin
# 密码
password: admin
# Druid连接配置
druid:
# Druid用户名
username: test
# Druid密码
password: test
# Druid 允许访问的IP,默认全部允许
# allow: 127.0.0.1
# Druid 拒绝访问的IP,默认不拒绝全部
# deny: 10.0.0.2
eureka:
client:
service-url:
defaultZone: http://admin:123456@192.168.4.119:8081/eureka/
feign:
client:
config:
default:
connectTimeout: 300000
readTimeout: 30000
loggerLevel: basic
okhttp:
enabled: true
hystrix:
enabled: true
# 设置熔断器超时时间
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 30000

View File

@@ -0,0 +1,25 @@
__ __ ______ ______
| \ | \ / \ / \
| $$ | $$| $$$$$$\ | $$$$$$\ ______ ______ ______ ____ ______
| $$__| $$| $$ \$$ | $$_ \$$/ \ | \ | \ \ / \
| $$ $$| $$ | $$ \ | $$$$$$\ \$$$$$$\| $$$$$$\$$$$\| $$$$$$\
| $$$$$$$$| $$ __ | $$$$ | $$ \$$/ $$| $$ | $$ | $$| $$ $$
| $$ | $$| $$__/ \ | $$ | $$ | $$$$$$$| $$ | $$ | $$| $$$$$$$$ __
| $$ | $$ \$$ $$ | $$ | $$ \$$ $$| $$ | $$ | $$ \$$ \| \
\$$ \$$ \$$$$$$ \$$ \$$ \$$$$$$$ \$$ \$$ \$$ \$$$$$$$ \$$
__ __ _______ __ __
| \ | \ | \ | \ | \
| $$\ | $$ ______ | $$$$$$$\ __ __ ______ | $$ | $$ ______ ______ ______
| $$$\| $$ / \ | $$__/ $$| \ | \ / \ | $$__| $$ / \ / \ / \
| $$$$\ $$| $$$$$$\ | $$ $$| $$ | $$| $$$$$$\ | $$ $$| $$$$$$\| $$$$$$\| $$$$$$\
| $$\$$ $$| $$ | $$ | $$$$$$$\| $$ | $$| $$ | $$ | $$$$$$$$| $$ | $$| $$ | $$| $$ $$
| $$ \$$$$| $$__/ $$ | $$__/ $$| $$__/ $$| $$__| $$ | $$ | $$| $$__/ $$| $$__/ $$| $$$$$$$$ __
| $$ \$$$ \$$ $$ | $$ $$ \$$ $$ \$$ $$ | $$ | $$ \$$ $$| $$ $$ \$$ \| \
\$$ \$$ \$$$$$$ \$$$$$$$ \$$$$$$ _\$$$$$$$ \$$ \$$ \$$$$$$ | $$$$$$$ \$$$$$$$ \$$
| \__| $$ | $$
\$$ $$ | $$
\$$$$$$ \$$

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation = "http://ehcache.org/ehcache.xsd"
updateCheck = "false">
<!-- 指定一个文件目录当EHCache把数据写到硬盘上时将把数据写到这个文件目录下 -->
<diskStore path = "java.io.tmpdir"/>
<!-- 默认的管理策略 -->
<defaultCache
eternal = "false"
maxElementsInMemory = "10000"
overflowToDisk = "true"
diskPersistent = "false"
timeToIdleSeconds = "120"
timeToLiveSeconds = "120"
diskExpiryThreadIntervalSeconds = "120"
memoryStoreEvictionPolicy = "LRU"/>
<!-- 此缓存最多可以存活timeToLiveSeconds秒如果期间超过timeToIdleSeconds秒未访问缓存失效 -->
<cache
name = "tableCache"
eternal = "false"
maxElementsInMemory = "10000"
overflowToDisk = "true"
diskPersistent = "false"
timeToIdleSeconds = "120"
timeToLiveSeconds = "180"
memoryStoreEvictionPolicy = "LRU"/>
<cache
name = "baseCache"
eternal = "false"
maxElementsInMemory = "10000"
overflowToDisk = "true"
diskPersistent = "false"
timeToIdleSeconds = "120"
timeToLiveSeconds = "180"
memoryStoreEvictionPolicy = "LRU"/>
<cache
name = "datasourceCache"
eternal = "true"
maxElementsInMemory = "10000"
overflowToDisk = "true"
diskPersistent = "false"
timeToIdleSeconds = "120"
timeToLiveSeconds = "180"
memoryStoreEvictionPolicy = "LRU"/>
<!-- maxElementsInMemory 内存中最大缓存对象数看着自己的heap大小来搞 -->
<!-- eternaltrue表示对象永不过期此时会忽略timeToIdleSeconds和timeToLiveSeconds属性默认为false -->
<!-- maxElementsOnDisk硬盘中最大缓存对象数若是0表示无穷大 -->
<!-- overflowToDisktrue表示当内存缓存的对象数目达到了maxElementsInMemory界限后
会把溢出的对象写到硬盘缓存中。注意如果缓存的对象要写入到硬盘中的话则该对象必须实现了Serializable接口才行。-->
<!-- diskSpoolBufferSizeMB磁盘缓存区大小默认为30MB。每个Cache都应该有自己的一个缓存区。-->
<!-- diskPersistent是否缓存虚拟机重启期数据 -->
<!-- diskExpiryThreadIntervalSeconds磁盘失效线程运行时间间隔默认为120秒 -->
<!-- timeToIdleSeconds 设定允许对象处于空闲状态的最长时间,以秒为单位。当对象自从最近一次被访问后,
如果处于空闲状态的时间超过了timeToIdleSeconds属性值这个对象就会过期
EHCache将把它从缓存中清空。只有当eternal属性为false该属性才有效。如果该属性值为0
则表示对象可以无限期地处于空闲状态 -->
<!-- timeToLiveSeconds设定对象允许存在于缓存中的最长时间以秒为单位。当对象自从被存放到缓存中后
如果处于缓存中的时间超过了 timeToLiveSeconds属性值这个对象就会过期
EHCache将把它从缓存中清除。只有当eternal属性为false该属性才有效。如果该属性值为0
则表示对象可以无限期地存在于缓存中。timeToLiveSeconds必须大于timeToIdleSeconds属性才有意义 -->
<!-- memoryStoreEvictionPolicy当达到maxElementsInMemory限制时
Ehcache将会根据指定的策略去清理内存。可选策略有LRU最近最少使用默认策略
FIFO先进先出、LFU最少访问次数-->
</ehcache>

View File

@@ -20,6 +20,7 @@
<module>hcframe-activiti</module>
<module>hcframe-es</module>
<module>hcframe-starter</module>
<module>hcframe-config</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@@ -1,5 +1,5 @@
# Base api
VUE_APP_BASE_API = '/common'
VUE_APP_BASE_API = '/config'
# vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable,
# to control whether the babel-plugin-dynamic-import-node plugin is enabled.

View File

@@ -7,7 +7,7 @@ const CONFIG: IConfig = {
// ACTIVTI_URL: 'http://192.168.43.42:8080/activiti',
// BASE_URL: 'http://192.168.43.42:8080/common'
ACTIVTI_URL: 'http://localhost:8081/activiti',
BASE_URL: 'http://localhost:8080/common'
BASE_URL: 'http://localhost:8080/config'
}
export default CONFIG

View File

@@ -441,7 +441,7 @@ export default class extends Vue {
}
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
await this.$router.push({ name: 'bpmnCreate', params: params })
await this.$router.push({ name: 'BpmnCreate', params: params })
localStorage.setItem('bpmnLocalstorage', JSON.stringify(params))
}
}
@@ -455,7 +455,7 @@ export default class extends Vue {
const { data } = await this.ActivitiApi.showBpmn(this.showBpmnParams)
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
await this.$router.push({ name: 'onlyViewBpmn', params: data })
await this.$router.push({ name: 'OnlyViewBpmn', params: data })
localStorage.setItem('showData', JSON.stringify(data))
}
@@ -478,7 +478,7 @@ export default class extends Vue {
}
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
await this.$router.push({ name: 'bpmnCreate', params: params })
await this.$router.push({ name: 'BpmnCreate', params: params })
localStorage.setItem('bpmnLocalstorage', JSON.stringify(params))
}

View File

@@ -37,7 +37,7 @@ module.exports = {
// ['^' + process.env.VUE_APP_BASE_API]: ''
// }
// }
'/common': {
'/config': {
target: 'http://localhost:8080/',
// target: 'http://192.168.43.42:8080/',
// target: 'http://127.0.0.1:8080',