mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-21 02:25:56 +08:00
Merge branch '5.X' into future/oauth2
# Conflicts: # ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/utils/LoginHelper.java
This commit is contained in:
commit
d5126fe24a
@ -1,6 +1,7 @@
|
|||||||
package org.dromara.common.idempotent.aspectj;
|
package org.dromara.common.idempotent.aspectj;
|
||||||
|
|
||||||
import cn.dev33.satoken.SaManager;
|
import cn.dev33.satoken.SaManager;
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import org.dromara.common.core.constant.GlobalConstants;
|
import org.dromara.common.core.constant.GlobalConstants;
|
||||||
@ -25,6 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 防止重复提交(参考美团GTIS防重系统)
|
* 防止重复提交(参考美团GTIS防重系统)
|
||||||
@ -39,10 +41,8 @@ public class RepeatSubmitAspect {
|
|||||||
@Before("@annotation(repeatSubmit)")
|
@Before("@annotation(repeatSubmit)")
|
||||||
public void doBefore(JoinPoint point, RepeatSubmit repeatSubmit) throws Throwable {
|
public void doBefore(JoinPoint point, RepeatSubmit repeatSubmit) throws Throwable {
|
||||||
// 如果注解不为0 则使用注解数值
|
// 如果注解不为0 则使用注解数值
|
||||||
long interval = 0;
|
long interval = repeatSubmit.timeUnit().toMillis(repeatSubmit.interval());
|
||||||
if (repeatSubmit.interval() > 0) {
|
|
||||||
interval = repeatSubmit.timeUnit().toMillis(repeatSubmit.interval());
|
|
||||||
}
|
|
||||||
if (interval < 1000) {
|
if (interval < 1000) {
|
||||||
throw new ServiceException("重复提交间隔时间不能小于'1'秒");
|
throw new ServiceException("重复提交间隔时间不能小于'1'秒");
|
||||||
}
|
}
|
||||||
@ -58,9 +58,7 @@ public class RepeatSubmitAspect {
|
|||||||
submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
|
submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
|
||||||
// 唯一标识(指定key + url + 消息头)
|
// 唯一标识(指定key + url + 消息头)
|
||||||
String cacheRepeatKey = GlobalConstants.REPEAT_SUBMIT_KEY + url + submitKey;
|
String cacheRepeatKey = GlobalConstants.REPEAT_SUBMIT_KEY + url + submitKey;
|
||||||
String key = RedisUtils.getCacheObject(cacheRepeatKey);
|
if (RedisUtils.setObjectIfAbsent(cacheRepeatKey, "", Duration.ofMillis(interval))) {
|
||||||
if (key == null) {
|
|
||||||
RedisUtils.setCacheObject(cacheRepeatKey, "", Duration.ofMillis(interval));
|
|
||||||
KEY_CACHE.set(cacheRepeatKey);
|
KEY_CACHE.set(cacheRepeatKey);
|
||||||
} else {
|
} else {
|
||||||
String message = repeatSubmit.message();
|
String message = repeatSubmit.message();
|
||||||
@ -78,7 +76,7 @@ public class RepeatSubmitAspect {
|
|||||||
*/
|
*/
|
||||||
@AfterReturning(pointcut = "@annotation(repeatSubmit)", returning = "jsonResult")
|
@AfterReturning(pointcut = "@annotation(repeatSubmit)", returning = "jsonResult")
|
||||||
public void doAfterReturning(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Object jsonResult) {
|
public void doAfterReturning(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Object jsonResult) {
|
||||||
if (jsonResult instanceof R r) {
|
if (jsonResult instanceof R<?> r) {
|
||||||
try {
|
try {
|
||||||
// 成功则不删除redis数据 保证在有效时间内无法重复提交
|
// 成功则不删除redis数据 保证在有效时间内无法重复提交
|
||||||
if (r.getCode() == R.SUCCESS) {
|
if (r.getCode() == R.SUCCESS) {
|
||||||
@ -107,19 +105,16 @@ public class RepeatSubmitAspect {
|
|||||||
* 参数拼装
|
* 参数拼装
|
||||||
*/
|
*/
|
||||||
private String argsArrayToString(Object[] paramsArray) {
|
private String argsArrayToString(Object[] paramsArray) {
|
||||||
StringBuilder params = new StringBuilder();
|
StringJoiner params = new StringJoiner(" ");
|
||||||
if (paramsArray != null && paramsArray.length > 0) {
|
if (ArrayUtil.isEmpty(paramsArray)) {
|
||||||
for (Object o : paramsArray) {
|
return params.toString();
|
||||||
if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) {
|
}
|
||||||
try {
|
for (Object o : paramsArray) {
|
||||||
params.append(JsonUtils.toJsonString(o)).append(" ");
|
if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) {
|
||||||
} catch (Exception e) {
|
params.add(JsonUtils.toJsonString(o));
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return params.toString().trim();
|
return params.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,13 +135,12 @@ public class RepeatSubmitAspect {
|
|||||||
}
|
}
|
||||||
} else if (Map.class.isAssignableFrom(clazz)) {
|
} else if (Map.class.isAssignableFrom(clazz)) {
|
||||||
Map map = (Map) o;
|
Map map = (Map) o;
|
||||||
for (Object value : map.entrySet()) {
|
for (Object value : map.values()) {
|
||||||
Map.Entry entry = (Map.Entry) value;
|
return value instanceof MultipartFile;
|
||||||
return entry.getValue() instanceof MultipartFile;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|
||||||
|| o instanceof BindingResult;
|
|| o instanceof BindingResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package org.dromara.common.log.aspect;
|
|||||||
|
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||||
import org.dromara.common.core.utils.ServletUtils;
|
import org.dromara.common.core.utils.ServletUtils;
|
||||||
@ -28,6 +29,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作日志记录处理
|
* 操作日志记录处理
|
||||||
@ -170,26 +172,23 @@ public class LogAspect {
|
|||||||
* 参数拼装
|
* 参数拼装
|
||||||
*/
|
*/
|
||||||
private String argsArrayToString(Object[] paramsArray, String[] excludeParamNames) {
|
private String argsArrayToString(Object[] paramsArray, String[] excludeParamNames) {
|
||||||
StringBuilder params = new StringBuilder();
|
StringJoiner params = new StringJoiner(" ");
|
||||||
if (paramsArray != null && paramsArray.length > 0) {
|
if (ArrayUtil.isEmpty(paramsArray)) {
|
||||||
for (Object o : paramsArray) {
|
return params.toString();
|
||||||
if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) {
|
}
|
||||||
try {
|
for (Object o : paramsArray) {
|
||||||
String str = JsonUtils.toJsonString(o);
|
if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) {
|
||||||
Dict dict = JsonUtils.parseMap(str);
|
String str = JsonUtils.toJsonString(o);
|
||||||
if (MapUtil.isNotEmpty(dict)) {
|
Dict dict = JsonUtils.parseMap(str);
|
||||||
MapUtil.removeAny(dict, EXCLUDE_PROPERTIES);
|
if (MapUtil.isNotEmpty(dict)) {
|
||||||
MapUtil.removeAny(dict, excludeParamNames);
|
MapUtil.removeAny(dict, EXCLUDE_PROPERTIES);
|
||||||
str = JsonUtils.toJsonString(dict);
|
MapUtil.removeAny(dict, excludeParamNames);
|
||||||
}
|
str = JsonUtils.toJsonString(dict);
|
||||||
params.append(str).append(" ");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
params.add(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return params.toString().trim();
|
return params.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -210,12 +209,11 @@ public class LogAspect {
|
|||||||
}
|
}
|
||||||
} else if (Map.class.isAssignableFrom(clazz)) {
|
} else if (Map.class.isAssignableFrom(clazz)) {
|
||||||
Map map = (Map) o;
|
Map map = (Map) o;
|
||||||
for (Object value : map.entrySet()) {
|
for (Object value : map.values()) {
|
||||||
Map.Entry entry = (Map.Entry) value;
|
return value instanceof MultipartFile;
|
||||||
return entry.getValue() instanceof MultipartFile;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|
||||||
|| o instanceof BindingResult;
|
|| o instanceof BindingResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -129,6 +129,18 @@ public class RedisUtils {
|
|||||||
batch.execute();
|
batch.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果不存在则设置 并返回 true 如果存在则返回 false
|
||||||
|
*
|
||||||
|
* @param key 缓存的键值
|
||||||
|
* @param value 缓存的值
|
||||||
|
* @return set成功或失败
|
||||||
|
*/
|
||||||
|
public static <T> boolean setObjectIfAbsent(final String key, final T value, final Duration duration) {
|
||||||
|
RBucket<T> bucket = CLIENT.getBucket(key);
|
||||||
|
return bucket.setIfAbsent(value, duration);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册对象监听器
|
* 注册对象监听器
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@ -66,10 +66,9 @@ public class LoginHelper {
|
|||||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||||
model.setTimeout(timeout).setActiveTimeout(activeTimeout);
|
model.setTimeout(timeout).setActiveTimeout(activeTimeout);
|
||||||
StpUtil.stpLogic.setLoginType(loginUser.getUserType())
|
StpUtil.login(loginUser.getLoginId(),
|
||||||
.login(loginUser.getLoginId(),
|
model.setExtra(TENANT_KEY, loginUser.getTenantId())
|
||||||
model.setExtra(TENANT_KEY, loginUser.getTenantId())
|
.setExtra(USER_KEY, loginUser.getUserId()));
|
||||||
.setExtra(USER_KEY, loginUser.getUserId()));
|
|
||||||
StpUtil.getTokenSession().set(LOGIN_USER_KEY, loginUser);
|
StpUtil.getTokenSession().set(LOGIN_USER_KEY, loginUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +152,7 @@ public class LoginHelper {
|
|||||||
* 获取用户类型
|
* 获取用户类型
|
||||||
*/
|
*/
|
||||||
public static UserType getUserType() {
|
public static UserType getUserType() {
|
||||||
String loginType = StpUtil.stpLogic.getLoginType();
|
String loginType = StpUtil.getLoginIdAsString();
|
||||||
return UserType.getUserType(loginType);
|
return UserType.getUserType(loginType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public interface ISysDictTypeService {
|
|||||||
* @param bo 字典类型信息
|
* @param bo 字典类型信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
List<SysDictTypeVo> insertDictType(SysDictTypeBo bo);
|
List<SysDictDataVo> insertDictType(SysDictTypeBo bo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改保存字典类型信息
|
* 修改保存字典类型信息
|
||||||
|
|||||||
@ -123,7 +123,6 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
|||||||
* @param dictType 字典类型
|
* @param dictType 字典类型
|
||||||
* @return 字典类型
|
* @return 字典类型
|
||||||
*/
|
*/
|
||||||
@Cacheable(cacheNames = CacheNames.SYS_DICT, key = "#dictType")
|
|
||||||
@Override
|
@Override
|
||||||
public SysDictTypeVo selectDictTypeByType(String dictType) {
|
public SysDictTypeVo selectDictTypeByType(String dictType) {
|
||||||
return baseMapper.selectVoById(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType));
|
return baseMapper.selectVoById(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType));
|
||||||
@ -163,10 +162,11 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
|||||||
*/
|
*/
|
||||||
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#bo.dictType")
|
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#bo.dictType")
|
||||||
@Override
|
@Override
|
||||||
public List<SysDictTypeVo> insertDictType(SysDictTypeBo bo) {
|
public List<SysDictDataVo> insertDictType(SysDictTypeBo bo) {
|
||||||
SysDictType dict = MapstructUtils.convert(bo, SysDictType.class);
|
SysDictType dict = MapstructUtils.convert(bo, SysDictType.class);
|
||||||
int row = baseMapper.insert(dict);
|
int row = baseMapper.insert(dict);
|
||||||
if (row > 0) {
|
if (row > 0) {
|
||||||
|
// 新增 type 下无 data 数据 返回空防止缓存穿透
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
throw new ServiceException("操作失败");
|
throw new ServiceException("操作失败");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user