mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 10:13:28 +08:00
merge dev
This commit is contained in:
commit
118d772986
@ -27,8 +27,9 @@
|
|||||||
|
|
||||||
## 赞助商
|
## 赞助商
|
||||||
|
|
||||||
MaxKey - https://gitee.com/dromara/MaxKey <br>
|
MaxKey 业界领先单点登录产品 - https://gitee.com/dromara/MaxKey <br>
|
||||||
CCFlow - https://gitee.com/opencc/RuoYi-JFlow <br>
|
CCFlow 驰聘低代码-流程-表单 - https://gitee.com/opencc/RuoYi-JFlow <br>
|
||||||
|
数舵科技 软件定制开发APP小程序等 - http://www.shuduokeji.com/ <br>
|
||||||
[如何成为赞助商 加群联系作者详谈](https://plus-doc.dromara.org/#/common/add_group)
|
[如何成为赞助商 加群联系作者详谈](https://plus-doc.dromara.org/#/common/add_group)
|
||||||
|
|
||||||
# 本框架与RuoYi的功能差异
|
# 本框架与RuoYi的功能差异
|
||||||
|
|||||||
36
pom.xml
36
pom.xml
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<revision>5.2.0-SNAPSHOT</revision>
|
<revision>5.2.0-SNAPSHOT</revision>
|
||||||
<spring-boot.version>3.2.1</spring-boot.version>
|
<spring-boot.version>3.2.3</spring-boot.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
@ -27,15 +27,15 @@
|
|||||||
<satoken.version>1.37.0</satoken.version>
|
<satoken.version>1.37.0</satoken.version>
|
||||||
<mybatis-plus.version>3.5.5</mybatis-plus.version>
|
<mybatis-plus.version>3.5.5</mybatis-plus.version>
|
||||||
<p6spy.version>3.9.1</p6spy.version>
|
<p6spy.version>3.9.1</p6spy.version>
|
||||||
<hutool.version>5.8.24</hutool.version>
|
<hutool.version>5.8.26</hutool.version>
|
||||||
<okhttp.version>4.10.0</okhttp.version>
|
<okhttp.version>4.10.0</okhttp.version>
|
||||||
<spring-boot-admin.version>3.2.0</spring-boot-admin.version>
|
<spring-boot-admin.version>3.2.2</spring-boot-admin.version>
|
||||||
<redisson.version>3.25.2</redisson.version>
|
<redisson.version>3.27.0</redisson.version>
|
||||||
<lock4j.version>2.2.5</lock4j.version>
|
<lock4j.version>2.2.7</lock4j.version>
|
||||||
<dynamic-ds.version>4.3.0</dynamic-ds.version>
|
<dynamic-ds.version>4.3.0</dynamic-ds.version>
|
||||||
<alibaba-ttl.version>2.14.4</alibaba-ttl.version>
|
<alibaba-ttl.version>2.14.4</alibaba-ttl.version>
|
||||||
<powerjob.version>4.3.6</powerjob.version>
|
<powerjob.version>4.3.6</powerjob.version>
|
||||||
<mapstruct-plus.version>1.3.5</mapstruct-plus.version>
|
<mapstruct-plus.version>1.3.6</mapstruct-plus.version>
|
||||||
<mapstruct-plus.lombok.version>0.2.0</mapstruct-plus.lombok.version>
|
<mapstruct-plus.lombok.version>0.2.0</mapstruct-plus.lombok.version>
|
||||||
<lombok.version>1.18.30</lombok.version>
|
<lombok.version>1.18.30</lombok.version>
|
||||||
<bouncycastle.version>1.76</bouncycastle.version>
|
<bouncycastle.version>1.76</bouncycastle.version>
|
||||||
@ -44,9 +44,10 @@
|
|||||||
<ip2region.version>2.7.0</ip2region.version>
|
<ip2region.version>2.7.0</ip2region.version>
|
||||||
|
|
||||||
<!-- OSS 配置 -->
|
<!-- OSS 配置 -->
|
||||||
<aws-java-sdk-s3.version>1.12.600</aws-java-sdk-s3.version>
|
<aws.sdk.version>2.23.0</aws.sdk.version>
|
||||||
|
<aws.crt.version>0.29.6</aws.crt.version>
|
||||||
<!-- SMS 配置 -->
|
<!-- SMS 配置 -->
|
||||||
<sms4j.version>2.2.0</sms4j.version>
|
<sms4j.version>3.1.1</sms4j.version>
|
||||||
<!-- 限制框架中的fastjson版本 -->
|
<!-- 限制框架中的fastjson版本 -->
|
||||||
<fastjson.version>1.2.83</fastjson.version>
|
<fastjson.version>1.2.83</fastjson.version>
|
||||||
|
|
||||||
@ -246,10 +247,23 @@
|
|||||||
<version>${okhttp.version}</version>
|
<version>${okhttp.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- AWS SDK for Java 2.x -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
<artifactId>aws-java-sdk-s3</artifactId>
|
<artifactId>s3</artifactId>
|
||||||
<version>${aws-java-sdk-s3.version}</version>
|
<version>${aws.sdk.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 使用AWS基于 CRT 的 S3 客户端 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>software.amazon.awssdk.crt</groupId>
|
||||||
|
<artifactId>aws-crt</artifactId>
|
||||||
|
<version>${aws.crt.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 基于 AWS CRT 的 S3 客户端的性能增强的 S3 传输管理器 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
|
<artifactId>s3-transfer-manager</artifactId>
|
||||||
|
<version>${aws.sdk.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--短信sms4j-->
|
<!--短信sms4j-->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@ -23,8 +23,8 @@ import org.dromara.common.social.config.properties.SocialLoginConfigProperties;
|
|||||||
import org.dromara.common.social.config.properties.SocialProperties;
|
import org.dromara.common.social.config.properties.SocialProperties;
|
||||||
import org.dromara.common.social.utils.SocialUtils;
|
import org.dromara.common.social.utils.SocialUtils;
|
||||||
import org.dromara.common.tenant.helper.TenantHelper;
|
import org.dromara.common.tenant.helper.TenantHelper;
|
||||||
|
import org.dromara.common.websocket.dto.WebSocketMessageDto;
|
||||||
import org.dromara.common.websocket.utils.WebSocketUtils;
|
import org.dromara.common.websocket.utils.WebSocketUtils;
|
||||||
import org.dromara.system.domain.SysClient;
|
|
||||||
import org.dromara.system.domain.bo.SysTenantBo;
|
import org.dromara.system.domain.bo.SysTenantBo;
|
||||||
import org.dromara.system.domain.vo.SysClientVo;
|
import org.dromara.system.domain.vo.SysClientVo;
|
||||||
import org.dromara.system.domain.vo.SysTenantVo;
|
import org.dromara.system.domain.vo.SysTenantVo;
|
||||||
@ -97,7 +97,10 @@ public class AuthController {
|
|||||||
|
|
||||||
Long userId = LoginHelper.getUserId();
|
Long userId = LoginHelper.getUserId();
|
||||||
scheduledExecutorService.schedule(() -> {
|
scheduledExecutorService.schedule(() -> {
|
||||||
WebSocketUtils.sendMessage(userId, "欢迎登录RuoYi-Vue-Plus后台管理系统");
|
WebSocketMessageDto dto = new WebSocketMessageDto();
|
||||||
|
dto.setMessage("欢迎登录RuoYi-Vue-Plus后台管理系统");
|
||||||
|
dto.setSessionKeys(List.of(userId));
|
||||||
|
WebSocketUtils.publishMessage(dto);
|
||||||
}, 3, TimeUnit.SECONDS);
|
}, 3, TimeUnit.SECONDS);
|
||||||
return R.ok(loginVo);
|
return R.ok(loginVo);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,9 @@ import cn.hutool.captcha.AbstractCaptcha;
|
|||||||
import cn.hutool.captcha.generator.CodeGenerator;
|
import cn.hutool.captcha.generator.CodeGenerator;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.core.constant.Constants;
|
import org.dromara.common.core.constant.Constants;
|
||||||
import org.dromara.common.core.constant.GlobalConstants;
|
import org.dromara.common.core.constant.GlobalConstants;
|
||||||
import org.dromara.common.core.domain.R;
|
import org.dromara.common.core.domain.R;
|
||||||
@ -21,11 +24,7 @@ import org.dromara.common.web.enums.CaptchaType;
|
|||||||
import org.dromara.sms4j.api.SmsBlend;
|
import org.dromara.sms4j.api.SmsBlend;
|
||||||
import org.dromara.sms4j.api.entity.SmsResponse;
|
import org.dromara.sms4j.api.entity.SmsResponse;
|
||||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||||
import org.dromara.sms4j.provider.enumerate.SupplierType;
|
|
||||||
import org.dromara.web.domain.vo.CaptchaVo;
|
import org.dromara.web.domain.vo.CaptchaVo;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
import org.springframework.expression.ExpressionParser;
|
import org.springframework.expression.ExpressionParser;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
@ -66,11 +65,11 @@ public class CaptchaController {
|
|||||||
String templateId = "";
|
String templateId = "";
|
||||||
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
||||||
map.put("code", code);
|
map.put("code", code);
|
||||||
SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA);
|
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
|
||||||
SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map);
|
SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map);
|
||||||
if (!"OK".equals(smsResponse.getCode())) {
|
if (!smsResponse.isSuccess()) {
|
||||||
log.error("验证码短信发送异常 => {}", smsResponse);
|
log.error("验证码短信发送异常 => {}", smsResponse);
|
||||||
return R.fail(smsResponse.getMessage());
|
return R.fail(smsResponse.getData().toString());
|
||||||
}
|
}
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
@ -121,6 +120,7 @@ public class CaptchaController {
|
|||||||
AbstractCaptcha captcha = SpringUtils.getBean(captchaProperties.getCategory().getClazz());
|
AbstractCaptcha captcha = SpringUtils.getBean(captchaProperties.getCategory().getClazz());
|
||||||
captcha.setGenerator(codeGenerator);
|
captcha.setGenerator(codeGenerator);
|
||||||
captcha.createCode();
|
captcha.createCode();
|
||||||
|
// 如果是数学验证码,使用SpEL表达式处理验证码结果
|
||||||
String code = captcha.getCode();
|
String code = captcha.getCode();
|
||||||
if (isMath) {
|
if (isMath) {
|
||||||
ExpressionParser parser = new SpelExpressionParser();
|
ExpressionParser parser = new SpelExpressionParser();
|
||||||
|
|||||||
@ -13,10 +13,19 @@ import lombok.Data;
|
|||||||
@AutoMapper(target = SysTenantVo.class)
|
@AutoMapper(target = SysTenantVo.class)
|
||||||
public class TenantListVo {
|
public class TenantListVo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户编号
|
||||||
|
*/
|
||||||
private String tenantId;
|
private String tenantId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业名称
|
||||||
|
*/
|
||||||
private String companyName;
|
private String companyName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 域名
|
||||||
|
*/
|
||||||
private String domain;
|
private String domain;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,11 @@ public interface IAuthStrategy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
|
*
|
||||||
|
* @param body 登录对象
|
||||||
|
* @param client 授权管理视图对象
|
||||||
|
* @param grantType 授权类型
|
||||||
|
* @return 登录验证信息
|
||||||
*/
|
*/
|
||||||
static LoginVo login(String body, SysClientVo client, String grantType) {
|
static LoginVo login(String body, SysClientVo client, String grantType) {
|
||||||
// 授权类型和客户端id
|
// 授权类型和客户端id
|
||||||
@ -31,6 +36,10 @@ public interface IAuthStrategy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
|
*
|
||||||
|
* @param body 登录对象
|
||||||
|
* @param client 授权管理视图对象
|
||||||
|
* @return 登录验证信息
|
||||||
*/
|
*/
|
||||||
LoginVo login(String body, SysClientVo client);
|
LoginVo login(String body, SysClientVo client);
|
||||||
|
|
||||||
|
|||||||
@ -145,10 +145,12 @@ public class SysLoginService {
|
|||||||
loginUser.setUserType(user.getUserType());
|
loginUser.setUserType(user.getUserType());
|
||||||
loginUser.setMenuPermission(permissionService.getMenuPermission(user.getUserId()));
|
loginUser.setMenuPermission(permissionService.getMenuPermission(user.getUserId()));
|
||||||
loginUser.setRolePermission(permissionService.getRolePermission(user.getUserId()));
|
loginUser.setRolePermission(permissionService.getRolePermission(user.getUserId()));
|
||||||
SysDeptVo dept = deptService.selectDeptById(user.getDeptId());
|
TenantHelper.dynamic(user.getTenantId(), () -> {
|
||||||
loginUser.setDeptName(ObjectUtil.isNull(dept) ? "" : dept.getDeptName());
|
SysDeptVo dept = deptService.selectDeptById(user.getDeptId());
|
||||||
List<SysRoleVo> roles = roleService.selectRolesByUserId(user.getUserId());
|
loginUser.setDeptName(ObjectUtil.isNull(dept) ? "" : dept.getDeptName());
|
||||||
loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class));
|
List<SysRoleVo> roles = roleService.selectRolesByUserId(user.getUserId());
|
||||||
|
loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class));
|
||||||
|
});
|
||||||
return loginUser;
|
return loginUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,7 @@ public class SysRegisterService {
|
|||||||
* @param uuid 唯一标识
|
* @param uuid 唯一标识
|
||||||
*/
|
*/
|
||||||
public void validateCaptcha(String tenantId, String username, String code, String uuid) {
|
public void validateCaptcha(String tenantId, String username, String code, String uuid) {
|
||||||
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, "");
|
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.blankToDefault(uuid, "");
|
||||||
String captcha = RedisUtils.getCacheObject(verifyKey);
|
String captcha = RedisUtils.getCacheObject(verifyKey);
|
||||||
RedisUtils.deleteObject(verifyKey);
|
RedisUtils.deleteObject(verifyKey);
|
||||||
if (captcha == null) {
|
if (captcha == null) {
|
||||||
|
|||||||
@ -149,36 +149,40 @@ mail:
|
|||||||
connectionTimeout: 0
|
connectionTimeout: 0
|
||||||
|
|
||||||
--- # sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商
|
--- # sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商
|
||||||
# https://wind.kim/doc/start 文档地址 各个厂商可同时使用
|
# https://sms4j.com/doc3/ 差异配置文档地址 支持单厂商多配置,可以配置多个同时使用
|
||||||
sms:
|
sms:
|
||||||
# 阿里云 dysmsapi.aliyuncs.com
|
# 配置源类型用于标定配置来源(interface,yaml)
|
||||||
alibaba:
|
config-type: yaml
|
||||||
#请求地址 默认为 dysmsapi.aliyuncs.com 如无特殊改变可以不用设置
|
# 用于标定yml中的配置是否开启短信拦截,接口配置不受此限制
|
||||||
requestUrl: dysmsapi.aliyuncs.com
|
restricted: true
|
||||||
#阿里云的accessKey
|
# 短信拦截限制单手机号每分钟最大发送,只对开启了拦截的配置有效
|
||||||
accessKeyId: xxxxxxx
|
minute-max: 1
|
||||||
#阿里云的accessKeySecret
|
# 短信拦截限制单手机号每日最大发送量,只对开启了拦截的配置有效
|
||||||
accessKeySecret: xxxxxxx
|
account-max: 30
|
||||||
#短信签名
|
# 以下配置来自于 org.dromara.sms4j.provider.config.BaseConfig类中
|
||||||
signature: 测试
|
blends:
|
||||||
tencent:
|
# 唯一ID 用于发送短信寻找具体配置 随便定义别用中文即可
|
||||||
#请求地址默认为 sms.tencentcloudapi.com 如无特殊改变可不用设置
|
# 可以同时存在两个相同厂商 例如: ali1 ali2 两个不同的阿里短信账号 也可用于区分租户
|
||||||
requestUrl: sms.tencentcloudapi.com
|
config1:
|
||||||
#腾讯云的accessKey
|
# 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||||
accessKeyId: xxxxxxx
|
supplier: alibaba
|
||||||
#腾讯云的accessKeySecret
|
# 有些称为accessKey有些称之为apiKey,也有称为sdkKey或者appId。
|
||||||
accessKeySecret: xxxxxxx
|
access-key-id: 您的accessKey
|
||||||
#短信签名
|
# 称为accessSecret有些称之为apiSecret
|
||||||
signature: 测试
|
access-key-secret: 您的accessKeySecret
|
||||||
#短信sdkAppId
|
signature: 您的短信签名
|
||||||
sdkAppId: appid
|
sdk-app-id: 您的sdkAppId
|
||||||
#地域信息默认为 ap-guangzhou 如无特殊改变可不用设置
|
config2:
|
||||||
territory: ap-guangzhou
|
# 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||||
|
supplier: tencent
|
||||||
|
access-key-id: 您的accessKey
|
||||||
|
access-key-secret: 您的accessKeySecret
|
||||||
|
signature: 您的短信签名
|
||||||
|
sdk-app-id: 您的sdkAppId
|
||||||
|
|
||||||
|
|
||||||
--- # 三方授权
|
--- # 三方授权
|
||||||
justauth:
|
justauth:
|
||||||
enabled: true
|
|
||||||
# 前端外网访问地址
|
# 前端外网访问地址
|
||||||
address: http://localhost:80
|
address: http://localhost:80
|
||||||
type:
|
type:
|
||||||
|
|||||||
@ -152,35 +152,39 @@ mail:
|
|||||||
connectionTimeout: 0
|
connectionTimeout: 0
|
||||||
|
|
||||||
--- # sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商
|
--- # sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商
|
||||||
# https://wind.kim/doc/start 文档地址 各个厂商可同时使用
|
# https://sms4j.com/doc3/ 差异配置文档地址 支持单厂商多配置,可以配置多个同时使用
|
||||||
sms:
|
sms:
|
||||||
# 阿里云 dysmsapi.aliyuncs.com
|
# 配置源类型用于标定配置来源(interface,yaml)
|
||||||
alibaba:
|
config-type: yaml
|
||||||
#请求地址 默认为 dysmsapi.aliyuncs.com 如无特殊改变可以不用设置
|
# 用于标定yml中的配置是否开启短信拦截,接口配置不受此限制
|
||||||
requestUrl: dysmsapi.aliyuncs.com
|
restricted: true
|
||||||
#阿里云的accessKey
|
# 短信拦截限制单手机号每分钟最大发送,只对开启了拦截的配置有效
|
||||||
accessKeyId: xxxxxxx
|
minute-max: 1
|
||||||
#阿里云的accessKeySecret
|
# 短信拦截限制单手机号每日最大发送量,只对开启了拦截的配置有效
|
||||||
accessKeySecret: xxxxxxx
|
account-max: 30
|
||||||
#短信签名
|
# 以下配置来自于 org.dromara.sms4j.provider.config.BaseConfig类中
|
||||||
signature: 测试
|
blends:
|
||||||
tencent:
|
# 唯一ID 用于发送短信寻找具体配置 随便定义别用中文即可
|
||||||
#请求地址默认为 sms.tencentcloudapi.com 如无特殊改变可不用设置
|
# 可以同时存在两个相同厂商 例如: ali1 ali2 两个不同的阿里短信账号 也可用于区分租户
|
||||||
requestUrl: sms.tencentcloudapi.com
|
config1:
|
||||||
#腾讯云的accessKey
|
# 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||||
accessKeyId: xxxxxxx
|
supplier: alibaba
|
||||||
#腾讯云的accessKeySecret
|
# 有些称为accessKey有些称之为apiKey,也有称为sdkKey或者appId。
|
||||||
accessKeySecret: xxxxxxx
|
access-key-id: 您的accessKey
|
||||||
#短信签名
|
# 称为accessSecret有些称之为apiSecret
|
||||||
signature: 测试
|
access-key-secret: 您的accessKeySecret
|
||||||
#短信sdkAppId
|
signature: 您的短信签名
|
||||||
sdkAppId: appid
|
sdk-app-id: 您的sdkAppId
|
||||||
#地域信息默认为 ap-guangzhou 如无特殊改变可不用设置
|
config2:
|
||||||
territory: ap-guangzhou
|
# 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||||
|
supplier: tencent
|
||||||
|
access-key-id: 您的accessKey
|
||||||
|
access-key-secret: 您的accessKeySecret
|
||||||
|
signature: 您的短信签名
|
||||||
|
sdk-app-id: 您的sdkAppId
|
||||||
|
|
||||||
--- # 三方授权
|
--- # 三方授权
|
||||||
justauth:
|
justauth:
|
||||||
enabled: true
|
|
||||||
# 前端外网访问地址
|
# 前端外网访问地址
|
||||||
address: http://localhost:80
|
address: http://localhost:80
|
||||||
type:
|
type:
|
||||||
@ -191,6 +195,13 @@ justauth:
|
|||||||
client-id: 876892492581044224
|
client-id: 876892492581044224
|
||||||
client-secret: x1Y5MTMwNzIwMjMxNTM4NDc3Mzche8
|
client-secret: x1Y5MTMwNzIwMjMxNTM4NDc3Mzche8
|
||||||
redirect-uri: ${justauth.address}/social-callback?source=maxkey
|
redirect-uri: ${justauth.address}/social-callback?source=maxkey
|
||||||
|
topiam:
|
||||||
|
# topiam 服务器地址
|
||||||
|
server-url: http://127.0.0.1:1989/api/v1/authorize/y0q************spq***********8ol
|
||||||
|
client-id: 449c4*********937************759
|
||||||
|
client-secret: ac7***********1e0************28d
|
||||||
|
redirect-uri: ${justauth.address}/social-callback?source=topiam
|
||||||
|
scopes: [ openid, email, phone, profile ]
|
||||||
qq:
|
qq:
|
||||||
client-id: 10**********6
|
client-id: 10**********6
|
||||||
client-secret: 1f7d08**********5b7**********29e
|
client-secret: 1f7d08**********5b7**********29e
|
||||||
|
|||||||
@ -47,6 +47,7 @@ logging:
|
|||||||
org.dromara: @logging.level@
|
org.dromara: @logging.level@
|
||||||
org.springframework: warn
|
org.springframework: warn
|
||||||
tech.powerjob.worker.background: warn
|
tech.powerjob.worker.background: warn
|
||||||
|
org.mybatis.spring.mapper: error
|
||||||
config: classpath:logback-plus.xml
|
config: classpath:logback-plus.xml
|
||||||
|
|
||||||
# 用户配置
|
# 用户配置
|
||||||
@ -63,7 +64,6 @@ spring:
|
|||||||
name: ${ruoyi.name}
|
name: ${ruoyi.name}
|
||||||
threads:
|
threads:
|
||||||
# 开启虚拟线程 仅jdk21可用
|
# 开启虚拟线程 仅jdk21可用
|
||||||
# 开启后还需更改 UndertowConfig 虚拟线程配置
|
|
||||||
virtual:
|
virtual:
|
||||||
enabled: false
|
enabled: false
|
||||||
# 资源信息
|
# 资源信息
|
||||||
@ -143,8 +143,7 @@ tenant:
|
|||||||
# MyBatisPlus配置
|
# MyBatisPlus配置
|
||||||
# https://baomidou.com/config/
|
# https://baomidou.com/config/
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
# 不支持多包, 如有需要可在注解配置 或 提升扫包等级
|
# 多包名使用 例如 org.dromara.**.mapper,org.xxx.**.mapper
|
||||||
# 例如 com.**.**.mapper
|
|
||||||
mapperPackage: org.dromara.**.mapper
|
mapperPackage: org.dromara.**.mapper
|
||||||
# 对应的 XML 文件位置
|
# 对应的 XML 文件位置
|
||||||
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
||||||
@ -231,6 +230,7 @@ xss:
|
|||||||
urlPatterns: /system/*,/monitor/*,/tool/*
|
urlPatterns: /system/*,/monitor/*,/tool/*
|
||||||
|
|
||||||
# 全局线程池相关配置
|
# 全局线程池相关配置
|
||||||
|
# 如使用JDK21请直接使用虚拟线程 不要开启此配置
|
||||||
thread-pool:
|
thread-pool:
|
||||||
# 是否开启线程池
|
# 是否开启线程池
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package org.dromara.common.core.config;
|
|||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 程序注解配置
|
* 程序注解配置
|
||||||
@ -11,6 +12,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
|||||||
@AutoConfiguration
|
@AutoConfiguration
|
||||||
// 表示通过aop框架暴露该代理对象,AopContext能够访问
|
// 表示通过aop框架暴露该代理对象,AopContext能够访问
|
||||||
@EnableAspectJAutoProxy(exposeProxy = true)
|
@EnableAspectJAutoProxy(exposeProxy = true)
|
||||||
|
@EnableAsync(proxyTargetClass = true)
|
||||||
public class ApplicationConfig {
|
public class ApplicationConfig {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,18 +5,19 @@ import org.dromara.common.core.exception.ServiceException;
|
|||||||
import org.dromara.common.core.utils.SpringUtils;
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步配置
|
* 异步配置
|
||||||
|
* <p>
|
||||||
|
* 如果未使用虚拟线程则生效
|
||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
@EnableAsync(proxyTargetClass = true)
|
|
||||||
@AutoConfiguration
|
@AutoConfiguration
|
||||||
public class AsyncConfig implements AsyncConfigurer {
|
public class AsyncConfig implements AsyncConfigurer {
|
||||||
|
|
||||||
@ -25,6 +26,9 @@ public class AsyncConfig implements AsyncConfigurer {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Executor getAsyncExecutor() {
|
public Executor getAsyncExecutor() {
|
||||||
|
if(SpringUtils.isVirtual()) {
|
||||||
|
return new VirtualThreadTaskExecutor("async-");
|
||||||
|
}
|
||||||
return SpringUtils.getBean("scheduledExecutorService");
|
return SpringUtils.getBean("scheduledExecutorService");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,49 @@
|
|||||||
|
package org.dromara.common.core.constant;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.RegexPool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 常用正则表达式字符串
|
||||||
|
* <p>
|
||||||
|
* 常用正则表达式集合,更多正则见: https://any86.github.io/any-rule/
|
||||||
|
*
|
||||||
|
* @author Feng
|
||||||
|
*/
|
||||||
|
public interface RegexConstants extends RegexPool {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典类型必须以字母开头,且只能为(小写字母,数字,下滑线)
|
||||||
|
*/
|
||||||
|
public static final String DICTIONARY_TYPE = "^[a-z][a-z0-9_]*$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 身份证号码(后6位)
|
||||||
|
*/
|
||||||
|
public static final String ID_CARD_LAST_6 = "^(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QQ号码
|
||||||
|
*/
|
||||||
|
public static final String QQ_NUMBER = "^[1-9][0-9]\\d{4,9}$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮政编码
|
||||||
|
*/
|
||||||
|
public static final String POSTAL_CODE = "^[1-9]\\d{5}$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册账号
|
||||||
|
*/
|
||||||
|
public static final String ACCOUNT = "^[a-zA-Z][a-zA-Z0-9_]{4,15}$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码:包含至少8个字符,包括大写字母、小写字母、数字和特殊字符
|
||||||
|
*/
|
||||||
|
public static final String PASSWORD = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用状态(0表示正常,1表示停用)
|
||||||
|
*/
|
||||||
|
public static final String STATUS = "^[01]$";
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
package org.dromara.common.core.factory;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.PatternPool;
|
||||||
|
import org.dromara.common.core.constant.RegexConstants;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正则表达式模式池工厂
|
||||||
|
* <p>初始化的时候将正则表达式加入缓存池当中</p>
|
||||||
|
* <p>提高正则表达式的性能,避免重复编译相同的正则表达式</p>
|
||||||
|
*
|
||||||
|
* @author 21001
|
||||||
|
*/
|
||||||
|
public class RegexPatternPoolFactory extends PatternPool {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典类型必须以字母开头,且只能为(小写字母,数字,下滑线)
|
||||||
|
*/
|
||||||
|
public static final Pattern DICTIONARY_TYPE = get(RegexConstants.DICTIONARY_TYPE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 身份证号码(后6位)
|
||||||
|
*/
|
||||||
|
public static final Pattern ID_CARD_LAST_6 = get(RegexConstants.ID_CARD_LAST_6);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QQ号码
|
||||||
|
*/
|
||||||
|
public static final Pattern QQ_NUMBER = get(RegexConstants.QQ_NUMBER);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮政编码
|
||||||
|
*/
|
||||||
|
public static final Pattern POSTAL_CODE = get(RegexConstants.POSTAL_CODE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册账号
|
||||||
|
*/
|
||||||
|
public static final Pattern ACCOUNT = get(RegexConstants.ACCOUNT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码:包含至少8个字符,包括大写字母、小写字母、数字和特殊字符
|
||||||
|
*/
|
||||||
|
public static final Pattern PASSWORD = get(RegexConstants.PASSWORD);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用状态(0表示正常,1表示停用)
|
||||||
|
*/
|
||||||
|
public static final Pattern STATUS = get(RegexConstants.STATUS);
|
||||||
|
|
||||||
|
}
|
||||||
@ -23,4 +23,20 @@ public interface UserService {
|
|||||||
*/
|
*/
|
||||||
String selectNicknameById(Long userId);
|
String selectNicknameById(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户ID查询用户手机号
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return 用户手机号
|
||||||
|
*/
|
||||||
|
String selectPhonenumberById(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户ID查询用户邮箱
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return 用户邮箱
|
||||||
|
*/
|
||||||
|
String selectEmailById(Long userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,9 @@ package org.dromara.common.core.utils;
|
|||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import org.springframework.aop.framework.AopContext;
|
import org.springframework.aop.framework.AopContext;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
|
import org.springframework.boot.autoconfigure.thread.Threading;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,4 +61,8 @@ public final class SpringUtils extends SpringUtil {
|
|||||||
return getApplicationContext();
|
return getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isVirtual() {
|
||||||
|
return Threading.VIRTUAL.isActive(getBean(Environment.class));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||||||
|
|
||||||
public static final String SEPARATOR = ",";
|
public static final String SEPARATOR = ",";
|
||||||
|
|
||||||
|
public static final String SLASH = "/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取参数不为空值
|
* 获取参数不为空值
|
||||||
*
|
*
|
||||||
|
|||||||
@ -0,0 +1,30 @@
|
|||||||
|
package org.dromara.common.core.utils.regex;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ReUtil;
|
||||||
|
import org.dromara.common.core.constant.RegexConstants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正则相关工具类
|
||||||
|
*
|
||||||
|
* @author Feng
|
||||||
|
*/
|
||||||
|
public final class RegexUtils extends ReUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从输入字符串中提取匹配的部分,如果没有匹配则返回默认值
|
||||||
|
*
|
||||||
|
* @param input 要提取的输入字符串
|
||||||
|
* @param regex 用于匹配的正则表达式,可以使用 {@link RegexConstants} 中定义的常量
|
||||||
|
* @param defaultInput 如果没有匹配时返回的默认值
|
||||||
|
* @return 如果找到匹配的部分,则返回匹配的部分,否则返回默认值
|
||||||
|
*/
|
||||||
|
public static String extractFromString(String input, String regex, String defaultInput) {
|
||||||
|
try {
|
||||||
|
return ReUtil.get(regex, input, 1);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return defaultInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,105 @@
|
|||||||
|
package org.dromara.common.core.utils.regex;
|
||||||
|
|
||||||
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
|
import cn.hutool.core.lang.Validator;
|
||||||
|
import org.dromara.common.core.factory.RegexPatternPoolFactory;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正则字段校验器
|
||||||
|
* 主要验证字段非空、是否为满足指定格式等
|
||||||
|
*
|
||||||
|
* @author Feng
|
||||||
|
*/
|
||||||
|
public class RegexValidator extends Validator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典类型必须以字母开头,且只能为(小写字母,数字,下滑线)
|
||||||
|
*/
|
||||||
|
public static final Pattern DICTIONARY_TYPE = RegexPatternPoolFactory.DICTIONARY_TYPE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 身份证号码(后6位)
|
||||||
|
*/
|
||||||
|
public static final Pattern ID_CARD_LAST_6 = RegexPatternPoolFactory.ID_CARD_LAST_6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QQ号码
|
||||||
|
*/
|
||||||
|
public static final Pattern QQ_NUMBER = RegexPatternPoolFactory.QQ_NUMBER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮政编码
|
||||||
|
*/
|
||||||
|
public static final Pattern POSTAL_CODE = RegexPatternPoolFactory.POSTAL_CODE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册账号
|
||||||
|
*/
|
||||||
|
public static final Pattern ACCOUNT = RegexPatternPoolFactory.ACCOUNT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码:包含至少8个字符,包括大写字母、小写字母、数字和特殊字符
|
||||||
|
*/
|
||||||
|
public static final Pattern PASSWORD = RegexPatternPoolFactory.PASSWORD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用状态(0表示正常,1表示停用)
|
||||||
|
*/
|
||||||
|
public static final Pattern STATUS = RegexPatternPoolFactory.STATUS;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查输入的账号是否匹配预定义的规则
|
||||||
|
*
|
||||||
|
* @param value 要验证的账号
|
||||||
|
* @return 如果账号符合规则,返回 true;否则,返回 false。
|
||||||
|
*/
|
||||||
|
public static boolean isAccount(CharSequence value) {
|
||||||
|
return isMatchRegex(ACCOUNT, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证输入的账号是否符合规则,如果不符合,则抛出 ValidateException 异常
|
||||||
|
*
|
||||||
|
* @param value 要验证的账号
|
||||||
|
* @param errorMsg 验证失败时抛出的异常消息
|
||||||
|
* @param <T> CharSequence 的子类型
|
||||||
|
* @return 如果验证通过,返回输入的账号
|
||||||
|
* @throws ValidateException 如果验证失败
|
||||||
|
*/
|
||||||
|
public static <T extends CharSequence> T validateAccount(T value, String errorMsg) throws ValidateException {
|
||||||
|
if (!isAccount(value)) {
|
||||||
|
throw new ValidateException(errorMsg);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查输入的状态是否匹配预定义的规则
|
||||||
|
*
|
||||||
|
* @param value 要验证的状态
|
||||||
|
* @return 如果状态符合规则,返回 true;否则,返回 false。
|
||||||
|
*/
|
||||||
|
public static boolean isStatus(CharSequence value) {
|
||||||
|
return isMatchRegex(STATUS, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证输入的状态是否符合规则,如果不符合,则抛出 ValidateException 异常
|
||||||
|
*
|
||||||
|
* @param value 要验证的状态
|
||||||
|
* @param errorMsg 验证失败时抛出的异常消息
|
||||||
|
* @param <T> CharSequence 的子类型
|
||||||
|
* @return 如果验证通过,返回输入的状态
|
||||||
|
* @throws ValidateException 如果验证失败
|
||||||
|
*/
|
||||||
|
public static <T extends CharSequence> T validateStatus(T value, String errorMsg) throws ValidateException {
|
||||||
|
if (!isStatus(value)) {
|
||||||
|
throw new ValidateException(errorMsg);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -22,11 +22,6 @@
|
|||||||
<artifactId>ruoyi-common-core</artifactId>
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mybatis.spring.boot</groupId>
|
|
||||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bouncycastle</groupId>
|
<groupId>org.bouncycastle</groupId>
|
||||||
<artifactId>bcprov-jdk15to18</artifactId>
|
<artifactId>bcprov-jdk15to18</artifactId>
|
||||||
@ -42,6 +37,18 @@
|
|||||||
<artifactId>spring-webmvc</artifactId>
|
<artifactId>spring-webmvc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis-spring</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package org.dromara.common.encrypt.config;
|
package org.dromara.common.encrypt.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
||||||
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.encrypt.core.EncryptorManager;
|
import org.dromara.common.encrypt.core.EncryptorManager;
|
||||||
import org.dromara.common.encrypt.interceptor.MybatisDecryptInterceptor;
|
import org.dromara.common.encrypt.interceptor.MybatisDecryptInterceptor;
|
||||||
import org.dromara.common.encrypt.interceptor.MybatisEncryptInterceptor;
|
import org.dromara.common.encrypt.interceptor.MybatisEncryptInterceptor;
|
||||||
@ -16,17 +19,18 @@ import org.springframework.context.annotation.Bean;
|
|||||||
* @author 老马
|
* @author 老马
|
||||||
* @version 4.6.0
|
* @version 4.6.0
|
||||||
*/
|
*/
|
||||||
@AutoConfiguration
|
@AutoConfiguration(after = MybatisPlusAutoConfiguration.class)
|
||||||
@EnableConfigurationProperties(EncryptorProperties.class)
|
@EnableConfigurationProperties(EncryptorProperties.class)
|
||||||
@ConditionalOnProperty(value = "mybatis-encryptor.enable", havingValue = "true")
|
@ConditionalOnProperty(value = "mybatis-encryptor.enable", havingValue = "true")
|
||||||
|
@Slf4j
|
||||||
public class EncryptorAutoConfiguration {
|
public class EncryptorAutoConfiguration {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EncryptorProperties properties;
|
private EncryptorProperties properties;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public EncryptorManager encryptorManager() {
|
public EncryptorManager encryptorManager(MybatisPlusProperties mybatisPlusProperties) {
|
||||||
return new EncryptorManager();
|
return new EncryptorManager(mybatisPlusProperties.getTypeAliasesPackage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ -38,4 +42,8 @@ public class EncryptorAutoConfiguration {
|
|||||||
public MybatisDecryptInterceptor mybatisDecryptInterceptor(EncryptorManager encryptorManager) {
|
public MybatisDecryptInterceptor mybatisDecryptInterceptor(EncryptorManager encryptorManager) {
|
||||||
return new MybatisDecryptInterceptor(encryptorManager, properties);
|
return new MybatisDecryptInterceptor(encryptorManager, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,23 @@
|
|||||||
package org.dromara.common.encrypt.core;
|
package org.dromara.common.encrypt.core;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.ibatis.io.Resources;
|
||||||
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.encrypt.annotation.EncryptField;
|
import org.dromara.common.encrypt.annotation.EncryptField;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||||
|
import org.springframework.core.type.ClassMetadata;
|
||||||
|
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -19,6 +28,7 @@ import java.util.stream.Collectors;
|
|||||||
* @version 4.6.0
|
* @version 4.6.0
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@NoArgsConstructor
|
||||||
public class EncryptorManager {
|
public class EncryptorManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,25 +41,24 @@ public class EncryptorManager {
|
|||||||
*/
|
*/
|
||||||
Map<Class<?>, Set<Field>> fieldCache = new ConcurrentHashMap<>();
|
Map<Class<?>, Set<Field>> fieldCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造方法传入类加密字段缓存
|
||||||
|
*
|
||||||
|
* @param typeAliasesPackage 实体类包
|
||||||
|
*/
|
||||||
|
public EncryptorManager(String typeAliasesPackage) {
|
||||||
|
scanEncryptClasses(typeAliasesPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取类加密字段缓存
|
* 获取类加密字段缓存
|
||||||
*/
|
*/
|
||||||
public Set<Field> getFieldCache(Class<?> sourceClazz) {
|
public Set<Field> getFieldCache(Class<?> sourceClazz) {
|
||||||
return fieldCache.computeIfAbsent(sourceClazz, clazz -> {
|
if (ObjectUtil.isNotNull(fieldCache)) {
|
||||||
Set<Field> fieldSet = new HashSet<>();
|
return fieldCache.get(sourceClazz);
|
||||||
while (clazz != null) {
|
}
|
||||||
Field[] fields = clazz.getDeclaredFields();
|
return null;
|
||||||
fieldSet.addAll(Arrays.asList(fields));
|
|
||||||
clazz = clazz.getSuperclass();
|
|
||||||
}
|
|
||||||
fieldSet = fieldSet.stream().filter(field ->
|
|
||||||
field.isAnnotationPresent(EncryptField.class) && field.getType() == String.class)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
for (Field field : fieldSet) {
|
|
||||||
field.setAccessible(true);
|
|
||||||
}
|
|
||||||
return fieldSet;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,4 +106,53 @@ public class EncryptorManager {
|
|||||||
return encryptor.decrypt(value);
|
return encryptor.decrypt(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 typeAliasesPackage 设置的扫描包 扫描缓存实体
|
||||||
|
*/
|
||||||
|
private void scanEncryptClasses(String typeAliasesPackage) {
|
||||||
|
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||||
|
CachingMetadataReaderFactory factory = new CachingMetadataReaderFactory();
|
||||||
|
String[] packagePatternArray = StringUtils.splitPreserveAllTokens(typeAliasesPackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
|
||||||
|
String classpath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX;
|
||||||
|
try {
|
||||||
|
for (String packagePattern : packagePatternArray) {
|
||||||
|
String path = ClassUtils.convertClassNameToResourcePath(packagePattern);
|
||||||
|
Resource[] resources = resolver.getResources(classpath + path + "/*.class");
|
||||||
|
for (Resource resource : resources) {
|
||||||
|
ClassMetadata classMetadata = factory.getMetadataReader(resource).getClassMetadata();
|
||||||
|
Class<?> clazz = Resources.classForName(classMetadata.getClassName());
|
||||||
|
Set<Field> encryptFieldSet = getEncryptFieldSetFromClazz(clazz);
|
||||||
|
if (CollUtil.isNotEmpty(encryptFieldSet)) {
|
||||||
|
fieldCache.put(clazz, encryptFieldSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("初始化数据安全缓存时出错:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得一个类的加密字段集合
|
||||||
|
*/
|
||||||
|
private Set<Field> getEncryptFieldSetFromClazz(Class<?> clazz) {
|
||||||
|
Set<Field> fieldSet = new HashSet<>();
|
||||||
|
// 判断clazz如果是接口,内部类,匿名类就直接返回
|
||||||
|
if (clazz.isInterface() || clazz.isMemberClass() || clazz.isAnonymousClass()) {
|
||||||
|
return fieldSet;
|
||||||
|
}
|
||||||
|
while (clazz != null) {
|
||||||
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
|
fieldSet.addAll(Arrays.asList(fields));
|
||||||
|
clazz = clazz.getSuperclass();
|
||||||
|
}
|
||||||
|
fieldSet = fieldSet.stream().filter(field ->
|
||||||
|
field.isAnnotationPresent(EncryptField.class) && field.getType() == String.class)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
for (Field field : fieldSet) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
}
|
||||||
|
return fieldSet;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import org.springframework.web.servlet.HandlerExecutionChain;
|
|||||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,8 +36,9 @@ public class CryptoFilter implements Filter {
|
|||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||||
HttpServletRequest servletRequest = (HttpServletRequest) request;
|
HttpServletRequest servletRequest = (HttpServletRequest) request;
|
||||||
HttpServletResponse servletResponse = (HttpServletResponse) response;
|
HttpServletResponse servletResponse = (HttpServletResponse) response;
|
||||||
|
// 获取加密注解
|
||||||
boolean responseFlag = false;
|
ApiEncrypt apiEncrypt = this.getApiEncryptAnnotation(servletRequest);
|
||||||
|
boolean responseFlag = apiEncrypt != null && apiEncrypt.response();
|
||||||
ServletRequest requestWrapper = null;
|
ServletRequest requestWrapper = null;
|
||||||
ServletResponse responseWrapper = null;
|
ServletResponse responseWrapper = null;
|
||||||
EncryptResponseBodyWrapper responseBodyWrapper = null;
|
EncryptResponseBodyWrapper responseBodyWrapper = null;
|
||||||
@ -49,9 +49,6 @@ public class CryptoFilter implements Filter {
|
|||||||
if (HttpMethod.PUT.matches(servletRequest.getMethod()) || HttpMethod.POST.matches(servletRequest.getMethod())) {
|
if (HttpMethod.PUT.matches(servletRequest.getMethod()) || HttpMethod.POST.matches(servletRequest.getMethod())) {
|
||||||
// 是否存在加密标头
|
// 是否存在加密标头
|
||||||
String headerValue = servletRequest.getHeader(properties.getHeaderFlag());
|
String headerValue = servletRequest.getHeader(properties.getHeaderFlag());
|
||||||
// 获取加密注解
|
|
||||||
ApiEncrypt apiEncrypt = this.getApiEncryptAnnotation(servletRequest);
|
|
||||||
responseFlag = apiEncrypt != null && apiEncrypt.response();
|
|
||||||
if (StringUtils.isNotBlank(headerValue)) {
|
if (StringUtils.isNotBlank(headerValue)) {
|
||||||
// 请求解密
|
// 请求解密
|
||||||
requestWrapper = new DecryptRequestBodyWrapper(servletRequest, properties.getPrivateKey(), properties.getHeaderFlag());
|
requestWrapper = new DecryptRequestBodyWrapper(servletRequest, properties.getPrivateKey(), properties.getHeaderFlag());
|
||||||
@ -65,13 +62,13 @@ public class CryptoFilter implements Filter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 判断是否响应加密
|
|
||||||
if (responseFlag) {
|
|
||||||
responseBodyWrapper = new EncryptResponseBodyWrapper(servletResponse);
|
|
||||||
responseWrapper = responseBodyWrapper;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 判断是否响应加密
|
||||||
|
if (responseFlag) {
|
||||||
|
responseBodyWrapper = new EncryptResponseBodyWrapper(servletResponse);
|
||||||
|
responseWrapper = responseBodyWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
chain.doFilter(
|
chain.doFilter(
|
||||||
ObjectUtil.defaultIfNull(requestWrapper, request),
|
ObjectUtil.defaultIfNull(requestWrapper, request),
|
||||||
|
|||||||
@ -73,7 +73,11 @@ public class MybatisDecryptInterceptor implements Interceptor {
|
|||||||
list.forEach(this::decryptHandler);
|
list.forEach(this::decryptHandler);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 不在缓存中的类,就是没有加密注解的类(当然也有可能是typeAliasesPackage写错)
|
||||||
Set<Field> fields = encryptorManager.getFieldCache(sourceObject.getClass());
|
Set<Field> fields = encryptorManager.getFieldCache(sourceObject.getClass());
|
||||||
|
if(ObjectUtil.isNull(fields)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
field.set(sourceObject, this.decryptField(Convert.toStr(field.get(sourceObject)), field));
|
field.set(sourceObject, this.decryptField(Convert.toStr(field.get(sourceObject)), field));
|
||||||
|
|||||||
@ -82,7 +82,11 @@ public class MybatisEncryptInterceptor implements Interceptor {
|
|||||||
list.forEach(this::encryptHandler);
|
list.forEach(this::encryptHandler);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 不在缓存中的类,就是没有加密注解的类(当然也有可能是typeAliasesPackage写错)
|
||||||
Set<Field> fields = encryptorManager.getFieldCache(sourceObject.getClass());
|
Set<Field> fields = encryptorManager.getFieldCache(sourceObject.getClass());
|
||||||
|
if(ObjectUtil.isNull(fields)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
field.set(sourceObject, this.encryptField(Convert.toStr(field.get(sourceObject)), field));
|
field.set(sourceObject, this.encryptField(Convert.toStr(field.get(sourceObject)), field));
|
||||||
|
|||||||
@ -21,4 +21,9 @@ public @interface CellMerge {
|
|||||||
*/
|
*/
|
||||||
int index() default -1;
|
int index() default -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合并需要依赖的其他字段名称
|
||||||
|
*/
|
||||||
|
String[] mergeBy() default {};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
package org.dromara.common.excel.core;
|
package org.dromara.common.excel.core;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.excel.annotation.ExcelProperty;
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
import com.alibaba.excel.metadata.Head;
|
import com.alibaba.excel.metadata.Head;
|
||||||
|
import com.alibaba.excel.write.handler.WorkbookWriteHandler;
|
||||||
|
import com.alibaba.excel.write.handler.context.WorkbookWriteHandlerContext;
|
||||||
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
|
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -15,10 +19,7 @@ import org.dromara.common.core.utils.reflect.ReflectUtils;
|
|||||||
import org.dromara.common.excel.annotation.CellMerge;
|
import org.dromara.common.excel.annotation.CellMerge;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列值重复合并策略
|
* 列值重复合并策略
|
||||||
@ -26,7 +27,7 @@ import java.util.Map;
|
|||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CellMergeStrategy extends AbstractMergeStrategy {
|
public class CellMergeStrategy extends AbstractMergeStrategy implements WorkbookWriteHandler {
|
||||||
|
|
||||||
private final List<CellRangeAddress> cellList;
|
private final List<CellRangeAddress> cellList;
|
||||||
private final boolean hasTitle;
|
private final boolean hasTitle;
|
||||||
@ -41,17 +42,28 @@ public class CellMergeStrategy extends AbstractMergeStrategy {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {
|
protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {
|
||||||
// judge the list is not null
|
//单元格写入了,遍历合并区域,如果该Cell在区域内,但非首行,则清空
|
||||||
if (CollUtil.isNotEmpty(cellList)) {
|
final int rowIndex = cell.getRowIndex();
|
||||||
// the judge is necessary
|
if (CollUtil.isNotEmpty(cellList)){
|
||||||
if (cell.getRowIndex() == rowIndex && cell.getColumnIndex() == 0) {
|
for (CellRangeAddress cellAddresses : cellList) {
|
||||||
for (CellRangeAddress item : cellList) {
|
final int firstRow = cellAddresses.getFirstRow();
|
||||||
sheet.addMergedRegion(item);
|
if (cellAddresses.isInRange(cell) && rowIndex != firstRow){
|
||||||
|
cell.setBlank();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterWorkbookDispose(final WorkbookWriteHandlerContext context) {
|
||||||
|
//当前表格写完后,统一写入
|
||||||
|
if (CollUtil.isNotEmpty(cellList)){
|
||||||
|
for (CellRangeAddress item : cellList) {
|
||||||
|
context.getWriteContext().writeSheetHolder().getSheet().addMergedRegion(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private List<CellRangeAddress> handle(List<?> list, boolean hasTitle) {
|
private List<CellRangeAddress> handle(List<?> list, boolean hasTitle) {
|
||||||
List<CellRangeAddress> cellList = new ArrayList<>();
|
List<CellRangeAddress> cellList = new ArrayList<>();
|
||||||
@ -93,35 +105,15 @@ public class CellMergeStrategy extends AbstractMergeStrategy {
|
|||||||
// 空值跳过不合并
|
// 空值跳过不合并
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cellValue.equals(val)) {
|
if (!cellValue.equals(val)) {
|
||||||
if (i - repeatCell.getCurrent() > 1) {
|
if ((i - repeatCell.getCurrent() > 1) && isMerge(list, i, field)) {
|
||||||
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex - 1, colNum, colNum));
|
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex - 1, colNum, colNum));
|
||||||
}
|
}
|
||||||
map.put(field, new RepeatCell(val, i));
|
map.put(field, new RepeatCell(val, i));
|
||||||
} else if (j == 0) {
|
} else if (i == list.size() - 1) {
|
||||||
if (i == list.size() - 1) {
|
if (i > repeatCell.getCurrent() && isMerge(list, i, field)) {
|
||||||
if (i > repeatCell.getCurrent()) {
|
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum));
|
||||||
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 判断前面的是否合并了
|
|
||||||
RepeatCell firstCell = map.get(mergeFields.get(0));
|
|
||||||
if (repeatCell.getCurrent() != firstCell.getCurrent()) {
|
|
||||||
if (i == list.size() - 1) {
|
|
||||||
if (i > repeatCell.getCurrent()) {
|
|
||||||
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum));
|
|
||||||
}
|
|
||||||
} else if (repeatCell.getCurrent() < firstCell.getCurrent()) {
|
|
||||||
if (i - repeatCell.getCurrent() > 1) {
|
|
||||||
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex - 1, colNum, colNum));
|
|
||||||
}
|
|
||||||
map.put(field, new RepeatCell(val, i));
|
|
||||||
}
|
|
||||||
} else if (i == list.size() - 1) {
|
|
||||||
if (i > repeatCell.getCurrent()) {
|
|
||||||
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,6 +122,24 @@ public class CellMergeStrategy extends AbstractMergeStrategy {
|
|||||||
return cellList;
|
return cellList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isMerge(List<?> list, int i, Field field) {
|
||||||
|
boolean isMerge = true;
|
||||||
|
CellMerge cm = field.getAnnotation(CellMerge.class);
|
||||||
|
final String[] mergeBy = cm.mergeBy();
|
||||||
|
if (StrUtil.isAllNotBlank(mergeBy)) {
|
||||||
|
//比对当前list(i)和list(i - 1)的各个属性值一一比对 如果全为真 则为真
|
||||||
|
for (String fieldName : mergeBy) {
|
||||||
|
final Object valCurrent = ReflectUtil.getFieldValue(list.get(i), fieldName);
|
||||||
|
final Object valPre = ReflectUtil.getFieldValue(list.get(i - 1), fieldName);
|
||||||
|
if (!Objects.equals(valPre, valCurrent)) {
|
||||||
|
//依赖字段如有任一不等值,则标记为不可合并
|
||||||
|
isMerge = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isMerge;
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
static class RepeatCell {
|
static class RepeatCell {
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import org.dromara.common.core.exception.ServiceException;
|
|||||||
import org.dromara.common.core.service.DictService;
|
import org.dromara.common.core.service.DictService;
|
||||||
import org.dromara.common.core.utils.SpringUtils;
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
import org.dromara.common.core.utils.StreamUtils;
|
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.ExcelDictFormat;
|
||||||
import org.dromara.common.excel.annotation.ExcelEnumFormat;
|
import org.dromara.common.excel.annotation.ExcelEnumFormat;
|
||||||
|
|
||||||
@ -99,15 +100,16 @@ public class ExcelDownHandler implements SheetWriteHandler {
|
|||||||
ExcelDictFormat format = field.getDeclaredAnnotation(ExcelDictFormat.class);
|
ExcelDictFormat format = field.getDeclaredAnnotation(ExcelDictFormat.class);
|
||||||
String dictType = format.dictType();
|
String dictType = format.dictType();
|
||||||
String converterExp = format.readConverterExp();
|
String converterExp = format.readConverterExp();
|
||||||
if (StrUtil.isNotBlank(dictType)) {
|
if (StringUtils.isNotBlank(dictType)) {
|
||||||
// 如果传递了字典名,则依据字典建立下拉
|
// 如果传递了字典名,则依据字典建立下拉
|
||||||
Collection<String> values = Optional.ofNullable(dictService.getAllDictByDictType(dictType))
|
Collection<String> values = Optional.ofNullable(dictService.getAllDictByDictType(dictType))
|
||||||
.orElseThrow(() -> new ServiceException(String.format("字典 %s 不存在", dictType)))
|
.orElseThrow(() -> new ServiceException(String.format("字典 %s 不存在", dictType)))
|
||||||
.values();
|
.values();
|
||||||
options = new ArrayList<>(values);
|
options = new ArrayList<>(values);
|
||||||
} else if (StrUtil.isNotBlank(converterExp)) {
|
} else if (StringUtils.isNotBlank(converterExp)) {
|
||||||
// 如果指定了确切的值,则直接解析确切的值
|
// 如果指定了确切的值,则直接解析确切的值
|
||||||
options = StrUtil.split(converterExp, format.separator(), true, true);
|
List<String> strList = StringUtils.splitList(converterExp, format.separator());
|
||||||
|
options = StreamUtils.toList(strList, s -> StringUtils.split(s, "=")[1]);
|
||||||
}
|
}
|
||||||
} else if (field.isAnnotationPresent(ExcelEnumFormat.class)) {
|
} else if (field.isAnnotationPresent(ExcelEnumFormat.class)) {
|
||||||
// 否则如果指定了@ExcelEnumFormat,则使用枚举的逻辑
|
// 否则如果指定了@ExcelEnumFormat,则使用枚举的逻辑
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
import org.dromara.common.core.factory.YmlPropertySourceFactory;
|
import org.dromara.common.core.factory.YmlPropertySourceFactory;
|
||||||
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
import org.dromara.common.mybatis.handler.InjectionMetaObjectHandler;
|
import org.dromara.common.mybatis.handler.InjectionMetaObjectHandler;
|
||||||
import org.dromara.common.mybatis.interceptor.PlusDataPermissionInterceptor;
|
import org.dromara.common.mybatis.interceptor.PlusDataPermissionInterceptor;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
@ -41,7 +42,7 @@ public class MybatisPlusConfig {
|
|||||||
* 数据权限拦截器
|
* 数据权限拦截器
|
||||||
*/
|
*/
|
||||||
public PlusDataPermissionInterceptor dataPermissionInterceptor() {
|
public PlusDataPermissionInterceptor dataPermissionInterceptor() {
|
||||||
return new PlusDataPermissionInterceptor();
|
return new PlusDataPermissionInterceptor(SpringUtils.getProperty("mybatis-plus.mapperPackage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -35,7 +35,6 @@ public interface BaseMapperPlus<T, V> extends BaseMapper<T> {
|
|||||||
Log log = LogFactory.getLog(BaseMapperPlus.class);
|
Log log = LogFactory.getLog(BaseMapperPlus.class);
|
||||||
|
|
||||||
default Class<V> currentVoClass() {
|
default Class<V> currentVoClass() {
|
||||||
GenericTypeUtils.resolveTypeArguments(this.getClass(), BaseMapperPlus.class);
|
|
||||||
return (Class<V>) GenericTypeUtils.resolveTypeArguments(this.getClass(), BaseMapperPlus.class)[1];
|
return (Class<V>) GenericTypeUtils.resolveTypeArguments(this.getClass(), BaseMapperPlus.class)[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,16 +29,17 @@ public class InjectionMetaObjectHandler implements MetaObjectHandler {
|
|||||||
? baseEntity.getCreateTime() : new Date();
|
? baseEntity.getCreateTime() : new Date();
|
||||||
baseEntity.setCreateTime(current);
|
baseEntity.setCreateTime(current);
|
||||||
baseEntity.setUpdateTime(current);
|
baseEntity.setUpdateTime(current);
|
||||||
LoginUser loginUser = getLoginUser();
|
if (ObjectUtil.isNull(baseEntity.getCreateBy())) {
|
||||||
if (ObjectUtil.isNotNull(loginUser)) {
|
LoginUser loginUser = getLoginUser();
|
||||||
Long userId = ObjectUtil.isNotNull(baseEntity.getCreateBy())
|
if (ObjectUtil.isNotNull(loginUser)) {
|
||||||
? baseEntity.getCreateBy() : loginUser.getUserId();
|
Long userId = loginUser.getUserId();
|
||||||
// 当前已登录 且 创建人为空 则填充
|
// 当前已登录 且 创建人为空 则填充
|
||||||
baseEntity.setCreateBy(userId);
|
baseEntity.setCreateBy(userId);
|
||||||
// 当前已登录 且 更新人为空 则填充
|
// 当前已登录 且 更新人为空 则填充
|
||||||
baseEntity.setUpdateBy(userId);
|
baseEntity.setUpdateBy(userId);
|
||||||
baseEntity.setCreateDept(ObjectUtil.isNotNull(baseEntity.getCreateDept())
|
baseEntity.setCreateDept(ObjectUtil.isNotNull(baseEntity.getCreateDept())
|
||||||
? baseEntity.getCreateDept() : loginUser.getDeptId());
|
? baseEntity.getCreateDept() : loginUser.getDeptId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -53,11 +54,12 @@ public class InjectionMetaObjectHandler implements MetaObjectHandler {
|
|||||||
Date current = new Date();
|
Date current = new Date();
|
||||||
// 更新时间填充(不管为不为空)
|
// 更新时间填充(不管为不为空)
|
||||||
baseEntity.setUpdateTime(current);
|
baseEntity.setUpdateTime(current);
|
||||||
LoginUser loginUser = getLoginUser();
|
|
||||||
// 当前已登录 更新人填充(不管为不为空)
|
// 当前已登录 更新人填充(不管为不为空)
|
||||||
if (ObjectUtil.isNotNull(loginUser)) {
|
Long userId = LoginHelper.getUserId();
|
||||||
baseEntity.setUpdateBy(loginUser.getUserId());
|
if (ObjectUtil.isNotNull(userId)) {
|
||||||
|
baseEntity.setUpdateBy(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
|
throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package org.dromara.common.mybatis.handler;
|
|||||||
|
|
||||||
import org.dromara.common.core.domain.R;
|
import org.dromara.common.core.domain.R;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.mybatis.spring.MyBatisSystemException;
|
import org.mybatis.spring.MyBatisSystemException;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
@ -35,7 +36,7 @@ public class MybatisExceptionHandler {
|
|||||||
public R<Void> handleCannotFindDataSourceException(MyBatisSystemException e, HttpServletRequest request) {
|
public R<Void> handleCannotFindDataSourceException(MyBatisSystemException e, HttpServletRequest request) {
|
||||||
String requestURI = request.getRequestURI();
|
String requestURI = request.getRequestURI();
|
||||||
String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
if ("CannotFindDataSourceException".contains(message)) {
|
if (StringUtils.contains("CannotFindDataSourceException", message)) {
|
||||||
log.error("请求地址'{}', 未找到数据源", requestURI);
|
log.error("请求地址'{}', 未找到数据源", requestURI);
|
||||||
return R.fail("未找到数据源,请联系管理员确认");
|
return R.fail("未找到数据源,请联系管理员确认");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package org.dromara.common.mybatis.handler;
|
|||||||
|
|
||||||
import cn.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.core.annotation.AnnotationUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ClassUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.jsqlparser.JSQLParserException;
|
import net.sf.jsqlparser.JSQLParserException;
|
||||||
@ -10,6 +9,7 @@ import net.sf.jsqlparser.expression.Expression;
|
|||||||
import net.sf.jsqlparser.expression.Parenthesis;
|
import net.sf.jsqlparser.expression.Parenthesis;
|
||||||
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
|
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
|
||||||
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||||
|
import org.apache.ibatis.io.Resources;
|
||||||
import org.dromara.common.core.domain.dto.RoleDTO;
|
import org.dromara.common.core.domain.dto.RoleDTO;
|
||||||
import org.dromara.common.core.domain.model.LoginUser;
|
import org.dromara.common.core.domain.model.LoginUser;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
@ -21,16 +21,26 @@ import org.dromara.common.mybatis.annotation.DataPermission;
|
|||||||
import org.dromara.common.mybatis.enums.DataScopeType;
|
import org.dromara.common.mybatis.enums.DataScopeType;
|
||||||
import org.dromara.common.mybatis.helper.DataPermissionHelper;
|
import org.dromara.common.mybatis.helper.DataPermissionHelper;
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.expression.BeanFactoryResolver;
|
import org.springframework.context.expression.BeanFactoryResolver;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||||
|
import org.springframework.core.type.ClassMetadata;
|
||||||
|
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||||
import org.springframework.expression.BeanResolver;
|
import org.springframework.expression.BeanResolver;
|
||||||
import org.springframework.expression.ExpressionParser;
|
import org.springframework.expression.ExpressionParser;
|
||||||
import org.springframework.expression.ParserContext;
|
import org.springframework.expression.ParserContext;
|
||||||
import org.springframework.expression.common.TemplateParserContext;
|
import org.springframework.expression.common.TemplateParserContext;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@ -58,9 +68,13 @@ public class PlusDataPermissionHandler {
|
|||||||
*/
|
*/
|
||||||
private final BeanResolver beanResolver = new BeanFactoryResolver(SpringUtils.getBeanFactory());
|
private final BeanResolver beanResolver = new BeanFactoryResolver(SpringUtils.getBeanFactory());
|
||||||
|
|
||||||
|
public PlusDataPermissionHandler(String mapperPackage) {
|
||||||
|
scanMapperClasses(mapperPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Expression getSqlSegment(Expression where, String mappedStatementId, boolean isSelect) {
|
public Expression getSqlSegment(Expression where, String mappedStatementId, boolean isSelect) {
|
||||||
DataColumn[] dataColumns = findAnnotation(mappedStatementId);
|
DataPermission dataPermission = getDataPermission(mappedStatementId);
|
||||||
LoginUser currentUser = DataPermissionHelper.getVariable("user");
|
LoginUser currentUser = DataPermissionHelper.getVariable("user");
|
||||||
if (ObjectUtil.isNull(currentUser)) {
|
if (ObjectUtil.isNull(currentUser)) {
|
||||||
currentUser = LoginHelper.getLoginUser();
|
currentUser = LoginHelper.getLoginUser();
|
||||||
@ -70,7 +84,7 @@ public class PlusDataPermissionHandler {
|
|||||||
if (LoginHelper.isSuperAdmin() || LoginHelper.isTenantAdmin()) {
|
if (LoginHelper.isSuperAdmin() || LoginHelper.isTenantAdmin()) {
|
||||||
return where;
|
return where;
|
||||||
}
|
}
|
||||||
String dataFilterSql = buildDataFilter(dataColumns, isSelect);
|
String dataFilterSql = buildDataFilter(dataPermission.value(), isSelect);
|
||||||
if (StringUtils.isBlank(dataFilterSql)) {
|
if (StringUtils.isBlank(dataFilterSql)) {
|
||||||
return where;
|
return where;
|
||||||
}
|
}
|
||||||
@ -144,43 +158,64 @@ public class PlusDataPermissionHandler {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataColumn[] findAnnotation(String mappedStatementId) {
|
/**
|
||||||
StringBuilder sb = new StringBuilder(mappedStatementId);
|
* 通过 mapperPackage 设置的扫描包 扫描缓存有注解的方法与类
|
||||||
int index = sb.lastIndexOf(".");
|
*/
|
||||||
String clazzName = sb.substring(0, index);
|
private void scanMapperClasses(String mapperPackage) {
|
||||||
String methodName = sb.substring(index + 1, sb.length());
|
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||||
Class<?> clazz;
|
CachingMetadataReaderFactory factory = new CachingMetadataReaderFactory();
|
||||||
|
String[] packagePatternArray = StringUtils.splitPreserveAllTokens(mapperPackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
|
||||||
|
String classpath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX;
|
||||||
try {
|
try {
|
||||||
clazz = ClassUtil.loadClass(clazzName);
|
for (String packagePattern : packagePatternArray) {
|
||||||
|
String path = ClassUtils.convertClassNameToResourcePath(packagePattern);
|
||||||
|
Resource[] resources = resolver.getResources(classpath + path + "/*.class");
|
||||||
|
for (Resource resource : resources) {
|
||||||
|
ClassMetadata classMetadata = factory.getMetadataReader(resource).getClassMetadata();
|
||||||
|
Class<?> clazz = Resources.classForName(classMetadata.getClassName());
|
||||||
|
findAnnotation(clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
log.error("初始化数据安全缓存时出错:{}", e.getMessage());
|
||||||
}
|
}
|
||||||
List<Method> methods = Arrays.stream(ClassUtil.getDeclaredMethods(clazz))
|
}
|
||||||
.filter(method -> method.getName().equals(methodName)).toList();
|
|
||||||
|
private void findAnnotation(Class<?> clazz) {
|
||||||
DataPermission dataPermission;
|
DataPermission dataPermission;
|
||||||
// 获取方法注解
|
// 获取方法注解
|
||||||
for (Method method : methods) {
|
for (Method method : clazz.getMethods()) {
|
||||||
dataPermission = dataPermissionCacheMap.get(mappedStatementId);
|
if (method.isDefault() || method.isVarArgs()) {
|
||||||
if (ObjectUtil.isNotNull(dataPermission)) {
|
continue;
|
||||||
return dataPermission.value();
|
|
||||||
}
|
}
|
||||||
|
String mappedStatementId = clazz.getName() + "." + method.getName();
|
||||||
if (AnnotationUtil.hasAnnotation(method, DataPermission.class)) {
|
if (AnnotationUtil.hasAnnotation(method, DataPermission.class)) {
|
||||||
dataPermission = AnnotationUtil.getAnnotation(method, DataPermission.class);
|
dataPermission = AnnotationUtil.getAnnotation(method, DataPermission.class);
|
||||||
dataPermissionCacheMap.put(mappedStatementId, dataPermission);
|
dataPermissionCacheMap.put(mappedStatementId, dataPermission);
|
||||||
return dataPermission.value();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataPermission = dataPermissionCacheMap.get(clazz.getName());
|
|
||||||
if (ObjectUtil.isNotNull(dataPermission)) {
|
|
||||||
return dataPermission.value();
|
|
||||||
}
|
|
||||||
// 获取类注解
|
// 获取类注解
|
||||||
if (AnnotationUtil.hasAnnotation(clazz, DataPermission.class)) {
|
if (AnnotationUtil.hasAnnotation(clazz, DataPermission.class)) {
|
||||||
dataPermission = AnnotationUtil.getAnnotation(clazz, DataPermission.class);
|
dataPermission = AnnotationUtil.getAnnotation(clazz, DataPermission.class);
|
||||||
dataPermissionCacheMap.put(clazz.getName(), dataPermission);
|
dataPermissionCacheMap.put(clazz.getName(), dataPermission);
|
||||||
return dataPermission.value();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataPermission getDataPermission(String mapperId) {
|
||||||
|
if (dataPermissionCacheMap.containsKey(mapperId)) {
|
||||||
|
return dataPermissionCacheMap.get(mapperId);
|
||||||
|
}
|
||||||
|
String clazzName = mapperId.substring(0, mapperId.lastIndexOf("."));
|
||||||
|
if (dataPermissionCacheMap.containsKey(clazzName)) {
|
||||||
|
return dataPermissionCacheMap.get(clazzName);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否无效
|
||||||
|
*/
|
||||||
|
public boolean invalid(String mapperId) {
|
||||||
|
return getDataPermission(mapperId) == null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,10 @@
|
|||||||
package org.dromara.common.mybatis.interceptor;
|
package org.dromara.common.mybatis.interceptor;
|
||||||
|
|
||||||
import cn.hutool.core.collection.ConcurrentHashSet;
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
|
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
|
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
|
||||||
import com.baomidou.mybatisplus.extension.parser.JsqlParserSupport;
|
import com.baomidou.mybatisplus.extension.parser.JsqlParserSupport;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
||||||
import org.dromara.common.mybatis.annotation.DataColumn;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.mybatis.handler.PlusDataPermissionHandler;
|
|
||||||
import net.sf.jsqlparser.expression.Expression;
|
import net.sf.jsqlparser.expression.Expression;
|
||||||
import net.sf.jsqlparser.statement.delete.Delete;
|
import net.sf.jsqlparser.statement.delete.Delete;
|
||||||
import net.sf.jsqlparser.statement.select.PlainSelect;
|
import net.sf.jsqlparser.statement.select.PlainSelect;
|
||||||
@ -22,11 +19,11 @@ import org.apache.ibatis.mapping.MappedStatement;
|
|||||||
import org.apache.ibatis.mapping.SqlCommandType;
|
import org.apache.ibatis.mapping.SqlCommandType;
|
||||||
import org.apache.ibatis.session.ResultHandler;
|
import org.apache.ibatis.session.ResultHandler;
|
||||||
import org.apache.ibatis.session.RowBounds;
|
import org.apache.ibatis.session.RowBounds;
|
||||||
|
import org.dromara.common.mybatis.handler.PlusDataPermissionHandler;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据权限拦截器
|
* 数据权限拦截器
|
||||||
@ -34,13 +31,14 @@ import java.util.Set;
|
|||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
* @version 3.5.0
|
* @version 3.5.0
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class PlusDataPermissionInterceptor extends JsqlParserSupport implements InnerInterceptor {
|
public class PlusDataPermissionInterceptor extends JsqlParserSupport implements InnerInterceptor {
|
||||||
|
|
||||||
private final PlusDataPermissionHandler dataPermissionHandler = new PlusDataPermissionHandler();
|
private final PlusDataPermissionHandler dataPermissionHandler;
|
||||||
/**
|
|
||||||
* 无效注解方法缓存用于快速返回
|
public PlusDataPermissionInterceptor(String mapperPackage) {
|
||||||
*/
|
this.dataPermissionHandler = new PlusDataPermissionHandler(mapperPackage);
|
||||||
private final Set<String> invalidCacheSet = new ConcurrentHashSet<>();
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
|
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
|
||||||
@ -49,12 +47,7 @@ public class PlusDataPermissionInterceptor extends JsqlParserSupport implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 检查是否无效 无数据权限注解
|
// 检查是否无效 无数据权限注解
|
||||||
if (invalidCacheSet.contains(ms.getId())) {
|
if (dataPermissionHandler.invalid(ms.getId())) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
DataColumn[] dataColumns = dataPermissionHandler.findAnnotation(ms.getId());
|
|
||||||
if (ArrayUtil.isEmpty(dataColumns)) {
|
|
||||||
invalidCacheSet.add(ms.getId());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 解析 sql 分配对应方法
|
// 解析 sql 分配对应方法
|
||||||
@ -72,12 +65,7 @@ public class PlusDataPermissionInterceptor extends JsqlParserSupport implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 检查是否无效 无数据权限注解
|
// 检查是否无效 无数据权限注解
|
||||||
if (invalidCacheSet.contains(ms.getId())) {
|
if (dataPermissionHandler.invalid(ms.getId())) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
DataColumn[] dataColumns = dataPermissionHandler.findAnnotation(ms.getId());
|
|
||||||
if (ArrayUtil.isEmpty(dataColumns)) {
|
|
||||||
invalidCacheSet.add(ms.getId());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
|
PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
|
||||||
|
|||||||
@ -6,8 +6,6 @@ logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
|
|||||||
appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
|
appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
|
||||||
# 使用日志系统记录 sql
|
# 使用日志系统记录 sql
|
||||||
#appender=com.p6spy.engine.spy.appender.Slf4JLogger
|
#appender=com.p6spy.engine.spy.appender.Slf4JLogger
|
||||||
# 设置 p6spy driver 代理
|
|
||||||
#deregisterdrivers=true
|
|
||||||
# 取消JDBC URL前缀
|
# 取消JDBC URL前缀
|
||||||
useprefix=true
|
useprefix=true
|
||||||
# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
|
# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
|
||||||
@ -16,12 +14,6 @@ excludecategories=info,debug,result,commit,resultset
|
|||||||
dateformat=yyyy-MM-dd HH:mm:ss
|
dateformat=yyyy-MM-dd HH:mm:ss
|
||||||
# SQL语句打印时间格式
|
# SQL语句打印时间格式
|
||||||
databaseDialectTimestampFormat=yyyy-MM-dd HH:mm:ss
|
databaseDialectTimestampFormat=yyyy-MM-dd HH:mm:ss
|
||||||
# 实际驱动可多个
|
|
||||||
#driverlist=org.h2.Driver
|
|
||||||
# 是否开启慢SQL记录
|
|
||||||
outagedetection=true
|
|
||||||
# 慢SQL记录标准 2 秒
|
|
||||||
outagedetectioninterval=2
|
|
||||||
# 是否过滤 Log
|
# 是否过滤 Log
|
||||||
filter=true
|
filter=true
|
||||||
# 过滤 Log 时所排除的 sql 关键字,以逗号分隔
|
# 过滤 Log 时所排除的 sql 关键字,以逗号分隔
|
||||||
|
|||||||
@ -26,10 +26,46 @@
|
|||||||
<artifactId>ruoyi-common-redis</artifactId>
|
<artifactId>ruoyi-common-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- AWS SDK for Java 2.x -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
<artifactId>aws-java-sdk-s3</artifactId>
|
<artifactId>s3</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<!-- 将基于 Netty 的 HTTP 客户端从类路径中移除 -->
|
||||||
|
<exclusion>
|
||||||
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
|
<artifactId>netty-nio-client</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<!-- 将基于 CRT 的 HTTP 客户端从类路径中移除 -->
|
||||||
|
<exclusion>
|
||||||
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
|
<artifactId>aws-crt-client</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<!-- 将基于 Apache 的 HTTP 客户端从类路径中移除 -->
|
||||||
|
<exclusion>
|
||||||
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
|
<artifactId>apache-client</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<!-- 将配置基于 URL 连接的 HTTP 客户端从类路径中移除 -->
|
||||||
|
<exclusion>
|
||||||
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
|
<artifactId>url-connection-client</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 使用AWS基于 CRT 的 S3 客户端 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>software.amazon.awssdk.crt</groupId>
|
||||||
|
<artifactId>aws-crt</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 基于 AWS CRT 的 S3 客户端的性能增强的 S3 传输管理器 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
|
<artifactId>s3-transfer-manager</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -2,73 +2,114 @@ package org.dromara.common.oss.core;
|
|||||||
|
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.amazonaws.ClientConfiguration;
|
import org.dromara.common.core.constant.Constants;
|
||||||
import com.amazonaws.HttpMethod;
|
|
||||||
import com.amazonaws.Protocol;
|
|
||||||
import com.amazonaws.auth.AWSCredentials;
|
|
||||||
import com.amazonaws.auth.AWSCredentialsProvider;
|
|
||||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
|
||||||
import com.amazonaws.auth.BasicAWSCredentials;
|
|
||||||
import com.amazonaws.client.builder.AwsClientBuilder;
|
|
||||||
import com.amazonaws.services.s3.AmazonS3;
|
|
||||||
import com.amazonaws.services.s3.AmazonS3Client;
|
|
||||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
|
||||||
import com.amazonaws.services.s3.model.*;
|
|
||||||
import org.dromara.common.core.utils.DateUtils;
|
import org.dromara.common.core.utils.DateUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
|
import org.dromara.common.core.utils.file.FileUtils;
|
||||||
import org.dromara.common.oss.constant.OssConstant;
|
import org.dromara.common.oss.constant.OssConstant;
|
||||||
import org.dromara.common.oss.entity.UploadResult;
|
import org.dromara.common.oss.entity.UploadResult;
|
||||||
import org.dromara.common.oss.enumd.AccessPolicyType;
|
import org.dromara.common.oss.enumd.AccessPolicyType;
|
||||||
import org.dromara.common.oss.enumd.PolicyType;
|
import org.dromara.common.oss.enumd.PolicyType;
|
||||||
import org.dromara.common.oss.exception.OssException;
|
import org.dromara.common.oss.exception.OssException;
|
||||||
import org.dromara.common.oss.properties.OssProperties;
|
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.AsyncRequestBody;
|
||||||
|
import software.amazon.awssdk.core.async.BlockingInputStreamAsyncRequestBody;
|
||||||
|
import software.amazon.awssdk.regions.Region;
|
||||||
|
import software.amazon.awssdk.services.s3.S3AsyncClient;
|
||||||
|
import software.amazon.awssdk.services.s3.S3Configuration;
|
||||||
|
import software.amazon.awssdk.services.s3.model.NoSuchBucketException;
|
||||||
|
import software.amazon.awssdk.services.s3.model.S3Exception;
|
||||||
|
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
|
||||||
|
import software.amazon.awssdk.transfer.s3.S3TransferManager;
|
||||||
|
import software.amazon.awssdk.transfer.s3.model.*;
|
||||||
|
import software.amazon.awssdk.transfer.s3.progress.LoggingTransferListener;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* S3 存储协议 所有兼容S3协议的云厂商均支持
|
* S3 存储协议 所有兼容S3协议的云厂商均支持
|
||||||
* 阿里云 腾讯云 七牛云 minio
|
* 阿里云 腾讯云 七牛云 minio
|
||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author AprilWind
|
||||||
*/
|
*/
|
||||||
public class OssClient {
|
public class OssClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务商
|
||||||
|
*/
|
||||||
private final String configKey;
|
private final String configKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置属性
|
||||||
|
*/
|
||||||
private final OssProperties properties;
|
private final OssProperties properties;
|
||||||
|
|
||||||
private final AmazonS3 client;
|
/**
|
||||||
|
* Amazon S3 异步客户端
|
||||||
|
*/
|
||||||
|
private final S3AsyncClient client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于管理 S3 数据传输的高级工具
|
||||||
|
*/
|
||||||
|
private final S3TransferManager transferManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AWS S3 预签名 URL 的生成器
|
||||||
|
*/
|
||||||
|
private final S3Presigner presigner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造方法
|
||||||
|
*
|
||||||
|
* @param configKey 配置键
|
||||||
|
* @param ossProperties Oss配置属性
|
||||||
|
*/
|
||||||
public OssClient(String configKey, OssProperties ossProperties) {
|
public OssClient(String configKey, OssProperties ossProperties) {
|
||||||
this.configKey = configKey;
|
this.configKey = configKey;
|
||||||
this.properties = ossProperties;
|
this.properties = ossProperties;
|
||||||
try {
|
try {
|
||||||
AwsClientBuilder.EndpointConfiguration endpointConfig =
|
// 创建 AWS 认证信息
|
||||||
new AwsClientBuilder.EndpointConfiguration(properties.getEndpoint(), properties.getRegion());
|
StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider.create(
|
||||||
|
AwsBasicCredentials.create(properties.getAccessKey(), properties.getSecretKey()));
|
||||||
|
|
||||||
AWSCredentials credentials = new BasicAWSCredentials(properties.getAccessKey(), properties.getSecretKey());
|
//创建AWS基于 CRT 的 S3 客户端
|
||||||
AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
|
this.client = S3AsyncClient.crtBuilder()
|
||||||
ClientConfiguration clientConfig = new ClientConfiguration();
|
.credentialsProvider(credentialsProvider)
|
||||||
if (OssConstant.IS_HTTPS.equals(properties.getIsHttps())) {
|
.endpointOverride(URI.create(getEndpoint()))
|
||||||
clientConfig.setProtocol(Protocol.HTTPS);
|
.region(of())
|
||||||
} else {
|
.targetThroughputInGbps(20.0)
|
||||||
clientConfig.setProtocol(Protocol.HTTP);
|
.minimumPartSizeInBytes(10 * 1025 * 1024L)
|
||||||
}
|
.checksumValidationEnabled(false)
|
||||||
AmazonS3ClientBuilder build = AmazonS3Client.builder()
|
.build();
|
||||||
.withEndpointConfiguration(endpointConfig)
|
|
||||||
.withClientConfiguration(clientConfig)
|
//AWS基于 CRT 的 S3 AsyncClient 实例用作 S3 传输管理器的底层客户端
|
||||||
.withCredentials(credentialsProvider)
|
this.transferManager = S3TransferManager.builder().s3Client(this.client).build();
|
||||||
.disableChunkedEncoding();
|
|
||||||
if (!StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE)) {
|
// 检查是否连接到 MinIO,MinIO 使用 HTTPS 限制使用域名访问,需要启用路径样式访问
|
||||||
|
S3Configuration config = S3Configuration.builder().chunkedEncodingEnabled(false)
|
||||||
// minio 使用https限制使用域名访问 需要此配置 站点填域名
|
// minio 使用https限制使用域名访问 需要此配置 站点填域名
|
||||||
build.enablePathStyleAccess();
|
.pathStyleAccessEnabled(!StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE)).build();
|
||||||
}
|
|
||||||
this.client = build.build();
|
|
||||||
|
|
||||||
|
// 创建 预签名 URL 的生成器 实例,用于生成 S3 预签名 URL
|
||||||
|
this.presigner = S3Presigner.builder()
|
||||||
|
.region(of())
|
||||||
|
.credentialsProvider(credentialsProvider)
|
||||||
|
.endpointOverride(URI.create(getDomain()))
|
||||||
|
.serviceConfiguration(config)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 创建存储桶
|
||||||
createBucket();
|
createBucket();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (e instanceof OssException) {
|
if (e instanceof OssException) {
|
||||||
@ -78,126 +119,158 @@ public class OssClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步创建存储桶
|
||||||
|
* 如果存储桶不存在,会进行创建;如果存储桶存在,不执行任何操作
|
||||||
|
*
|
||||||
|
* @throws OssException 当创建存储桶时发生异常时抛出
|
||||||
|
*/
|
||||||
public void createBucket() {
|
public void createBucket() {
|
||||||
|
String bucketName = properties.getBucketName();
|
||||||
try {
|
try {
|
||||||
String bucketName = properties.getBucketName();
|
// 尝试获取存储桶的信息
|
||||||
if (client.doesBucketExistV2(bucketName)) {
|
client.headBucket(
|
||||||
return;
|
x -> x.bucket(bucketName)
|
||||||
|
.build())
|
||||||
|
.join();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (ex.getCause() instanceof NoSuchBucketException) {
|
||||||
|
try {
|
||||||
|
// 存储桶不存在,尝试创建存储桶
|
||||||
|
client.createBucket(
|
||||||
|
x -> x.bucket(bucketName))
|
||||||
|
.join();
|
||||||
|
|
||||||
|
// 设置存储桶的访问策略(Bucket Policy)
|
||||||
|
client.putBucketPolicy(
|
||||||
|
x -> x.bucket(bucketName)
|
||||||
|
.policy(getPolicy(bucketName, getAccessPolicy().getPolicyType())))
|
||||||
|
.join();
|
||||||
|
} catch (S3Exception e) {
|
||||||
|
// 存储桶创建或策略设置失败
|
||||||
|
throw new OssException("创建Bucket失败, 请核对配置信息:[" + e.getMessage() + "]");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new OssException("判断Bucket是否存在失败,请核对配置信息:[" + ex.getMessage() + "]");
|
||||||
}
|
}
|
||||||
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
|
|
||||||
AccessPolicyType accessPolicy = getAccessPolicy();
|
|
||||||
createBucketRequest.setCannedAcl(accessPolicy.getAcl());
|
|
||||||
client.createBucket(createBucketRequest);
|
|
||||||
client.setBucketPolicy(bucketName, getPolicy(bucketName, accessPolicy.getPolicyType()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new OssException("创建Bucket失败, 请核对配置信息:[" + e.getMessage() + "]");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UploadResult upload(byte[] data, String path, String contentType) {
|
/**
|
||||||
return upload(new ByteArrayInputStream(data), path, contentType);
|
* 上传文件到 Amazon S3,并返回上传结果
|
||||||
|
*
|
||||||
|
* @param filePath 本地文件路径
|
||||||
|
* @param key 在 Amazon S3 中的对象键
|
||||||
|
* @param md5Digest 本地文件的 MD5 哈希值(可选)
|
||||||
|
* @return UploadResult 包含上传后的文件信息
|
||||||
|
* @throws OssException 如果上传失败,抛出自定义异常
|
||||||
|
*/
|
||||||
|
public UploadResult upload(Path filePath, String key, String md5Digest) {
|
||||||
|
try {
|
||||||
|
// 构建上传请求对象
|
||||||
|
FileUpload fileUpload = transferManager.uploadFile(
|
||||||
|
x -> x.putObjectRequest(
|
||||||
|
y -> y.bucket(properties.getBucketName())
|
||||||
|
.key(key)
|
||||||
|
.contentMD5(StringUtils.isNotEmpty(md5Digest) ? md5Digest : null)
|
||||||
|
.build())
|
||||||
|
.addTransferListener(LoggingTransferListener.create())
|
||||||
|
.source(filePath).build());
|
||||||
|
|
||||||
|
// 等待上传完成并获取上传结果
|
||||||
|
CompletedFileUpload uploadResult = fileUpload.completionFuture().join();
|
||||||
|
String eTag = uploadResult.response().eTag();
|
||||||
|
|
||||||
|
// 提取上传结果中的 ETag,并构建一个自定义的 UploadResult 对象
|
||||||
|
return UploadResult.builder().url(getUrl() + StringUtils.SLASH + key).filename(key).eTag(eTag).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 捕获异常并抛出自定义异常
|
||||||
|
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
||||||
|
} finally {
|
||||||
|
// 无论上传是否成功,最终都会删除临时文件
|
||||||
|
FileUtils.del(filePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UploadResult upload(InputStream inputStream, String path, String contentType) {
|
/**
|
||||||
|
* 上传 InputStream 到 Amazon S3
|
||||||
|
*
|
||||||
|
* @param inputStream 要上传的输入流
|
||||||
|
* @param key 在 Amazon S3 中的对象键
|
||||||
|
* @param length 输入流的长度
|
||||||
|
* @return UploadResult 包含上传后的文件信息
|
||||||
|
* @throws OssException 如果上传失败,抛出自定义异常
|
||||||
|
*/
|
||||||
|
public UploadResult upload(InputStream inputStream, String key, Long length) {
|
||||||
|
// 如果输入流不是 ByteArrayInputStream,则将其读取为字节数组再创建 ByteArrayInputStream
|
||||||
if (!(inputStream instanceof ByteArrayInputStream)) {
|
if (!(inputStream instanceof ByteArrayInputStream)) {
|
||||||
inputStream = new ByteArrayInputStream(IoUtil.readBytes(inputStream));
|
inputStream = new ByteArrayInputStream(IoUtil.readBytes(inputStream));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ObjectMetadata metadata = new ObjectMetadata();
|
// 创建异步请求体(length如果为空会报错)
|
||||||
metadata.setContentType(contentType);
|
BlockingInputStreamAsyncRequestBody body = AsyncRequestBody.forBlockingInputStream(length);
|
||||||
metadata.setContentLength(inputStream.available());
|
|
||||||
PutObjectRequest putObjectRequest = new PutObjectRequest(properties.getBucketName(), path, inputStream, metadata);
|
// 使用 transferManager 进行上传
|
||||||
// 设置上传对象的 Acl 为公共读
|
Upload upload = transferManager.upload(
|
||||||
putObjectRequest.setCannedAcl(getAccessPolicy().getAcl());
|
x -> x.requestBody(body)
|
||||||
client.putObject(putObjectRequest);
|
.putObjectRequest(
|
||||||
|
y -> y.bucket(properties.getBucketName())
|
||||||
|
.key(key)
|
||||||
|
.build())
|
||||||
|
.build());
|
||||||
|
|
||||||
|
// 将输入流写入请求体
|
||||||
|
body.writeInputStream(inputStream);
|
||||||
|
|
||||||
|
// 等待文件上传操作完成
|
||||||
|
CompletedUpload uploadResult = upload.completionFuture().join();
|
||||||
|
String eTag = uploadResult.response().eTag();
|
||||||
|
|
||||||
|
// 提取上传结果中的 ETag,并构建一个自定义的 UploadResult 对象
|
||||||
|
return UploadResult.builder().url(getUrl() + StringUtils.SLASH + key).filename(key).eTag(eTag).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
||||||
}
|
}
|
||||||
return UploadResult.builder().url(getUrl() + "/" + path).filename(path).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UploadResult upload(File file, String path) {
|
|
||||||
try {
|
|
||||||
PutObjectRequest putObjectRequest = new PutObjectRequest(properties.getBucketName(), path, file);
|
|
||||||
// 设置上传对象的 Acl 为公共读
|
|
||||||
putObjectRequest.setCannedAcl(getAccessPolicy().getAcl());
|
|
||||||
client.putObject(putObjectRequest);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
|
||||||
}
|
|
||||||
return UploadResult.builder().url(getUrl() + "/" + path).filename(path).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete(String path) {
|
|
||||||
path = path.replace(getUrl() + "/", "");
|
|
||||||
try {
|
|
||||||
client.deleteObject(properties.getBucketName(), path);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new OssException("删除文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
|
||||||
return upload(data, getPath(properties.getPrefix(), suffix), contentType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) {
|
|
||||||
return upload(inputStream, getPath(properties.getPrefix(), suffix), contentType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UploadResult uploadSuffix(File file, String suffix) {
|
|
||||||
return upload(file, getPath(properties.getPrefix(), suffix));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件元数据
|
* 下载文件从 Amazon S3 到临时目录
|
||||||
*
|
*
|
||||||
* @param path 完整文件路径
|
* @param path 文件在 Amazon S3 中的对象键
|
||||||
|
* @return 下载后的文件在本地的临时路径
|
||||||
|
* @throws OssException 如果下载失败,抛出自定义异常
|
||||||
*/
|
*/
|
||||||
public ObjectMetadata getObjectMetadata(String path) {
|
public Path fileDownload(String path) {
|
||||||
path = path.replace(getUrl() + "/", "");
|
// 构建临时文件
|
||||||
S3Object object = client.getObject(properties.getBucketName(), path);
|
Path tempFilePath = FileUtils.createTempFile().toPath();
|
||||||
return object.getObjectMetadata();
|
// 使用 S3TransferManager 下载文件
|
||||||
|
FileDownload downloadFile = transferManager.downloadFile(
|
||||||
|
x -> x.getObjectRequest(
|
||||||
|
y -> y.bucket(properties.getBucketName())
|
||||||
|
.key(removeBaseUrl(path))
|
||||||
|
.build())
|
||||||
|
.addTransferListener(LoggingTransferListener.create())
|
||||||
|
.destination(tempFilePath)
|
||||||
|
.build());
|
||||||
|
// 等待文件下载操作完成
|
||||||
|
downloadFile.completionFuture().join();
|
||||||
|
return tempFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getObjectContent(String path) {
|
/**
|
||||||
path = path.replace(getUrl() + "/", "");
|
* 删除云存储服务中指定路径下文件
|
||||||
S3Object object = client.getObject(properties.getBucketName(), path);
|
*
|
||||||
return object.getObjectContent();
|
* @param path 指定路径
|
||||||
}
|
*/
|
||||||
|
public void delete(String path) {
|
||||||
public String getUrl() {
|
try {
|
||||||
String domain = properties.getDomain();
|
client.deleteObject(
|
||||||
String endpoint = properties.getEndpoint();
|
x -> x.bucket(properties.getBucketName())
|
||||||
String header = OssConstant.IS_HTTPS.equals(properties.getIsHttps()) ? "https://" : "http://";
|
.key(removeBaseUrl(path))
|
||||||
// 云服务商直接返回
|
.build());
|
||||||
if (StringUtils.containsAny(endpoint, OssConstant.CLOUD_SERVICE)) {
|
} catch (Exception e) {
|
||||||
if (StringUtils.isNotBlank(domain)) {
|
throw new OssException("删除文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
||||||
return header + domain;
|
|
||||||
}
|
|
||||||
return header + properties.getBucketName() + "." + endpoint;
|
|
||||||
}
|
}
|
||||||
// minio 单独处理
|
|
||||||
if (StringUtils.isNotBlank(domain)) {
|
|
||||||
return header + domain + "/" + properties.getBucketName();
|
|
||||||
}
|
|
||||||
return header + endpoint + "/" + properties.getBucketName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath(String prefix, String suffix) {
|
|
||||||
// 生成uuid
|
|
||||||
String uuid = IdUtil.fastSimpleUUID();
|
|
||||||
// 文件路径
|
|
||||||
String path = DateUtils.datePath() + "/" + uuid;
|
|
||||||
if (StringUtils.isNotBlank(prefix)) {
|
|
||||||
path = prefix + "/" + path;
|
|
||||||
}
|
|
||||||
return path + suffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getConfigKey() {
|
|
||||||
return configKey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -207,14 +280,189 @@ public class OssClient {
|
|||||||
* @param second 授权时间
|
* @param second 授权时间
|
||||||
*/
|
*/
|
||||||
public String getPrivateUrl(String objectKey, Integer second) {
|
public String getPrivateUrl(String objectKey, Integer second) {
|
||||||
GeneratePresignedUrlRequest generatePresignedUrlRequest =
|
// 使用 AWS S3 预签名 URL 的生成器 获取对象的预签名 URL
|
||||||
new GeneratePresignedUrlRequest(properties.getBucketName(), objectKey)
|
URL url = presigner.presignGetObject(
|
||||||
.withMethod(HttpMethod.GET)
|
x -> x.signatureDuration(Duration.ofSeconds(second))
|
||||||
.withExpiration(new Date(System.currentTimeMillis() + 1000L * second));
|
.getObjectRequest(
|
||||||
URL url = client.generatePresignedUrl(generatePresignedUrlRequest);
|
y -> y.bucket(properties.getBucketName())
|
||||||
|
.key(objectKey)
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.url();
|
||||||
return url.toString();
|
return url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传 byte[] 数据到 Amazon S3,使用指定的后缀构造对象键。
|
||||||
|
*
|
||||||
|
* @param data 要上传的 byte[] 数据
|
||||||
|
* @param suffix 对象键的后缀
|
||||||
|
* @return UploadResult 包含上传后的文件信息
|
||||||
|
* @throws OssException 如果上传失败,抛出自定义异常
|
||||||
|
*/
|
||||||
|
public UploadResult uploadSuffix(byte[] data, String suffix) {
|
||||||
|
return upload(new ByteArrayInputStream(data), getPath(properties.getPrefix(), suffix), Long.valueOf(data.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传 InputStream 到 Amazon S3,使用指定的后缀构造对象键。
|
||||||
|
*
|
||||||
|
* @param inputStream 要上传的输入流
|
||||||
|
* @param suffix 对象键的后缀
|
||||||
|
* @param length 输入流的长度
|
||||||
|
* @return UploadResult 包含上传后的文件信息
|
||||||
|
* @throws OssException 如果上传失败,抛出自定义异常
|
||||||
|
*/
|
||||||
|
public UploadResult uploadSuffix(InputStream inputStream, String suffix, Long length) {
|
||||||
|
return upload(inputStream, getPath(properties.getPrefix(), suffix), length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件到 Amazon S3,使用指定的后缀构造对象键
|
||||||
|
*
|
||||||
|
* @param file 要上传的文件
|
||||||
|
* @param suffix 对象键的后缀
|
||||||
|
* @return UploadResult 包含上传后的文件信息
|
||||||
|
* @throws OssException 如果上传失败,抛出自定义异常
|
||||||
|
*/
|
||||||
|
public UploadResult uploadSuffix(File file, String suffix) {
|
||||||
|
return upload(file.toPath(), getPath(properties.getPrefix(), suffix), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件输入流
|
||||||
|
*
|
||||||
|
* @param path 完整文件路径
|
||||||
|
* @return 输入流
|
||||||
|
*/
|
||||||
|
public InputStream getObjectContent(String path) throws IOException {
|
||||||
|
// 下载文件到临时目录
|
||||||
|
Path tempFilePath = fileDownload(path);
|
||||||
|
// 创建输入流
|
||||||
|
InputStream inputStream = Files.newInputStream(tempFilePath);
|
||||||
|
// 删除临时文件
|
||||||
|
FileUtils.del(tempFilePath);
|
||||||
|
// 返回对象内容的输入流
|
||||||
|
return inputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 S3 客户端的终端点 URL
|
||||||
|
*
|
||||||
|
* @return 终端点 URL
|
||||||
|
*/
|
||||||
|
public String getEndpoint() {
|
||||||
|
// 根据配置文件中的是否使用 HTTPS,设置协议头部
|
||||||
|
String header = getIsHttps();
|
||||||
|
// 拼接协议头部和终端点,得到完整的终端点 URL
|
||||||
|
return header + properties.getEndpoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 S3 客户端的终端点 URL(自定义域名)
|
||||||
|
*
|
||||||
|
* @return 终端点 URL
|
||||||
|
*/
|
||||||
|
public String getDomain() {
|
||||||
|
// 从配置中获取域名、终端点、是否使用 HTTPS 等信息
|
||||||
|
String domain = properties.getDomain();
|
||||||
|
String endpoint = properties.getEndpoint();
|
||||||
|
String header = getIsHttps();
|
||||||
|
|
||||||
|
// 如果是云服务商,直接返回域名或终端点
|
||||||
|
if (StringUtils.containsAny(endpoint, OssConstant.CLOUD_SERVICE)) {
|
||||||
|
return StringUtils.isNotEmpty(domain) ? header + domain : header + endpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是 MinIO,处理域名并返回
|
||||||
|
if (StringUtils.isNotEmpty(domain)) {
|
||||||
|
return domain.startsWith(Constants.HTTPS) || domain.startsWith(Constants.HTTP) ? domain : header + domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回终端点
|
||||||
|
return header + endpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据传入的 region 参数返回相应的 AWS 区域
|
||||||
|
* 如果 region 参数非空,使用 Region.of 方法创建并返回对应的 AWS 区域对象
|
||||||
|
* 如果 region 参数为空,返回一个默认的 AWS 区域(例如,us-east-1),作为广泛支持的区域
|
||||||
|
*
|
||||||
|
* @return 对应的 AWS 区域对象,或者默认的广泛支持的区域(us-east-1)
|
||||||
|
*/
|
||||||
|
public Region of() {
|
||||||
|
//AWS 区域字符串
|
||||||
|
String region = properties.getRegion();
|
||||||
|
// 如果 region 参数非空,使用 Region.of 方法创建对应的 AWS 区域对象,否则返回默认区域
|
||||||
|
return StringUtils.isNotEmpty(region) ? Region.of(region) : Region.US_EAST_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取云存储服务的URL
|
||||||
|
*
|
||||||
|
* @return 文件路径
|
||||||
|
*/
|
||||||
|
public String getUrl() {
|
||||||
|
String domain = properties.getDomain();
|
||||||
|
String endpoint = properties.getEndpoint();
|
||||||
|
String header = getIsHttps();
|
||||||
|
// 云服务商直接返回
|
||||||
|
if (StringUtils.containsAny(endpoint, OssConstant.CLOUD_SERVICE)) {
|
||||||
|
return header + (StringUtils.isNotEmpty(domain) ? domain : properties.getBucketName() + "." + endpoint);
|
||||||
|
}
|
||||||
|
// MinIO 单独处理
|
||||||
|
if (StringUtils.isNotEmpty(domain)) {
|
||||||
|
// 如果 domain 以 "https://" 或 "http://" 开头
|
||||||
|
return (domain.startsWith(Constants.HTTPS) || domain.startsWith(Constants.HTTP)) ?
|
||||||
|
domain + StringUtils.SLASH + properties.getBucketName() : header + domain + StringUtils.SLASH + properties.getBucketName();
|
||||||
|
}
|
||||||
|
return header + endpoint + StringUtils.SLASH + properties.getBucketName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成一个符合特定规则的、唯一的文件路径。通过使用日期、UUID、前缀和后缀等元素的组合,确保了文件路径的独一无二性
|
||||||
|
*
|
||||||
|
* @param prefix 前缀
|
||||||
|
* @param suffix 后缀
|
||||||
|
* @return 文件路径
|
||||||
|
*/
|
||||||
|
public String getPath(String prefix, String suffix) {
|
||||||
|
// 生成uuid
|
||||||
|
String uuid = IdUtil.fastSimpleUUID();
|
||||||
|
// 生成日期路径
|
||||||
|
String datePath = DateUtils.datePath();
|
||||||
|
// 拼接路径
|
||||||
|
String path = StringUtils.isNotEmpty(prefix) ?
|
||||||
|
prefix + StringUtils.SLASH + datePath + StringUtils.SLASH + uuid : datePath + StringUtils.SLASH + uuid;
|
||||||
|
return path + suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除路径中的基础URL部分,得到相对路径
|
||||||
|
*
|
||||||
|
* @param path 完整的路径,包括基础URL和相对路径
|
||||||
|
* @return 去除基础URL后的相对路径
|
||||||
|
*/
|
||||||
|
public String removeBaseUrl(String path) {
|
||||||
|
return path.replace(getUrl() + StringUtils.SLASH, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务商
|
||||||
|
*/
|
||||||
|
public String getConfigKey() {
|
||||||
|
return configKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取是否使用 HTTPS 的配置,并返回相应的协议头部。
|
||||||
|
*
|
||||||
|
* @return 协议头部,根据是否使用 HTTPS 返回 "https://" 或 "http://"
|
||||||
|
*/
|
||||||
|
public String getIsHttps() {
|
||||||
|
return OssConstant.IS_HTTPS.equals(properties.getIsHttps()) ? Constants.HTTPS : Constants.HTTP;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查配置是否相同
|
* 检查配置是否相同
|
||||||
*/
|
*/
|
||||||
@ -231,32 +479,77 @@ public class OssClient {
|
|||||||
return AccessPolicyType.getByType(properties.getAccessPolicy());
|
return AccessPolicyType.getByType(properties.getAccessPolicy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成 AWS S3 存储桶访问策略
|
||||||
|
*
|
||||||
|
* @param bucketName 存储桶
|
||||||
|
* @param policyType 桶策略类型
|
||||||
|
* @return 符合 AWS S3 存储桶访问策略格式的字符串
|
||||||
|
*/
|
||||||
private static String getPolicy(String bucketName, PolicyType policyType) {
|
private static String getPolicy(String bucketName, PolicyType policyType) {
|
||||||
StringBuilder builder = new StringBuilder();
|
String policy = switch (policyType) {
|
||||||
builder.append("{\n\"Statement\": [\n{\n\"Action\": [\n");
|
case WRITE -> """
|
||||||
builder.append(switch (policyType) {
|
{
|
||||||
case WRITE -> "\"s3:GetBucketLocation\",\n\"s3:ListBucketMultipartUploads\"\n";
|
"Version": "2012-10-17",
|
||||||
case READ_WRITE -> "\"s3:GetBucketLocation\",\n\"s3:ListBucket\",\n\"s3:ListBucketMultipartUploads\"\n";
|
"Statement": []
|
||||||
default -> "\"s3:GetBucketLocation\"\n";
|
}
|
||||||
});
|
""";
|
||||||
builder.append("],\n\"Effect\": \"Allow\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::");
|
case READ_WRITE -> """
|
||||||
builder.append(bucketName);
|
{
|
||||||
builder.append("\"\n},\n");
|
"Version": "2012-10-17",
|
||||||
if (policyType == PolicyType.READ) {
|
"Statement": [
|
||||||
builder.append("{\n\"Action\": [\n\"s3:ListBucket\"\n],\n\"Effect\": \"Deny\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::");
|
{
|
||||||
builder.append(bucketName);
|
"Effect": "Allow",
|
||||||
builder.append("\"\n},\n");
|
"Principal": "*",
|
||||||
}
|
"Action": [
|
||||||
builder.append("{\n\"Action\": ");
|
"s3:GetBucketLocation",
|
||||||
builder.append(switch (policyType) {
|
"s3:ListBucket",
|
||||||
case WRITE -> "[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n";
|
"s3:ListBucketMultipartUploads"
|
||||||
case READ_WRITE -> "[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:GetObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n";
|
],
|
||||||
default -> "\"s3:GetObject\",\n";
|
"Resource": "arn:aws:s3:::bucketName"
|
||||||
});
|
},
|
||||||
builder.append("\"Effect\": \"Allow\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::");
|
{
|
||||||
builder.append(bucketName);
|
"Effect": "Allow",
|
||||||
builder.append("/*\"\n}\n],\n\"Version\": \"2012-10-17\"\n}\n");
|
"Principal": "*",
|
||||||
return builder.toString();
|
"Action": [
|
||||||
|
"s3:AbortMultipartUpload",
|
||||||
|
"s3:DeleteObject",
|
||||||
|
"s3:GetObject",
|
||||||
|
"s3:ListMultipartUploadParts",
|
||||||
|
"s3:PutObject"
|
||||||
|
],
|
||||||
|
"Resource": "arn:aws:s3:::bucketName/*"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
case READ -> """
|
||||||
|
{
|
||||||
|
"Version": "2012-10-17",
|
||||||
|
"Statement": [
|
||||||
|
{
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Principal": "*",
|
||||||
|
"Action": ["s3:GetBucketLocation"],
|
||||||
|
"Resource": "arn:aws:s3:::bucketName"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Effect": "Deny",
|
||||||
|
"Principal": "*",
|
||||||
|
"Action": ["s3:ListBucket"],
|
||||||
|
"Resource": "arn:aws:s3:::bucketName"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Principal": "*",
|
||||||
|
"Action": "s3:GetObject",
|
||||||
|
"Resource": "arn:aws:s3:::bucketName/*"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
};
|
||||||
|
return policy.replaceAll("bucketName", bucketName);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,4 +21,10 @@ public class UploadResult {
|
|||||||
* 文件名
|
* 文件名
|
||||||
*/
|
*/
|
||||||
private String filename;
|
private String filename;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已上传对象的实体标记(用来校验文件)
|
||||||
|
*/
|
||||||
|
private String eTag;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
package org.dromara.common.oss.enumd;
|
package org.dromara.common.oss.enumd;
|
||||||
|
|
||||||
import com.amazonaws.services.s3.model.CannedAccessControlList;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import software.amazon.awssdk.services.s3.model.BucketCannedACL;
|
||||||
|
import software.amazon.awssdk.services.s3.model.ObjectCannedACL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 桶访问策略配置
|
* 桶访问策略配置
|
||||||
@ -16,27 +17,32 @@ public enum AccessPolicyType {
|
|||||||
/**
|
/**
|
||||||
* private
|
* private
|
||||||
*/
|
*/
|
||||||
PRIVATE("0", CannedAccessControlList.Private, PolicyType.WRITE),
|
PRIVATE("0", BucketCannedACL.PRIVATE, ObjectCannedACL.PRIVATE, PolicyType.WRITE),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* public
|
* public
|
||||||
*/
|
*/
|
||||||
PUBLIC("1", CannedAccessControlList.PublicRead, PolicyType.READ),
|
PUBLIC("1", BucketCannedACL.PUBLIC_READ_WRITE, ObjectCannedACL.PUBLIC_READ_WRITE, PolicyType.READ_WRITE),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* custom
|
* custom
|
||||||
*/
|
*/
|
||||||
CUSTOM("2",CannedAccessControlList.PublicRead, PolicyType.READ);
|
CUSTOM("2", BucketCannedACL.PUBLIC_READ, ObjectCannedACL.PUBLIC_READ, PolicyType.READ);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 桶 权限类型
|
* 桶 权限类型(数据库值)
|
||||||
*/
|
*/
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 桶 权限类型
|
||||||
|
*/
|
||||||
|
private final BucketCannedACL bucketCannedACL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件对象 权限类型
|
* 文件对象 权限类型
|
||||||
*/
|
*/
|
||||||
private final CannedAccessControlList acl;
|
private final ObjectCannedACL objectCannedACL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 桶策略类型
|
* 桶策略类型
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package org.dromara.common.oss.factory;
|
package org.dromara.common.oss.factory;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.core.constant.CacheNames;
|
import org.dromara.common.core.constant.CacheNames;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.json.utils.JsonUtils;
|
import org.dromara.common.json.utils.JsonUtils;
|
||||||
@ -9,10 +10,10 @@ import org.dromara.common.oss.exception.OssException;
|
|||||||
import org.dromara.common.oss.properties.OssProperties;
|
import org.dromara.common.oss.properties.OssProperties;
|
||||||
import org.dromara.common.redis.utils.CacheUtils;
|
import org.dromara.common.redis.utils.CacheUtils;
|
||||||
import org.dromara.common.redis.utils.RedisUtils;
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传Factory
|
* 文件上传Factory
|
||||||
@ -23,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
public class OssFactory {
|
public class OssFactory {
|
||||||
|
|
||||||
private static final Map<String, OssClient> CLIENT_CACHE = new ConcurrentHashMap<>();
|
private static final Map<String, OssClient> CLIENT_CACHE = new ConcurrentHashMap<>();
|
||||||
|
private static final ReentrantLock LOCK = new ReentrantLock();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取默认实例
|
* 获取默认实例
|
||||||
@ -39,7 +41,7 @@ public class OssFactory {
|
|||||||
/**
|
/**
|
||||||
* 根据类型获取实例
|
* 根据类型获取实例
|
||||||
*/
|
*/
|
||||||
public static synchronized OssClient instance(String configKey) {
|
public static OssClient instance(String configKey) {
|
||||||
String json = CacheUtils.get(CacheNames.SYS_OSS_CONFIG, configKey);
|
String json = CacheUtils.get(CacheNames.SYS_OSS_CONFIG, configKey);
|
||||||
if (json == null) {
|
if (json == null) {
|
||||||
throw new OssException("系统异常, '" + configKey + "'配置信息不存在!");
|
throw new OssException("系统异常, '" + configKey + "'配置信息不存在!");
|
||||||
@ -48,16 +50,19 @@ public class OssFactory {
|
|||||||
// 使用租户标识避免多个租户相同key实例覆盖
|
// 使用租户标识避免多个租户相同key实例覆盖
|
||||||
String key = properties.getTenantId() + ":" + configKey;
|
String key = properties.getTenantId() + ":" + configKey;
|
||||||
OssClient client = CLIENT_CACHE.get(key);
|
OssClient client = CLIENT_CACHE.get(key);
|
||||||
if (client == null) {
|
// 客户端不存在或配置不相同则重新构建
|
||||||
CLIENT_CACHE.put(key, new OssClient(configKey, properties));
|
if (client == null || !client.checkPropertiesSame(properties)) {
|
||||||
log.info("创建OSS实例 key => {}", configKey);
|
LOCK.lock();
|
||||||
return CLIENT_CACHE.get(key);
|
try {
|
||||||
}
|
client = CLIENT_CACHE.get(key);
|
||||||
// 配置不相同则重新构建
|
if (client == null || !client.checkPropertiesSame(properties)) {
|
||||||
if (!client.checkPropertiesSame(properties)) {
|
CLIENT_CACHE.put(key, new OssClient(configKey, properties));
|
||||||
CLIENT_CACHE.put(key, new OssClient(configKey, properties));
|
log.info("创建OSS实例 key => {}", configKey);
|
||||||
log.info("重载OSS实例 key => {}", configKey);
|
return CLIENT_CACHE.get(key);
|
||||||
return CLIENT_CACHE.get(key);
|
}
|
||||||
|
} finally {
|
||||||
|
LOCK.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,29 +1,29 @@
|
|||||||
package org.dromara.common.ratelimiter.aspectj;
|
package org.dromara.common.ratelimiter.aspectj;
|
||||||
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import org.dromara.common.core.constant.GlobalConstants;
|
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
|
||||||
import org.dromara.common.core.utils.MessageUtils;
|
|
||||||
import org.dromara.common.core.utils.ServletUtils;
|
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
|
||||||
import org.dromara.common.ratelimiter.annotation.RateLimiter;
|
|
||||||
import org.dromara.common.ratelimiter.enums.LimitType;
|
|
||||||
import org.dromara.common.redis.utils.RedisUtils;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.dromara.common.core.constant.GlobalConstants;
|
||||||
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
|
import org.dromara.common.core.utils.MessageUtils;
|
||||||
|
import org.dromara.common.core.utils.ServletUtils;
|
||||||
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
|
import org.dromara.common.ratelimiter.annotation.RateLimiter;
|
||||||
|
import org.dromara.common.ratelimiter.enums.LimitType;
|
||||||
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
import org.redisson.api.RateType;
|
import org.redisson.api.RateType;
|
||||||
|
import org.springframework.context.expression.BeanFactoryResolver;
|
||||||
|
import org.springframework.context.expression.MethodBasedEvaluationContext;
|
||||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||||
import org.springframework.core.ParameterNameDiscoverer;
|
import org.springframework.core.ParameterNameDiscoverer;
|
||||||
import org.springframework.expression.EvaluationContext;
|
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
import org.springframework.expression.ExpressionParser;
|
import org.springframework.expression.ExpressionParser;
|
||||||
import org.springframework.expression.ParserContext;
|
import org.springframework.expression.ParserContext;
|
||||||
import org.springframework.expression.common.TemplateParserContext;
|
import org.springframework.expression.common.TemplateParserContext;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@ -44,21 +44,18 @@ public class RateLimiterAspect {
|
|||||||
* 定义spel解析模版
|
* 定义spel解析模版
|
||||||
*/
|
*/
|
||||||
private final ParserContext parserContext = new TemplateParserContext();
|
private final ParserContext parserContext = new TemplateParserContext();
|
||||||
/**
|
|
||||||
* 定义spel上下文对象进行解析
|
|
||||||
*/
|
|
||||||
private final EvaluationContext context = new StandardEvaluationContext();
|
|
||||||
/**
|
/**
|
||||||
* 方法参数解析器
|
* 方法参数解析器
|
||||||
*/
|
*/
|
||||||
private final ParameterNameDiscoverer pnd = new DefaultParameterNameDiscoverer();
|
private final ParameterNameDiscoverer pnd = new DefaultParameterNameDiscoverer();
|
||||||
|
|
||||||
|
|
||||||
@Before("@annotation(rateLimiter)")
|
@Before("@annotation(rateLimiter)")
|
||||||
public void doBefore(JoinPoint point, RateLimiter rateLimiter) throws Throwable {
|
public void doBefore(JoinPoint point, RateLimiter rateLimiter) {
|
||||||
int time = rateLimiter.time();
|
int time = rateLimiter.time();
|
||||||
int count = rateLimiter.count();
|
int count = rateLimiter.count();
|
||||||
String combineKey = getCombineKey(rateLimiter, point);
|
|
||||||
try {
|
try {
|
||||||
|
String combineKey = getCombineKey(rateLimiter, point);
|
||||||
RateType rateType = RateType.OVERALL;
|
RateType rateType = RateType.OVERALL;
|
||||||
if (rateLimiter.limitType() == LimitType.CLUSTER) {
|
if (rateLimiter.limitType() == LimitType.CLUSTER) {
|
||||||
rateType = RateType.PER_CLIENT;
|
rateType = RateType.PER_CLIENT;
|
||||||
@ -76,42 +73,29 @@ public class RateLimiterAspect {
|
|||||||
if (e instanceof ServiceException) {
|
if (e instanceof ServiceException) {
|
||||||
throw e;
|
throw e;
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("服务器限流异常,请稍候再试");
|
throw new RuntimeException("服务器限流异常,请稍候再试", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCombineKey(RateLimiter rateLimiter, JoinPoint point) {
|
private String getCombineKey(RateLimiter rateLimiter, JoinPoint point) {
|
||||||
String key = rateLimiter.key();
|
String key = rateLimiter.key();
|
||||||
// 获取方法(通过方法签名来获取)
|
if (StringUtils.isNotBlank(key)) {
|
||||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||||
Method method = signature.getMethod();
|
Method targetMethod = signature.getMethod();
|
||||||
Class<?> targetClass = method.getDeclaringClass();
|
|
||||||
// 判断是否是spel格式
|
|
||||||
if (StringUtils.containsAny(key, "#")) {
|
|
||||||
// 获取参数值
|
|
||||||
Object[] args = point.getArgs();
|
Object[] args = point.getArgs();
|
||||||
// 获取方法上参数的名称
|
//noinspection DataFlowIssue
|
||||||
String[] parameterNames = pnd.getParameterNames(method);
|
MethodBasedEvaluationContext context =
|
||||||
if (ArrayUtil.isEmpty(parameterNames)) {
|
new MethodBasedEvaluationContext(null, targetMethod, args, pnd);
|
||||||
throw new ServiceException("限流key解析异常!请联系管理员!");
|
context.setBeanResolver(new BeanFactoryResolver(SpringUtils.getBeanFactory()));
|
||||||
}
|
Expression expression;
|
||||||
for (int i = 0; i < parameterNames.length; i++) {
|
if (StringUtils.startsWith(key, parserContext.getExpressionPrefix())
|
||||||
context.setVariable(parameterNames[i], args[i]);
|
&& StringUtils.endsWith(key, parserContext.getExpressionSuffix())) {
|
||||||
}
|
expression = parser.parseExpression(key, parserContext);
|
||||||
// 解析返回给key
|
} else {
|
||||||
try {
|
expression = parser.parseExpression(key);
|
||||||
Expression expression;
|
|
||||||
if (StringUtils.startsWith(key, parserContext.getExpressionPrefix())
|
|
||||||
&& StringUtils.endsWith(key, parserContext.getExpressionSuffix())) {
|
|
||||||
expression = parser.parseExpression(key, parserContext);
|
|
||||||
} else {
|
|
||||||
expression = parser.parseExpression(key);
|
|
||||||
}
|
|
||||||
key = expression.getValue(context, String.class) + ":";
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ServiceException("限流key解析异常!请联系管理员!");
|
|
||||||
}
|
}
|
||||||
|
key = expression.getValue(context, String.class);
|
||||||
}
|
}
|
||||||
StringBuilder stringBuffer = new StringBuilder(GlobalConstants.RATE_LIMIT_KEY);
|
StringBuilder stringBuffer = new StringBuilder(GlobalConstants.RATE_LIMIT_KEY);
|
||||||
stringBuffer.append(ServletUtils.getRequest().getRequestURI()).append(":");
|
stringBuffer.append(ServletUtils.getRequest().getRequestURI()).append(":");
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"org.dromara.common.ratelimiter.annotation.RateLimiter@key": {
|
||||||
|
"method": {
|
||||||
|
"parameters": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
import org.dromara.common.redis.config.properties.RedissonProperties;
|
import org.dromara.common.redis.config.properties.RedissonProperties;
|
||||||
import org.dromara.common.redis.handler.KeyPrefixHandler;
|
import org.dromara.common.redis.handler.KeyPrefixHandler;
|
||||||
import org.redisson.client.codec.StringCodec;
|
import org.redisson.client.codec.StringCodec;
|
||||||
@ -16,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* redis配置
|
* redis配置
|
||||||
@ -48,6 +50,9 @@ public class RedisConfig {
|
|||||||
// 缓存 Lua 脚本 减少网络传输(redisson 大部分的功能都是基于 Lua 脚本实现)
|
// 缓存 Lua 脚本 减少网络传输(redisson 大部分的功能都是基于 Lua 脚本实现)
|
||||||
.setUseScriptCache(true)
|
.setUseScriptCache(true)
|
||||||
.setCodec(codec);
|
.setCodec(codec);
|
||||||
|
if (SpringUtils.isVirtual()) {
|
||||||
|
config.setNettyExecutor(new VirtualThreadTaskExecutor("redisson-"));
|
||||||
|
}
|
||||||
RedissonProperties.SingleServerConfig singleServerConfig = redissonProperties.getSingleServerConfig();
|
RedissonProperties.SingleServerConfig singleServerConfig = redissonProperties.getSingleServerConfig();
|
||||||
if (ObjectUtil.isNotNull(singleServerConfig)) {
|
if (ObjectUtil.isNotNull(singleServerConfig)) {
|
||||||
// 使用单机模式
|
// 使用单机模式
|
||||||
|
|||||||
@ -101,13 +101,18 @@ public class LoginHelper {
|
|||||||
return Convert.toLong(getExtra(DEPT_KEY));
|
return Convert.toLong(getExtra(DEPT_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前 Token 的扩展信息
|
||||||
|
*
|
||||||
|
* @param key 键值
|
||||||
|
* @return 对应的扩展数据
|
||||||
|
*/
|
||||||
private static Object getExtra(String key) {
|
private static Object getExtra(String key) {
|
||||||
try {
|
try {
|
||||||
return StpUtil.getExtra(key);
|
return StpUtil.getExtra(key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,12 +140,17 @@ public class LoginHelper {
|
|||||||
return UserConstants.SUPER_ADMIN_ID.equals(userId);
|
return UserConstants.SUPER_ADMIN_ID.equals(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为超级管理员
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
public static boolean isSuperAdmin() {
|
public static boolean isSuperAdmin() {
|
||||||
return isSuperAdmin(getUserId());
|
return isSuperAdmin(getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否为超级管理员
|
* 是否为租户管理员
|
||||||
*
|
*
|
||||||
* @param rolePermission 角色权限标识组
|
* @param rolePermission 角色权限标识组
|
||||||
* @return 结果
|
* @return 结果
|
||||||
@ -149,10 +159,20 @@ public class LoginHelper {
|
|||||||
return rolePermission.contains(TenantConstants.TENANT_ADMIN_ROLE_KEY);
|
return rolePermission.contains(TenantConstants.TENANT_ADMIN_ROLE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为租户管理员
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
public static boolean isTenantAdmin() {
|
public static boolean isTenantAdmin() {
|
||||||
return Convert.toBool(isTenantAdmin(getLoginUser().getRolePermission()));
|
return Convert.toBool(isTenantAdmin(getLoginUser().getRolePermission()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查当前用户是否已登录
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
public static boolean isLogin() {
|
public static boolean isLogin() {
|
||||||
return getLoginUser() != null;
|
return getLoginUser() != null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,13 +20,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara.sms4j</groupId>
|
<groupId>org.dromara.sms4j</groupId>
|
||||||
<artifactId>sms4j-spring-boot-starter</artifactId>
|
<artifactId>sms4j-spring-boot-starter</artifactId>
|
||||||
<exclusions>
|
</dependency>
|
||||||
<!-- 排除京东短信内存在的fastjson等待作者后续修复 -->
|
|
||||||
<exclusion>
|
<!-- RuoYi Common Redis-->
|
||||||
<groupId>com.alibaba</groupId>
|
<dependency>
|
||||||
<artifactId>fastjson</artifactId>
|
<groupId>org.dromara</groupId>
|
||||||
</exclusion>
|
<artifactId>ruoyi-common-redis</artifactId>
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@ -1,14 +1,24 @@
|
|||||||
package org.dromara.common.sms.config;
|
package org.dromara.common.sms.config;
|
||||||
|
|
||||||
|
import org.dromara.common.sms.core.dao.PlusSmsDao;
|
||||||
|
import org.dromara.sms4j.api.dao.SmsDao;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信配置类(暂时没用 预留扩展)
|
* 短信配置类
|
||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Feng
|
||||||
* @version 4.2.0
|
|
||||||
*/
|
*/
|
||||||
@AutoConfiguration
|
@AutoConfiguration(after = {RedisAutoConfiguration.class})
|
||||||
public class SmsAutoConfiguration {
|
public class SmsAutoConfiguration {
|
||||||
|
|
||||||
|
@Primary
|
||||||
|
@Bean
|
||||||
|
public SmsDao smsDao() {
|
||||||
|
return new PlusSmsDao();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,72 @@
|
|||||||
|
package org.dromara.common.sms.core.dao;
|
||||||
|
|
||||||
|
import org.dromara.common.core.constant.GlobalConstants;
|
||||||
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
|
import org.dromara.sms4j.api.dao.SmsDao;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SmsDao缓存配置 (使用框架自带RedisUtils实现 协议统一)
|
||||||
|
* <p>主要用于短信重试和拦截的缓存
|
||||||
|
*
|
||||||
|
* @author Feng
|
||||||
|
*/
|
||||||
|
public class PlusSmsDao implements SmsDao {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储
|
||||||
|
*
|
||||||
|
* @param key 键
|
||||||
|
* @param value 值
|
||||||
|
* @param cacheTime 缓存时间(单位:秒)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void set(String key, Object value, long cacheTime) {
|
||||||
|
RedisUtils.setCacheObject(GlobalConstants.GLOBAL_REDIS_KEY + key, value, Duration.ofSeconds(cacheTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储
|
||||||
|
*
|
||||||
|
* @param key 键
|
||||||
|
* @param value 值
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void set(String key, Object value) {
|
||||||
|
RedisUtils.setCacheObject(GlobalConstants.GLOBAL_REDIS_KEY + key, value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取
|
||||||
|
*
|
||||||
|
* @param key 键
|
||||||
|
* @return 值
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Object get(String key) {
|
||||||
|
return RedisUtils.getCacheObject(GlobalConstants.GLOBAL_REDIS_KEY + key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove
|
||||||
|
* <p> 根据key移除缓存
|
||||||
|
*
|
||||||
|
* @param key 缓存键
|
||||||
|
* @return 被删除的value
|
||||||
|
* @author :Wind
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Object remove(String key) {
|
||||||
|
return RedisUtils.deleteObject(GlobalConstants.GLOBAL_REDIS_KEY + key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void clean() {
|
||||||
|
RedisUtils.deleteObject(GlobalConstants.GLOBAL_REDIS_KEY + "sms:");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -16,11 +16,6 @@ import java.util.Map;
|
|||||||
@ConfigurationProperties(prefix = "justauth")
|
@ConfigurationProperties(prefix = "justauth")
|
||||||
public class SocialProperties {
|
public class SocialProperties {
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否启用
|
|
||||||
*/
|
|
||||||
private Boolean enabled;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 授权类型
|
* 授权类型
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara</groupId>
|
<groupId>org.dromara</groupId>
|
||||||
<artifactId>ruoyi-common-mybatis</artifactId>
|
<artifactId>ruoyi-common-mybatis</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@ -2,9 +2,11 @@ package org.dromara.common.web.config;
|
|||||||
|
|
||||||
import io.undertow.server.DefaultByteBufferPool;
|
import io.undertow.server.DefaultByteBufferPool;
|
||||||
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
|
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
|
||||||
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
||||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||||
|
import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undertow 自定义配置
|
* Undertow 自定义配置
|
||||||
@ -24,10 +26,12 @@ public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServle
|
|||||||
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
|
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
|
||||||
webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(false, 512));
|
webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(false, 512));
|
||||||
deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
|
deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
|
||||||
// 使用虚拟线程 解除下方注释 仅限jdk21
|
// 使用虚拟线程
|
||||||
// if (SpringUtils.getProperty("spring.threads.virtual.enabled", Boolean.class, false)) {
|
if (SpringUtils.isVirtual()) {
|
||||||
// deploymentInfo.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
|
VirtualThreadTaskExecutor executor = new VirtualThreadTaskExecutor("undertow-");
|
||||||
// }
|
deploymentInfo.setExecutor(executor);
|
||||||
|
deploymentInfo.setAsyncExecutor(executor);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package org.dromara.monitor.admin.config;
|
|||||||
import de.codecentric.boot.admin.server.config.EnableAdminServer;
|
import de.codecentric.boot.admin.server.config.EnableAdminServer;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
|
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
|
||||||
import org.springframework.boot.task.TaskExecutorBuilder;
|
import org.springframework.boot.task.ThreadPoolTaskExecutorBuilder;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
@ -23,7 +23,7 @@ public class AdminServerConfig {
|
|||||||
@Lazy
|
@Lazy
|
||||||
@Bean(name = TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME)
|
@Bean(name = TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME)
|
||||||
@ConditionalOnMissingBean(Executor.class)
|
@ConditionalOnMissingBean(Executor.class)
|
||||||
public ThreadPoolTaskExecutor applicationTaskExecutor(TaskExecutorBuilder builder) {
|
public ThreadPoolTaskExecutor applicationTaskExecutor(ThreadPoolTaskExecutorBuilder builder) {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import org.dromara.common.core.domain.R;
|
|||||||
import org.dromara.sms4j.api.SmsBlend;
|
import org.dromara.sms4j.api.SmsBlend;
|
||||||
import org.dromara.sms4j.api.entity.SmsResponse;
|
import org.dromara.sms4j.api.entity.SmsResponse;
|
||||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||||
import org.dromara.sms4j.provider.enumerate.SupplierType;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -25,7 +24,6 @@ import java.util.LinkedHashMap;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/demo/sms")
|
@RequestMapping("/demo/sms")
|
||||||
public class SmsController {
|
public class SmsController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送短信Aliyun
|
* 发送短信Aliyun
|
||||||
*
|
*
|
||||||
@ -36,7 +34,7 @@ public class SmsController {
|
|||||||
public R<Object> sendAliyun(String phones, String templateId) {
|
public R<Object> sendAliyun(String phones, String templateId) {
|
||||||
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
||||||
map.put("code", "1234");
|
map.put("code", "1234");
|
||||||
SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA);
|
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
|
||||||
SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, map);
|
SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, map);
|
||||||
return R.ok(smsResponse);
|
return R.ok(smsResponse);
|
||||||
}
|
}
|
||||||
@ -52,9 +50,33 @@ public class SmsController {
|
|||||||
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
||||||
// map.put("2", "测试测试");
|
// map.put("2", "测试测试");
|
||||||
map.put("1", "1234");
|
map.put("1", "1234");
|
||||||
SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.TENCENT);
|
SmsBlend smsBlend = SmsFactory.getSmsBlend("config2");
|
||||||
SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, map);
|
SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, map);
|
||||||
return R.ok(smsResponse);
|
return R.ok(smsResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加黑名单
|
||||||
|
*
|
||||||
|
* @param phone 手机号
|
||||||
|
*/
|
||||||
|
@GetMapping("/addBlacklist")
|
||||||
|
public R<Object> addBlacklist(String phone){
|
||||||
|
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
|
||||||
|
smsBlend.joinInBlacklist(phone);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除黑名单
|
||||||
|
*
|
||||||
|
* @param phone 手机号
|
||||||
|
*/
|
||||||
|
@GetMapping("/removeBlacklist")
|
||||||
|
public R<Object> removeBlacklist(String phone){
|
||||||
|
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
|
||||||
|
smsBlend.removeFromBlacklist(phone);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,7 @@ public class GenTableColumn extends BaseEntity {
|
|||||||
/**
|
/**
|
||||||
* 列描述
|
* 列描述
|
||||||
*/
|
*/
|
||||||
@TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR)
|
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
||||||
private String columnComment;
|
private String columnComment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,43 +64,43 @@ public class GenTableColumn extends BaseEntity {
|
|||||||
/**
|
/**
|
||||||
* 是否主键(1是)
|
* 是否主键(1是)
|
||||||
*/
|
*/
|
||||||
@TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR)
|
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
||||||
private String isPk;
|
private String isPk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否自增(1是)
|
* 是否自增(1是)
|
||||||
*/
|
*/
|
||||||
@TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR)
|
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
||||||
private String isIncrement;
|
private String isIncrement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否必填(1是)
|
* 是否必填(1是)
|
||||||
*/
|
*/
|
||||||
@TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR)
|
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
||||||
private String isRequired;
|
private String isRequired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否为插入字段(1是)
|
* 是否为插入字段(1是)
|
||||||
*/
|
*/
|
||||||
@TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR)
|
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
||||||
private String isInsert;
|
private String isInsert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否编辑字段(1是)
|
* 是否编辑字段(1是)
|
||||||
*/
|
*/
|
||||||
@TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR)
|
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
||||||
private String isEdit;
|
private String isEdit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否列表字段(1是)
|
* 是否列表字段(1是)
|
||||||
*/
|
*/
|
||||||
@TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR)
|
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
||||||
private String isList;
|
private String isList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否查询字段(1是)
|
* 是否查询字段(1是)
|
||||||
*/
|
*/
|
||||||
@TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR)
|
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
||||||
private String isQuery;
|
private String isQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import org.dromara.common.excel.utils.ExcelUtil;
|
|||||||
import ${packageName}.domain.vo.${ClassName}Vo;
|
import ${packageName}.domain.vo.${ClassName}Vo;
|
||||||
import ${packageName}.domain.bo.${ClassName}Bo;
|
import ${packageName}.domain.bo.${ClassName}Bo;
|
||||||
import ${packageName}.service.I${ClassName}Service;
|
import ${packageName}.service.I${ClassName}Service;
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud)
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
#elseif($table.tree)
|
#elseif($table.tree)
|
||||||
#end
|
#end
|
||||||
@ -44,7 +44,7 @@ public class ${ClassName}Controller extends BaseController {
|
|||||||
*/
|
*/
|
||||||
@SaCheckPermission("${permissionPrefix}:list")
|
@SaCheckPermission("${permissionPrefix}:list")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud)
|
||||||
public TableDataInfo<${ClassName}Vo> list(${ClassName}Bo bo, PageQuery pageQuery) {
|
public TableDataInfo<${ClassName}Vo> list(${ClassName}Bo bo, PageQuery pageQuery) {
|
||||||
return ${className}Service.queryPageList(bo, pageQuery);
|
return ${className}Service.queryPageList(bo, pageQuery);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package ${packageName}.service;
|
|||||||
import ${packageName}.domain.${ClassName};
|
import ${packageName}.domain.${ClassName};
|
||||||
import ${packageName}.domain.vo.${ClassName}Vo;
|
import ${packageName}.domain.vo.${ClassName}Vo;
|
||||||
import ${packageName}.domain.bo.${ClassName}Bo;
|
import ${packageName}.domain.bo.${ClassName}Bo;
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud)
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
#end
|
#end
|
||||||
@ -24,7 +24,7 @@ public interface I${ClassName}Service {
|
|||||||
*/
|
*/
|
||||||
${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField});
|
${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField});
|
||||||
|
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud)
|
||||||
/**
|
/**
|
||||||
* 查询${functionName}列表
|
* 查询${functionName}列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package ${packageName}.service.impl;
|
|||||||
|
|
||||||
import org.dromara.common.core.utils.MapstructUtils;
|
import org.dromara.common.core.utils.MapstructUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud)
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@ -41,7 +41,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
|||||||
return baseMapper.selectVoById(${pkColumn.javaField});
|
return baseMapper.selectVoById(${pkColumn.javaField});
|
||||||
}
|
}
|
||||||
|
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud)
|
||||||
/**
|
/**
|
||||||
* 查询${functionName}列表
|
* 查询${functionName}列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -113,7 +113,7 @@ public class SysPostController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param postIds 岗位ID串
|
* @param postIds 岗位ID串
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("system:dept:query")
|
@SaCheckPermission("system:post:query")
|
||||||
@GetMapping("/optionselect")
|
@GetMapping("/optionselect")
|
||||||
public R<List<SysPostVo>> optionselect(@RequestParam(required = false) Long[] postIds) {
|
public R<List<SysPostVo>> optionselect(@RequestParam(required = false) Long[] postIds) {
|
||||||
return R.ok(postService.selectPostByIds(postIds == null ? null : List.of(postIds)));
|
return R.ok(postService.selectPostByIds(postIds == null ? null : List.of(postIds)));
|
||||||
|
|||||||
@ -214,7 +214,7 @@ public class SysUserController extends BaseController {
|
|||||||
@SaCheckPermission("system:user:query")
|
@SaCheckPermission("system:user:query")
|
||||||
@GetMapping("/optionselect")
|
@GetMapping("/optionselect")
|
||||||
public R<List<SysUserVo>> optioselect(@RequestParam(required = false) Long[] userIds,
|
public R<List<SysUserVo>> optioselect(@RequestParam(required = false) Long[] userIds,
|
||||||
@RequestParam(required = false) Long deptId) {
|
@RequestParam(required = false) Long deptId) {
|
||||||
return R.ok(userService.selectUserByIds(userIds == null ? null : List.of(userIds), deptId));
|
return R.ok(userService.selectUserByIds(userIds == null ? null : List.of(userIds), deptId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import jakarta.validation.constraints.Pattern;
|
|||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.dromara.common.core.constant.RegexConstants;
|
||||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||||
import org.dromara.system.domain.SysDictType;
|
import org.dromara.system.domain.SysDictType;
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ public class SysDictTypeBo extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
@NotBlank(message = "字典类型不能为空")
|
@NotBlank(message = "字典类型不能为空")
|
||||||
@Size(min = 0, max = 100, message = "字典类型类型长度不能超过{max}个字符")
|
@Size(min = 0, max = 100, message = "字典类型类型长度不能超过{max}个字符")
|
||||||
@Pattern(regexp = "^[a-z][a-z0-9_]*$", message = "字典类型必须以字母开头,且只能为(小写字母,数字,下滑线)")
|
@Pattern(regexp = RegexConstants.DICTIONARY_TYPE, message = "字典类型必须以字母开头,且只能为(小写字母,数字,下滑线)")
|
||||||
private String dictType;
|
private String dictType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -31,12 +31,11 @@ public interface ISysOssConfigService {
|
|||||||
*/
|
*/
|
||||||
TableDataInfo<SysOssConfigVo> queryPageList(SysOssConfigBo bo, PageQuery pageQuery);
|
TableDataInfo<SysOssConfigVo> queryPageList(SysOssConfigBo bo, PageQuery pageQuery);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据新增业务对象插入对象存储配置
|
* 根据新增业务对象插入对象存储配置
|
||||||
*
|
*
|
||||||
* @param bo 对象存储配置新增业务对象
|
* @param bo 对象存储配置新增业务对象
|
||||||
* @return
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
Boolean insertByBo(SysOssConfigBo bo);
|
Boolean insertByBo(SysOssConfigBo bo);
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ public interface ISysOssConfigService {
|
|||||||
* 根据编辑业务对象修改对象存储配置
|
* 根据编辑业务对象修改对象存储配置
|
||||||
*
|
*
|
||||||
* @param bo 对象存储配置编辑业务对象
|
* @param bo 对象存储配置编辑业务对象
|
||||||
* @return
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
Boolean updateByBo(SysOssConfigBo bo);
|
Boolean updateByBo(SysOssConfigBo bo);
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ public interface ISysOssConfigService {
|
|||||||
*
|
*
|
||||||
* @param ids 主键集合
|
* @param ids 主键集合
|
||||||
* @param isValid 是否校验,true-删除前校验,false-不校验
|
* @param isValid 是否校验,true-删除前校验,false-不校验
|
||||||
* @return
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||||
|
|
||||||
|
|||||||
@ -19,18 +19,62 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface ISysOssService {
|
public interface ISysOssService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询OSS对象存储列表
|
||||||
|
*
|
||||||
|
* @param sysOss OSS对象存储分页查询对象
|
||||||
|
* @param pageQuery 分页查询实体类
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
TableDataInfo<SysOssVo> queryPageList(SysOssBo sysOss, PageQuery pageQuery);
|
TableDataInfo<SysOssVo> queryPageList(SysOssBo sysOss, PageQuery pageQuery);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据一组 ossIds 获取对应的 SysOssVo 列表
|
||||||
|
*
|
||||||
|
* @param ossIds 一组文件在数据库中的唯一标识集合
|
||||||
|
* @return 包含 SysOssVo 对象的列表
|
||||||
|
*/
|
||||||
List<SysOssVo> listByIds(Collection<Long> ossIds);
|
List<SysOssVo> listByIds(Collection<Long> ossIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 ossId 从缓存或数据库中获取 SysOssVo 对象
|
||||||
|
*
|
||||||
|
* @param ossId 文件在数据库中的唯一标识
|
||||||
|
* @return SysOssVo 对象,包含文件信息
|
||||||
|
*/
|
||||||
SysOssVo getById(Long ossId);
|
SysOssVo getById(Long ossId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传 MultipartFile 到对象存储服务,并保存文件信息到数据库
|
||||||
|
*
|
||||||
|
* @param file 要上传的 MultipartFile 对象
|
||||||
|
* @return 上传成功后的 SysOssVo 对象,包含文件信息
|
||||||
|
*/
|
||||||
SysOssVo upload(MultipartFile file);
|
SysOssVo upload(MultipartFile file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件到对象存储服务,并保存文件信息到数据库
|
||||||
|
*
|
||||||
|
* @param file 要上传的文件对象
|
||||||
|
* @return 上传成功后的 SysOssVo 对象,包含文件信息
|
||||||
|
*/
|
||||||
SysOssVo upload(File file);
|
SysOssVo upload(File file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件下载方法,支持一次性下载完整文件
|
||||||
|
*
|
||||||
|
* @param ossId OSS对象ID
|
||||||
|
* @param response HttpServletResponse对象,用于设置响应头和向客户端发送文件内容
|
||||||
|
*/
|
||||||
void download(Long ossId, HttpServletResponse response) throws IOException;
|
void download(Long ossId, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除OSS对象存储
|
||||||
|
*
|
||||||
|
* @param ids OSS对象ID串
|
||||||
|
* @param isValid 判断是否需要校验
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -215,8 +215,8 @@ public interface ISysUserService {
|
|||||||
/**
|
/**
|
||||||
* 通过部门id查询当前部门所有用户
|
* 通过部门id查询当前部门所有用户
|
||||||
*
|
*
|
||||||
* @param deptId
|
* @param deptId 部门id
|
||||||
* @return
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
List<SysUserVo> selectUserListByDept(Long deptId);
|
List<SysUserVo> selectUserListByDept(Long deptId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,31 +5,29 @@ import cn.hutool.http.useragent.UserAgent;
|
|||||||
import cn.hutool.http.useragent.UserAgentUtil;
|
import cn.hutool.http.useragent.UserAgentUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.core.constant.Constants;
|
import org.dromara.common.core.constant.Constants;
|
||||||
import org.dromara.common.core.utils.MapstructUtils;
|
import org.dromara.common.core.utils.MapstructUtils;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
||||||
import org.dromara.common.log.event.LogininforEvent;
|
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
||||||
import org.dromara.common.core.utils.ServletUtils;
|
import org.dromara.common.core.utils.ServletUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.core.utils.ip.AddressUtils;
|
import org.dromara.common.core.utils.ip.AddressUtils;
|
||||||
|
import org.dromara.common.log.event.LogininforEvent;
|
||||||
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
import org.dromara.system.domain.SysClient;
|
|
||||||
import org.dromara.system.domain.SysLogininfor;
|
import org.dromara.system.domain.SysLogininfor;
|
||||||
import org.dromara.system.domain.bo.SysLogininforBo;
|
import org.dromara.system.domain.bo.SysLogininforBo;
|
||||||
import org.dromara.system.domain.vo.SysClientVo;
|
import org.dromara.system.domain.vo.SysClientVo;
|
||||||
import org.dromara.system.domain.vo.SysLogininforVo;
|
import org.dromara.system.domain.vo.SysLogininforVo;
|
||||||
import org.dromara.system.mapper.SysClientMapper;
|
|
||||||
import org.dromara.system.mapper.SysLogininforMapper;
|
import org.dromara.system.mapper.SysLogininforMapper;
|
||||||
import org.dromara.system.service.ISysClientService;
|
import org.dromara.system.service.ISysClientService;
|
||||||
import org.dromara.system.service.ISysLogininforService;
|
import org.dromara.system.service.ISysLogininforService;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -61,10 +59,10 @@ public class SysLogininforServiceImpl implements ISysLogininforService {
|
|||||||
final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
||||||
final String ip = ServletUtils.getClientIP(request);
|
final String ip = ServletUtils.getClientIP(request);
|
||||||
// 客户端信息
|
// 客户端信息
|
||||||
String clientid = request.getHeader(LoginHelper.CLIENT_KEY);
|
String clientId = request.getHeader(LoginHelper.CLIENT_KEY);
|
||||||
SysClientVo client = null;
|
SysClientVo client = null;
|
||||||
if (StringUtils.isNotBlank(clientid)) {
|
if (StringUtils.isNotBlank(clientId)) {
|
||||||
client = clientService.queryByClientId(clientid);
|
client = clientService.queryByClientId(clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
String address = AddressUtils.getRealAddressByIP(ip);
|
String address = AddressUtils.getRealAddressByIP(ip);
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.dromara.common.core.constant.CacheNames;
|
import org.dromara.common.core.constant.CacheNames;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.core.service.OssService;
|
import org.dromara.common.core.service.OssService;
|
||||||
@ -25,8 +27,6 @@ import org.dromara.system.domain.bo.SysOssBo;
|
|||||||
import org.dromara.system.domain.vo.SysOssVo;
|
import org.dromara.system.domain.vo.SysOssVo;
|
||||||
import org.dromara.system.mapper.SysOssMapper;
|
import org.dromara.system.mapper.SysOssMapper;
|
||||||
import org.dromara.system.service.ISysOssService;
|
import org.dromara.system.service.ISysOssService;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -36,7 +36,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传 服务层实现
|
* 文件上传 服务层实现
|
||||||
@ -49,6 +52,13 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
|
|
||||||
private final SysOssMapper baseMapper;
|
private final SysOssMapper baseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询OSS对象存储列表
|
||||||
|
*
|
||||||
|
* @param bo OSS对象存储分页查询对象
|
||||||
|
* @param pageQuery 分页查询实体类
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TableDataInfo<SysOssVo> queryPageList(SysOssBo bo, PageQuery pageQuery) {
|
public TableDataInfo<SysOssVo> queryPageList(SysOssBo bo, PageQuery pageQuery) {
|
||||||
LambdaQueryWrapper<SysOss> lqw = buildQueryWrapper(bo);
|
LambdaQueryWrapper<SysOss> lqw = buildQueryWrapper(bo);
|
||||||
@ -58,6 +68,12 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
return TableDataInfo.build(result);
|
return TableDataInfo.build(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据一组 ossIds 获取对应的 SysOssVo 列表
|
||||||
|
*
|
||||||
|
* @param ossIds 一组文件在数据库中的唯一标识集合
|
||||||
|
* @return 包含 SysOssVo 对象的列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysOssVo> listByIds(Collection<Long> ossIds) {
|
public List<SysOssVo> listByIds(Collection<Long> ossIds) {
|
||||||
List<SysOssVo> list = new ArrayList<>();
|
List<SysOssVo> list = new ArrayList<>();
|
||||||
@ -75,6 +91,12 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据一组 ossIds 获取对应文件的 URL 列表
|
||||||
|
*
|
||||||
|
* @param ossIds 以逗号分隔的 ossId 字符串
|
||||||
|
* @return 以逗号分隔的文件 URL 字符串
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String selectUrlByIds(String ossIds) {
|
public String selectUrlByIds(String ossIds) {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
@ -107,12 +129,25 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
return lqw;
|
return lqw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 ossId 从缓存或数据库中获取 SysOssVo 对象
|
||||||
|
*
|
||||||
|
* @param ossId 文件在数据库中的唯一标识
|
||||||
|
* @return SysOssVo 对象,包含文件信息
|
||||||
|
*/
|
||||||
@Cacheable(cacheNames = CacheNames.SYS_OSS, key = "#ossId")
|
@Cacheable(cacheNames = CacheNames.SYS_OSS, key = "#ossId")
|
||||||
@Override
|
@Override
|
||||||
public SysOssVo getById(Long ossId) {
|
public SysOssVo getById(Long ossId) {
|
||||||
return baseMapper.selectVoById(ossId);
|
return baseMapper.selectVoById(ossId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件下载方法,支持一次性下载完整文件
|
||||||
|
*
|
||||||
|
* @param ossId OSS对象ID
|
||||||
|
* @param response HttpServletResponse对象,用于设置响应头和向客户端发送文件内容
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void download(Long ossId, HttpServletResponse response) throws IOException {
|
public void download(Long ossId, HttpServletResponse response) throws IOException {
|
||||||
SysOssVo sysOss = SpringUtils.getAopProxy(this).getById(ossId);
|
SysOssVo sysOss = SpringUtils.getAopProxy(this).getById(ossId);
|
||||||
@ -122,7 +157,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName());
|
FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName());
|
||||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
|
||||||
OssClient storage = OssFactory.instance(sysOss.getService());
|
OssClient storage = OssFactory.instance(sysOss.getService());
|
||||||
try(InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) {
|
try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) {
|
||||||
int available = inputStream.available();
|
int available = inputStream.available();
|
||||||
IoUtil.copy(inputStream, response.getOutputStream(), available);
|
IoUtil.copy(inputStream, response.getOutputStream(), available);
|
||||||
response.setContentLength(available);
|
response.setContentLength(available);
|
||||||
@ -131,6 +166,13 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传 MultipartFile 到对象存储服务,并保存文件信息到数据库
|
||||||
|
*
|
||||||
|
* @param file 要上传的 MultipartFile 对象
|
||||||
|
* @return 上传成功后的 SysOssVo 对象,包含文件信息
|
||||||
|
* @throws ServiceException 如果上传过程中发生异常,则抛出 ServiceException 异常
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SysOssVo upload(MultipartFile file) {
|
public SysOssVo upload(MultipartFile file) {
|
||||||
String originalfileName = file.getOriginalFilename();
|
String originalfileName = file.getOriginalFilename();
|
||||||
@ -138,7 +180,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
OssClient storage = OssFactory.instance();
|
OssClient storage = OssFactory.instance();
|
||||||
UploadResult uploadResult;
|
UploadResult uploadResult;
|
||||||
try {
|
try {
|
||||||
uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
|
uploadResult = storage.uploadSuffix(file.getBytes(), suffix);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ServiceException(e.getMessage());
|
throw new ServiceException(e.getMessage());
|
||||||
}
|
}
|
||||||
@ -146,6 +188,12 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult);
|
return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件到对象存储服务,并保存文件信息到数据库
|
||||||
|
*
|
||||||
|
* @param file 要上传的文件对象
|
||||||
|
* @return 上传成功后的 SysOssVo 对象,包含文件信息
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SysOssVo upload(File file) {
|
public SysOssVo upload(File file) {
|
||||||
String originalfileName = file.getName();
|
String originalfileName = file.getName();
|
||||||
@ -169,6 +217,13 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
return this.matchingUrl(sysOssVo);
|
return this.matchingUrl(sysOssVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除OSS对象存储
|
||||||
|
*
|
||||||
|
* @param ids OSS对象ID串
|
||||||
|
* @param isValid 判断是否需要校验
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
@ -183,7 +238,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 匹配Url
|
* 桶类型为 private 的URL 修改为临时URL时长为120s
|
||||||
*
|
*
|
||||||
* @param oss OSS对象
|
* @param oss OSS对象
|
||||||
* @return oss 匹配Url的OSS对象
|
* @return oss 匹配Url的OSS对象
|
||||||
|
|||||||
@ -579,4 +579,30 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|||||||
return ObjectUtil.isNull(sysUser) ? null : sysUser.getNickName();
|
return ObjectUtil.isNull(sysUser) ? null : sysUser.getNickName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户ID查询用户手机号
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return 用户手机号
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String selectPhonenumberById(Long userId) {
|
||||||
|
SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
||||||
|
.select(SysUser::getPhonenumber).eq(SysUser::getUserId, userId));
|
||||||
|
return ObjectUtil.isNull(sysUser) ? null : sysUser.getPhonenumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户ID查询用户邮箱
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return 用户邮箱
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String selectEmailById(Long userId) {
|
||||||
|
SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
||||||
|
.select(SysUser::getEmail).eq(SysUser::getUserId, userId));
|
||||||
|
return ObjectUtil.isNull(sysUser) ? null : sysUser.getEmail();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user