From 81f12007104f8d7b0d8f28dfe18a8eb2d70eb821 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?=
<15040126243@163.com>
Date: Mon, 11 Nov 2024 13:58:56 +0800
Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E6=95=B0?=
=?UTF-8?q?=E6=8D=AE=E6=9D=83=E9=99=90=E6=9F=A5=E8=AF=A2=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E7=BC=93=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../common/core/constant/CacheNames.java | 10 ++++++
.../common/core/utils/ObjectUtils.java | 32 +++++++++++--------
.../dubbo/RemoteDataScopeServiceImpl.java | 5 ++-
.../service/impl/SysDeptServiceImpl.java | 12 +++++--
.../service/impl/SysRoleServiceImpl.java | 5 +++
5 files changed, 47 insertions(+), 17 deletions(-)
diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java
index 28ba1773..bf8efc55 100644
--- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java
+++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java
@@ -60,6 +60,16 @@ public interface CacheNames {
*/
String SYS_OSS = "sys_oss#30d";
+ /**
+ * 角色自定义权限
+ */
+ String SYS_ROLE_CUSTOM = "sys_role_custom#30d";
+
+ /**
+ * 部门及以下权限
+ */
+ String SYS_DEPT_AND_CHILD = "sys_dept_and_child#30d";
+
/**
* OSS配置
*/
diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ObjectUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ObjectUtils.java
index afd67052..a4940c07 100644
--- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ObjectUtils.java
+++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/ObjectUtils.java
@@ -15,28 +15,32 @@ import java.util.function.Function;
public class ObjectUtils extends ObjectUtil {
/**
- * 如果对象不为空,则获取对象中的某个字段
- *
- * 例:
- *
- * public class User {
- *
private String name;
- *
// 省略 getter/setter
- *
}
- *
- *
- * User user = userService.queryById(userId);
- *
String name = ObjectUtils.notNullGetter(user,User::getName);
- *
+ * 如果对象不为空,则获取对象中的某个字段 ObjectUtils.notNullGetter(user, User::getName);
+ *
* @param obj 对象
* @param func 获取方法
* @return 对象字段
*/
- public static E notNullGetter(T obj, Function func) {
+ public static E notNullGetter(T obj, Function func) {
if (isNotNull(obj) && isNotNull(func)) {
return func.apply(obj);
}
return null;
}
+ /**
+ * 如果对象不为空,则获取对象中的某个字段 ObjectUtils.notNullGetter(user, User::getName, "");
+ *
+ * @param obj 对象
+ * @param func 获取方法
+ * @param defaultValue 默认值
+ * @return 对象字段
+ */
+ public static E notNullGetter(T obj, Function func, E defaultValue) {
+ if (isNotNull(obj) && isNotNull(func)) {
+ return func.apply(obj);
+ }
+ return defaultValue;
+ }
+
}
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDataScopeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDataScopeServiceImpl.java
index a07e2011..790297df 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDataScopeServiceImpl.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDataScopeServiceImpl.java
@@ -6,13 +6,14 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
+import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.utils.StreamUtils;
-import org.dromara.common.mybatis.helper.DataBaseHelper;
import org.dromara.system.api.RemoteDataScopeService;
import org.dromara.system.domain.SysDept;
import org.dromara.system.domain.SysRoleDept;
import org.dromara.system.mapper.SysDeptMapper;
import org.dromara.system.mapper.SysRoleDeptMapper;
+import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
@@ -39,6 +40,7 @@ public class RemoteDataScopeServiceImpl implements RemoteDataScopeService {
* @param roleId 角色ID
* @return 返回角色的自定义权限语句,如果没有找到则返回 null
*/
+ @Cacheable(cacheNames = CacheNames.SYS_ROLE_CUSTOM, key = "#roleId")
@Override
public String getRoleCustom(Long roleId) {
if (ObjectUtil.isNull(roleId)) {
@@ -60,6 +62,7 @@ public class RemoteDataScopeServiceImpl implements RemoteDataScopeService {
* @param deptId 部门ID
* @return 返回部门及其下级的权限语句,如果没有找到则返回 null
*/
+ @Cacheable(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, key = "#deptId")
@Override
public String getDeptAndChild(Long deptId) {
if (ObjectUtil.isNull(deptId)) {
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java
index 9b076541..b4d9b9d6 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java
@@ -29,6 +29,7 @@ import org.dromara.system.mapper.SysUserMapper;
import org.dromara.system.service.ISysDeptService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
+import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@@ -258,6 +259,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @param bo 部门信息
* @return 结果
*/
+ @CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, allEntries = true)
@Override
public int insertDept(SysDeptBo bo) {
SysDept info = baseMapper.selectById(bo.getParentId());
@@ -276,7 +278,10 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @param bo 部门信息
* @return 结果
*/
- @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId")
+ @Caching(evict = {
+ @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId"),
+ @CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, allEntries = true)
+ })
@Override
public int updateDept(SysDeptBo bo) {
SysDept dept = MapstructUtils.convert(bo, SysDept.class);
@@ -346,7 +351,10 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @param deptId 部门ID
* @return 结果
*/
- @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
+ @Caching(evict = {
+ @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId"),
+ @CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, key = "#deptId")
+ })
@Override
public int deleteDeptById(Long deptId) {
return baseMapper.deleteById(deptId);
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java
index 61609c37..57d14076 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java
@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
+import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.constant.TenantConstants;
import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.core.exception.ServiceException;
@@ -33,6 +34,7 @@ import org.dromara.system.mapper.SysRoleMapper;
import org.dromara.system.mapper.SysRoleMenuMapper;
import org.dromara.system.mapper.SysUserRoleMapper;
import org.dromara.system.service.ISysRoleService;
+import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -328,6 +330,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
* @param bo 角色信息
* @return 结果
*/
+ @CacheEvict(cacheNames = CacheNames.SYS_ROLE_CUSTOM, key = "#bo.roleId")
@Override
@Transactional(rollbackFor = Exception.class)
public int authDataScope(SysRoleBo bo) {
@@ -388,6 +391,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
* @param roleId 角色ID
* @return 结果
*/
+ @CacheEvict(cacheNames = CacheNames.SYS_ROLE_CUSTOM, key = "#roleId")
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteRoleById(Long roleId) {
@@ -404,6 +408,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
* @param roleIds 需要删除的角色ID
* @return 结果
*/
+ @CacheEvict(cacheNames = CacheNames.SYS_ROLE_CUSTOM, allEntries = true)
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteRoleByIds(Long[] roleIds) {