mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-03-11 17:20:09 +08:00
Compare commits
124 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d7195c61d | ||
|
|
aaede419bc | ||
|
|
75d8d374bc | ||
|
|
07b29e06cf | ||
|
|
3cbbd0698d | ||
|
|
5312131635 | ||
|
|
91f505539e | ||
|
|
c9774e78c4 | ||
|
|
337c2f7170 | ||
|
|
f773818642 | ||
|
|
9bf8ae5583 | ||
|
|
d190b89681 | ||
|
|
d89e09b94e | ||
|
|
1452ae9685 | ||
|
|
28772b8b30 | ||
|
|
ab201f9d9e | ||
|
|
1f5f969d20 | ||
|
|
a89a124a0e | ||
|
|
536b6db527 | ||
|
|
f8e3cff83d | ||
|
|
6b3ed18c33 | ||
|
|
e669fa3210 | ||
|
|
2d116146ce | ||
|
|
ed9de38c6f | ||
|
|
28d4c88387 | ||
|
|
c656f3340d | ||
|
|
cd0ee3f016 | ||
|
|
48ea66cb1a | ||
|
|
34c3b81190 | ||
|
|
1bb597b855 | ||
|
|
348d7fc534 | ||
|
|
76218091ad | ||
|
|
95c9e37797 | ||
|
|
aa277b373b | ||
|
|
79d9f47053 | ||
|
|
f984f08a14 | ||
|
|
6f94095bb0 | ||
|
|
2d4685ac5f | ||
|
|
7f9e4e14f0 | ||
|
|
c5777c01c1 | ||
|
|
459e9caf14 | ||
|
|
0940ba6762 | ||
|
|
d8ed23f227 | ||
|
|
948eba6566 | ||
|
|
1a14bdf256 | ||
|
|
bbc684b335 | ||
|
|
2b8f4e1d2c | ||
|
|
d634c2a292 | ||
|
|
8b97e7bc53 | ||
|
|
874ad7c9b7 | ||
|
|
89d6f6f247 | ||
|
|
1324a1cb16 | ||
|
|
961bca462e | ||
|
|
496df8494e | ||
|
|
2f1f9689e0 | ||
|
|
8110413fdf | ||
|
|
c1f64d3450 | ||
|
|
cb00f4c9c1 | ||
|
|
79512c69b2 | ||
|
|
a5fb128f11 | ||
|
|
8a04e3c88f | ||
|
|
dac447b76f | ||
|
|
35a9e4c8e8 | ||
|
|
0d87c12d3c | ||
|
|
f20a0c4342 | ||
|
|
6c8d637bd2 | ||
|
|
20e9957db2 | ||
|
|
9baded9326 | ||
|
|
b5902debb6 | ||
|
|
bcd5bb0f86 | ||
|
|
1a461f7d3d | ||
|
|
e23d99d85b | ||
|
|
f07c20afab | ||
|
|
420553eaa6 | ||
|
|
1d8d93eaa3 | ||
|
|
5f0d09fd45 | ||
|
|
1c2b7d7017 | ||
|
|
5fb2890167 | ||
|
|
1165c8dc06 | ||
|
|
ee09377997 | ||
|
|
1921b22a57 | ||
|
|
8718989c52 | ||
|
|
36069cd0e4 | ||
|
|
39b19ac361 | ||
|
|
279488e7ed | ||
|
|
e28e15d943 | ||
|
|
b44b5551e3 | ||
|
|
0cb4b35f53 | ||
|
|
9571e71707 | ||
|
|
dfa7d88255 | ||
|
|
8d29091afa | ||
|
|
116fa0053d | ||
|
|
0c08455b32 | ||
|
|
581203ba15 | ||
|
|
50fa220471 | ||
|
|
287effdc6d | ||
|
|
1d4fcf737a | ||
|
|
e672a3bc6c | ||
|
|
ec703ceeb8 | ||
|
|
6aa4e83413 | ||
|
|
65d677ac90 | ||
|
|
aca2b6d498 | ||
|
|
dd5f72cc99 | ||
|
|
b1d3d87360 | ||
|
|
e67fc5ebd4 | ||
|
|
6a2c74537e | ||
|
|
041e226059 | ||
|
|
0418b6c6ff | ||
|
|
c9272acce2 | ||
|
|
8d51adee10 | ||
|
|
6d4cc28dcd | ||
|
|
fc35a1469f | ||
|
|
f70a37c050 | ||
|
|
181f461984 | ||
|
|
75618347fa | ||
|
|
5a57e6b835 | ||
|
|
d1d47d2599 | ||
|
|
f35938a068 | ||
|
|
888c14615d | ||
|
|
fa6c9696f0 | ||
|
|
37038449ab | ||
|
|
9bff358afd | ||
|
|
d2a45156a2 | ||
|
|
9df0a8de1c |
@@ -2,7 +2,7 @@
|
||||
<configuration default="false" name="ruoyi-monitor-admin" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
|
||||
<deployment type="dockerfile">
|
||||
<settings>
|
||||
<option name="imageTag" value="ruoyi/ruoyi-monitor-admin:5.5.1" />
|
||||
<option name="imageTag" value="ruoyi/ruoyi-monitor-admin:5.5.3" />
|
||||
<option name="buildOnly" value="true" />
|
||||
<option name="sourceFilePath" value="ruoyi-extend/ruoyi-monitor-admin/Dockerfile" />
|
||||
</settings>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<configuration default="false" name="ruoyi-server" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
|
||||
<deployment type="dockerfile">
|
||||
<settings>
|
||||
<option name="imageTag" value="ruoyi/ruoyi-server:5.5.1" />
|
||||
<option name="imageTag" value="ruoyi/ruoyi-server:5.5.3" />
|
||||
<option name="buildOnly" value="true" />
|
||||
<option name="sourceFilePath" value="ruoyi-admin/Dockerfile" />
|
||||
</settings>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<configuration default="false" name="ruoyi-snailjob-server" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
|
||||
<deployment type="dockerfile">
|
||||
<settings>
|
||||
<option name="imageTag" value="ruoyi/ruoyi-snailjob-server:5.5.1" />
|
||||
<option name="imageTag" value="ruoyi/ruoyi-snailjob-server:5.5.3" />
|
||||
<option name="buildOnly" value="true" />
|
||||
<option name="sourceFilePath" value="ruoyi-extend/ruoyi-snailjob-server/Dockerfile" />
|
||||
</settings>
|
||||
|
||||
13
README.md
13
README.md
@@ -5,13 +5,12 @@
|
||||
## 平台简介
|
||||
|
||||
[](https://gitee.com/dromara/RuoYi-Vue-Plus)
|
||||
[](https://github.com/dromara/RuoYi-Vue-Plus)
|
||||
[](https://github.com/dromara/RuoYi-Vue-Plus)
|
||||
[](https://gitcode.com/dromara/RuoYi-Vue-Plus)
|
||||
[](https://gitee.com/dromara/RuoYi-Vue-Plus/blob/5.X/LICENSE)
|
||||
[](https://www.jetbrains.com/?from=RuoYi-Vue-Plus)
|
||||
<br>
|
||||
[](https://gitee.com/dromara/RuoYi-Vue-Plus)
|
||||
[]()
|
||||
[](https://gitee.com/dromara/RuoYi-Vue-Plus)
|
||||
[]()
|
||||
[]()
|
||||
[]()
|
||||
|
||||
@@ -33,12 +32,12 @@
|
||||
|
||||
MaxKey 业界领先单点登录产品 - https://gitee.com/dromara/MaxKey <br>
|
||||
CCFlow 驰聘低代码-流程-表单 - https://gitee.com/opencc/RuoYi-JFlow <br>
|
||||
数舵科技 软件定制开发APP小程序等 - http://www.shuduokeji.com/ <br>
|
||||
数舵科技 软件定制开发APP小程序等 - https://www.shuduokeji.com/ <br>
|
||||
引迈信息 软件开发平台 - https://www.jnpfsoft.com/index.html?from=plus-doc <br>
|
||||
<font color="red">**启山商城系统 多租户商城源码可免费商用可二次开发 - https://www.73app.cn/** </font><br>
|
||||
Mall4J 高质量Java商城系统 - https://www.mall4j.com/cn/?statId=11 <br>
|
||||
aizuda flowlong 工作流 - https://gitee.com/aizuda/flowlong <br>
|
||||
Ruoyi-Plus-Uniapp - https://ruoyi.plus <br>
|
||||
Topiam IAM/IDaaS身份管理平台 - https://www.topiam.cn/ <br>
|
||||
|
||||
[如何成为赞助商 加群联系作者详谈 每日PV2500-3000 IP1700-2500](https://plus-doc.dromara.org/#/common/add_group)
|
||||
|
||||
@@ -54,7 +53,7 @@ Ruoyi-Plus-Uniapp - https://ruoyi.plus <br>
|
||||
| 权限注解 | 采用 Sa-Token 支持注解 登录校验、角色校验、权限校验、二级认证校验、HttpBasic校验、忽略校验<br/>角色与权限校验支持多种条件 如 `AND` `OR` 或 `权限 OR 角色` 等复杂表达式 | 只支持是否存在匹配 |
|
||||
| 三方鉴权 | 采用 JustAuth 第三方登录组件 支持微信、钉钉等数十种三方认证 | 无 |
|
||||
| 关系数据库支持 | 原生支持 MySQL、Oracle、PostgreSQL、SQLServer<br/>可同时使用异构切换(支持其他 mybatis-plus 支持的所有数据库 只需要增加jdbc依赖即可使用 达梦金仓等均有成功案例) | 支持 Mysql、Oracle 不支持同时使用、不支持异构切换 |
|
||||
| 缓存数据库 | 支持 Redis 5-7 支持大部分新功能特性 如 分布式限流、分布式队列 | Redis 简单 get set 支持 |
|
||||
| 缓存数据库 | 支持 Redis >= 6 支持大部分新功能特性 如 分布式限流、分布式队列 | Redis 简单 get set 支持 |
|
||||
| Redis客户端 | 采用 Redisson Redis官方推荐 基于Netty的客户端工具<br/>支持Redis 90%以上的命令 底层优化规避很多不正确的用法 例如: keys被转换为scan<br/>支持单机、哨兵、单主集群、多主集群等模式 | Lettuce + RedisTemplate 支持模式少 工具使用繁琐<br/>连接池采用 common-pool Bug多经常性出问题 |
|
||||
| 缓存注解 | 采用 Spring-Cache 注解 对其扩展了实现支持了更多功能<br/>例如 过期时间 最大空闲时间 组最大长度等 只需一个注解即可完成数据自动缓存 | 需手动编写Redis代码逻辑 |
|
||||
| ORM框架 | 采用 Mybatis-Plus 基于对象几乎不用写SQL全java操作 功能强大插件众多<br/>例如多租户插件 分页插件 乐观锁插件等等 | 采用 Mybatis 基于XML需要手写SQL |
|
||||
|
||||
33
pom.xml
33
pom.xml
@@ -13,32 +13,32 @@
|
||||
<description>Dromara RuoYi-Vue-Plus多租户管理系统</description>
|
||||
|
||||
<properties>
|
||||
<revision>5.5.1</revision>
|
||||
<spring-boot.version>3.5.7</spring-boot.version>
|
||||
<revision>5.5.3</revision>
|
||||
<spring-boot.version>3.5.11</spring-boot.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>17</java.version>
|
||||
<mybatis.version>3.5.16</mybatis.version>
|
||||
<springdoc.version>2.8.13</springdoc.version>
|
||||
<mybatis.version>3.5.19</mybatis.version>
|
||||
<springdoc.version>2.8.15</springdoc.version>
|
||||
<therapi-javadoc.version>0.15.0</therapi-javadoc.version>
|
||||
<fastexcel.version>1.3.0</fastexcel.version>
|
||||
<velocity.version>2.3</velocity.version>
|
||||
<satoken.version>1.44.0</satoken.version>
|
||||
<mybatis-plus.version>3.5.14</mybatis-plus.version>
|
||||
<mybatis-plus.version>3.5.16</mybatis-plus.version>
|
||||
<p6spy.version>3.9.1</p6spy.version>
|
||||
<hutool.version>5.8.40</hutool.version>
|
||||
<spring-boot-admin.version>3.5.5</spring-boot-admin.version>
|
||||
<redisson.version>3.51.0</redisson.version>
|
||||
<hutool.version>5.8.43</hutool.version>
|
||||
<spring-boot-admin.version>3.5.6</spring-boot-admin.version>
|
||||
<redisson.version>3.52.0</redisson.version>
|
||||
<lock4j.version>2.2.7</lock4j.version>
|
||||
<dynamic-ds.version>4.3.1</dynamic-ds.version>
|
||||
<snailjob.version>1.8.0</snailjob.version>
|
||||
<snailjob.version>1.9.0</snailjob.version>
|
||||
<mapstruct-plus.version>1.5.0</mapstruct-plus.version>
|
||||
<mapstruct-plus.lombok.version>0.2.0</mapstruct-plus.lombok.version>
|
||||
<lombok.version>1.18.40</lombok.version>
|
||||
<lombok.version>1.18.42</lombok.version>
|
||||
<bouncycastle.version>1.80</bouncycastle.version>
|
||||
<justauth.version>1.16.7</justauth.version>
|
||||
<!-- 离线IP地址定位库 -->
|
||||
<ip2region.version>2.7.0</ip2region.version>
|
||||
<ip2region.version>3.3.4</ip2region.version>
|
||||
<!-- OSS 配置 -->
|
||||
<aws.sdk.version>2.28.22</aws.sdk.version>
|
||||
<!-- SMS 配置 -->
|
||||
@@ -46,9 +46,9 @@
|
||||
<!-- 限制框架中的fastjson版本 -->
|
||||
<fastjson.version>1.2.83</fastjson.version>
|
||||
<!-- 面向运行时的D-ORM依赖 -->
|
||||
<anyline.version>8.7.2-20250603</anyline.version>
|
||||
<anyline.version>8.7.3-20251210</anyline.version>
|
||||
<!-- 工作流配置 -->
|
||||
<warm-flow.version>1.8.2</warm-flow.version>
|
||||
<warm-flow.version>1.8.4</warm-flow.version>
|
||||
|
||||
<!-- 插件版本 -->
|
||||
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
|
||||
@@ -226,13 +226,13 @@
|
||||
<artifactId>s3</artifactId>
|
||||
<version>${aws.sdk.version}</version>
|
||||
</dependency>
|
||||
<!-- 基于 AWS CRT 的 S3 客户端的性能增强的 S3 传输管理器 -->
|
||||
<!-- 客户端的性能增强传输管理器 -->
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>s3-transfer-manager</artifactId>
|
||||
<version>${aws.sdk.version}</version>
|
||||
</dependency>
|
||||
<!-- 将基于 Netty 的 HTTP 客户端从类路径中移除 -->
|
||||
<!-- 适用于 Netty 的客户端 -->
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>netty-nio-client</artifactId>
|
||||
@@ -375,8 +375,7 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<release>${java.version}</release>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -106,7 +107,7 @@ public class AuthController {
|
||||
Long userId = LoginHelper.getUserId();
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
SseMessageDto dto = new SseMessageDto();
|
||||
dto.setMessage("欢迎登录RuoYi-Vue-Plus后台管理系统");
|
||||
dto.setMessage(DateUtils.getTodayHour(new Date()) + "好,欢迎登录 RuoYi-Vue-Plus 后台管理系统");
|
||||
dto.setUserIds(List.of(userId));
|
||||
SseMessageUtils.publishMessage(dto);
|
||||
}, 5, TimeUnit.SECONDS);
|
||||
@@ -147,8 +148,8 @@ public class AuthController {
|
||||
StpUtil.checkLogin();
|
||||
// 获取第三方登录信息
|
||||
AuthResponse<AuthUser> response = SocialUtils.loginAuth(
|
||||
loginBody.getSource(), loginBody.getSocialCode(),
|
||||
loginBody.getSocialState(), socialProperties);
|
||||
loginBody.getSource(), loginBody.getSocialCode(),
|
||||
loginBody.getSocialState(), socialProperties);
|
||||
AuthUser authUserData = response.getData();
|
||||
// 判断授权响应是否成功
|
||||
if (!response.ok()) {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package org.dromara.web.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.hutool.captcha.AbstractCaptcha;
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.captcha.generator.MathGenerator;
|
||||
import cn.hutool.captcha.generator.RandomGenerator;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
@@ -14,14 +15,13 @@ import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.utils.reflect.ReflectUtils;
|
||||
import org.dromara.common.mail.config.properties.MailProperties;
|
||||
import org.dromara.common.mail.utils.MailUtils;
|
||||
import org.dromara.common.ratelimiter.annotation.RateLimiter;
|
||||
import org.dromara.common.ratelimiter.enums.LimitType;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.web.core.WaveAndCircleCaptcha;
|
||||
import org.dromara.common.web.config.properties.CaptchaProperties;
|
||||
import org.dromara.common.web.enums.CaptchaType;
|
||||
import org.dromara.sms4j.api.SmsBlend;
|
||||
import org.dromara.sms4j.api.entity.SmsResponse;
|
||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||
@@ -33,6 +33,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.awt.*;
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
@@ -130,19 +131,21 @@ public class CaptchaController {
|
||||
String uuid = IdUtil.simpleUUID();
|
||||
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + uuid;
|
||||
// 生成验证码
|
||||
CaptchaType captchaType = captchaProperties.getType();
|
||||
String captchaType = captchaProperties.getType();
|
||||
CodeGenerator codeGenerator;
|
||||
if (CaptchaType.MATH == captchaType) {
|
||||
codeGenerator = ReflectUtils.newInstance(captchaType.getClazz(), captchaProperties.getNumberLength(), false);
|
||||
if ("math".equals(captchaType)) {
|
||||
codeGenerator = new MathGenerator(captchaProperties.getNumberLength(), false);
|
||||
} else {
|
||||
codeGenerator = ReflectUtils.newInstance(captchaType.getClazz(), captchaProperties.getCharLength());
|
||||
codeGenerator = new RandomGenerator(captchaProperties.getCharLength());
|
||||
}
|
||||
AbstractCaptcha captcha = SpringUtils.getBean(captchaProperties.getCategory().getClazz());
|
||||
WaveAndCircleCaptcha captcha = new WaveAndCircleCaptcha(160, 60);
|
||||
// captcha.setBackground(Color.WHITE); // 不设置就是透明底
|
||||
captcha.setFont(new Font("Arial", Font.BOLD, 45));
|
||||
captcha.setGenerator(codeGenerator);
|
||||
captcha.createCode();
|
||||
// 如果是数学验证码,使用SpEL表达式处理验证码结果
|
||||
String code = captcha.getCode();
|
||||
if (CaptchaType.MATH == captchaType) {
|
||||
if ("math".equals(captchaType)) {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
Expression exp = parser.parseExpression(StringUtils.remove(code, "="));
|
||||
code = exp.getValue(String.class);
|
||||
|
||||
@@ -8,7 +8,7 @@ server:
|
||||
# undertow 配置
|
||||
undertow:
|
||||
# HTTP post内容的最大大小。当值为-1时,默认值为大小是无限的
|
||||
max-http-post-size: -1
|
||||
max-http-post-size: 1GB
|
||||
# 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
|
||||
# 每块buffer的空间大小,越小的空间被利用越充分
|
||||
buffer-size: 512
|
||||
@@ -24,9 +24,7 @@ captcha:
|
||||
# 是否启用验证码校验
|
||||
enable: true
|
||||
# 验证码类型 math 数组计算 char 字符验证
|
||||
type: MATH
|
||||
# line 线段干扰 circle 圆圈干扰 shear 扭曲干扰
|
||||
category: CIRCLE
|
||||
type: math
|
||||
# 数字验证码位数
|
||||
numberLength: 1
|
||||
# 字符验证码长度
|
||||
|
||||
@@ -5,7 +5,7 @@ user.jcaptcha.expire=验证码已失效
|
||||
user.not.exists=对不起, 您的账号:{0} 不存在.
|
||||
user.password.not.match=用户不存在/密码错误
|
||||
user.password.retry.limit.count=密码输入错误{0}次
|
||||
user.password.retry.limit.exceed=密码输入错误{0}次,帐户锁定{1}分钟
|
||||
user.password.retry.limit.exceed=密码输入错误{0}次,账户锁定{1}分钟
|
||||
user.password.delete=对不起,您的账号:{0} 已被删除
|
||||
user.blocked=对不起,您的账号:{0} 已禁用,请联系管理员
|
||||
role.blocked=角色已封禁,请联系管理员
|
||||
@@ -47,10 +47,10 @@ repeat.submit.message=不允许重复提交,请稍候再试
|
||||
rate.limiter.message=访问过于频繁,请稍候再试
|
||||
sms.code.not.blank=短信验证码不能为空
|
||||
sms.code.retry.limit.count=短信验证码输入错误{0}次
|
||||
sms.code.retry.limit.exceed=短信验证码输入错误{0}次,帐户锁定{1}分钟
|
||||
sms.code.retry.limit.exceed=短信验证码输入错误{0}次,账户锁定{1}分钟
|
||||
email.code.not.blank=邮箱验证码不能为空
|
||||
email.code.retry.limit.count=邮箱验证码输入错误{0}次
|
||||
email.code.retry.limit.exceed=邮箱验证码输入错误{0}次,帐户锁定{1}分钟
|
||||
email.code.retry.limit.exceed=邮箱验证码输入错误{0}次,账户锁定{1}分钟
|
||||
xcx.code.not.blank=小程序[code]不能为空
|
||||
social.source.not.blank=第三方登录平台[source]不能为空
|
||||
social.code.not.blank=第三方登录平台[code]不能为空
|
||||
|
||||
@@ -5,7 +5,7 @@ user.jcaptcha.expire=验证码已失效
|
||||
user.not.exists=对不起, 您的账号:{0} 不存在.
|
||||
user.password.not.match=用户不存在/密码错误
|
||||
user.password.retry.limit.count=密码输入错误{0}次
|
||||
user.password.retry.limit.exceed=密码输入错误{0}次,帐户锁定{1}分钟
|
||||
user.password.retry.limit.exceed=密码输入错误{0}次,账户锁定{1}分钟
|
||||
user.password.delete=对不起,您的账号:{0} 已被删除
|
||||
user.blocked=对不起,您的账号:{0} 已禁用,请联系管理员
|
||||
role.blocked=角色已封禁,请联系管理员
|
||||
@@ -47,10 +47,10 @@ repeat.submit.message=不允许重复提交,请稍候再试
|
||||
rate.limiter.message=访问过于频繁,请稍候再试
|
||||
sms.code.not.blank=短信验证码不能为空
|
||||
sms.code.retry.limit.count=短信验证码输入错误{0}次
|
||||
sms.code.retry.limit.exceed=短信验证码输入错误{0}次,帐户锁定{1}分钟
|
||||
sms.code.retry.limit.exceed=短信验证码输入错误{0}次,账户锁定{1}分钟
|
||||
email.code.not.blank=邮箱验证码不能为空
|
||||
email.code.retry.limit.count=邮箱验证码输入错误{0}次
|
||||
email.code.retry.limit.exceed=邮箱验证码输入错误{0}次,帐户锁定{1}分钟
|
||||
email.code.retry.limit.exceed=邮箱验证码输入错误{0}次,账户锁定{1}分钟
|
||||
xcx.code.not.blank=小程序[code]不能为空
|
||||
social.source.not.blank=第三方登录平台[source]不能为空
|
||||
social.code.not.blank=第三方登录平台[code]不能为空
|
||||
|
||||
Binary file not shown.
@@ -14,7 +14,7 @@
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<revision>5.5.1</revision>
|
||||
<revision>5.5.3</revision>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -3,10 +3,8 @@ package org.dromara.common.core.config;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||
import org.dromara.common.core.config.properties.ThreadPoolProperties;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||
|
||||
@@ -19,7 +17,6 @@ import java.util.concurrent.*;
|
||||
**/
|
||||
@Slf4j
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(ThreadPoolProperties.class)
|
||||
public class ThreadPoolConfig {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package org.dromara.common.core.config.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* 线程池 配置属性
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "thread-pool")
|
||||
public class ThreadPoolProperties {
|
||||
|
||||
/**
|
||||
* 是否开启线程池
|
||||
*/
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* 队列最大长度
|
||||
*/
|
||||
private int queueCapacity;
|
||||
|
||||
/**
|
||||
* 线程池维护线程所允许的空闲时间
|
||||
*/
|
||||
private int keepAliveSeconds;
|
||||
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public interface CacheNames {
|
||||
String SYS_USER_NAME = "sys_user_name#30d";
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
* 用户昵称
|
||||
*/
|
||||
String SYS_NICKNAME = "sys_nickname#30d";
|
||||
|
||||
|
||||
@@ -82,4 +82,10 @@ public interface SystemConstants {
|
||||
*/
|
||||
Long DEFAULT_DEPT_ID = 100L;
|
||||
|
||||
/**
|
||||
* 排除敏感属性字段
|
||||
*/
|
||||
String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -67,7 +67,8 @@ public class CompleteTaskDTO implements Serializable {
|
||||
|
||||
public Map<String, Object> getVariables() {
|
||||
if (variables == null) {
|
||||
return new HashMap<>(16);
|
||||
variables = new HashMap<>(16);
|
||||
return variables;
|
||||
}
|
||||
variables.entrySet().removeIf(entry -> Objects.isNull(entry.getValue()));
|
||||
return variables;
|
||||
|
||||
@@ -23,8 +23,8 @@ public class FlowCopyDTO implements Serializable {
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
* 用户昵称
|
||||
*/
|
||||
private String userName;
|
||||
private String nickName;
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,8 @@ public class StartProcessDTO implements Serializable {
|
||||
|
||||
public Map<String, Object> getVariables() {
|
||||
if (variables == null) {
|
||||
return new HashMap<>(16);
|
||||
variables = new HashMap<>(16);
|
||||
return variables;
|
||||
}
|
||||
variables.entrySet().removeIf(entry -> Objects.isNull(entry.getValue()));
|
||||
return variables;
|
||||
|
||||
@@ -61,7 +61,7 @@ public class UserDTO implements Serializable {
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
* 账号状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class UserOnlineDTO implements Serializable {
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
* 用户账号
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package org.dromara.common.core.service;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通用 参数配置服务
|
||||
*
|
||||
@@ -15,4 +21,80 @@ public interface ConfigService {
|
||||
*/
|
||||
String getConfigValue(String configKey);
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取布尔值
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @return Boolean 值
|
||||
*/
|
||||
default Boolean getConfigBool(String configKey) {
|
||||
return Convert.toBool(getConfigValue(configKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取整数值
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @return Integer 值
|
||||
*/
|
||||
default Integer getConfigInt(String configKey) {
|
||||
return Convert.toInt(getConfigValue(configKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取长整型值
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @return Long 值
|
||||
*/
|
||||
default Long getConfigLong(String configKey) {
|
||||
return Convert.toLong(getConfigValue(configKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取 BigDecimal 值
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @return BigDecimal 值
|
||||
*/
|
||||
default BigDecimal getConfigDecimal(String configKey) {
|
||||
return Convert.toBigDecimal(getConfigValue(configKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取 Map 类型的配置
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @return Dict 对象,如果配置为空或无法解析,返回空 Dict
|
||||
*/
|
||||
Dict getConfigMap(String configKey);
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取 Map 类型的配置列表
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @return Dict 列表,如果配置为空或无法解析,返回空列表
|
||||
*/
|
||||
List<Dict> getConfigArrayMap(String configKey);
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取指定类型的配置对象
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @param clazz 目标对象类型
|
||||
* @param <T> 目标对象泛型
|
||||
* @return 对象实例,如果配置为空或无法解析,返回 null
|
||||
*/
|
||||
<T> T getConfigObject(String configKey, Class<T> clazz);
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取指定类型的配置列表
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @param clazz 目标元素类型
|
||||
* @param <T> 元素类型泛型
|
||||
* @return 指定类型列表,如果配置为空或无法解析,返回空列表
|
||||
*/
|
||||
<T> List<T> getConfigArray(String configKey, Class<T> clazz);
|
||||
|
||||
}
|
||||
|
||||
@@ -21,18 +21,18 @@ public interface UserService {
|
||||
String selectUserNameById(Long userId);
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户账户
|
||||
* 通过用户ID查询用户昵称
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户名称
|
||||
* @return 用户昵称
|
||||
*/
|
||||
String selectNicknameById(Long userId);
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户账户
|
||||
* 通过用户ID查询用户昵称
|
||||
*
|
||||
* @param userIds 用户ID 多个用逗号隔开
|
||||
* @return 用户名称
|
||||
* @return 用户昵称
|
||||
*/
|
||||
String selectNicknameByIds(String userIds);
|
||||
|
||||
@@ -93,11 +93,11 @@ public interface UserService {
|
||||
List<UserDTO> selectUsersByPostIds(List<Long> postIds);
|
||||
|
||||
/**
|
||||
* 根据用户 ID 列表查询用户名称映射关系
|
||||
* 根据用户 ID 列表查询用户昵称映射关系
|
||||
*
|
||||
* @param userIds 用户 ID 列表
|
||||
* @return Map,其中 key 为用户 ID,value 为对应的用户名称
|
||||
* @return Map,其中 key 为用户 ID,value 为对应的用户昵称
|
||||
*/
|
||||
Map<Long, String> selectUserNamesByIds(List<Long> userIds);
|
||||
Map<Long, String> selectUserNicksByIds(List<Long> userIds);
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public interface WorkflowService {
|
||||
* @param businessIds 业务id
|
||||
* @return 结果
|
||||
*/
|
||||
boolean deleteInstance(List<Long> businessIds);
|
||||
boolean deleteInstance(List<String> businessIds);
|
||||
|
||||
/**
|
||||
* 获取当前流程状态
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.dromara.common.core.utils;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import org.dromara.common.core.enums.FormatsType;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
@@ -297,4 +299,80 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据指定日期时间获取时间段(凌晨 / 上午 / 中午 / 下午 / 晚上)
|
||||
*
|
||||
* @param date 日期时间
|
||||
* @return 时间段描述
|
||||
*/
|
||||
public static String getTodayHour(Date date) {
|
||||
int hour = DateUtil.hour(date, true);
|
||||
if (hour <= 6) {
|
||||
return "凌晨";
|
||||
} else if (hour < 12) {
|
||||
return "上午";
|
||||
} else if (hour == 12) {
|
||||
return "中午";
|
||||
} else if (hour <= 18) {
|
||||
return "下午";
|
||||
} else {
|
||||
return "晚上";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将日期格式化为仿微信的友好时间
|
||||
* <p>
|
||||
* 规则说明:
|
||||
* 1. 未来时间:yyyy-MM-dd HH:mm
|
||||
* 2. 今天:
|
||||
* - 1 分钟内:刚刚
|
||||
* - 1 小时内:X 分钟前
|
||||
* - 超过 1 小时:凌晨/上午/中午/下午/晚上 HH:mm
|
||||
* 3. 昨天:昨天 HH:mm
|
||||
* 4. 本周:周X HH:mm
|
||||
* 5. 今年内:MM-dd HH:mm
|
||||
* 6. 非今年:yyyy-MM-dd HH:mm
|
||||
*
|
||||
* @param date 日期时间
|
||||
* @return 格式化后的时间描述
|
||||
*/
|
||||
public static String formatFriendlyTime(Date date) {
|
||||
if (date == null) {
|
||||
return "";
|
||||
}
|
||||
Date now = DateUtil.date();
|
||||
|
||||
// 未来时间或非今年
|
||||
if (date.after(now) || DateUtil.year(date) != DateUtil.year(now)) {
|
||||
return parseDateToStr(FormatsType.YYYY_MM_DD_HH_MM, date);
|
||||
}
|
||||
|
||||
// 今天
|
||||
if (DateUtil.isSameDay(date, now)) {
|
||||
long minutes = DateUtil.between(date, now, DateUnit.MINUTE);
|
||||
if (minutes < 1) {
|
||||
return "刚刚";
|
||||
}
|
||||
if (minutes < 60) {
|
||||
return minutes + "分钟前";
|
||||
}
|
||||
return getTodayHour(date) + " " + DateUtil.format(date, "HH:mm");
|
||||
}
|
||||
|
||||
// 昨天
|
||||
if (DateUtil.isSameDay(date, DateUtil.yesterday())) {
|
||||
return "昨天 " + DateUtil.format(date, "HH:mm");
|
||||
}
|
||||
|
||||
// 本周
|
||||
if (DateUtil.isSameWeek(date, now, true)) {
|
||||
return DateUtil.dayOfWeekEnum(date).toChinese("周")
|
||||
+ " " + DateUtil.format(date, "HH:mm");
|
||||
}
|
||||
|
||||
// 今年内其它时间
|
||||
return DateUtil.format(date, "MM-dd HH:mm");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.dromara.common.core.utils;
|
||||
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 脱敏工具类
|
||||
*
|
||||
* @author AprilWind
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class DesensitizedUtils extends DesensitizedUtil {
|
||||
|
||||
/**
|
||||
* 灵活脱敏方法
|
||||
*
|
||||
* @param value 原始字符串
|
||||
* @param prefixVisible 前面可见长度
|
||||
* @param suffixVisible 后面可见长度
|
||||
* @param maskLength 中间掩码长度(固定显示多少 *,如果总长度不足则自动缩减)
|
||||
* @return 脱敏后字符串
|
||||
*/
|
||||
public static String mask(String value, int prefixVisible, int suffixVisible, int maskLength) {
|
||||
if (StrUtil.isBlank(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
int len = value.length();
|
||||
int prefixMaskLimit = prefixVisible + maskLength;
|
||||
int fullLimit = prefixMaskLimit + suffixVisible;
|
||||
|
||||
// 规则 1:长度 <= 中间掩码长度 → 全掩码
|
||||
if (len <= maskLength) {
|
||||
return StrUtil.repeat('*', len);
|
||||
}
|
||||
String mask = StrUtil.repeat('*', maskLength);
|
||||
|
||||
// 规则 2:长度 <= 前缀 + 中间掩码
|
||||
if (len <= prefixMaskLimit) {
|
||||
return value.substring(0, len - maskLength) + mask;
|
||||
}
|
||||
|
||||
String prefix = value.substring(0, prefixVisible);
|
||||
|
||||
// 规则 3:长度 <= 前缀 + 中间掩码 + 后缀
|
||||
if (len <= fullLimit) {
|
||||
int suffixLen = len - prefixMaskLimit;
|
||||
return prefix + mask + value.substring(len - suffixLen);
|
||||
}
|
||||
|
||||
// 规则 4:标准形态
|
||||
return prefix + mask + value.substring(len - suffixVisible);
|
||||
}
|
||||
|
||||
/**
|
||||
* 高安全级别脱敏方法(Token / 私钥)
|
||||
*
|
||||
* @param value 原始字符串
|
||||
* @param prefixVisible 前面可见长度(推荐0~4)
|
||||
* @param suffixVisible 后面可见长度(推荐0~4)
|
||||
* @return 脱敏后字符串
|
||||
*/
|
||||
public static String maskHighSecurity(String value, int prefixVisible, int suffixVisible) {
|
||||
if (StrUtil.isBlank(value)) {
|
||||
return value;
|
||||
}
|
||||
int len = value.length();
|
||||
|
||||
// 规则1:长度 <= 前缀可见长度 → 全部掩码
|
||||
if (len <= prefixVisible) {
|
||||
return StrUtil.repeat('*', len);
|
||||
}
|
||||
|
||||
// 规则2:长度 <= 前缀 + 后缀可见长度 → 优先掩码后面
|
||||
if (len <= prefixVisible + suffixVisible) {
|
||||
return value.substring(0, len - prefixVisible) + StrUtil.repeat('*', prefixVisible);
|
||||
}
|
||||
|
||||
// 规则3:标准形态 → 前后可见,中间全部掩码
|
||||
return value.substring(0, prefixVisible)
|
||||
+ StrUtil.repeat('*', len - prefixVisible - suffixVisible)
|
||||
+ value.substring(len - suffixVisible);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,51 +20,24 @@ public class AddressUtils {
|
||||
public static final String UNKNOWN_IP = "XX XX";
|
||||
// 内网地址
|
||||
public static final String LOCAL_ADDRESS = "内网IP";
|
||||
// 未知地址
|
||||
public static final String UNKNOWN_ADDRESS = "未知";
|
||||
|
||||
public static String getRealAddressByIP(String ip) {
|
||||
// 处理空串并过滤HTML标签
|
||||
ip = HtmlUtil.cleanHtmlTag(StringUtils.blankToDefault(ip,""));
|
||||
// 判断是否为IPv4
|
||||
if (NetUtils.isIPv4(ip)) {
|
||||
return resolverIPv4Region(ip);
|
||||
}
|
||||
boolean isIPv4 = NetUtils.isIPv4(ip);
|
||||
// 判断是否为IPv6
|
||||
if (NetUtils.isIPv6(ip)) {
|
||||
return resolverIPv6Region(ip);
|
||||
}
|
||||
boolean isIPv6 = NetUtils.isIPv6(ip);
|
||||
// 如果不是IPv4或IPv6,则返回未知IP
|
||||
return UNKNOWN_IP;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据IPv4地址查询IP归属行政区域
|
||||
* @param ip ipv4地址
|
||||
* @return 归属行政区域
|
||||
*/
|
||||
private static String resolverIPv4Region(String ip){
|
||||
if (!isIPv4 && !isIPv6) {
|
||||
return UNKNOWN_IP;
|
||||
}
|
||||
// 内网不查询
|
||||
if (NetUtils.isInnerIP(ip)) {
|
||||
if ((isIPv4 && NetUtils.isInnerIP(ip)) || (isIPv6 && NetUtils.isInnerIPv6(ip))) {
|
||||
return LOCAL_ADDRESS;
|
||||
}
|
||||
return RegionUtils.getCityInfo(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据IPv6地址查询IP归属行政区域
|
||||
* @param ip ipv6地址
|
||||
* @return 归属行政区域
|
||||
*/
|
||||
private static String resolverIPv6Region(String ip){
|
||||
// 内网不查询
|
||||
if (NetUtils.isInnerIPv6(ip)) {
|
||||
return LOCAL_ADDRESS;
|
||||
}
|
||||
log.warn("ip2region不支持IPV6地址解析:{}", ip);
|
||||
// 不支持IPv6,不再进行没有必要的IP地址信息的解析,直接返回
|
||||
// 如有需要,可自行实现IPv6地址信息解析逻辑,并在这里返回
|
||||
return UNKNOWN_ADDRESS;
|
||||
// Tips:Ip2Region 提供了精简的IPv6地址库,精简的IPv6地址库并不能完全支持IPv6地址的查询,且准确度上可能会存在问题,如需要准确的IPv6地址查询,建议自行实现
|
||||
return RegionUtils.getRegion(ip);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,50 +1,154 @@
|
||||
package org.dromara.common.core.utils.ip;
|
||||
|
||||
import cn.hutool.core.io.resource.NoResourceException;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.lionsoul.ip2region.xdb.Searcher;
|
||||
import org.lionsoul.ip2region.service.Config;
|
||||
import org.lionsoul.ip2region.service.Ip2Region;
|
||||
import org.lionsoul.ip2region.xdb.Util;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* 根据ip地址定位工具类,离线方式
|
||||
* 参考地址:<a href="https://gitee.com/lionsoul/ip2region/tree/master/binding/java">集成 ip2region 实现离线IP地址定位库</a>
|
||||
* IP地址行政区域工具类
|
||||
* 参考地址:<a href="https://gitee.com/lionsoul/ip2region/tree/master/binding/java">ip2region xdb java 查询客户端实现</a>
|
||||
* xdb数据库文件下载:<a href="https://gitee.com/lionsoul/ip2region/tree/master/data">ip2region data</a>
|
||||
*
|
||||
* @author lishuyan
|
||||
* @author 秋辞未寒
|
||||
*/
|
||||
@Slf4j
|
||||
public class RegionUtils {
|
||||
|
||||
// IP地址库文件名称
|
||||
public static final String IP_XDB_FILENAME = "ip2region.xdb";
|
||||
// 默认IPv4地址库文件路径
|
||||
// 下载地址:https://gitee.com/lionsoul/ip2region/blob/master/data/ip2region_v4.xdb
|
||||
public static final String DEFAULT_IPV4_XDB_PATH = "ip2region_v4.xdb";
|
||||
|
||||
private static final Searcher SEARCHER;
|
||||
// 默认IPv6地址库文件路径
|
||||
// 下载地址:https://gitee.com/lionsoul/ip2region/blob/master/data/ip2region_v6.xdb
|
||||
public static final String DEFAULT_IPV6_XDB_PATH = "ip2region_v6.xdb";
|
||||
|
||||
// 默认缓存切片大小为15MB(仅针对BufferCache全量读取有效,如果你的xdb数据库很大,合理设置该值可以有效提升BufferCache模式下的查询效率,具体可以查看Ip2Region的README)
|
||||
// 注意:设置过大的值可能会申请内存时,因内存不足而导致OOM,请合理设置该值。
|
||||
// README:https://gitee.com/lionsoul/ip2region/tree/master/binding/java
|
||||
public static final int DEFAULT_CACHE_SLICE_BYTES = 1024 * 1024 * 15;
|
||||
|
||||
// 未知地址
|
||||
public static final String UNKNOWN_ADDRESS = "未知";
|
||||
|
||||
// Ip2Region服务实例
|
||||
private static Ip2Region ip2Region;
|
||||
|
||||
// 初始化Ip2Region服务实例
|
||||
static {
|
||||
try {
|
||||
// 1、将 ip2region 数据库文件 xdb 从 ClassPath 加载到内存。
|
||||
// 2、基于加载到内存的 xdb 数据创建一个 Searcher 查询对象。
|
||||
SEARCHER = Searcher.newWithBuffer(ResourceUtil.readBytes(IP_XDB_FILENAME));
|
||||
log.info("RegionUtils初始化成功,加载IP地址库数据成功!");
|
||||
} catch (NoResourceException e) {
|
||||
throw new ServiceException("RegionUtils初始化失败,原因:IP地址库数据不存在!");
|
||||
// 注意:Ip2Region 的xdb文件加载策略 CachePolicy 有三种,分别是:BufferCache(全量读取xdb到内存中)、VIndexCache(默认策略,按需读取并缓存)、NoCache(实时读取)
|
||||
// 本项目工具使用的 CachePolicy 为 BufferCache,BufferCache会加载整个xdb文件到内存中,setXdbInputStream 仅支持 BufferCache 策略。
|
||||
// 因为加载整个xdb文件会耗费非常大的内存,如果你不希望加载整个xdb到内存中,更推荐使用 VIndexCache 或 NoCache(即实时读取文件)策略和 setXdbPath/setXdbFile 加载方法(需要注意的一点,setXdbPath 和 setXdbFile 不支持读取ClassPath(即源码和resource目录)中的文件)。
|
||||
// 一般而言,更建议把xdb数据库放到一个指定的文件目录中(即不打包进jar包中),然后使用 VIndexCache + 配合SearcherPool的并发池读取数据,更方便随时更新xdb数据库
|
||||
|
||||
InputStream v4InputStream = ResourceUtil.getStream(DEFAULT_IPV4_XDB_PATH);
|
||||
|
||||
// IPv4配置
|
||||
Config v4Config = Config.custom()
|
||||
.setCachePolicy(Config.BufferCache)
|
||||
//.setXdbFile(v4TempXdb)
|
||||
.setXdbInputStream(v4InputStream)
|
||||
//
|
||||
.setCacheSliceBytes(DEFAULT_CACHE_SLICE_BYTES)
|
||||
.asV4();
|
||||
|
||||
// IPv6配置
|
||||
Config v6Config = null;
|
||||
InputStream v6XdbInputStream = ResourceUtil.getStreamSafe(DEFAULT_IPV6_XDB_PATH);
|
||||
if (v6XdbInputStream == null) {
|
||||
log.warn("未加载 IPv6 地址库:未在类路径下找到文件 {}。当前仅启用 IPv4 查询。如需启用 IPv6,请将 ip2region_v6.xdb 放置到 resources 目录", DEFAULT_IPV6_XDB_PATH);
|
||||
} else {
|
||||
v6Config = Config.custom()
|
||||
.setCachePolicy(Config.BufferCache)
|
||||
//.setXdbFile(v6TempXdb)
|
||||
.setXdbInputStream(v6XdbInputStream)
|
||||
.setCacheSliceBytes(DEFAULT_CACHE_SLICE_BYTES)
|
||||
.asV6();
|
||||
}
|
||||
|
||||
// 初始化Ip2Region实例
|
||||
RegionUtils.ip2Region = Ip2Region.create(v4Config, v6Config);
|
||||
log.debug("IP工具初始化成功,加载IP地址库数据成功!");
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException("RegionUtils初始化失败,原因:" + e.getMessage());
|
||||
throw new ServiceException("RegionUtils初始化失败,原因:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据IP地址离线获取城市
|
||||
*
|
||||
* @param ipString ip地址字符串
|
||||
*/
|
||||
public static String getCityInfo(String ip) {
|
||||
public static String getRegion(String ipString) {
|
||||
try {
|
||||
// 3、执行查询
|
||||
String region = SEARCHER.search(StringUtils.trim(ip));
|
||||
return region.replace("0|", "").replace("|0", "");
|
||||
String region = ip2Region.search(ipString);
|
||||
if (StringUtils.isBlank(region)) {
|
||||
return UNKNOWN_ADDRESS;
|
||||
}
|
||||
return StringUtils.replace(region, "0", UNKNOWN_ADDRESS);
|
||||
} catch (Exception e) {
|
||||
log.error("IP地址离线获取城市异常 {}", ip);
|
||||
return "未知";
|
||||
log.error("IP地址离线获取城市异常 {}", ipString);
|
||||
return UNKNOWN_ADDRESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据IP地址离线获取城市
|
||||
*
|
||||
* @param ipBytes ip地址字节数组
|
||||
*/
|
||||
public static String getRegion(byte[] ipBytes) {
|
||||
try {
|
||||
String region = ip2Region.search(ipBytes);
|
||||
if (StringUtils.isBlank(region)) {
|
||||
return UNKNOWN_ADDRESS;
|
||||
}
|
||||
return StringUtils.replace(region, "0", UNKNOWN_ADDRESS);
|
||||
} catch (Exception e) {
|
||||
log.error("IP地址离线获取城市异常 {}", Util.ipToString(ipBytes));
|
||||
return UNKNOWN_ADDRESS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭Ip2Region服务
|
||||
*/
|
||||
public static void close() {
|
||||
if (ip2Region == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ip2Region.close(10000);
|
||||
} catch (Exception e) {
|
||||
log.error("Ip2Region服务关闭异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭Ip2Region服务
|
||||
*
|
||||
* @param timeout 关闭超时时间
|
||||
*/
|
||||
public static void close(final Duration timeout) {
|
||||
if (ip2Region == null) {
|
||||
return;
|
||||
}
|
||||
if (timeout == null) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ip2Region.close(timeout.toMillis());
|
||||
} catch (Exception e) {
|
||||
log.error("Ip2Region服务关闭异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.doc.config.properties.SpringDocProperties;
|
||||
import org.dromara.common.doc.core.resolver.JavadocResolver;
|
||||
import org.dromara.common.doc.core.resolver.SaTokenAnnotationMetadataJavadocResolver;
|
||||
import org.dromara.common.doc.handler.OpenApiHandler;
|
||||
import org.springdoc.core.configuration.SpringDocConfiguration;
|
||||
import org.springdoc.core.customizers.OpenApiBuilderCustomizer;
|
||||
@@ -84,8 +86,9 @@ public class SpringDocConfig {
|
||||
SecurityService securityParser,
|
||||
SpringDocConfigProperties springDocConfigProperties, PropertyResolverUtils propertyResolverUtils,
|
||||
Optional<List<OpenApiBuilderCustomizer>> openApiBuilderCustomisers,
|
||||
Optional<List<ServerBaseUrlCustomizer>> serverBaseUrlCustomisers, Optional<JavadocProvider> javadocProvider) {
|
||||
return new OpenApiHandler(openAPI, securityParser, springDocConfigProperties, propertyResolverUtils, openApiBuilderCustomisers, serverBaseUrlCustomisers, javadocProvider);
|
||||
Optional<List<ServerBaseUrlCustomizer>> serverBaseUrlCustomisers, Optional<JavadocProvider> javadocProvider,
|
||||
List<JavadocResolver> javadocResolvers) {
|
||||
return new OpenApiHandler(openAPI, securityParser, springDocConfigProperties, propertyResolverUtils, openApiBuilderCustomisers, serverBaseUrlCustomisers, javadocProvider, javadocResolvers);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,6 +115,14 @@ public class SpringDocConfig {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册SaToken JavaDoc权限注解解析器
|
||||
*/
|
||||
@Bean
|
||||
public JavadocResolver saTokenAnnotationJavadocResolver() {
|
||||
return new SaTokenAnnotationMetadataJavadocResolver();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单独使用一个类便于判断 解决springdoc路径拼接重复问题
|
||||
*
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
package org.dromara.common.doc.core.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 存储权限框架注解解析后的权限和角色信息
|
||||
*
|
||||
* @author AprilWind
|
||||
*/
|
||||
@Data
|
||||
@JsonInclude(Include.NON_EMPTY)
|
||||
public class SaTokenSecurityMetadata {
|
||||
|
||||
/**
|
||||
* 权限校验信息列表(对应 @SaCheckPermission 注解)
|
||||
*/
|
||||
private List<AuthInfo> permissions = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 角色校验信息列表(对应 @SaCheckRole 注解)
|
||||
*/
|
||||
private List<AuthInfo> roles = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 是否忽略校验(对应 @SaIgnore 注解)
|
||||
*/
|
||||
private boolean ignore = false;
|
||||
|
||||
/**
|
||||
* 添加权限信息
|
||||
*
|
||||
* @param values 权限值数组
|
||||
* @param mode 校验模式(AND/OR)
|
||||
* @param type 权限类型
|
||||
* @param orRoles 或角色数组
|
||||
*/
|
||||
public void addPermission(String[] values, String mode, String type, String[] orRoles) {
|
||||
if (values != null && values.length > 0) {
|
||||
AuthInfo authInfo = new AuthInfo();
|
||||
authInfo.setValues(values);
|
||||
authInfo.setMode(mode);
|
||||
authInfo.setType(type);
|
||||
if (orRoles != null && orRoles.length > 0) {
|
||||
authInfo.setOrValues(orRoles);
|
||||
authInfo.setOrType("role");
|
||||
}
|
||||
this.permissions.add(authInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加角色信息
|
||||
*
|
||||
* @param values 角色值数组
|
||||
* @param mode 校验模式(AND/OR)
|
||||
* @param type 角色类型
|
||||
*/
|
||||
public void addRole(String[] values, String mode, String type) {
|
||||
if (values != null && values.length > 0) {
|
||||
AuthInfo authInfo = new AuthInfo();
|
||||
authInfo.setValues(values);
|
||||
authInfo.setMode(mode);
|
||||
authInfo.setType(type);
|
||||
this.roles.add(authInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 Markdown 结构的权限说明
|
||||
*
|
||||
* @return Markdown 文本
|
||||
*/
|
||||
public String toMarkdownString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<br><h3>访问权限</h3><br>");
|
||||
|
||||
if (ignore) {
|
||||
sb.append("> **权限策略**:忽略权限检查<br>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
if (!ignore && permissions.isEmpty() && roles.isEmpty()){
|
||||
sb.append("> **权限策略**:需要登录<br><br>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
if (!permissions.isEmpty()) {
|
||||
sb.append("**权限校验:**<br><br>");
|
||||
|
||||
permissions.forEach(p -> {
|
||||
String permTags = Arrays.stream(p.getValues())
|
||||
.map(v -> "`" + v + "`")
|
||||
.collect(Collectors.joining(p.getModeSymbol()));
|
||||
|
||||
sb.append("- ").append(permTags).append("<br>");
|
||||
|
||||
if (p.getOrValues() != null && p.getOrValues().length > 0) {
|
||||
String orTags = Arrays.stream(p.getOrValues())
|
||||
.map(v -> "`" + v + "`")
|
||||
.collect(Collectors.joining(p.getModeSymbol()));
|
||||
sb.append(" - 或角色:").append(orTags).append("<br>");
|
||||
}
|
||||
});
|
||||
|
||||
sb.append("<br>");
|
||||
}
|
||||
|
||||
if (!roles.isEmpty()) {
|
||||
sb.append("**角色校验:**<br><br>");
|
||||
|
||||
roles.forEach(r -> {
|
||||
|
||||
String roleTags = Arrays.stream(r.getValues())
|
||||
.map(v -> "`" + v + "`")
|
||||
.collect(Collectors.joining(r.getModeSymbol()));
|
||||
|
||||
sb.append("- ").append(roleTags).append("<br>");
|
||||
});
|
||||
}
|
||||
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 认证信息
|
||||
*/
|
||||
@Data
|
||||
@JsonInclude(Include.NON_EMPTY)
|
||||
public static class AuthInfo {
|
||||
|
||||
/**
|
||||
* 权限或角色值数组
|
||||
*/
|
||||
private String[] values;
|
||||
|
||||
/**
|
||||
* 校验模式(AND/OR)
|
||||
*/
|
||||
private String mode;
|
||||
|
||||
/**
|
||||
* 类型说明
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 或权限/角色值数组(用于权限校验时的或角色校验)
|
||||
*/
|
||||
private String[] orValues;
|
||||
|
||||
/**
|
||||
* 或值的类型(role/permission)
|
||||
*/
|
||||
private String orType;
|
||||
|
||||
/**
|
||||
* 重写mode的获取方法,返回符号而非文字
|
||||
* @return AND→&,OR→|,默认→&
|
||||
*/
|
||||
public String getModeSymbol() {
|
||||
if (mode == null) {
|
||||
return " & "; // 默认AND,返回&
|
||||
}
|
||||
return "AND".equalsIgnoreCase(mode) ? " & " : " | ";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package org.dromara.common.doc.core.resolver;
|
||||
|
||||
import cn.hutool.core.annotation.AnnotationUtil;
|
||||
import cn.hutool.core.util.ClassLoaderUtil;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 抽象元数据 Javadoc 解析器
|
||||
*
|
||||
* @param <M> 元数据类型
|
||||
* @author 秋辞未寒
|
||||
*/
|
||||
public abstract class AbstractMetadataJavadocResolver<M> implements JavadocResolver {
|
||||
|
||||
public static final int HIGHEST_PRECEDENCE = Integer.MIN_VALUE;
|
||||
public static final int LOWEST_PRECEDENCE = Integer.MAX_VALUE;
|
||||
|
||||
private final Supplier<M> metadataProvider;
|
||||
|
||||
private final int order;
|
||||
|
||||
public AbstractMetadataJavadocResolver(Supplier<M> metadataProvider) {
|
||||
this(metadataProvider, LOWEST_PRECEDENCE);
|
||||
}
|
||||
|
||||
public AbstractMetadataJavadocResolver(Supplier<M> metadataProvider, int order) {
|
||||
this.metadataProvider = metadataProvider;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolve(HandlerMethod handlerMethod, Operation operation) {
|
||||
return resolve(handlerMethod, operation, metadataProvider.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行解析并返回解析到的 Javadoc 内容
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param operation Swagger Operation实例
|
||||
* @param metadata 元信息
|
||||
* @return 解析到的 Javadoc 内容
|
||||
*/
|
||||
public abstract String resolve(HandlerMethod handlerMethod, Operation operation, M metadata);
|
||||
|
||||
/**
|
||||
* 检查处理器方法所属的类上是否存在注解
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param annotationClass 注解类
|
||||
* @return 是否存在注解
|
||||
*/
|
||||
public boolean hasClassAnnotation(HandlerMethod handlerMethod,Class<? extends Annotation> annotationClass){
|
||||
return AnnotationUtil.hasAnnotation(handlerMethod.getBeanType(), annotationClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查处理器方法所属的类上是否存在注解
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param annotationTypeName 注解类名称
|
||||
* @return 是否存在注解
|
||||
*/
|
||||
public boolean hasClassAnnotation(HandlerMethod handlerMethod, String annotationTypeName){
|
||||
return AnnotationUtil.hasAnnotation(handlerMethod.getBeanType(), annotationTypeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查处理器方法上是否存在注解
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param annotationClass 注解类
|
||||
* @return 是否存在注解
|
||||
*/
|
||||
public boolean hasMethodAnnotation(HandlerMethod handlerMethod,Class<? extends Annotation> annotationClass){
|
||||
return AnnotationUtil.hasAnnotation(handlerMethod.getMethod(), annotationClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查处理器方法上是否存在注解
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param annotationTypeName 注解类名称
|
||||
* @return 是否存在注解
|
||||
*/
|
||||
public boolean hasMethodAnnotation(HandlerMethod handlerMethod, String annotationTypeName){
|
||||
return AnnotationUtil.hasAnnotation(handlerMethod.getMethod(), annotationTypeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查处理器方法上是否存在注解
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param annotationClass 注解类
|
||||
* @return 是否存在注解
|
||||
*/
|
||||
public boolean hasAnnotation(HandlerMethod handlerMethod,Class<? extends Annotation> annotationClass){
|
||||
return this.hasClassAnnotation(handlerMethod, annotationClass) || this.hasMethodAnnotation(handlerMethod, annotationClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查处理器方法上是否存在注解
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param annotationTypeName 注解类名称
|
||||
* @return 是否存在注解
|
||||
*/
|
||||
public boolean hasAnnotation(HandlerMethod handlerMethod, String annotationTypeName){
|
||||
return this.hasClassAnnotation(handlerMethod, annotationTypeName) || this.hasMethodAnnotation(handlerMethod, annotationTypeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取处理器方法所属类上的注解的值
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param annotationClass 注解类
|
||||
* @return 注解的值
|
||||
*/
|
||||
public Map<String, Object> getClassAnnotationValueMap(HandlerMethod handlerMethod, Class<? extends Annotation> annotationClass) {
|
||||
return AnnotationUtil.getAnnotationValueMap(handlerMethod.getBeanType(), annotationClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取处理器方法所属类上的注解的值
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param annotationClassName 注解类名称
|
||||
* @return 注解的值
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> getClassAnnotationValueMap(HandlerMethod handlerMethod, String annotationClassName) {
|
||||
Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) ClassLoaderUtil.loadClass(annotationClassName, false);
|
||||
return AnnotationUtil.getAnnotationValueMap(handlerMethod.getBeanType(), annotationClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取处理器方法上的注解的值
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param annotationClass 注解类
|
||||
* @return 注解的值
|
||||
*/
|
||||
public Map<String, Object> getMethodAnnotationValueMap(HandlerMethod handlerMethod, Class<? extends Annotation> annotationClass) {
|
||||
return AnnotationUtil.getAnnotationValueMap(handlerMethod.getMethod(), annotationClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取处理器方法所属类上的注解的值
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param annotationClassName 注解类名称
|
||||
* @return 注解的值
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> getMethodAnnotationValueMap(HandlerMethod handlerMethod, String annotationClassName) {
|
||||
Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) ClassLoaderUtil.loadClass(annotationClassName, false);
|
||||
return AnnotationUtil.getAnnotationValueMap(handlerMethod.getMethod(), annotationClass);
|
||||
}
|
||||
|
||||
private Map<String, Object> getAnnotationValueMap(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationClass) {
|
||||
return AnnotationUtil.getAnnotationValueMap(annotatedElement, annotationClass);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.dromara.common.doc.core.resolver;
|
||||
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
|
||||
/**
|
||||
* Javadoc解析器接口
|
||||
*
|
||||
* @author echo
|
||||
* @author 秋辞未寒
|
||||
*/
|
||||
public interface JavadocResolver extends Comparable<JavadocResolver>, Ordered {
|
||||
|
||||
/**
|
||||
* 检查解析器是否支持解析 HandlerMethod
|
||||
* @param handlerMethod 处理器方法
|
||||
* @return 是否支持解析
|
||||
*/
|
||||
boolean supports(HandlerMethod handlerMethod);
|
||||
|
||||
/**
|
||||
* 执行解析并返回解析到的 Javadoc 内容
|
||||
* @param handlerMethod 处理器方法
|
||||
* @param operation Swagger Operation实例
|
||||
* @return 解析到的 Javadoc 内容
|
||||
*/
|
||||
String resolve(HandlerMethod handlerMethod, Operation operation);
|
||||
|
||||
/**
|
||||
* 获取解析器优先级
|
||||
*/
|
||||
default int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取解析器的名称
|
||||
*
|
||||
* @return 解析器名称
|
||||
*/
|
||||
default String getName() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
default int compareTo(@NotNull JavadocResolver o) {
|
||||
return Integer.compare(getOrder(), o.getOrder());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package org.dromara.common.doc.core.resolver;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ClassLoaderUtil;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.doc.core.model.SaTokenSecurityMetadata;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 基于JavaDoc的SaToken权限解析器
|
||||
*
|
||||
* @author echo
|
||||
* @author 秋辞未寒
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Slf4j
|
||||
public class SaTokenAnnotationMetadataJavadocResolver extends AbstractMetadataJavadocResolver<SaTokenSecurityMetadata> {
|
||||
|
||||
/**
|
||||
* 默认元数据提供者,每次解析都会创建一个新的元数据对象
|
||||
*/
|
||||
public static final Supplier<SaTokenSecurityMetadata> DEFAULT_METADATA_PROVIDER = SaTokenSecurityMetadata::new;
|
||||
|
||||
private static final String BASE_CLASS_NAME = "cn.dev33.satoken.annotation";
|
||||
private static final String SA_CHECK_ROLE_CLASS_NAME = BASE_CLASS_NAME + ".SaCheckRole";
|
||||
private static final String SA_CHECK_PERMISSION_CLASS_NAME = BASE_CLASS_NAME + ".SaCheckPermission";
|
||||
private static final String SA_IGNORE_CLASS_NAME = BASE_CLASS_NAME + ".SaIgnore";
|
||||
private static final String SA_CHECK_LOGIN_NAME = BASE_CLASS_NAME + ".SaCheckLogin";
|
||||
|
||||
private static final Class<? extends Annotation> SA_CHECK_ROLE_CLASS;
|
||||
private static final Class<? extends Annotation> SA_CHECK_PERMISSION_CLASS;
|
||||
private static final Class<? extends Annotation> SA_IGNORE_CLASS;
|
||||
private static final Class<? extends Annotation> SA_CHECK_LOGIN_CLASS;
|
||||
|
||||
|
||||
static {
|
||||
// 通过类加载器去加载注解类Class实例
|
||||
SA_CHECK_ROLE_CLASS = (Class<? extends Annotation>) ClassLoaderUtil.loadClass(SA_CHECK_ROLE_CLASS_NAME, false);
|
||||
SA_CHECK_PERMISSION_CLASS = (Class<? extends Annotation>) ClassLoaderUtil.loadClass(SA_CHECK_PERMISSION_CLASS_NAME, false);
|
||||
SA_IGNORE_CLASS = (Class<? extends Annotation>) ClassLoaderUtil.loadClass(SA_IGNORE_CLASS_NAME, false);
|
||||
SA_CHECK_LOGIN_CLASS = (Class<? extends Annotation>) ClassLoaderUtil.loadClass(SA_CHECK_LOGIN_NAME, false);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("SaTokenAnnotationJavadocResolver init success, load annotation class: {}", List.of(SA_CHECK_ROLE_CLASS, SA_CHECK_PERMISSION_CLASS, SA_IGNORE_CLASS, SA_CHECK_LOGIN_CLASS));
|
||||
}
|
||||
}
|
||||
|
||||
public SaTokenAnnotationMetadataJavadocResolver() {
|
||||
this(DEFAULT_METADATA_PROVIDER);
|
||||
}
|
||||
|
||||
public SaTokenAnnotationMetadataJavadocResolver(Supplier<SaTokenSecurityMetadata> metadataProvider) {
|
||||
super(metadataProvider);
|
||||
}
|
||||
|
||||
public SaTokenAnnotationMetadataJavadocResolver(int order) {
|
||||
this(DEFAULT_METADATA_PROVIDER,order);
|
||||
}
|
||||
|
||||
public SaTokenAnnotationMetadataJavadocResolver(Supplier<SaTokenSecurityMetadata> metadataProvider, int order) {
|
||||
super(metadataProvider,order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(HandlerMethod handlerMethod) {
|
||||
return hasAnnotation(handlerMethod, SA_CHECK_ROLE_CLASS) || hasAnnotation(handlerMethod, SA_CHECK_PERMISSION_CLASS) || hasAnnotation(handlerMethod, SA_IGNORE_CLASS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolve(HandlerMethod handlerMethod, Operation operation, SaTokenSecurityMetadata metadata) {
|
||||
// 检查是否忽略校验
|
||||
if(hasAnnotation(handlerMethod, SA_IGNORE_CLASS_NAME)){
|
||||
metadata.setIgnore(true);
|
||||
return metadata.toMarkdownString();
|
||||
}
|
||||
|
||||
// 解析权限校验
|
||||
resolvePermissionCheck(handlerMethod, metadata);
|
||||
|
||||
// 解析角色校验
|
||||
resolveRoleCheck(handlerMethod, metadata);
|
||||
return metadata.toMarkdownString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析权限校验
|
||||
*/
|
||||
private void resolvePermissionCheck(HandlerMethod handlerMethod, SaTokenSecurityMetadata metadata) {
|
||||
// 解析获取方法上的注解角色信息
|
||||
if (hasMethodAnnotation(handlerMethod, SA_CHECK_PERMISSION_CLASS_NAME)) {
|
||||
Map<String, Object> annotationValueMap = getMethodAnnotationValueMap(handlerMethod, SA_CHECK_PERMISSION_CLASS);
|
||||
resolvePermissionAnnotation(metadata, annotationValueMap);
|
||||
}
|
||||
// 解析获取类上的注解角色信息
|
||||
if (hasClassAnnotation(handlerMethod, SA_CHECK_PERMISSION_CLASS_NAME)) {
|
||||
Map<String, Object> annotationValueMap = getClassAnnotationValueMap(handlerMethod, SA_CHECK_PERMISSION_CLASS);
|
||||
resolvePermissionAnnotation(metadata, annotationValueMap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析权限注解
|
||||
*/
|
||||
private void resolvePermissionAnnotation(SaTokenSecurityMetadata metadata, Map<String, Object> annotationValueMap) {
|
||||
try {
|
||||
// 反射获取注解属性
|
||||
Object value = annotationValueMap.get( "value");
|
||||
Object mode = annotationValueMap.get( "mode");
|
||||
Object type = annotationValueMap.get( "type");
|
||||
Object orRole = annotationValueMap.get( "orRole");
|
||||
|
||||
String[] values = Convert.toStrArray(value);
|
||||
String modeStr = mode != null ? mode.toString() : "AND";
|
||||
String typeStr = type != null ? type.toString() : "";
|
||||
String[] orRoles = Convert.toStrArray(orRole);
|
||||
|
||||
metadata.addPermission(values, modeStr, typeStr, orRoles);
|
||||
} catch (Exception ignore) {
|
||||
// 忽略解析错误
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析角色校验
|
||||
*/
|
||||
private void resolveRoleCheck(HandlerMethod handlerMethod, SaTokenSecurityMetadata metadata) {
|
||||
// 解析获取方法上的注解角色信息
|
||||
if (hasMethodAnnotation(handlerMethod, SA_CHECK_ROLE_CLASS_NAME)) {
|
||||
Map<String, Object> annotationValueMap = getMethodAnnotationValueMap(handlerMethod, SA_CHECK_ROLE_CLASS);
|
||||
resolveRoleAnnotation(metadata, annotationValueMap);
|
||||
}
|
||||
// 解析获取类上的注解角色信息
|
||||
if (hasClassAnnotation(handlerMethod, SA_CHECK_ROLE_CLASS_NAME)) {
|
||||
Map<String, Object> annotationValueMap = getClassAnnotationValueMap(handlerMethod, SA_CHECK_ROLE_CLASS);
|
||||
resolveRoleAnnotation(metadata, annotationValueMap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析角色注解
|
||||
*/
|
||||
private void resolveRoleAnnotation(SaTokenSecurityMetadata metadata, Map<String, Object> annotationValueMap) {
|
||||
try {
|
||||
// 反射获取注解属性
|
||||
Object value = annotationValueMap.get("value");
|
||||
Object mode = annotationValueMap.get("mode");
|
||||
Object type = annotationValueMap.get("type");
|
||||
|
||||
String[] values = Convert.toStrArray(value);
|
||||
String modeStr = mode != null ? mode.toString() : "AND";
|
||||
String typeStr = type != null ? type.toString() : "";
|
||||
|
||||
metadata.addRole(values, modeStr, typeStr);
|
||||
} catch (Exception ignore) {
|
||||
// 忽略解析错误
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import io.swagger.v3.oas.models.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.doc.core.resolver.JavadocResolver;
|
||||
import org.springdoc.core.customizers.OpenApiBuilderCustomizer;
|
||||
import org.springdoc.core.customizers.ServerBaseUrlCustomizer;
|
||||
import org.springdoc.core.properties.SpringDocConfigProperties;
|
||||
@@ -83,6 +84,11 @@ public class OpenApiHandler extends OpenAPIService {
|
||||
*/
|
||||
private final PropertyResolverUtils propertyResolverUtils;
|
||||
|
||||
/**
|
||||
* Javadoc解析器接口
|
||||
*/
|
||||
private final List<JavadocResolver> javadocResolvers;
|
||||
|
||||
/**
|
||||
* The javadoc provider.
|
||||
*/
|
||||
@@ -123,7 +129,8 @@ public class OpenApiHandler extends OpenAPIService {
|
||||
SpringDocConfigProperties springDocConfigProperties, PropertyResolverUtils propertyResolverUtils,
|
||||
Optional<List<OpenApiBuilderCustomizer>> openApiBuilderCustomizers,
|
||||
Optional<List<ServerBaseUrlCustomizer>> serverBaseUrlCustomizers,
|
||||
Optional<JavadocProvider> javadocProvider) {
|
||||
Optional<JavadocProvider> javadocProvider,
|
||||
List<JavadocResolver> javadocResolvers) {
|
||||
super(openAPI, securityParser, springDocConfigProperties, propertyResolverUtils, openApiBuilderCustomizers, serverBaseUrlCustomizers, javadocProvider);
|
||||
if (openAPI.isPresent()) {
|
||||
this.openAPI = openAPI.get();
|
||||
@@ -140,6 +147,7 @@ public class OpenApiHandler extends OpenAPIService {
|
||||
this.openApiBuilderCustomisers = openApiBuilderCustomizers;
|
||||
this.serverBaseUrlCustomizers = serverBaseUrlCustomizers;
|
||||
this.javadocProvider = javadocProvider;
|
||||
this.javadocResolvers = javadocResolvers == null ? new ArrayList<>() : javadocResolvers;
|
||||
if (springDocConfigProperties.isUseFqn())
|
||||
TypeNameResolver.std.setUseFqn(true);
|
||||
}
|
||||
@@ -220,6 +228,22 @@ public class OpenApiHandler extends OpenAPIService {
|
||||
securityParser.buildSecurityRequirement(securityRequirements, operation);
|
||||
}
|
||||
|
||||
if (javadocProvider.isPresent()) {
|
||||
String description = javadocProvider.get().getMethodJavadocDescription(handlerMethod.getMethod());
|
||||
String summary = javadocProvider.get().getFirstSentence(description);
|
||||
if (StringUtils.isNotBlank(description)){
|
||||
operation.setSummary(summary);
|
||||
}
|
||||
// 调用解析器提取JavaDoc中的权限信息
|
||||
if (javadocResolvers != null && !javadocResolvers.isEmpty()) {
|
||||
for (JavadocResolver resolver : javadocResolvers) {
|
||||
String desc = resolver.resolve(handlerMethod, operation);
|
||||
description = description + desc;
|
||||
}
|
||||
operation.setDescription(description);
|
||||
}
|
||||
}
|
||||
|
||||
return operation;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.executor.parameter.ParameterHandler;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.plugin.Intercepts;
|
||||
import org.apache.ibatis.plugin.Invocation;
|
||||
import org.apache.ibatis.plugin.Signature;
|
||||
import org.apache.ibatis.plugin.*;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.encrypt.annotation.EncryptField;
|
||||
import org.dromara.common.encrypt.core.EncryptContext;
|
||||
@@ -42,19 +39,19 @@ public class MybatisEncryptInterceptor implements Interceptor {
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
return invocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object plugin(Object target) {
|
||||
Object target = invocation.getTarget();
|
||||
if (target instanceof ParameterHandler parameterHandler) {
|
||||
// 进行加密操作
|
||||
Object parameterObject = parameterHandler.getParameterObject();
|
||||
if (ObjectUtil.isNotNull(parameterObject) && !(parameterObject instanceof String)) {
|
||||
this.encryptHandler(parameterObject);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object plugin(Object target) {
|
||||
return Plugin.wrap(target, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.dromara.common.excel.annotation;
|
||||
|
||||
import org.dromara.common.excel.core.ExcelOptionsProvider;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Excel动态下拉选项注解
|
||||
*
|
||||
* @author Angus
|
||||
*/
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
public @interface ExcelDynamicOptions {
|
||||
|
||||
/**
|
||||
* 提供者类全限定名
|
||||
* <p>
|
||||
* {@link org.dromara.common.excel.core.ExcelOptionsProvider} 接口实现类 class
|
||||
*/
|
||||
Class<? extends ExcelOptionsProvider> providerClass();
|
||||
}
|
||||
@@ -29,7 +29,10 @@ public class CellMergeHandler {
|
||||
// 行合并开始下标
|
||||
this.rowIndex = hasTitle ? 1 : 0;
|
||||
}
|
||||
|
||||
private CellMergeHandler(final boolean hasTitle, final int rowIndex) {
|
||||
this.hasTitle = hasTitle;
|
||||
this.rowIndex = hasTitle ? rowIndex : 0;
|
||||
}
|
||||
@SneakyThrows
|
||||
public List<CellRangeAddress> handle(List<?> rows) {
|
||||
// 如果入参为空集合则返回空集
|
||||
@@ -103,6 +106,10 @@ public class CellMergeHandler {
|
||||
}
|
||||
|
||||
if (isAddResult && i > current) {
|
||||
//如果是同一行,则跳过合并
|
||||
if (current + rowIndex == lastRow) {
|
||||
continue;
|
||||
}
|
||||
result.add(new CellRangeAddress(current + rowIndex, lastRow, colNum, colNum));
|
||||
}
|
||||
}
|
||||
@@ -147,12 +154,12 @@ public class CellMergeHandler {
|
||||
private boolean isMerge(Object currentRow, Object preRow, CellMerge cellMerge) {
|
||||
final String[] mergeBy = cellMerge.mergeBy();
|
||||
if (StrUtil.isAllNotBlank(mergeBy)) {
|
||||
//比对当前行和上一行的各个属性值一一比对 如果全为真 则为真
|
||||
// 比对当前行和上一行的各个属性值一一比对 如果全为真 则为真
|
||||
for (String fieldName : mergeBy) {
|
||||
final Object valCurrent = ReflectUtil.getFieldValue(currentRow, fieldName);
|
||||
final Object valPre = ReflectUtil.getFieldValue(preRow, fieldName);
|
||||
if (!Objects.equals(valPre, valCurrent)) {
|
||||
//依赖字段如有任一不等值,则标记为不可合并
|
||||
// 依赖字段如有任一不等值,则标记为不可合并
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -177,6 +184,16 @@ public class CellMergeHandler {
|
||||
return new FieldColumnIndex(colIndex, cellMerge);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 创建一个单元格合并处理器实例
|
||||
*
|
||||
* @param hasTitle 是否合并标题
|
||||
* @param rowIndex 行索引
|
||||
* @return 单元格合并处理器
|
||||
*/
|
||||
public static CellMergeHandler of(final boolean hasTitle, final int rowIndex) {
|
||||
return new CellMergeHandler(hasTitle, rowIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个单元格合并处理器实例
|
||||
|
||||
@@ -2,15 +2,16 @@ package org.dromara.common.excel.core;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.idev.excel.metadata.Head;
|
||||
import cn.idev.excel.write.handler.WorkbookWriteHandler;
|
||||
import cn.idev.excel.write.handler.context.WorkbookWriteHandlerContext;
|
||||
import cn.idev.excel.write.handler.SheetWriteHandler;
|
||||
import cn.idev.excel.write.merge.AbstractMergeStrategy;
|
||||
import cn.idev.excel.write.metadata.holder.WriteSheetHolder;
|
||||
import cn.idev.excel.write.metadata.holder.WriteWorkbookHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 列值重复合并策略
|
||||
@@ -18,7 +19,7 @@ import java.util.*;
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
public class CellMergeStrategy extends AbstractMergeStrategy implements WorkbookWriteHandler {
|
||||
public class CellMergeStrategy extends AbstractMergeStrategy implements SheetWriteHandler {
|
||||
|
||||
private final List<CellRangeAddress> cellList;
|
||||
|
||||
@@ -30,29 +31,34 @@ public class CellMergeStrategy extends AbstractMergeStrategy implements Workbook
|
||||
this.cellList = CellMergeHandler.of(hasTitle).handle(list);
|
||||
}
|
||||
|
||||
public CellMergeStrategy(List<?> list, boolean hasTitle, int rowIndex) {
|
||||
this.cellList = CellMergeHandler.of(hasTitle, rowIndex).handle(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {
|
||||
if (CollUtil.isEmpty(cellList)){
|
||||
if (CollUtil.isEmpty(cellList)) {
|
||||
return;
|
||||
}
|
||||
//单元格写入了,遍历合并区域,如果该Cell在区域内,但非首行,则清空
|
||||
// 单元格写入了,遍历合并区域,如果该Cell在区域内,但非首行,则清空
|
||||
final int rowIndex = cell.getRowIndex();
|
||||
for (CellRangeAddress cellAddresses : cellList) {
|
||||
final int firstRow = cellAddresses.getFirstRow();
|
||||
if (cellAddresses.isInRange(cell) && rowIndex != firstRow){
|
||||
if (cellAddresses.isInRange(cell) && rowIndex != firstRow) {
|
||||
cell.setBlank();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterWorkbookDispose(final WorkbookWriteHandlerContext context) {
|
||||
if (CollUtil.isEmpty(cellList)){
|
||||
public void afterSheetCreate(final WriteWorkbookHolder writeWorkbookHolder, final WriteSheetHolder writeSheetHolder) {
|
||||
if (CollUtil.isEmpty(cellList)) {
|
||||
return;
|
||||
}
|
||||
//当前表格写完后,统一写入
|
||||
// 在 Sheet 创建时提前写入合并区域;后续写入只会影响首格,不会移除合并
|
||||
final Sheet sheet = writeSheetHolder.getSheet();
|
||||
for (CellRangeAddress item : cellList) {
|
||||
context.getWriteContext().writeSheetHolder().getSheet().addMergedRegion(item);
|
||||
sheet.addMergedRegion(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
||||
import org.dromara.common.excel.annotation.ExcelDynamicOptions;
|
||||
import org.dromara.common.excel.annotation.ExcelEnumFormat;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -117,6 +118,15 @@ public class ExcelDownHandler implements SheetWriteHandler {
|
||||
ExcelEnumFormat format = field.getDeclaredAnnotation(ExcelEnumFormat.class);
|
||||
List<Object> values = EnumUtil.getFieldValues(format.enumClass(), format.textField());
|
||||
options = StreamUtils.toList(values, Convert::toStr);
|
||||
} else if (field.isAnnotationPresent(ExcelDynamicOptions.class)) {
|
||||
// 处理动态下拉选项
|
||||
ExcelDynamicOptions dynamicOptions = field.getDeclaredAnnotation(ExcelDynamicOptions.class);
|
||||
// 获取提供者实例
|
||||
ExcelOptionsProvider provider = SpringUtils.getBean(dynamicOptions.providerClass());
|
||||
Set<String> providerOptions = provider.getOptions();
|
||||
if (CollUtil.isNotEmpty(providerOptions)) {
|
||||
options = new ArrayList<>(providerOptions);
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(options)) {
|
||||
// 仅当下拉可选项不为空时执行
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.dromara.common.excel.core;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Excel下拉选项数据提供接口
|
||||
*
|
||||
* @author Angus
|
||||
*/
|
||||
public interface ExcelOptionsProvider {
|
||||
|
||||
/**
|
||||
* 获取下拉选项数据
|
||||
*
|
||||
* @return 下拉选项列表
|
||||
*/
|
||||
Set<String> getOptions();
|
||||
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.domain.model.LoginUser;
|
||||
import org.dromara.common.core.utils.ServletUtils;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
@@ -39,12 +40,6 @@ import java.util.*;
|
||||
@AutoConfiguration
|
||||
public class LogAspect {
|
||||
|
||||
/**
|
||||
* 排除敏感属性字段
|
||||
*/
|
||||
public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
|
||||
|
||||
|
||||
/**
|
||||
* 计时 key
|
||||
*/
|
||||
@@ -160,7 +155,7 @@ public class LogAspect {
|
||||
String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
|
||||
operLog.setOperParam(StringUtils.substring(params, 0, 3800));
|
||||
} else {
|
||||
MapUtil.removeAny(paramsMap, EXCLUDE_PROPERTIES);
|
||||
MapUtil.removeAny(paramsMap, SystemConstants.EXCLUDE_PROPERTIES);
|
||||
MapUtil.removeAny(paramsMap, excludeParamNames);
|
||||
operLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 3800));
|
||||
}
|
||||
@@ -174,7 +169,7 @@ public class LogAspect {
|
||||
if (ArrayUtil.isEmpty(paramsArray)) {
|
||||
return params.toString();
|
||||
}
|
||||
String[] exclude = ArrayUtil.addAll(excludeParamNames, EXCLUDE_PROPERTIES);
|
||||
String[] exclude = ArrayUtil.addAll(excludeParamNames, SystemConstants.EXCLUDE_PROPERTIES);
|
||||
for (Object o : paramsArray) {
|
||||
if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) {
|
||||
String str = "";
|
||||
|
||||
@@ -192,7 +192,7 @@ public class MailUtils {
|
||||
/**
|
||||
* 发送邮件给多人
|
||||
*
|
||||
* @param mailAccount 邮件帐户信息
|
||||
* @param mailAccount 邮件账户信息
|
||||
* @param tos 收件人列表
|
||||
* @param subject 标题
|
||||
* @param content 正文
|
||||
@@ -207,7 +207,7 @@ public class MailUtils {
|
||||
/**
|
||||
* 发送邮件给多人
|
||||
*
|
||||
* @param mailAccount 邮件帐户信息
|
||||
* @param mailAccount 邮件账户信息
|
||||
* @param tos 收件人列表
|
||||
* @param ccs 抄送人列表,可以为null或空
|
||||
* @param bccs 密送人列表,可以为null或空
|
||||
@@ -343,7 +343,7 @@ public class MailUtils {
|
||||
/**
|
||||
* 发送邮件给多人
|
||||
*
|
||||
* @param mailAccount 邮件帐户信息
|
||||
* @param mailAccount 邮件账户信息
|
||||
* @param tos 收件人列表
|
||||
* @param subject 标题
|
||||
* @param content 正文
|
||||
@@ -360,7 +360,7 @@ public class MailUtils {
|
||||
/**
|
||||
* 发送邮件给多人
|
||||
*
|
||||
* @param mailAccount 邮件帐户信息
|
||||
* @param mailAccount 邮件账户信息
|
||||
* @param tos 收件人列表
|
||||
* @param ccs 抄送人列表,可以为null或空
|
||||
* @param bccs 密送人列表,可以为null或空
|
||||
@@ -400,7 +400,7 @@ public class MailUtils {
|
||||
/**
|
||||
* 发送邮件给多人
|
||||
*
|
||||
* @param mailAccount 邮件帐户信息
|
||||
* @param mailAccount 邮件账户信息
|
||||
* @param useGlobalSession 是否全局共享Session
|
||||
* @param tos 收件人列表
|
||||
* @param ccs 抄送人列表,可以为null或空
|
||||
|
||||
@@ -42,7 +42,7 @@ public class DataBaseHelper {
|
||||
String databaseProductName = metaData.getDatabaseProductName();
|
||||
return DataBaseType.find(databaseProductName);
|
||||
} catch (SQLException e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
throw new RuntimeException("获取数据库类型失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.function.Supplier;
|
||||
* @version 3.5.0
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("unchecked cast")
|
||||
@SuppressWarnings("unchecked")
|
||||
public class DataPermissionHelper {
|
||||
|
||||
private static final String DATA_PERMISSION_KEY = "data:permission";
|
||||
@@ -112,7 +112,7 @@ public class DataPermissionHelper {
|
||||
/**
|
||||
* 开启忽略数据权限(开启后需手动调用 {@link #disableIgnore()} 关闭)
|
||||
*/
|
||||
public static void enableIgnore() {
|
||||
private static void enableIgnore() {
|
||||
IgnoreStrategy ignoreStrategy = getIgnoreStrategy();
|
||||
if (ObjectUtil.isNull(ignoreStrategy)) {
|
||||
InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().dataPermission(true).build());
|
||||
@@ -126,7 +126,7 @@ public class DataPermissionHelper {
|
||||
/**
|
||||
* 关闭忽略数据权限
|
||||
*/
|
||||
public static void disableIgnore() {
|
||||
private static void disableIgnore() {
|
||||
IgnoreStrategy ignoreStrategy = getIgnoreStrategy();
|
||||
if (ObjectUtil.isNotNull(ignoreStrategy)) {
|
||||
boolean noOtherIgnoreStrategy = !Boolean.TRUE.equals(ignoreStrategy.getDynamicTableName())
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package org.dromara.common.mybatis.utils;
|
||||
|
||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
|
||||
/**
|
||||
* ID 生成工具类
|
||||
*
|
||||
* @author AprilWind
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class IdGeneratorUtil {
|
||||
|
||||
private static final IdentifierGenerator GENERATOR = SpringUtils.getBean(IdentifierGenerator.class);
|
||||
|
||||
/**
|
||||
* 生成字符串类型主键 ID
|
||||
* <p>
|
||||
* 调用 {@link IdentifierGenerator#nextId(Object)},返回 String 格式 ID。
|
||||
* </p>
|
||||
*
|
||||
* @return 字符串格式主键 ID
|
||||
*/
|
||||
public static String nextId() {
|
||||
return GENERATOR.nextId(null).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 Long 类型主键 ID
|
||||
* <p>
|
||||
* 自动将生成的数字型主键转换为 Long 类型
|
||||
* </p>
|
||||
*
|
||||
* @return Long 类型主键 ID
|
||||
*/
|
||||
public static Long nextLongId() {
|
||||
return GENERATOR.nextId(null).longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 Number 类型主键 ID
|
||||
* <p>
|
||||
* 推荐在需要保留原始 Number 类型时使用
|
||||
* </p>
|
||||
*
|
||||
* @return Number 类型主键 ID
|
||||
*/
|
||||
public static Number nextNumberId() {
|
||||
return GENERATOR.nextId(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据实体生成数字型主键 ID
|
||||
* <p>
|
||||
* 若自定义的 {@link IdentifierGenerator} 根据实体内容生成 ID,则可以使用本方法
|
||||
* </p>
|
||||
*
|
||||
* @param entity 实体对象
|
||||
* @return Number 类型主键 ID
|
||||
*/
|
||||
public static Number nextId(Object entity) {
|
||||
return GENERATOR.nextId(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据实体生成字符串主键 ID
|
||||
* <p>
|
||||
* 与 {@link #nextId(Object)} 类似,但返回 String 类型
|
||||
* </p>
|
||||
*
|
||||
* @param entity 实体对象
|
||||
* @return 字符串格式主键 ID
|
||||
*/
|
||||
public static String nextStringId(Object entity) {
|
||||
return GENERATOR.nextId(entity).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 32 位 UUID
|
||||
* <p>
|
||||
* 底层使用 {@link IdWorker#get32UUID()}
|
||||
* </p>
|
||||
*
|
||||
* @return 32 位 UUID 字符串
|
||||
*/
|
||||
public static String nextUUID() {
|
||||
return IdWorker.get32UUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据实体生成 32 位 UUID
|
||||
* <p>
|
||||
* 默认 {@link IdentifierGenerator#nextUUID(Object)} 实现忽略实体,但保留该方法便于扩展。
|
||||
* </p>
|
||||
*
|
||||
* @param entity 实体对象
|
||||
* @return 32 位 UUID 字符串
|
||||
*/
|
||||
public static String nextUUID(Object entity) {
|
||||
return GENERATOR.nextUUID(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成带指定前缀的字符串主键 ID
|
||||
* <p>
|
||||
* 示例:prefix = "ORD",生成结果形如:{@code ORD20251211000123}
|
||||
* </p>
|
||||
*
|
||||
* @param prefix 自定义前缀
|
||||
* @return 带前缀的字符串主键 ID
|
||||
*/
|
||||
public static String nextIdWithPrefix(String prefix) {
|
||||
return prefix + nextId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成带前缀的 UUID
|
||||
*
|
||||
* @param prefix 前缀
|
||||
* @return prefix + UUID
|
||||
*/
|
||||
public static String nextUUIDWithPrefix(String prefix) {
|
||||
return prefix + nextUUID();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>s3</artifactId>
|
||||
<exclusions>
|
||||
<!-- 将基于 CRT 的 HTTP 客户端从类路径中移除 -->
|
||||
<!-- 东西 30M 特别大的 jar 包 性能跟 Netty 差不多 有需要可以自行替换使用 -->
|
||||
<exclusion>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>aws-crt-client</artifactId>
|
||||
@@ -49,13 +49,13 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- 将基于 Netty 的 HTTP 客户端从类路径中移除 -->
|
||||
<!-- 适用于 Netty 的客户端 -->
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>netty-nio-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 基于 AWS CRT 的 S3 客户端的性能增强的 S3 传输管理器 -->
|
||||
<!-- 客户端的性能增强传输管理器 -->
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>s3-transfer-manager</artifactId>
|
||||
|
||||
@@ -14,7 +14,9 @@ import org.dromara.common.oss.exception.OssException;
|
||||
import org.dromara.common.oss.properties.OssProperties;
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||
import software.amazon.awssdk.core.async.*;
|
||||
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
|
||||
import software.amazon.awssdk.core.async.BlockingInputStreamAsyncRequestBody;
|
||||
import software.amazon.awssdk.core.async.ResponsePublisher;
|
||||
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.s3.S3AsyncClient;
|
||||
@@ -33,6 +35,7 @@ import java.nio.channels.WritableByteChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -94,7 +97,11 @@ public class OssClient {
|
||||
.region(of())
|
||||
.forcePathStyle(isStyle)
|
||||
.httpClient(NettyNioAsyncHttpClient.builder()
|
||||
.connectionTimeout(Duration.ofSeconds(60)).build())
|
||||
.connectionTimeout(Duration.ofSeconds(60))
|
||||
.connectionAcquisitionTimeout(Duration.ofSeconds(30))
|
||||
.maxConcurrency(100)
|
||||
.maxPendingConnectionAcquires(1000)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
//AWS基于 CRT 的 S3 AsyncClient 实例用作 S3 传输管理器的底层客户端
|
||||
@@ -134,7 +141,8 @@ public class OssClient {
|
||||
try {
|
||||
// 构建上传请求对象
|
||||
FileUpload fileUpload = transferManager.uploadFile(
|
||||
x -> x.putObjectRequest(
|
||||
x -> {
|
||||
x.source(filePath).putObjectRequest(
|
||||
y -> y.bucket(properties.getBucketName())
|
||||
.key(key)
|
||||
.contentMD5(StringUtils.isNotEmpty(md5Digest) ? md5Digest : null)
|
||||
@@ -142,10 +150,13 @@ public class OssClient {
|
||||
// 用于设置对象的访问控制列表(ACL)。不同云厂商对ACL的支持和实现方式有所不同,
|
||||
// 因此根据具体的云服务提供商,你可能需要进行不同的配置(自行开启,阿里云有acl权限配置,腾讯云没有acl权限配置)
|
||||
//.acl(getAccessPolicy().getObjectCannedACL())
|
||||
.build())
|
||||
.addTransferListener(LoggingTransferListener.create())
|
||||
.source(filePath).build());
|
||||
|
||||
.build()
|
||||
);
|
||||
if (log.isDebugEnabled()) {
|
||||
x.addTransferListener(LoggingTransferListener.create());
|
||||
}
|
||||
}
|
||||
);
|
||||
// 等待上传完成并获取上传结果
|
||||
CompletedFileUpload uploadResult = fileUpload.completionFuture().join();
|
||||
String eTag = uploadResult.response().eTag();
|
||||
@@ -185,16 +196,21 @@ public class OssClient {
|
||||
|
||||
// 使用 transferManager 进行上传
|
||||
Upload upload = transferManager.upload(
|
||||
x -> x.requestBody(body).addTransferListener(LoggingTransferListener.create())
|
||||
.putObjectRequest(
|
||||
x -> {
|
||||
x.requestBody(body).putObjectRequest(
|
||||
y -> y.bucket(properties.getBucketName())
|
||||
.key(key)
|
||||
.contentType(contentType)
|
||||
// 用于设置对象的访问控制列表(ACL)。不同云厂商对ACL的支持和实现方式有所不同,
|
||||
// 因此根据具体的云服务提供商,你可能需要进行不同的配置(自行开启,阿里云有acl权限配置,腾讯云没有acl权限配置)
|
||||
//.acl(getAccessPolicy().getObjectCannedACL())
|
||||
.build())
|
||||
.build());
|
||||
.build()
|
||||
);
|
||||
if (log.isDebugEnabled()) {
|
||||
x.addTransferListener(LoggingTransferListener.create());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// 将输入流写入请求体
|
||||
body.writeInputStream(inputStream);
|
||||
@@ -222,13 +238,17 @@ public class OssClient {
|
||||
Path tempFilePath = FileUtils.createTempFile().toPath();
|
||||
// 使用 S3TransferManager 下载文件
|
||||
FileDownload downloadFile = transferManager.downloadFile(
|
||||
x -> x.getObjectRequest(
|
||||
x -> {
|
||||
x.destination(tempFilePath).getObjectRequest(
|
||||
y -> y.bucket(properties.getBucketName())
|
||||
.key(removeBaseUrl(path))
|
||||
.build())
|
||||
.addTransferListener(LoggingTransferListener.create())
|
||||
.destination(tempFilePath)
|
||||
.build());
|
||||
.build()
|
||||
);
|
||||
if (log.isDebugEnabled()) {
|
||||
x.addTransferListener(LoggingTransferListener.create());
|
||||
}
|
||||
}
|
||||
);
|
||||
// 等待文件下载操作完成
|
||||
downloadFile.completionFuture().join();
|
||||
return tempFilePath;
|
||||
@@ -237,8 +257,8 @@ public class OssClient {
|
||||
/**
|
||||
* 下载文件从 Amazon S3 到 输出流
|
||||
*
|
||||
* @param key 文件在 Amazon S3 中的对象键
|
||||
* @param out 输出流
|
||||
* @param key 文件在 Amazon S3 中的对象键
|
||||
* @param out 输出流
|
||||
* @param consumer 自定义处理逻辑
|
||||
* @throws OssException 如果下载失败,抛出自定义异常
|
||||
*/
|
||||
@@ -253,26 +273,24 @@ public class OssClient {
|
||||
/**
|
||||
* 下载文件从 Amazon S3 到 输出流
|
||||
*
|
||||
* @param key 文件在 Amazon S3 中的对象键
|
||||
* @param key 文件在 Amazon S3 中的对象键
|
||||
* @param contentLengthConsumer 文件大小消费者函数
|
||||
* @return 写出订阅器
|
||||
* @throws OssException 如果下载失败,抛出自定义异常
|
||||
*/
|
||||
public WriteOutSubscriber<OutputStream> download(String key, Consumer<Long> contentLengthConsumer) {
|
||||
try {
|
||||
// 构建下载请求
|
||||
DownloadRequest<ResponsePublisher<GetObjectResponse>> publisherDownloadRequest = DownloadRequest.builder()
|
||||
// 文件对象
|
||||
.getObjectRequest(y -> y.bucket(properties.getBucketName())
|
||||
.key(key)
|
||||
.build())
|
||||
.addTransferListener(LoggingTransferListener.create())
|
||||
DownloadRequest.TypedBuilder<ResponsePublisher<GetObjectResponse>> typedBuilder = DownloadRequest.builder()
|
||||
// 使用发布订阅转换器
|
||||
.responseTransformer(AsyncResponseTransformer.toPublisher())
|
||||
.build();
|
||||
// 文件对象
|
||||
.getObjectRequest(y -> y.bucket(properties.getBucketName()).key(key).build());
|
||||
if (log.isDebugEnabled()) {
|
||||
typedBuilder.addTransferListener(LoggingTransferListener.create());
|
||||
}
|
||||
|
||||
// 使用 S3TransferManager 下载文件
|
||||
Download<ResponsePublisher<GetObjectResponse>> publisherDownload = transferManager.download(publisherDownloadRequest);
|
||||
Download<ResponsePublisher<GetObjectResponse>> publisherDownload = transferManager.download(typedBuilder.build());
|
||||
// 获取下载发布订阅转换器
|
||||
ResponsePublisher<GetObjectResponse> publisher = publisherDownload.completionFuture().join().result();
|
||||
// 执行文件大小消费者函数
|
||||
@@ -282,7 +300,7 @@ public class OssClient {
|
||||
// 构建写出订阅器对象
|
||||
return out -> {
|
||||
// 创建可写入的字节通道
|
||||
try(WritableByteChannel channel = Channels.newChannel(out)){
|
||||
try (WritableByteChannel channel = Channels.newChannel(out)) {
|
||||
// 订阅数据
|
||||
publisher.subscribe(byteBuffer -> {
|
||||
while (byteBuffer.hasRemaining()) {
|
||||
@@ -317,13 +335,13 @@ public class OssClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取私有URL链接
|
||||
* 创建下载请求的预签名URL
|
||||
*
|
||||
* @param objectKey 对象KEY
|
||||
* @param expiredTime 链接授权到期时间
|
||||
*/
|
||||
public String getPrivateUrl(String objectKey, Duration expiredTime) {
|
||||
// 使用 AWS S3 预签名 URL 的生成器 获取对象的预签名 URL
|
||||
public String createPresignedGetUrl(String objectKey, Duration expiredTime) {
|
||||
// 使用 AWS S3 预签名 URL 的生成器 获取下载对象的预签名 URL
|
||||
URL url = presigner.presignGetObject(
|
||||
x -> x.signatureDuration(expiredTime)
|
||||
.getObjectRequest(
|
||||
@@ -332,7 +350,28 @@ public class OssClient {
|
||||
.build())
|
||||
.build())
|
||||
.url();
|
||||
return url.toString();
|
||||
return url.toExternalForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建上传请求的预签名URL
|
||||
*
|
||||
* @param objectKey 对象KEY
|
||||
* @param expiredTime 链接授权到期时间
|
||||
* @param metadata 元数据
|
||||
*/
|
||||
public String createPresignedPutUrl(String objectKey, Duration expiredTime, Map<String, String> metadata) {
|
||||
// 使用 AWS S3 预签名 URL 的生成器 获取上传文件对象的预签名 URL
|
||||
URL url = presigner.presignPutObject(
|
||||
x -> x.signatureDuration(expiredTime)
|
||||
.putObjectRequest(
|
||||
y -> y.bucket(properties.getBucketName())
|
||||
.key(objectKey)
|
||||
.metadata(metadata)
|
||||
.build())
|
||||
.build())
|
||||
.url();
|
||||
return url.toExternalForm();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,16 +43,12 @@
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– redis序列化替代方案 比json快无数的跨语言二进制序列化 –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.fury</groupId>-->
|
||||
<!-- <artifactId>fury-core</artifactId>-->
|
||||
<!-- <version>0.9.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.slf4j</groupId>-->
|
||||
<!-- <artifactId>slf4j-api</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- redis序列化替代方案 比json快无数的跨语言二进制序列化 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.fory</groupId>
|
||||
<artifactId>fory-core</artifactId>
|
||||
<version>0.13.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -53,9 +53,10 @@ public class RedisConfig {
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
// 指定序列化输入的类型,类必须是非final修饰的。序列化时将对象全类名一起保存下来
|
||||
om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
// LoggerFactory.useSlf4jLogging(true);
|
||||
// FuryCodec furyCodec = new FuryCodec();
|
||||
// CompositeCodec codec = new CompositeCodec(StringCodec.INSTANCE, furyCodec, furyCodec);
|
||||
// org.apache.fory.logging.LoggerFactory 包别引入错了
|
||||
// LoggerFactory.useSlf4jLogging(true);
|
||||
// ForyCodec foryCodec = new ForyCodec();
|
||||
// CompositeCodec codec = new CompositeCodec(StringCodec.INSTANCE, foryCodec, foryCodec);
|
||||
TypedJsonJacksonCodec jsonCodec = new TypedJsonJacksonCodec(Object.class, om);
|
||||
// 组合序列化 key 使用 String 内容使用通用 json 格式
|
||||
CompositeCodec codec = new CompositeCodec(StringCodec.INSTANCE, jsonCodec, jsonCodec);
|
||||
|
||||
@@ -113,7 +113,7 @@ public class PlusSaTokenDao implements SaTokenDaoBySessionFollowObject {
|
||||
* @param key 键名称
|
||||
* @return object
|
||||
*/
|
||||
@SuppressWarnings("unchecked cast")
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getObject(String key, Class<T> classType) {
|
||||
Object o = CAFFEINE.get(key, k -> RedisUtils.getCacheObject(key));
|
||||
|
||||
@@ -63,7 +63,7 @@ public class LoginHelper {
|
||||
/**
|
||||
* 获取用户(多级缓存)
|
||||
*/
|
||||
@SuppressWarnings("unchecked cast")
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends LoginUser> T getLoginUser() {
|
||||
SaSession session = StpUtil.getTokenSession();
|
||||
if (ObjectUtil.isNull(session)) {
|
||||
@@ -75,7 +75,7 @@ public class LoginHelper {
|
||||
/**
|
||||
* 获取用户基于token
|
||||
*/
|
||||
@SuppressWarnings("unchecked cast")
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends LoginUser> T getLoginUser(String token) {
|
||||
SaSession session = StpUtil.getTokenSessionByToken(token);
|
||||
if (ObjectUtil.isNull(session)) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.dromara.common.sensitive.core;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.dromara.common.core.utils.DesensitizedUtils;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -80,6 +81,18 @@ public enum SensitiveStrategy {
|
||||
*/
|
||||
FIRST_MASK(DesensitizedUtil::firstMask),
|
||||
|
||||
/**
|
||||
* 通用字符串脱敏
|
||||
* 可配置前后可见长度和中间掩码长度
|
||||
* 默认示例:前4位可见,后4位可见,中间固定4个*
|
||||
*/
|
||||
STRING_MASK(s -> DesensitizedUtils.mask(s, 4, 4, 4)),
|
||||
|
||||
/**
|
||||
* 高安全级别脱敏(Token / 私钥):前2位可见,后2位可见,中间全部掩码
|
||||
*/
|
||||
MASK_HIGH_SECURITY(s -> DesensitizedUtils.maskHighSecurity(s, 2, 2)),
|
||||
|
||||
/**
|
||||
* 清空为""
|
||||
*/
|
||||
|
||||
@@ -25,9 +25,24 @@ import java.util.Objects;
|
||||
@Slf4j
|
||||
public class SensitiveHandler extends JsonSerializer<String> implements ContextualSerializer {
|
||||
|
||||
private SensitiveStrategy strategy;
|
||||
private String[] roleKey;
|
||||
private String[] perms;
|
||||
private final SensitiveStrategy strategy;
|
||||
private final String[] roleKey;
|
||||
private final String[] perms;
|
||||
|
||||
/**
|
||||
* 提供给 jackson 创建上下文序列化器时使用 不然会报错
|
||||
*/
|
||||
public SensitiveHandler() {
|
||||
this.strategy = null;
|
||||
this.roleKey = null;
|
||||
this.perms = null;
|
||||
}
|
||||
|
||||
public SensitiveHandler(SensitiveStrategy strategy, String[] strings, String[] perms) {
|
||||
this.strategy = strategy;
|
||||
this.roleKey = strings;
|
||||
this.perms = perms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
@@ -48,10 +63,7 @@ public class SensitiveHandler extends JsonSerializer<String> implements Contextu
|
||||
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
|
||||
Sensitive annotation = property.getAnnotation(Sensitive.class);
|
||||
if (Objects.nonNull(annotation) && Objects.equals(String.class, property.getType().getRawClass())) {
|
||||
this.strategy = annotation.strategy();
|
||||
this.roleKey = annotation.roleKey();
|
||||
this.perms = annotation.perms();
|
||||
return this;
|
||||
return new SensitiveHandler(annotation.strategy(), annotation.roleKey(), annotation.perms());
|
||||
}
|
||||
return prov.findValueSerializer(property.getType(), property);
|
||||
}
|
||||
|
||||
@@ -28,9 +28,14 @@ public class SocialLoginConfigProperties {
|
||||
private String redirectUri;
|
||||
|
||||
/**
|
||||
* 是否获取unionId
|
||||
* 是否需要申请unionid,目前只针对qq登录
|
||||
*/
|
||||
private boolean unionId;
|
||||
private Boolean unionId;
|
||||
|
||||
/**
|
||||
* Microsoft Entra ID(原微软 AAD)中的租户 ID
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* Coding 企业名称
|
||||
|
||||
@@ -57,7 +57,7 @@ public class SocialUtils {
|
||||
case "taobao" -> new AuthTaobaoRequest(builder.build(), STATE_CACHE);
|
||||
case "douyin" -> new AuthDouyinRequest(builder.build(), STATE_CACHE);
|
||||
case "linkedin" -> new AuthLinkedinRequest(builder.build(), STATE_CACHE);
|
||||
case "microsoft" -> new AuthMicrosoftRequest(builder.build(), STATE_CACHE);
|
||||
case "microsoft" -> new AuthMicrosoftRequest(builder.tenantId(obj.getTenantId()).build(), STATE_CACHE);
|
||||
case "renren" -> new AuthRenrenRequest(builder.build(), STATE_CACHE);
|
||||
case "stack_overflow" -> new AuthStackOverflowRequest(builder.stackOverflowKey(obj.getStackOverflowKey()).build(), STATE_CACHE);
|
||||
case "huawei" -> new AuthHuaweiV3Request(builder.build(), STATE_CACHE);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class TenantHelper {
|
||||
/**
|
||||
* 开启忽略租户(开启后需手动调用 {@link #disableIgnore()} 关闭)
|
||||
*/
|
||||
public static void enableIgnore() {
|
||||
private static void enableIgnore() {
|
||||
IgnoreStrategy ignoreStrategy = getIgnoreStrategy();
|
||||
if (ObjectUtil.isNull(ignoreStrategy)) {
|
||||
InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build());
|
||||
@@ -69,7 +69,7 @@ public class TenantHelper {
|
||||
/**
|
||||
* 关闭忽略租户
|
||||
*/
|
||||
public static void disableIgnore() {
|
||||
private static void disableIgnore() {
|
||||
IgnoreStrategy ignoreStrategy = getIgnoreStrategy();
|
||||
if (ObjectUtil.isNotNull(ignoreStrategy)) {
|
||||
boolean noOtherIgnoreStrategy = !Boolean.TRUE.equals(ignoreStrategy.getDynamicTableName())
|
||||
|
||||
@@ -13,7 +13,7 @@ public interface TransConstant {
|
||||
String USER_ID_TO_NAME = "user_id_to_name";
|
||||
|
||||
/**
|
||||
* 用户id转用户名称
|
||||
* 用户id转用户昵称
|
||||
*/
|
||||
String USER_ID_TO_NICKNAME = "user_id_to_nickname";
|
||||
|
||||
|
||||
@@ -31,7 +31,18 @@ public class TranslationHandler extends JsonSerializer<Object> implements Contex
|
||||
*/
|
||||
public static final Map<String, TranslationInterface<?>> TRANSLATION_MAPPER = new ConcurrentHashMap<>();
|
||||
|
||||
private Translation translation;
|
||||
private final Translation translation;
|
||||
|
||||
/**
|
||||
* 提供给 jackson 创建上下文序列化器时使用 不然会报错
|
||||
*/
|
||||
public TranslationHandler() {
|
||||
this.translation = null;
|
||||
}
|
||||
|
||||
public TranslationHandler(Translation translation) {
|
||||
this.translation = translation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
@@ -63,8 +74,7 @@ public class TranslationHandler extends JsonSerializer<Object> implements Contex
|
||||
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
|
||||
Translation translation = property.getAnnotation(Translation.class);
|
||||
if (Objects.nonNull(translation)) {
|
||||
this.translation = translation;
|
||||
return this;
|
||||
return new TranslationHandler(translation);
|
||||
}
|
||||
return prov.findValueSerializer(property.getType(), property);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.dromara.common.translation.constant.TransConstant;
|
||||
import org.dromara.common.translation.core.TranslationInterface;
|
||||
|
||||
/**
|
||||
* 用户名称翻译实现
|
||||
* 用户昵称翻译实现
|
||||
*
|
||||
* @author may
|
||||
*/
|
||||
@@ -20,7 +20,7 @@ public class NicknameTranslationImpl implements TranslationInterface<String> {
|
||||
@Override
|
||||
public String translation(Object key, String other) {
|
||||
if (key instanceof Long id) {
|
||||
return userService.selectNicknameByIds(id.toString());
|
||||
return userService.selectNicknameById(id);
|
||||
} else if (key instanceof String ids) {
|
||||
return userService.selectNicknameByIds(ids);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.dromara.common.translation.core.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import org.dromara.common.core.service.UserService;
|
||||
import org.dromara.common.translation.annotation.TranslationType;
|
||||
import org.dromara.common.translation.constant.TransConstant;
|
||||
@@ -19,9 +20,6 @@ public class UserNameTranslationImpl implements TranslationInterface<String> {
|
||||
|
||||
@Override
|
||||
public String translation(Object key, String other) {
|
||||
if (key instanceof Long id) {
|
||||
return userService.selectUserNameById(id);
|
||||
}
|
||||
return null;
|
||||
return userService.selectUserNameById(Convert.toLong(key));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
package org.dromara.common.web.config;
|
||||
|
||||
import cn.hutool.captcha.CaptchaUtil;
|
||||
import cn.hutool.captcha.CircleCaptcha;
|
||||
import cn.hutool.captcha.LineCaptcha;
|
||||
import cn.hutool.captcha.ShearCaptcha;
|
||||
import org.dromara.common.web.config.properties.CaptchaProperties;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* 验证码配置
|
||||
@@ -21,45 +13,4 @@ import java.awt.*;
|
||||
@EnableConfigurationProperties(CaptchaProperties.class)
|
||||
public class CaptchaConfig {
|
||||
|
||||
private static final int WIDTH = 160;
|
||||
private static final int HEIGHT = 60;
|
||||
private static final Color BACKGROUND = Color.LIGHT_GRAY;
|
||||
private static final Font FONT = new Font("Arial", Font.BOLD, 48);
|
||||
|
||||
/**
|
||||
* 圆圈干扰验证码
|
||||
*/
|
||||
@Lazy
|
||||
@Bean
|
||||
public CircleCaptcha circleCaptcha() {
|
||||
CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(WIDTH, HEIGHT);
|
||||
captcha.setBackground(BACKGROUND);
|
||||
captcha.setFont(FONT);
|
||||
return captcha;
|
||||
}
|
||||
|
||||
/**
|
||||
* 线段干扰的验证码
|
||||
*/
|
||||
@Lazy
|
||||
@Bean
|
||||
public LineCaptcha lineCaptcha() {
|
||||
LineCaptcha captcha = CaptchaUtil.createLineCaptcha(WIDTH, HEIGHT);
|
||||
captcha.setBackground(BACKGROUND);
|
||||
captcha.setFont(FONT);
|
||||
return captcha;
|
||||
}
|
||||
|
||||
/**
|
||||
* 扭曲干扰验证码
|
||||
*/
|
||||
@Lazy
|
||||
@Bean
|
||||
public ShearCaptcha shearCaptcha() {
|
||||
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(WIDTH, HEIGHT);
|
||||
captcha.setBackground(BACKGROUND);
|
||||
captcha.setFont(FONT);
|
||||
return captcha;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package org.dromara.common.web.config;
|
||||
|
||||
import io.undertow.UndertowOptions;
|
||||
import io.undertow.server.DefaultByteBufferPool;
|
||||
import io.undertow.server.handlers.DisallowedMethodsHandler;
|
||||
import io.undertow.util.HttpString;
|
||||
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||
@@ -18,6 +21,9 @@ import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||
@AutoConfiguration
|
||||
public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
|
||||
|
||||
@Autowired
|
||||
private ServerProperties serverProperties;
|
||||
|
||||
/**
|
||||
* 自定义 Undertow 配置
|
||||
* <p>
|
||||
@@ -31,6 +37,11 @@ public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServle
|
||||
*/
|
||||
@Override
|
||||
public void customize(UndertowServletWebServerFactory factory) {
|
||||
long bytes = serverProperties.getUndertow().getMaxHttpPostSize().toBytes();
|
||||
factory.addBuilderCustomizers(builder -> {
|
||||
builder.setServerOption(UndertowOptions.MULTIPART_MAX_ENTITY_SIZE, bytes);
|
||||
});
|
||||
|
||||
factory.addDeploymentInfoCustomizers(deploymentInfo -> {
|
||||
// 配置 WebSocket 部署信息,设置 WebSocket 使用的缓冲区池
|
||||
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.dromara.common.web.config.properties;
|
||||
|
||||
import org.dromara.common.web.enums.CaptchaCategory;
|
||||
import org.dromara.common.web.enums.CaptchaType;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@@ -19,12 +17,7 @@ public class CaptchaProperties {
|
||||
/**
|
||||
* 验证码类型
|
||||
*/
|
||||
private CaptchaType type;
|
||||
|
||||
/**
|
||||
* 验证码类别
|
||||
*/
|
||||
private CaptchaCategory category;
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 数字验证码位数
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
package org.dromara.common.web.core;
|
||||
|
||||
import cn.hutool.captcha.AbstractCaptcha;
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.captcha.generator.RandomGenerator;
|
||||
import cn.hutool.core.img.GraphicsUtil;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.Serial;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* 带干扰线、波浪、圆的验证码
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public class WaveAndCircleCaptcha extends AbstractCaptcha {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// 构造方法(略,与之前一致)
|
||||
public WaveAndCircleCaptcha(int width, int height) {
|
||||
this(width, height, 4);
|
||||
}
|
||||
|
||||
public WaveAndCircleCaptcha(int width, int height, int codeCount) {
|
||||
this(width, height, codeCount, 6);
|
||||
}
|
||||
|
||||
public WaveAndCircleCaptcha(int width, int height, int codeCount, int interfereCount) {
|
||||
this(width, height, new RandomGenerator(codeCount), interfereCount);
|
||||
}
|
||||
|
||||
public WaveAndCircleCaptcha(int width, int height, CodeGenerator generator, int interfereCount) {
|
||||
super(width, height, generator, interfereCount);
|
||||
}
|
||||
|
||||
public WaveAndCircleCaptcha(int width, int height, int codeCount, int interfereCount, float size) {
|
||||
super(width, height, new RandomGenerator(codeCount), interfereCount, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image createImage(String code) {
|
||||
final BufferedImage image = new BufferedImage(
|
||||
width,
|
||||
height,
|
||||
(null == this.background) ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_INT_RGB
|
||||
);
|
||||
final Graphics2D g = ImgUtil.createGraphics(image, this.background);
|
||||
|
||||
try {
|
||||
drawString(g, code);
|
||||
// 扭曲
|
||||
shear(g, this.width, this.height, ObjectUtil.defaultIfNull(this.background, Color.WHITE));
|
||||
drawInterfere(g);
|
||||
} finally {
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
private void drawString(Graphics2D g, String code) {
|
||||
// 设置抗锯齿(让字体渲染更清晰)
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
if (this.textAlpha != null) {
|
||||
g.setComposite(this.textAlpha);
|
||||
}
|
||||
|
||||
GraphicsUtil.drawStringColourful(g, code, this.font, this.width, this.height);
|
||||
}
|
||||
|
||||
protected void drawInterfere(Graphics2D g) {
|
||||
ThreadLocalRandom random = RandomUtil.getRandom();
|
||||
int circleCount = Math.max(0, this.interfereCount - 1);
|
||||
|
||||
// 圈圈
|
||||
for (int i = 0; i < circleCount; i++) {
|
||||
g.setColor(ImgUtil.randomColor(random));
|
||||
int x = random.nextInt(width);
|
||||
int y = random.nextInt(height);
|
||||
int w = random.nextInt(height >> 1);
|
||||
int h = random.nextInt(height >> 1);
|
||||
g.drawOval(x, y, w, h);
|
||||
}
|
||||
|
||||
// 仅 1 条平滑波浪线
|
||||
if (this.interfereCount >= 1) {
|
||||
g.setColor(getRandomColor(120, 230, random));
|
||||
drawSmoothWave(g, random);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawSmoothWave(Graphics2D g, ThreadLocalRandom random) {
|
||||
int amplitude = random.nextInt(8) + 5; // 波动幅度
|
||||
int wavelength = random.nextInt(40) + 30; // 波长
|
||||
double phase = random.nextDouble() * Math.PI * 2;
|
||||
|
||||
// ✅ 关键:限制 baseY 在中间区域
|
||||
int centerY = height / 2;
|
||||
int verticalJitter = Math.max(5, height / 6); // 至少偏移5像素
|
||||
int baseY = centerY - verticalJitter + random.nextInt(verticalJitter * 2);
|
||||
|
||||
g.setStroke(new BasicStroke(2.5f)); // 线宽
|
||||
|
||||
int[] xPoints = new int[width];
|
||||
int[] yPoints = new int[width];
|
||||
for (int x = 0; x < width; x++) {
|
||||
int y = baseY + (int) (amplitude * Math.sin((double) x / wavelength * 2 * Math.PI + phase));
|
||||
// 限制 y 不要超出图像边界(可选)
|
||||
y = Math.max(amplitude, Math.min(y, height - amplitude));
|
||||
xPoints[x] = x;
|
||||
yPoints[x] = y;
|
||||
}
|
||||
g.drawPolyline(xPoints, yPoints, width);
|
||||
}
|
||||
|
||||
private Color getRandomColor(int min, int max, ThreadLocalRandom random) {
|
||||
int range = max - min;
|
||||
return new Color(
|
||||
min + random.nextInt(range),
|
||||
min + random.nextInt(range),
|
||||
min + random.nextInt(range)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扭曲
|
||||
*
|
||||
* @param g {@link Graphics}
|
||||
* @param w1 w1
|
||||
* @param h1 h1
|
||||
* @param color 颜色
|
||||
*/
|
||||
private void shear(Graphics g, int w1, int h1, Color color) {
|
||||
shearX(g, w1, h1, color);
|
||||
shearY(g, w1, h1, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* X坐标扭曲
|
||||
*
|
||||
* @param g {@link Graphics}
|
||||
* @param w1 宽
|
||||
* @param h1 高
|
||||
* @param color 颜色
|
||||
*/
|
||||
private void shearX(Graphics g, int w1, int h1, Color color) {
|
||||
|
||||
int period = RandomUtil.randomInt(this.width);
|
||||
|
||||
int frames = 1;
|
||||
int phase = RandomUtil.randomInt(2);
|
||||
|
||||
for (int i = 0; i < h1; i++) {
|
||||
double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
|
||||
g.copyArea(0, i, w1, 1, (int) d, 0);
|
||||
g.setColor(color);
|
||||
g.drawLine((int) d, i, 0, i);
|
||||
g.drawLine((int) d + w1, i, w1, i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Y坐标扭曲
|
||||
*
|
||||
* @param g {@link Graphics}
|
||||
* @param w1 宽
|
||||
* @param h1 高
|
||||
* @param color 颜色
|
||||
*/
|
||||
private void shearY(Graphics g, int w1, int h1, Color color) {
|
||||
|
||||
int period = RandomUtil.randomInt(this.height >> 1);
|
||||
|
||||
int frames = 20;
|
||||
int phase = 7;
|
||||
for (int i = 0; i < w1; i++) {
|
||||
double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
|
||||
g.copyArea(i, 0, 1, h1, 0, (int) d);
|
||||
g.setColor(color);
|
||||
// 擦除原位置的痕迹
|
||||
g.drawLine(i, (int) d, i, 0);
|
||||
g.drawLine(i, (int) d + h1, i, h1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package org.dromara.common.web.enums;
|
||||
|
||||
import cn.hutool.captcha.AbstractCaptcha;
|
||||
import cn.hutool.captcha.CircleCaptcha;
|
||||
import cn.hutool.captcha.LineCaptcha;
|
||||
import cn.hutool.captcha.ShearCaptcha;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 验证码类别
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum CaptchaCategory {
|
||||
|
||||
/**
|
||||
* 线段干扰
|
||||
*/
|
||||
LINE(LineCaptcha.class),
|
||||
|
||||
/**
|
||||
* 圆圈干扰
|
||||
*/
|
||||
CIRCLE(CircleCaptcha.class),
|
||||
|
||||
/**
|
||||
* 扭曲干扰
|
||||
*/
|
||||
SHEAR(ShearCaptcha.class);
|
||||
|
||||
private final Class<? extends AbstractCaptcha> clazz;
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package org.dromara.common.web.enums;
|
||||
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.captcha.generator.MathGenerator;
|
||||
import cn.hutool.captcha.generator.RandomGenerator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 验证码类型
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum CaptchaType {
|
||||
|
||||
/**
|
||||
* 数字
|
||||
*/
|
||||
MATH(MathGenerator.class),
|
||||
|
||||
/**
|
||||
* 字符
|
||||
*/
|
||||
CHAR(RandomGenerator.class);
|
||||
|
||||
private final Class<? extends CodeGenerator> clazz;
|
||||
}
|
||||
@@ -14,7 +14,9 @@ import org.dromara.common.core.exception.SseException;
|
||||
import org.dromara.common.core.exception.base.BaseException;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.springframework.context.MessageSourceResolvable;
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.expression.ExpressionException;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
@@ -24,6 +26,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.context.request.async.AsyncRequestTimeoutException;
|
||||
import org.springframework.web.method.annotation.HandlerMethodValidationException;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
import org.springframework.web.servlet.NoHandlerFoundException;
|
||||
|
||||
@@ -43,7 +46,7 @@ public class GlobalExceptionHandler {
|
||||
*/
|
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||
public R<Void> handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e,
|
||||
HttpServletRequest request) {
|
||||
HttpServletRequest request) {
|
||||
String requestURI = request.getRequestURI();
|
||||
log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
|
||||
return R.fail(HttpStatus.HTTP_BAD_METHOD, e.getMessage());
|
||||
@@ -190,6 +193,16 @@ public class GlobalExceptionHandler {
|
||||
return R.fail(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法参数校验异常 用于处理 @Validated 注解
|
||||
*/
|
||||
@ExceptionHandler(HandlerMethodValidationException.class)
|
||||
public R<Void> handlerMethodValidationException(HandlerMethodValidationException e) {
|
||||
log.error(e.getMessage());
|
||||
String message = StreamUtils.join(e.getAllErrors(), MessageSourceResolvable::getDefaultMessage, ", ");
|
||||
return R.fail(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON 解析异常(Jackson 在处理 JSON 格式出错时抛出)
|
||||
* 可能是请求体格式非法,也可能是服务端反序列化失败
|
||||
@@ -210,4 +223,13 @@ public class GlobalExceptionHandler {
|
||||
return R.fail(HttpStatus.HTTP_BAD_REQUEST, "请求参数格式错误:" + e.getMostSpecificCause().getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* SpEL 表达式相关异常
|
||||
*/
|
||||
@ExceptionHandler(ExpressionException.class)
|
||||
public R<Void> handleSpelException(ExpressionException e, HttpServletRequest request) {
|
||||
log.error("请求地址'{}',SpEL解析异常: {}", request.getRequestURI(), e.getMessage());
|
||||
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, "SpEL解析失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,17 @@ package org.dromara.common.web.interceptor;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.time.StopWatch;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.web.filter.RepeatedlyRequestWrapper;
|
||||
@@ -14,8 +20,10 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* web的调用时间统计拦截器
|
||||
@@ -31,19 +39,25 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
String url = request.getMethod() + " " + request.getRequestURI();
|
||||
|
||||
// 打印请求参数
|
||||
if (isJsonRequest(request)) {
|
||||
String jsonParam = "";
|
||||
if (request instanceof RepeatedlyRequestWrapper) {
|
||||
BufferedReader reader = request.getReader();
|
||||
jsonParam = IoUtil.read(reader);
|
||||
jsonParam = IoUtil.read(request.getReader());
|
||||
if (StringUtils.isNotBlank(jsonParam)) {
|
||||
ObjectMapper objectMapper = JsonUtils.getObjectMapper();
|
||||
JsonNode rootNode = objectMapper.readTree(jsonParam);
|
||||
removeSensitiveFields(rootNode, SystemConstants.EXCLUDE_PROPERTIES);
|
||||
jsonParam = rootNode.toString();
|
||||
}
|
||||
}
|
||||
log.info("[PLUS]开始请求 => URL[{}],参数类型[json],参数:[{}]", url, jsonParam);
|
||||
} else {
|
||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
if (MapUtil.isNotEmpty(parameterMap)) {
|
||||
String parameters = JsonUtils.toJsonString(parameterMap);
|
||||
Map<String, String[]> map = new LinkedHashMap<>(parameterMap);
|
||||
MapUtil.removeAny(map, SystemConstants.EXCLUDE_PROPERTIES);
|
||||
String parameters = JsonUtils.toJsonString(map);
|
||||
log.info("[PLUS]开始请求 => URL[{}],参数类型[param],参数:[{}]", url, parameters);
|
||||
} else {
|
||||
log.info("[PLUS]开始请求 => URL[{}],无参数", url);
|
||||
@@ -57,6 +71,30 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void removeSensitiveFields(JsonNode node, String[] excludeProperties) {
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
if (node.isObject()) {
|
||||
ObjectNode objectNode = (ObjectNode) node;
|
||||
// 收集要删除的字段名(避免 ConcurrentModification)
|
||||
Set<String> fieldsToRemove = new HashSet<>();
|
||||
objectNode.fieldNames().forEachRemaining(fieldName -> {
|
||||
if (ArrayUtil.contains(excludeProperties, fieldName)) {
|
||||
fieldsToRemove.add(fieldName);
|
||||
}
|
||||
});
|
||||
fieldsToRemove.forEach(objectNode::remove);
|
||||
// 递归处理子节点
|
||||
objectNode.elements().forEachRemaining(child -> removeSensitiveFields(child, excludeProperties));
|
||||
} else if (node.isArray()) {
|
||||
ArrayNode arrayNode = (ArrayNode) node;
|
||||
for (JsonNode child : arrayNode) {
|
||||
removeSensitiveFields(child, excludeProperties);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.dromara.common.websocket.holder.WebSocketSessionHolder;
|
||||
import org.dromara.common.websocket.utils.WebSocketUtils;
|
||||
import org.springframework.web.socket.*;
|
||||
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
import org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -33,7 +34,7 @@ public class PlusWebSocketHandler extends AbstractWebSocketHandler {
|
||||
log.info("[connect] invalid token received. sessionId: {}", session.getId());
|
||||
return;
|
||||
}
|
||||
WebSocketSessionHolder.addSession(loginUser.getUserId(), session);
|
||||
WebSocketSessionHolder.addSession(loginUser.getUserId(), new ConcurrentWebSocketSessionDecorator(session, 10 * 1000, 64000));
|
||||
log.info("[connect] sessionId: {},userId:{},userType:{}", session.getId(), loginUser.getUserId(), loginUser.getUserType());
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ public class WebSocketUtils {
|
||||
* @param session WebSocket会话
|
||||
* @param message 要发送的WebSocket消息对象
|
||||
*/
|
||||
private synchronized static void sendMessage(WebSocketSession session, WebSocketMessage<?> message) {
|
||||
private static void sendMessage(WebSocketSession session, WebSocketMessage<?> message) {
|
||||
if (session == null || !session.isOpen()) {
|
||||
log.warn("[send] session会话已经关闭");
|
||||
} else {
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
package com.aizuda.snailjob.server.common.register;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.snailjob.common.core.enums.NodeTypeEnum;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
import com.aizuda.snailjob.common.core.util.NetUtil;
|
||||
import com.aizuda.snailjob.common.core.util.SnailJobVersion;
|
||||
import com.aizuda.snailjob.common.core.util.StreamUtils;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.aizuda.snailjob.server.common.cache.CacheConsumerGroup;
|
||||
import com.aizuda.snailjob.server.common.config.SystemProperties;
|
||||
import com.aizuda.snailjob.server.common.convert.RegisterNodeInfoConverter;
|
||||
import com.aizuda.snailjob.server.common.dto.ServerNodeExtAttrs;
|
||||
import com.aizuda.snailjob.server.common.handler.InstanceManager;
|
||||
import com.aizuda.snailjob.template.datasource.persistence.po.ServerNode;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 服务端注册
|
||||
*
|
||||
* @author opensnail
|
||||
* @date 2023-06-07
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@Component(ServerRegister.BEAN_NAME)
|
||||
@RequiredArgsConstructor
|
||||
public class ServerRegister extends AbstractRegister {
|
||||
public static final String BEAN_NAME = "serverRegister";
|
||||
private final ScheduledExecutorService serverRegisterNode = Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "server-register-node"));
|
||||
public static final int DELAY_TIME = 30;
|
||||
public static final String CURRENT_CID;
|
||||
public static final String GROUP_NAME = "DEFAULT_SERVER";
|
||||
public static final String NAMESPACE_ID = "DEFAULT_SERVER_NAMESPACE_ID";
|
||||
private final InstanceManager instanceManager;
|
||||
private final SystemProperties systemProperties;
|
||||
private final ServerProperties serverProperties;
|
||||
|
||||
static {
|
||||
CURRENT_CID = IdUtil.getSnowflakeNextIdStr();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(int type) {
|
||||
return getNodeType().equals(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beforeProcessor(RegisterContext context) {
|
||||
// 新增扩展参数
|
||||
ServerNodeExtAttrs serverNodeExtAttrs = new ServerNodeExtAttrs();
|
||||
serverNodeExtAttrs.setWebPort(serverProperties.getPort());
|
||||
serverNodeExtAttrs.setSystemVersion(SnailJobVersion.getVersion());
|
||||
|
||||
context.setGroupName(GROUP_NAME);
|
||||
context.setHostId(CURRENT_CID);
|
||||
String serverHost = systemProperties.getServerHost();
|
||||
if (StrUtil.isEmptyIfStr(serverHost)) {
|
||||
serverHost = NetUtil.getLocalIpStr();
|
||||
}
|
||||
context.setHostIp(serverHost);
|
||||
context.setHostPort(systemProperties.getServerPort());
|
||||
context.setContextPath(Optional.ofNullable(serverProperties.getServlet().getContextPath()).orElse(StrUtil.EMPTY));
|
||||
context.setNamespaceId(NAMESPACE_ID);
|
||||
context.setExtAttrs(JsonUtil.toJsonString(serverNodeExtAttrs));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalDateTime getExpireAt() {
|
||||
return LocalDateTime.now().plusSeconds(DELAY_TIME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doRegister(RegisterContext context, ServerNode serverNode) {
|
||||
refreshExpireAt(Lists.newArrayList(serverNode));
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void afterProcessor(final ServerNode serverNode) {
|
||||
try {
|
||||
// 同步当前POD消费的组的节点信息
|
||||
// netty的client只会注册到一个服务端,若组分配的和client连接的不是一个POD则会导致当前POD没有其他客户端的注册信息
|
||||
ConcurrentMap<String /*groupName*/, Set<String>/*namespaceId*/> allConsumerGroupName = CacheConsumerGroup.getAllConsumerGroupName();
|
||||
if (CollUtil.isNotEmpty(allConsumerGroupName)) {
|
||||
Set<String> namespaceIdSets = StreamUtils.toSetByFlatMap(allConsumerGroupName.values(), Set::stream);
|
||||
if (CollUtil.isEmpty(namespaceIdSets)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ServerNode> serverNodes = serverNodeMapper.selectList(
|
||||
new LambdaQueryWrapper<ServerNode>()
|
||||
.eq(ServerNode::getNodeType, NodeTypeEnum.CLIENT.getType())
|
||||
.in(ServerNode::getNamespaceId, namespaceIdSets)
|
||||
.in(ServerNode::getGroupName, allConsumerGroupName.keySet()));
|
||||
for (final ServerNode node : serverNodes) {
|
||||
// 刷新全量本地缓存
|
||||
instanceManager.registerOrUpdate(RegisterNodeInfoConverter.INSTANCE.toRegisterNodeInfo(node));
|
||||
// 刷新过期时间
|
||||
CacheConsumerGroup.addOrUpdate(node.getGroupName(), node.getNamespaceId());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SnailJobLog.LOCAL.error("Client refresh failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer getNodeType() {
|
||||
return NodeTypeEnum.SERVER.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
SnailJobLog.LOCAL.info("ServerRegister start");
|
||||
|
||||
serverRegisterNode.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
this.register(new RegisterContext());
|
||||
} catch (Exception e) {
|
||||
SnailJobLog.LOCAL.error("Server-side registration failed", e);
|
||||
}
|
||||
}, 0, DELAY_TIME * 2 / 3, TimeUnit.SECONDS);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
SnailJobLog.LOCAL.info("ServerRegister close");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package org.dromara.demo.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* SaToken 权限测试 接口文档输出测试
|
||||
*
|
||||
* @author AprilWind
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/demo/saTokenDoc")
|
||||
public class SaTokenTestController {
|
||||
|
||||
// ====================== 基础场景:单一校验规则 ======================
|
||||
|
||||
/**
|
||||
* 场景1:仅登录校验(无角色/权限限制,只需登录态)
|
||||
*/
|
||||
@SaCheckLogin
|
||||
@GetMapping("/basic/loginOnly")
|
||||
public R<Void> loginOnly() {
|
||||
log.info("【场景1】仅登录校验通过");
|
||||
return R.ok("仅登录校验通过,无需角色/权限");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景2:单一角色校验(AND模式,默认)
|
||||
*/
|
||||
@SaCheckRole("admin")
|
||||
@GetMapping("/basic/singleRole")
|
||||
public R<Void> singleRole() {
|
||||
log.info("【场景2】单一角色(admin)校验通过");
|
||||
return R.ok("拥有admin角色,校验通过");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景3:单一权限校验(AND模式,默认)
|
||||
*/
|
||||
@SaCheckPermission("system:user:view")
|
||||
@GetMapping("/basic/singlePermission")
|
||||
public R<Void> singlePermission() {
|
||||
log.info("【场景3】单一权限(system:user:view)校验通过");
|
||||
return R.ok("拥有system:user:view权限,校验通过");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景4:忽略所有权限校验(SaIgnore优先级最高)
|
||||
*/
|
||||
@SaIgnore
|
||||
@SaCheckRole("none_exist") // 该注解会被忽略
|
||||
@GetMapping("/basic/ignoreAll")
|
||||
public R<Void> ignoreAll() {
|
||||
log.info("【场景4】SaIgnore忽略所有权限校验");
|
||||
return R.ok("SaIgnore生效,所有权限校验被忽略");
|
||||
}
|
||||
|
||||
// ====================== 进阶场景:多条件组合(AND/OR) ======================
|
||||
|
||||
/**
|
||||
* 场景5:多角色AND模式(必须同时拥有所有角色)
|
||||
*/
|
||||
@SaCheckRole(value = {"admin", "operator"}, mode = SaMode.AND)
|
||||
@GetMapping("/advance/multiRoleAnd")
|
||||
public R<Void> multiRoleAnd() {
|
||||
log.info("【场景5】多角色AND模式(admin+operator)校验通过");
|
||||
return R.ok("同时拥有admin和operator角色,校验通过");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景6:多角色OR模式(拥有任一角色即可)
|
||||
*/
|
||||
@SaCheckRole(value = {"admin", "test"}, mode = SaMode.OR)
|
||||
@GetMapping("/advance/multiRoleOr")
|
||||
public R<Void> multiRoleOr() {
|
||||
log.info("【场景6】多角色OR模式(admin|test)校验通过");
|
||||
return R.ok("拥有admin或test角色,校验通过");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景7:多权限AND模式(必须同时拥有所有权限)
|
||||
*/
|
||||
@SaCheckPermission(value = {"system:user:edit", "system:log:view"}, mode = SaMode.AND)
|
||||
@GetMapping("/advance/multiPermAnd")
|
||||
public R<Void> multiPermAnd() {
|
||||
log.info("【场景7】多权限AND模式(system:user:edit+system:log:view)校验通过");
|
||||
return R.ok("同时拥有system:user:edit和system:log:view权限,校验通过");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景8:多权限OR模式(拥有任一权限即可)
|
||||
*/
|
||||
@SaCheckPermission(value = {"system:user:add", "system:user:delete"}, mode = SaMode.OR)
|
||||
@GetMapping("/advance/multiPermOr")
|
||||
public R<Void> multiPermOr() {
|
||||
log.info("【场景8】多权限OR模式(system:user:add|system:user:delete)校验通过");
|
||||
return R.ok("拥有system:user:add或system:user:delete权限,校验通过");
|
||||
}
|
||||
|
||||
// ====================== 高级场景:通配符/混合组合 ======================
|
||||
|
||||
/**
|
||||
* 场景9:权限通配符匹配(前缀匹配)
|
||||
* 拥有system:user:* 即可匹配所有用户模块权限
|
||||
*/
|
||||
@SaCheckPermission("system:user:*")
|
||||
@GetMapping("/advanced/permWildcardPrefix")
|
||||
public R<Void> permWildcardPrefix() {
|
||||
log.info("【场景9】权限通配符(system:user:*)校验通过");
|
||||
return R.ok("拥有system:user:*前缀权限,校验通过");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景10:角色通配符匹配(前缀匹配)
|
||||
* 拥有admin_* 即可匹配所有admin开头的角色
|
||||
*/
|
||||
@SaCheckRole("admin_*")
|
||||
@GetMapping("/advanced/roleWildcardPrefix")
|
||||
public R<Void> roleWildcardPrefix() {
|
||||
log.info("【场景10】角色通配符(admin_*)校验通过");
|
||||
return R.ok("拥有admin_*前缀角色,校验通过");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景11:权限+角色混合AND模式(所有条件必须满足)
|
||||
* 需同时满足:拥有admin角色 + 拥有system:user:all权限
|
||||
*/
|
||||
@SaCheckRole("admin")
|
||||
@SaCheckPermission("system:user:all")
|
||||
@GetMapping("/advanced/mixRolePermAnd")
|
||||
public R<Void> mixRolePermAnd() {
|
||||
log.info("【场景11】角色+权限混合AND(admin+system:user:all)校验通过");
|
||||
return R.ok("拥有admin角色且拥有system:user:all权限,校验通过");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景12:权限+角色混合OR模式(任一条件满足即可)
|
||||
* 满足任一:拥有super_admin角色 | 拥有system:manage权限
|
||||
*/
|
||||
@SaCheckRole(value = {"super_admin"}, mode = SaMode.OR)
|
||||
@SaCheckPermission(value = {"system:manage"}, mode = SaMode.OR)
|
||||
@GetMapping("/advanced/mixRolePermOr")
|
||||
public R<Void> mixRolePermOr() {
|
||||
log.info("【场景12】角色+权限混合OR(super_admin|system:manage)校验通过");
|
||||
return R.ok("拥有super_admin角色或system:manage权限,校验通过");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景13:orRole参数(权限校验失败时,兜底角色校验)
|
||||
* 核心逻辑:无system:user:export权限时,检查是否有admin/operator角色
|
||||
*/
|
||||
@SaCheckPermission(value = "system:user:export", orRole = {"admin", "operator"})
|
||||
@GetMapping("/advanced/permWithOrRole")
|
||||
public R<Void> permWithOrRole() {
|
||||
log.info("【场景13】权限+orRole兜底校验通过");
|
||||
return R.ok("拥有system:user:export权限,或拥有admin/operator角色,校验通过");
|
||||
}
|
||||
|
||||
// ====================== 特殊场景:临时权限/注解覆盖 ======================
|
||||
|
||||
/**
|
||||
* 场景14:SaIgnore局部覆盖(方法注解覆盖类注解,若有)
|
||||
* 假设类上有@SaCheckLogin,方法上@SaIgnore会覆盖
|
||||
*/
|
||||
@SaIgnore
|
||||
@GetMapping("/special/ignoreOverride")
|
||||
public R<Void> ignoreOverride() {
|
||||
log.info("【场景14】SaIgnore覆盖类级别权限注解");
|
||||
return R.ok("方法级SaIgnore覆盖类级别权限校验");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景15:临时权限校验(SaCheckPermission逻辑:临时权限>永久权限)
|
||||
* 注:临时权限需通过SaToken API手动设置,如 SaHolder.getStpLogic().setTempPermission("system:temp:test")
|
||||
*/
|
||||
@SaCheckPermission("system:temp:test")
|
||||
@GetMapping("/special/tempPermission")
|
||||
public R<Void> tempPermission() {
|
||||
log.info("【场景15】临时权限(system:temp:test)校验通过");
|
||||
return R.ok("临时权限校验通过(需先通过API设置临时权限)");
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景16:登录类型指定(多端登录场景,如PC/APP/小程序)
|
||||
* 注:需配合SaToken多账号体系配置
|
||||
*/
|
||||
@SaCheckLogin(type = "PC") // 仅校验PC端的登录态
|
||||
@GetMapping("/special/loginTypeSpecify")
|
||||
public R<Void> loginTypeSpecify() {
|
||||
log.info("【场景16】指定登录类型(PC)校验通过");
|
||||
return R.ok("仅PC端登录态校验通过");
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import org.dromara.common.log.annotation.Log;
|
||||
import org.dromara.common.log.enums.BusinessType;
|
||||
import org.dromara.demo.domain.TestDemo;
|
||||
import org.dromara.demo.domain.bo.TestDemoBo;
|
||||
import org.dromara.demo.domain.bo.TestDemoImportVo;
|
||||
import org.dromara.demo.domain.vo.TestDemoImportVo;
|
||||
import org.dromara.demo.domain.vo.TestDemoVo;
|
||||
import org.dromara.demo.service.ITestDemoService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -35,8 +35,8 @@ public class ExportDemoVo implements Serializable {
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@ExcelProperty(value = "用户名", index = 0)
|
||||
@NotEmpty(message = "用户名不能为空", groups = AddGroup.class)
|
||||
@ExcelProperty(value = "用户昵称", index = 0)
|
||||
@NotEmpty(message = "用户昵称不能为空", groups = AddGroup.class)
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package org.dromara.demo.domain.bo;
|
||||
package org.dromara.demo.domain.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.dromara.demo.domain.TestDemo;
|
||||
|
||||
/**
|
||||
* 测试单表业务对象 test_demo
|
||||
@@ -13,6 +15,7 @@ import jakarta.validation.constraints.NotNull;
|
||||
* @date 2021-07-26
|
||||
*/
|
||||
@Data
|
||||
@AutoMapper(target = TestDemo.class)
|
||||
public class TestDemoImportVo {
|
||||
|
||||
/**
|
||||
@@ -62,6 +62,8 @@ public class TestDemoServiceImpl implements ITestDemoService {
|
||||
private LambdaQueryWrapper<TestDemo> buildQueryWrapper(TestDemoBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<TestDemo> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(bo.getDeptId() != null, TestDemo::getDeptId, bo.getDeptId());
|
||||
lqw.eq(bo.getUserId() != null, TestDemo::getUserId, bo.getUserId());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getTestKey()), TestDemo::getTestKey, bo.getTestKey());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getValue()), TestDemo::getValue, bo.getValue());
|
||||
lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.dromara.demo.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.demo.domain.TestTree;
|
||||
@@ -9,7 +10,6 @@ import org.dromara.demo.domain.bo.TestTreeBo;
|
||||
import org.dromara.demo.domain.vo.TestTreeVo;
|
||||
import org.dromara.demo.mapper.TestTreeMapper;
|
||||
import org.dromara.demo.service.ITestTreeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -44,6 +44,8 @@ public class TestTreeServiceImpl implements ITestTreeService {
|
||||
private LambdaQueryWrapper<TestTree> buildQueryWrapper(TestTreeBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<TestTree> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(bo.getDeptId() != null, TestTree::getDeptId, bo.getDeptId());
|
||||
lqw.eq(bo.getUserId() != null, TestTree::getUserId, bo.getUserId());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getTreeName()), TestTree::getTreeName, bo.getTreeName());
|
||||
lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
|
||||
TestTree::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime"));
|
||||
|
||||
@@ -90,10 +90,12 @@ public class GenController extends BaseController {
|
||||
/**
|
||||
* 导入表结构(保存)
|
||||
*
|
||||
* @param tables 表名串
|
||||
* @param tables 表名串
|
||||
* @param dataName 数据源名称
|
||||
*/
|
||||
@SaCheckPermission("tool:gen:import")
|
||||
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
|
||||
@Lock4j(keys = {"#dataName"}, acquireTimeout = 10000)
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/importTable")
|
||||
public R<Void> importTableSave(String tables, String dataName) {
|
||||
@@ -175,7 +177,7 @@ public class GenController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("tool:gen:edit")
|
||||
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
||||
@Lock4j
|
||||
@Lock4j(keys = {"#tableId"}, acquireTimeout = 5000)
|
||||
@GetMapping("/synchDb/{tableId}")
|
||||
public R<Void> synchDb(@PathVariable("tableId") Long tableId) {
|
||||
genTableService.synchDb(tableId);
|
||||
@@ -214,7 +216,7 @@ public class GenController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("tool:gen:list")
|
||||
@GetMapping(value = "/getDataNames")
|
||||
public R<Object> getCurrentDataSourceNameList(){
|
||||
public R<Object> getCurrentDataSourceNameList() {
|
||||
return R.ok(DataBaseHelper.getDataSourceNameList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,12 @@ import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 代码生成业务字段表 gen_table_column
|
||||
@@ -115,6 +114,7 @@ public class GenTableColumn extends BaseEntity {
|
||||
/**
|
||||
* 字典类型
|
||||
*/
|
||||
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
||||
private String dictType;
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -28,6 +27,7 @@ import org.dromara.common.core.utils.file.FileUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.mybatis.utils.IdGeneratorUtil;
|
||||
import org.dromara.generator.constant.GenConstants;
|
||||
import org.dromara.generator.domain.GenTable;
|
||||
import org.dromara.generator.domain.GenTableColumn;
|
||||
@@ -60,7 +60,6 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
|
||||
private final GenTableMapper baseMapper;
|
||||
private final GenTableColumnMapper genTableColumnMapper;
|
||||
private final IdentifierGenerator identifierGenerator;
|
||||
|
||||
private static final String[] TABLE_IGNORE = new String[]{"sj_", "flow_", "gen_"};
|
||||
|
||||
@@ -322,7 +321,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
GenTable table = baseMapper.selectGenTableById(tableId);
|
||||
List<Long> menuIds = new ArrayList<>();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
menuIds.add(identifierGenerator.nextId(null).longValue());
|
||||
menuIds.add(IdGeneratorUtil.nextLongId());
|
||||
}
|
||||
table.setMenuIds(menuIds);
|
||||
// 设置主键列信息
|
||||
@@ -468,7 +467,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
GenTable table = baseMapper.selectGenTableById(tableId);
|
||||
List<Long> menuIds = new ArrayList<>();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
menuIds.add(identifierGenerator.nextId(null).longValue());
|
||||
menuIds.add(IdGeneratorUtil.nextLongId());
|
||||
}
|
||||
table.setMenuIds(menuIds);
|
||||
// 设置主键列信息
|
||||
@@ -524,6 +523,9 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
* @param table 业务表信息
|
||||
*/
|
||||
public void setPkColumn(GenTable table) {
|
||||
if (CollUtil.isEmpty(table.getColumns())) {
|
||||
throw new ServiceException("表【" + table.getTableName() + "】字段为空,请检查表结构");
|
||||
}
|
||||
for (GenTableColumn column : table.getColumns()) {
|
||||
if (column.isPk()) {
|
||||
table.setPkColumn(column);
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.stream.IntStream;
|
||||
*
|
||||
* @author 老马
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Component
|
||||
@JobExecutor(name = "testMapJobAnnotation")
|
||||
public class TestMapJobAnnotation {
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.stream.IntStream;
|
||||
*
|
||||
* @author 老马
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Component
|
||||
@JobExecutor(name = "testMapReduceAnnotation1")
|
||||
public class TestMapReduceAnnotation1 {
|
||||
|
||||
@@ -83,7 +83,7 @@ public class SysDictDataController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增字典类型
|
||||
* 新增字典数据
|
||||
*/
|
||||
@SaCheckPermission("system:dict:add")
|
||||
@Log(title = "字典数据", businessType = BusinessType.INSERT)
|
||||
@@ -98,7 +98,7 @@ public class SysDictDataController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改保存字典类型
|
||||
* 修改保存字典数据
|
||||
*/
|
||||
@SaCheckPermission("system:dict:edit")
|
||||
@Log(title = "字典数据", businessType = BusinessType.UPDATE)
|
||||
@@ -113,12 +113,12 @@ public class SysDictDataController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字典类型
|
||||
* 删除字典数据
|
||||
*
|
||||
* @param dictCodes 字典code串
|
||||
*/
|
||||
@SaCheckPermission("system:dict:remove")
|
||||
@Log(title = "字典类型", businessType = BusinessType.DELETE)
|
||||
@Log(title = "字典数据", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{dictCodes}")
|
||||
public R<Void> remove(@PathVariable Long[] dictCodes) {
|
||||
dictDataService.deleteDictDataByIds(Arrays.asList(dictCodes));
|
||||
|
||||
@@ -137,6 +137,8 @@ public class SysMenuController extends BaseController {
|
||||
return R.fail("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
||||
} else if (SystemConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) {
|
||||
return R.fail("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
||||
} else if (!menuService.checkRouteConfigUnique(menu)) {
|
||||
return R.fail("新增菜单'" + menu.getMenuName() + "'失败,路由名称或地址已存在");
|
||||
}
|
||||
return toAjax(menuService.insertMenu(menu));
|
||||
}
|
||||
@@ -156,6 +158,8 @@ public class SysMenuController extends BaseController {
|
||||
return R.fail("修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
||||
} else if (menu.getMenuId().equals(menu.getParentId())) {
|
||||
return R.fail("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
|
||||
} else if (!menuService.checkRouteConfigUnique(menu)) {
|
||||
return R.fail("修改菜单'" + menu.getMenuName() + "'失败,路由名称或地址已存在");
|
||||
}
|
||||
return toAjax(menuService.updateMenu(menu));
|
||||
}
|
||||
|
||||
@@ -2,21 +2,20 @@ package org.dromara.system.controller.system;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.validate.QueryGroup;
|
||||
import org.dromara.common.web.core.BaseController;
|
||||
import org.dromara.common.log.annotation.Log;
|
||||
import org.dromara.common.log.enums.BusinessType;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.web.core.BaseController;
|
||||
import org.dromara.system.domain.bo.SysOssBo;
|
||||
import org.dromara.system.domain.vo.SysOssUploadVo;
|
||||
import org.dromara.system.domain.vo.SysOssVo;
|
||||
import org.dromara.system.service.ISysOssService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -70,9 +69,6 @@ public class SysOssController extends BaseController {
|
||||
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R<SysOssUploadVo> upload(@RequestPart("file") MultipartFile file) {
|
||||
if (ObjectUtil.isNull(file)) {
|
||||
return R.fail("上传文件不能为空");
|
||||
}
|
||||
SysOssVo oss = ossService.upload(file);
|
||||
SysOssUploadVo uploadVo = new SysOssUploadVo();
|
||||
uploadVo.setUrl(oss.getUrl());
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.dromara.system.controller.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
@@ -114,7 +115,7 @@ public class SysProfileController extends BaseController {
|
||||
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
||||
@PostMapping(value = "/avatar", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R<AvatarVo> avatar(@RequestPart("avatarfile") MultipartFile avatarfile) {
|
||||
if (!avatarfile.isEmpty()) {
|
||||
if (ObjectUtil.isNotNull(avatarfile) && !avatarfile.isEmpty()) {
|
||||
String extension = FileUtil.extName(avatarfile.getOriginalFilename());
|
||||
if (!StringUtils.equalsAnyIgnoreCase(extension, MimeTypeUtils.IMAGE_EXTENSION)) {
|
||||
return R.fail("文件格式不正确,请上传" + Arrays.toString(MimeTypeUtils.IMAGE_EXTENSION) + "格式");
|
||||
|
||||
@@ -130,11 +130,11 @@ public class SysMenu extends BaseEntity {
|
||||
public String getRouterPath() {
|
||||
String routerPath = this.path;
|
||||
// 内链打开外网方式
|
||||
if (getParentId() != 0L && isInnerLink()) {
|
||||
if (!Constants.TOP_PARENT_ID.equals(getParentId()) && isInnerLink()) {
|
||||
routerPath = innerLinkReplaceEach(routerPath);
|
||||
}
|
||||
// 非外链并且是一级目录(类型为目录)
|
||||
if (0L == getParentId() && SystemConstants.TYPE_DIR.equals(getMenuType())
|
||||
if (Constants.TOP_PARENT_ID.equals(getParentId()) && SystemConstants.TYPE_DIR.equals(getMenuType())
|
||||
&& SystemConstants.NO_FRAME.equals(getIsFrame())) {
|
||||
routerPath = "/" + this.path;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public class SysMenu extends BaseEntity {
|
||||
String component = SystemConstants.LAYOUT;
|
||||
if (StringUtils.isNotEmpty(this.component) && !isMenuFrame()) {
|
||||
component = this.component;
|
||||
} else if (StringUtils.isEmpty(this.component) && getParentId() != 0L && isInnerLink()) {
|
||||
} else if (StringUtils.isEmpty(this.component) && !Constants.TOP_PARENT_ID.equals(getParentId()) && isInnerLink()) {
|
||||
component = SystemConstants.INNER_LINK;
|
||||
} else if (StringUtils.isEmpty(this.component) && isParentView()) {
|
||||
component = SystemConstants.PARENT_VIEW;
|
||||
@@ -164,7 +164,7 @@ public class SysMenu extends BaseEntity {
|
||||
* 是否为菜单内部跳转
|
||||
*/
|
||||
public boolean isMenuFrame() {
|
||||
return getParentId() == 0L && SystemConstants.TYPE_MENU.equals(menuType) && isFrame.equals(SystemConstants.NO_FRAME);
|
||||
return Constants.TOP_PARENT_ID.equals(getParentId()) && SystemConstants.TYPE_MENU.equals(menuType) && isFrame.equals(SystemConstants.NO_FRAME);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +178,7 @@ public class SysMenu extends BaseEntity {
|
||||
* 是否为parent_view组件
|
||||
*/
|
||||
public boolean isParentView() {
|
||||
return getParentId() != 0L && SystemConstants.TYPE_DIR.equals(menuType);
|
||||
return !Constants.TOP_PARENT_ID.equals(getParentId()) && SystemConstants.TYPE_DIR.equals(menuType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,7 +78,7 @@ public class SysUser extends TenantEntity {
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
* 账号状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class SysUserOnline {
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
* 用户账号
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class SysUserBo extends BaseEntity {
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
* 账号状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
|
||||
@@ -34,13 +34,13 @@ public class SysUserExportVo implements Serializable {
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
@ExcelProperty(value = "登录名称")
|
||||
@ExcelProperty(value = "用户账号")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@ExcelProperty(value = "用户名称")
|
||||
@ExcelProperty(value = "用户昵称")
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
@@ -63,9 +63,9 @@ public class SysUserExportVo implements Serializable {
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
* 账号状态(0正常 1停用)
|
||||
*/
|
||||
@ExcelProperty(value = "帐号状态", converter = ExcelDictConvert.class)
|
||||
@ExcelProperty(value = "账号状态", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "sys_normal_disable")
|
||||
private String status;
|
||||
|
||||
|
||||
@@ -38,13 +38,13 @@ public class SysUserImportVo implements Serializable {
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
@ExcelProperty(value = "登录名称")
|
||||
@ExcelProperty(value = "用户账号")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@ExcelProperty(value = "用户名称")
|
||||
@ExcelProperty(value = "用户昵称")
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
@@ -67,9 +67,9 @@ public class SysUserImportVo implements Serializable {
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
* 账号状态(0正常 1停用)
|
||||
*/
|
||||
@ExcelProperty(value = "帐号状态", converter = ExcelDictConvert.class)
|
||||
@ExcelProperty(value = "账号状态", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "sys_normal_disable")
|
||||
private String status;
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public class SysUserVo implements Serializable {
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
* 账号状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
|
||||
@@ -160,4 +160,13 @@ public interface ISysMenuService {
|
||||
* @return 结果
|
||||
*/
|
||||
boolean checkMenuNameUnique(SysMenuBo menu);
|
||||
|
||||
/**
|
||||
* 校验路由组合是否唯一
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
boolean checkRouteConfigUnique(SysMenuBo menu);
|
||||
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public interface ISysUserService {
|
||||
String selectUserPostGroup(Long userId);
|
||||
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
* 校验用户账号是否唯一
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
@@ -174,7 +174,7 @@ public interface ISysUserService {
|
||||
* 修改用户状态
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param status 帐号状态
|
||||
* @param status 账号状态
|
||||
* @return 结果
|
||||
*/
|
||||
int updateUserStatus(Long userId, String status);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.dromara.system.service.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
@@ -14,6 +15,7 @@ import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.ObjectUtils;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.redis.utils.CacheUtils;
|
||||
@@ -82,6 +84,7 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
|
||||
|
||||
/**
|
||||
* 获取注册开关
|
||||
*
|
||||
* @param tenantId 租户id
|
||||
* @return true开启,false关闭
|
||||
*/
|
||||
@@ -212,4 +215,54 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
|
||||
return SpringUtils.getAopProxy(this).selectConfigByKey(configKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取 Map 类型的配置
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @return Dict 对象,如果配置为空或无法解析,返回空 Dict
|
||||
*/
|
||||
@Override
|
||||
public Dict getConfigMap(String configKey) {
|
||||
String configValue = getConfigValue(configKey);
|
||||
return JsonUtils.parseMap(configValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取 Map 类型的配置列表
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @return Dict 列表,如果配置为空或无法解析,返回空列表
|
||||
*/
|
||||
@Override
|
||||
public List<Dict> getConfigArrayMap(String configKey) {
|
||||
String configValue = getConfigValue(configKey);
|
||||
return JsonUtils.parseArrayMap(configValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取指定类型的配置对象
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @param clazz 目标对象类型
|
||||
* @return 对象实例,如果配置为空或无法解析,返回 null
|
||||
*/
|
||||
@Override
|
||||
public <T> T getConfigObject(String configKey, Class<T> clazz) {
|
||||
String configValue = getConfigValue(configKey);
|
||||
return JsonUtils.parseObject(configValue, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数 key 获取指定类型的配置列表=
|
||||
*
|
||||
* @param configKey 参数 key
|
||||
* @param clazz 目标元素类型
|
||||
* @return 指定类型列表,如果配置为空或无法解析,返回空列表
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> getConfigArray(String configKey, Class<T> clazz) {
|
||||
String configValue = getConfigValue(configKey);
|
||||
return JsonUtils.parseArray(configValue, clazz);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -229,6 +229,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
@Override
|
||||
public String getDictLabel(String dictType, String dictValue, String separator) {
|
||||
List<SysDictDataVo> datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
|
||||
if (CollUtil.isEmpty(datas)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
Map<String, String> map = StreamUtils.toMap(datas, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel);
|
||||
if (StringUtils.containsAny(dictValue, separator)) {
|
||||
return Arrays.stream(dictValue.split(separator))
|
||||
@@ -250,6 +253,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
@Override
|
||||
public String getDictValue(String dictType, String dictLabel, String separator) {
|
||||
List<SysDictDataVo> datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
|
||||
if (CollUtil.isEmpty(datas)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
Map<String, String> map = StreamUtils.toMap(datas, SysDictDataVo::getDictLabel, SysDictDataVo::getDictValue);
|
||||
if (StringUtils.containsAny(dictLabel, separator)) {
|
||||
return Arrays.stream(dictLabel.split(separator))
|
||||
@@ -269,6 +275,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
@Override
|
||||
public Map<String, String> getAllDictByDictType(String dictType) {
|
||||
List<SysDictDataVo> list = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
// 保证顺序
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
for (SysDictDataVo vo : list) {
|
||||
@@ -286,6 +295,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
@Override
|
||||
public DictTypeDTO getDictType(String dictType) {
|
||||
SysDictTypeVo vo = SpringUtils.getAopProxy(this).selectDictTypeByType(dictType);
|
||||
if (ObjectUtil.isNull(vo)) {
|
||||
return null;
|
||||
}
|
||||
return BeanUtil.toBean(vo, DictTypeDTO.class);
|
||||
}
|
||||
|
||||
@@ -298,6 +310,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
@Override
|
||||
public List<DictDataDTO> getDictData(String dictType) {
|
||||
List<SysDictDataVo> list = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return BeanUtil.copyToList(list, DictDataDTO.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
@@ -29,13 +30,17 @@ import org.dromara.system.service.ISysMenuService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 菜单 业务层处理
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysMenuServiceImpl implements ISysMenuService {
|
||||
@@ -107,7 +112,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||
/**
|
||||
* 根据用户ID查询菜单
|
||||
*
|
||||
* @param userId 用户名称
|
||||
* @param userId 用户ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
@Override
|
||||
@@ -353,6 +358,51 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||
return !exist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验路由名称是否唯一
|
||||
*
|
||||
* @param menuBo 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean checkRouteConfigUnique(SysMenuBo menuBo) {
|
||||
SysMenu menu = MapstructUtils.convert(menuBo, SysMenu.class);
|
||||
if (SystemConstants.TYPE_BUTTON.equals(menu.getMenuType())) {
|
||||
return true;
|
||||
}
|
||||
long menuId = ObjectUtil.isNull(menu.getMenuId()) ? -1L : menu.getMenuId();
|
||||
Long parentId = menu.getParentId();
|
||||
String path = menu.getPath();
|
||||
String routeName = StringUtils.isEmpty(menu.getRouteName()) ? path : menu.getRouteName();
|
||||
List<SysMenu> sysMenuList = baseMapper.selectList(
|
||||
new LambdaQueryWrapper<SysMenu>()
|
||||
.in(SysMenu::getMenuType, SystemConstants.TYPE_DIR, SystemConstants.TYPE_MENU)
|
||||
.and(w ->
|
||||
w.eq(SysMenu::getPath, path).or().eq(SysMenu::getPath, routeName)
|
||||
));
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
if (!sysMenu.getMenuId().equals(menuId)) {
|
||||
Long dbParentId = sysMenu.getParentId();
|
||||
String dbPath = sysMenu.getPath();
|
||||
String dbRouteName = StringUtils.isEmpty(sysMenu.getRouteName()) ? dbPath : sysMenu.getRouteName();
|
||||
if (StringUtils.equalsAnyIgnoreCase(path, dbPath) && parentId.equals(dbParentId)) {
|
||||
log.warn("[同级路由冲突] 同级下已存在相同路由路径 '{}',冲突菜单:{}", dbPath, sysMenu.getMenuName());
|
||||
return false;
|
||||
} else if (StringUtils.equalsAnyIgnoreCase(path, dbPath)
|
||||
&& Constants.TOP_PARENT_ID.equals(parentId)
|
||||
&& Constants.TOP_PARENT_ID.equals(dbParentId)) {
|
||||
log.warn("[根目录路由冲突] 根目录下路由 '{}' 必须唯一,已被菜单 '{}' 占用", path, sysMenu.getMenuName());
|
||||
return false;
|
||||
} else if (StringUtils.equalsAnyIgnoreCase(routeName, dbRouteName)
|
||||
&& sysMenu.getMenuType().equals(menu.getMenuType())) {
|
||||
log.warn("[路由名称冲突] 路由名称 '{}' 需全局唯一,已被菜单 '{}' 使用", routeName, sysMenu.getMenuName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父节点的ID获取所有子节点
|
||||
*
|
||||
|
||||
@@ -192,6 +192,9 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
||||
*/
|
||||
@Override
|
||||
public SysOssVo upload(MultipartFile file) {
|
||||
if (ObjectUtil.isNull(file) || file.isEmpty()) {
|
||||
throw new ServiceException("上传文件不能为空");
|
||||
}
|
||||
String originalfileName = file.getOriginalFilename();
|
||||
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
|
||||
OssClient storage = OssFactory.instance();
|
||||
@@ -216,12 +219,16 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
||||
*/
|
||||
@Override
|
||||
public SysOssVo upload(File file) {
|
||||
if (ObjectUtil.isNull(file) || !file.isFile() || file.length() <= 0) {
|
||||
throw new ServiceException("上传文件不能为空");
|
||||
}
|
||||
String originalfileName = file.getName();
|
||||
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
|
||||
OssClient storage = OssFactory.instance();
|
||||
long length = file.length();
|
||||
UploadResult uploadResult = storage.uploadSuffix(file, suffix);
|
||||
SysOssExt ext1 = new SysOssExt();
|
||||
ext1.setFileSize(file.length());
|
||||
ext1.setFileSize(length);
|
||||
// 保存文件信息
|
||||
return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult, ext1);
|
||||
}
|
||||
@@ -270,7 +277,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
||||
OssClient storage = OssFactory.instance(oss.getService());
|
||||
// 仅修改桶类型为 private 的URL,临时URL时长为120s
|
||||
if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) {
|
||||
oss.setUrl(storage.getPrivateUrl(oss.getFileName(), Duration.ofSeconds(120)));
|
||||
oss.setUrl(storage.createPresignedGetUrl(oss.getFileName(), Duration.ofSeconds(120)));
|
||||
}
|
||||
return oss;
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
* 校验用户账号是否唯一
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
@@ -375,7 +375,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||
* 修改用户状态
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param status 帐号状态
|
||||
* @param status 账号状态
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@@ -497,6 +497,11 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||
roleList.remove(SystemConstants.SUPER_ADMIN_ID);
|
||||
}
|
||||
|
||||
// 移除超管角色后若无剩余角色,说明仅选了超管角色且不允许分配,显式报错
|
||||
if (roleList.isEmpty()) {
|
||||
throw new ServiceException("不允许为普通用户分配超级管理员角色,请至少选择一个其他角色");
|
||||
}
|
||||
|
||||
// 校验是否有权限访问这些角色(含数据权限控制)
|
||||
if (roleMapper.selectRoleCount(roleList) != roleList.size()) {
|
||||
throw new ServiceException("没有权限访问角色的数据");
|
||||
@@ -594,10 +599,10 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户账户
|
||||
* 通过用户ID查询用户昵称
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户账户
|
||||
* @return 用户昵称
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(cacheNames = CacheNames.SYS_NICKNAME, key = "#userId")
|
||||
@@ -608,10 +613,10 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户账户
|
||||
* 通过用户ID查询用户昵称
|
||||
*
|
||||
* @param userIds 用户ID 多个用逗号隔开
|
||||
* @return 用户账户
|
||||
* @return 用户昵称
|
||||
*/
|
||||
@Override
|
||||
public String selectNicknameByIds(String userIds) {
|
||||
@@ -751,13 +756,13 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户 ID 列表查询用户名称映射关系
|
||||
* 根据用户 ID 列表查询用户昵称映射关系
|
||||
*
|
||||
* @param userIds 用户 ID 列表
|
||||
* @return Map,其中 key 为用户 ID,value 为对应的用户名称
|
||||
* @return Map,其中 key 为用户 ID,value 为对应的用户昵称
|
||||
*/
|
||||
@Override
|
||||
public Map<Long, String> selectUserNamesByIds(List<Long> userIds) {
|
||||
public Map<Long, String> selectUserNicksByIds(List<Long> userIds) {
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user