add: jetcache、flyflow、重发、限流
This commit is contained in:
@@ -31,6 +31,34 @@
|
|||||||
<configuration.version>1.9</configuration.version>
|
<configuration.version>1.9</configuration.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!--重试-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.retry</groupId>
|
||||||
|
<artifactId>spring-retry</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--限流-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.forezp</groupId>
|
||||||
|
<artifactId>distributed-limit-core</artifactId>
|
||||||
|
<version>1.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
<!--引入flyway-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.flywaydb</groupId>
|
||||||
|
<artifactId>flyway-core</artifactId>
|
||||||
|
<version>6.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.flywaydb</groupId>
|
||||||
|
<artifactId>flyway-mysql</artifactId>
|
||||||
|
<version>9.21.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!--反射-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
<version>0.9.10</version>
|
||||||
|
</dependency>
|
||||||
<!-- https://onew.me/logback/2018/09/17/logback_win.html-->
|
<!-- https://onew.me/logback/2018/09/17/logback_win.html-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.fusesource.jansi</groupId>
|
<groupId>org.fusesource.jansi</groupId>
|
||||||
@@ -43,11 +71,17 @@
|
|||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>13.0</version>
|
<version>13.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.codehaus.groovy</groupId>-->
|
||||||
|
<!-- <artifactId>groovy-all</artifactId>-->
|
||||||
|
<!-- <version>3.0.13</version>-->
|
||||||
|
<!-- <type>pom</type>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.groovy</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>groovy-all</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>3.0.13</version>
|
<version>29.0-jre</version>
|
||||||
<type>pom</type>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- 日志链路追踪 https://tlog.yomahub.com/pages/f62a84/#%E5%90%8C%E6%AD%A5%E6%97%A5%E5%BF%97-->
|
<!-- 日志链路追踪 https://tlog.yomahub.com/pages/f62a84/#%E5%90%8C%E6%AD%A5%E6%97%A5%E5%BF%97-->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -49,11 +49,11 @@ public class AuthorizationController {
|
|||||||
|
|
||||||
@ApiOperation("登录授权")
|
@ApiOperation("登录授权")
|
||||||
@PostMapping(value = "/login")
|
@PostMapping(value = "/login")
|
||||||
public ResponseEntity<Object> login(@RequestBody Map authMap) throws Exception {
|
public ResponseEntity<Object> login(@RequestBody Map authMap, HttpServletRequest request) throws Exception {
|
||||||
if (ObjectUtil.isEmpty(authMap)){
|
if (ObjectUtil.isEmpty(authMap)){
|
||||||
return ResponseEntity.noContent().build();
|
return ResponseEntity.noContent().build();
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok(onlineUserService.login(authMap));
|
return ResponseEntity.ok(onlineUserService.login(authMap, request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -65,4 +65,5 @@ public interface ISysDeptService extends IService<SysDept> {
|
|||||||
|
|
||||||
void createDept(SysDept dept);
|
void createDept(SysDept dept);
|
||||||
|
|
||||||
|
List<SysDept> getUserDeptByUserId(String userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,4 +41,6 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String findAllChild(String pid);
|
String findAllChild(String pid);
|
||||||
|
|
||||||
|
List<SysDept> getUserDeptByUserId(String userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,4 +37,17 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
)
|
)
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getUserDeptByUserId" resultType="org.nl.system.service.dept.dao.SysDept">
|
||||||
|
SELECT
|
||||||
|
sd.*
|
||||||
|
FROM
|
||||||
|
sys_dept sd
|
||||||
|
WHERE sd.dept_id IN (
|
||||||
|
SELECT
|
||||||
|
d.dept_id
|
||||||
|
FROM
|
||||||
|
`sys_user_dept` d
|
||||||
|
WHERE d.user_id = #{userId}
|
||||||
|
) AND sd.is_used = TRUE
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -176,4 +176,9 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
sysDeptMapper.updateSubCount(dept.getPid());
|
sysDeptMapper.updateSubCount(dept.getPid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysDept> getUserDeptByUserId(String userId) {
|
||||||
|
return sysDeptMapper.getUserDeptByUserId(userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ public class LuceneDefaultAppender extends UnsynchronizedAppenderBase<ILogging
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void append(ILoggingEvent eventObject) {
|
protected void append(ILoggingEvent eventObject) {
|
||||||
IndexWriter indexWriter = LuceneIndexWriter.getIndexWriter();
|
// IndexWriter indexWriter = LuceneIndexWriter.getIndexWriter();
|
||||||
Document document = new Document();
|
// Document document = new Document();
|
||||||
document.add(new StringField("status_code", "01", Field.Store.YES));
|
// document.add(new StringField("status_code", "01", Field.Store.YES));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,11 @@ package org.nl.system.service.secutiry.impl;
|
|||||||
import cn.dev33.satoken.secure.SaSecureUtil;
|
import cn.dev33.satoken.secure.SaSecureUtil;
|
||||||
import cn.dev33.satoken.stp.SaLoginModel;
|
import cn.dev33.satoken.stp.SaLoginModel;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -28,6 +30,8 @@ import org.nl.common.utils.*;
|
|||||||
import org.nl.config.RsaProperties;
|
import org.nl.config.RsaProperties;
|
||||||
import org.nl.common.exception.BadRequestException;
|
import org.nl.common.exception.BadRequestException;
|
||||||
import org.nl.common.utils.dto.CurrentUser;
|
import org.nl.common.utils.dto.CurrentUser;
|
||||||
|
import org.nl.system.service.dept.ISysDeptService;
|
||||||
|
import org.nl.system.service.dept.dao.SysDept;
|
||||||
import org.nl.system.service.secutiry.dto.UserDto;
|
import org.nl.system.service.secutiry.dto.UserDto;
|
||||||
import org.nl.system.service.role.ISysRoleService;
|
import org.nl.system.service.role.ISysRoleService;
|
||||||
import org.nl.system.service.secutiry.dto.AuthUserDto;
|
import org.nl.system.service.secutiry.dto.AuthUserDto;
|
||||||
@@ -55,6 +59,8 @@ public class OnlineUserService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ISysUserService sysUserService;
|
private ISysUserService sysUserService;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private ISysDeptService deptService;
|
||||||
|
@Autowired
|
||||||
private ISysRoleService roleService;
|
private ISysRoleService roleService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisUtils redisUtils;
|
private RedisUtils redisUtils;
|
||||||
@@ -69,20 +75,27 @@ public class OnlineUserService {
|
|||||||
* @param token /
|
* @param token /
|
||||||
* @param request /
|
* @param request /
|
||||||
*/
|
*/
|
||||||
public void save(UserDto userDto, String token, HttpServletRequest request){
|
public void save(SysUser userDto, String token, HttpServletRequest request){
|
||||||
// String dept = userDto.getDept().getName();
|
// 获取用户部门
|
||||||
String dept = "";
|
List<SysDept> userDeptByUserId = deptService.getUserDeptByUserId(userDto.getUser_id());
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (SysDept dept : userDeptByUserId) {
|
||||||
|
sb.append(dept.getName()).append("、");
|
||||||
|
}
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
sb.setLength(sb.length() - 1);
|
||||||
|
}
|
||||||
|
String dept = sb.toString();
|
||||||
String ip = StringUtils.getIp(request);
|
String ip = StringUtils.getIp(request);
|
||||||
String browser = StringUtils.getBrowser(request);
|
String browser = StringUtils.getBrowser(request);
|
||||||
// String address = StringUtils.getCityInfo(ip);
|
String address = StringUtils.getCityInfo(ip);
|
||||||
String address = "局域网";
|
|
||||||
OnlineUserDto onlineUserDto = null;
|
OnlineUserDto onlineUserDto = null;
|
||||||
try {
|
try {
|
||||||
// onlineUserDto = new OnlineUserDto(userDto.getUsername(), userDto.getNickName(), dept, browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
|
onlineUserDto = new OnlineUserDto(userDto.getUsername(), userDto.getPerson_name(), dept, browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(),e);
|
log.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
redisUtils.set(token, onlineUserDto, StpUtil.getTokenTimeout());
|
redisUtils.set("oline-" + userDto.getUsername(), onlineUserDto, StpUtil.getTokenTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,7 +122,7 @@ public class OnlineUserService {
|
|||||||
Collections.reverse(keys);
|
Collections.reverse(keys);
|
||||||
List<OnlineUserDto> onlineUserDtos = new ArrayList<>();
|
List<OnlineUserDto> onlineUserDtos = new ArrayList<>();
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
if (key.length() == 1511) {
|
if (key.startsWith("oline-")) {
|
||||||
OnlineUserDto onlineUserDto = (OnlineUserDto) redisUtils.get(key);
|
OnlineUserDto onlineUserDto = (OnlineUserDto) redisUtils.get(key);
|
||||||
if(StrUtil.isNotEmpty(filter)){
|
if(StrUtil.isNotEmpty(filter)){
|
||||||
if(onlineUserDto.toString().contains(filter)){
|
if(onlineUserDto.toString().contains(filter)){
|
||||||
@@ -127,10 +140,26 @@ public class OnlineUserService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 踢出用户
|
* 踢出用户
|
||||||
* @param key /
|
* @param key: OnlineUserDto /
|
||||||
*/
|
*/
|
||||||
public void kickOut(String key){
|
public void kickOut(OnlineUserDto key) {
|
||||||
|
// 获取用户
|
||||||
|
SysUser one = sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, key.getUserName()));
|
||||||
|
if (ObjectUtil.isNotEmpty(one)) {
|
||||||
|
redisUtils.del("oline-" + one.getUsername());
|
||||||
|
}
|
||||||
|
// 下线
|
||||||
|
StpUtil.logoutByTokenValue(key.getKey()); // 通过token强退
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 踢出用户
|
||||||
|
* @param key:token /
|
||||||
|
*/
|
||||||
|
public void kickOut(String key) {
|
||||||
redisUtils.del(key);
|
redisUtils.del(key);
|
||||||
|
// 下线
|
||||||
|
StpUtil.logoutByTokenValue(key); // 通过token强退
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,7 +240,7 @@ public class OnlineUserService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public Map<String, Object> login(Map paramMap){
|
public Map<String, Object> login(Map paramMap, HttpServletRequest request){
|
||||||
// 密码解密 - 前端的加密规则: encrypt
|
// 密码解密 - 前端的加密规则: encrypt
|
||||||
AuthUserDto authUser = JSON.toJavaObject((JSON) JSON.toJSON(paramMap), AuthUserDto.class);
|
AuthUserDto authUser = JSON.toJavaObject((JSON) JSON.toJSON(paramMap), AuthUserDto.class);
|
||||||
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
||||||
@@ -263,7 +292,7 @@ public class OnlineUserService {
|
|||||||
put("user", user);
|
put("user", user);
|
||||||
}};
|
}};
|
||||||
// 保存在线信息
|
// 保存在线信息
|
||||||
// onlineUserService.save(userDto, StpUtil.getTokenValue(), request);
|
this.save(userInfo, StpUtil.getTokenValue(), request);
|
||||||
return authInfo;
|
return authInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,14 @@ spring:
|
|||||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||||
# url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:nl-sso-server}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
# url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:nl-sso-server}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
||||||
url: jdbc:log4jdbc:mysql://${DB_HOST:47.111.78.178}:${DB_PORT:3306}/${DB_NAME:stand_lms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
# url: jdbc:log4jdbc:mysql://${DB_HOST:47.111.78.178}:${DB_PORT:3306}/${DB_NAME:stand_lms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
||||||
username: ${DB_USER:root}
|
|
||||||
password: ${DB_PWD:P@ssw0rd}
|
|
||||||
# password: ${DB_PWD:P@ssw0rd}
|
|
||||||
# url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:nl-sso-server}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
|
||||||
# url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:stand_lms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
|
||||||
# username: ${DB_USER:root}
|
# username: ${DB_USER:root}
|
||||||
|
# password: ${DB_PWD:P@ssw0rd}
|
||||||
|
# password: ${DB_PWD:P@ssw0rd}
|
||||||
|
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:stand_lms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
||||||
|
username: ${DB_USER:root}
|
||||||
# password: ${DB_PWD:Root.123456}
|
# password: ${DB_PWD:Root.123456}
|
||||||
# password: ${DB_PWD:12356}
|
password: ${DB_PWD:12356}
|
||||||
# 初始连接数
|
# 初始连接数
|
||||||
initial-size: 5
|
initial-size: 5
|
||||||
# 最小连接数
|
# 最小连接数
|
||||||
@@ -57,9 +56,25 @@ spring:
|
|||||||
wall:
|
wall:
|
||||||
config:
|
config:
|
||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
||||||
|
flyway:
|
||||||
|
# 是否启用flyway
|
||||||
|
enabled: true
|
||||||
|
# 编码格式,默认UTF-8
|
||||||
|
encoding: UTF-8
|
||||||
|
# 迁移sql脚本文件存放路径,默认db/migration
|
||||||
|
locations: classpath:db/migration
|
||||||
|
# 迁移sql脚本文件名称的前缀,默认V
|
||||||
|
sql-migration-prefix: V
|
||||||
|
# 迁移sql脚本文件名称的分隔符,默认2个下划线__
|
||||||
|
sql-migration-separator: __
|
||||||
|
# 迁移sql脚本文件名称的后缀
|
||||||
|
sql-migration-suffixes: .sql
|
||||||
|
# 迁移时是否进行校验,默认true
|
||||||
|
validate-on-migrate: true
|
||||||
|
# 当迁移发现数据库非空且存在没有元数据的表时,自动执行基准迁移,新建schema_version表
|
||||||
|
baseline-on-migrate: true
|
||||||
redis:
|
redis:
|
||||||
#数据库索引
|
#数据库索引
|
||||||
database: ${REDIS_DB:2}
|
|
||||||
host: ${REDIS_HOST:127.0.0.1}
|
host: ${REDIS_HOST:127.0.0.1}
|
||||||
port: ${REDIS_PORT:6379}
|
port: ${REDIS_PORT:6379}
|
||||||
# password: ${REDIS_PWD:}
|
# password: ${REDIS_PWD:}
|
||||||
@@ -70,6 +85,7 @@ spring:
|
|||||||
threads: 4
|
threads: 4
|
||||||
nettyThreads: 4
|
nettyThreads: 4
|
||||||
singleServerConfig:
|
singleServerConfig:
|
||||||
|
database: 2
|
||||||
connectionMinimumIdleSize: 8
|
connectionMinimumIdleSize: 8
|
||||||
connectionPoolSize: 8
|
connectionPoolSize: 8
|
||||||
address: redis://127.0.0.1:6379
|
address: redis://127.0.0.1:6379
|
||||||
@@ -169,7 +185,7 @@ sa-token:
|
|||||||
token-session-check-login: false
|
token-session-check-login: false
|
||||||
alone-redis:
|
alone-redis:
|
||||||
# Redis数据库索引(默认为0)
|
# Redis数据库索引(默认为0)
|
||||||
database: 2
|
database: 4
|
||||||
# Redis服务器地址
|
# Redis服务器地址
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
# Redis服务器连接端口
|
# Redis服务器连接端口
|
||||||
@@ -178,3 +194,22 @@ sa-token:
|
|||||||
password:
|
password:
|
||||||
# 连接超时时间
|
# 连接超时时间
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
|
jetcache:
|
||||||
|
statIntervalMinutes: 15 # 统计间隔,默认0:表示不统计
|
||||||
|
areaInCacheName: false # areaName是否作为缓存key前缀,默认True
|
||||||
|
local:
|
||||||
|
default: # 默认default,可以配置更多的area
|
||||||
|
type: linkedhashmap # 已支持可选:linkedhashmap、caffeine
|
||||||
|
keyConvertor: fastjson # key转换器
|
||||||
|
remote:
|
||||||
|
default:
|
||||||
|
type: redis
|
||||||
|
keyConvertor: fastjson
|
||||||
|
valueEncoder: java # 序列化器,只有remote需要
|
||||||
|
valueDecoder: java # 序列化器,只有remote需要
|
||||||
|
poolConfig:
|
||||||
|
minIdle: 5
|
||||||
|
maxIdle: 20
|
||||||
|
maxTotal: 50
|
||||||
|
host: 127.0.0.1
|
||||||
|
port: 6379
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user