update 优化 数据权限查询增加缓存

dev
疯狂的狮子Li 1 year ago
parent 7cff7894da
commit 81f1200710

@ -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
*/

@ -15,28 +15,32 @@ import java.util.function.Function;
public class ObjectUtils extends ObjectUtil {
/**
*
* <p>
*
* <code>
* <p> public class User {
* <p> private String name;
* <p> // 省略 getter/setter
* <p> }
* </code>
* <code>
* <p> User user = userService.queryById(userId);
* <p> String name = ObjectUtils.notNullGetter(user,User::getName);
* </code>
* ObjectUtils.notNullGetter(user, User::getName);
*
* @param obj
* @param func
* @return
*/
public static <T,E> E notNullGetter(T obj, Function<T,E> func) {
public static <T, E> E notNullGetter(T obj, Function<T, E> 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 <T, E> E notNullGetter(T obj, Function<T, E> func, E defaultValue) {
if (isNotNull(obj) && isNotNull(func)) {
return func.apply(obj);
}
return defaultValue;
}
}

@ -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)) {

@ -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);

@ -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) {

Loading…
Cancel
Save