feat:提交角色授权
This commit is contained in:
@@ -10,6 +10,7 @@ import com.tiesheng.util.config.TsTokenConfig;
|
|||||||
import com.tiesheng.util.exception.ApiException;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
import com.tiesheng.util.pojos.TokenBean;
|
import com.tiesheng.util.pojos.TokenBean;
|
||||||
import com.tiesheng.util.service.TsCacheService;
|
import com.tiesheng.util.service.TsCacheService;
|
||||||
|
import com.tiesheng.util.service.role.TsAuthorityHandler;
|
||||||
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;
|
||||||
@@ -23,14 +24,14 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
public class HasAuthorityAspect {
|
public class RoleAuthorityAspect {
|
||||||
|
|
||||||
public static final String CACHE_HAS_AUTHORITY = "CACHE:HAS_AUTHORITY:{}";
|
public static final String CACHE_HAS_AUTHORITY = "CACHE:HAS_AUTHORITY:{}";
|
||||||
|
|
||||||
@Resource
|
|
||||||
CoreRoleUserMapper coreRoleUserMapper;
|
|
||||||
@Resource
|
@Resource
|
||||||
TsTokenConfig tsTokenConfig;
|
TsTokenConfig tsTokenConfig;
|
||||||
|
@Resource
|
||||||
|
TsAuthorityHandler tsAuthorityHandler;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,9 +58,7 @@ public class HasAuthorityAspect {
|
|||||||
.stream().filter(StrUtil::isNotEmpty).collect(Collectors.toList());
|
.stream().filter(StrUtil::isNotEmpty).collect(Collectors.toList());
|
||||||
|
|
||||||
if (CollUtil.isEmpty(authorityList)) {
|
if (CollUtil.isEmpty(authorityList)) {
|
||||||
List<CoreRoleAuthority> list = coreRoleUserMapper.getOwnerAuthorityLeafList(tokenBean.getId(),
|
authorityList = tsAuthorityHandler.getAuthorities(tokenBean);
|
||||||
tokenBean.getRoleId());
|
|
||||||
authorityList = list.stream().map(CoreRoleAuthority::getNo).collect(Collectors.toList());
|
|
||||||
if (CollUtil.isNotEmpty(authorityList)) {
|
if (CollUtil.isNotEmpty(authorityList)) {
|
||||||
TsCacheService.of().put(cacheKey, StrUtil.join(";", authorityList));
|
TsCacheService.of().put(cacheKey, StrUtil.join(";", authorityList));
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ public class RoleController {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 橘色的权限编辑
|
* 角色的权限编辑
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -158,11 +158,7 @@ public class RoleController {
|
|||||||
@PostMapping("/user/update")
|
@PostMapping("/user/update")
|
||||||
@RoleAuthority(value = "userUpdate")
|
@RoleAuthority(value = "userUpdate")
|
||||||
public ApiResp<String> userUpdate(@RequestBody CoreRoleUser roleUser) {
|
public ApiResp<String> userUpdate(@RequestBody CoreRoleUser roleUser) {
|
||||||
if (StrUtil.isNotEmpty(roleUser.getId())) {
|
coreRoleService.roleUserUpdate(roleUser);
|
||||||
coreRoleService.getUserMapper().updateById(roleUser);
|
|
||||||
} else {
|
|
||||||
coreRoleService.getUserMapper().insert(roleUser);
|
|
||||||
}
|
|
||||||
return ApiResp.respOK("");
|
return ApiResp.respOK("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,10 +171,7 @@ public class RoleController {
|
|||||||
@PostMapping("/user/deleted")
|
@PostMapping("/user/deleted")
|
||||||
@RoleAuthority(value = "userDeleted")
|
@RoleAuthority(value = "userDeleted")
|
||||||
public ApiResp<String> userDeleted(@RequestBody @Valid IdDTO dto) {
|
public ApiResp<String> userDeleted(@RequestBody @Valid IdDTO dto) {
|
||||||
CoreRoleUser coreRoleUser = new CoreRoleUser();
|
coreRoleService.roleUserDeleted(dto.getId());
|
||||||
coreRoleUser.setId(dto.getId());
|
|
||||||
coreRoleUser.setIsDeleted(1);
|
|
||||||
coreRoleService.getUserMapper().updateById(coreRoleUser);
|
|
||||||
return ApiResp.respOK("");
|
return ApiResp.respOK("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,18 +3,23 @@ package com.tiesheng.role.service;
|
|||||||
import cn.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.core.annotation.AnnotationUtil;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.lang.Validator;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.tiesheng.annotation.role.RoleAuthority;
|
import com.tiesheng.annotation.role.RoleAuthority;
|
||||||
|
import com.tiesheng.role.config.RoleAuthorityAspect;
|
||||||
import com.tiesheng.role.mapper.*;
|
import com.tiesheng.role.mapper.*;
|
||||||
import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
||||||
import com.tiesheng.role.pojos.dao.CoreRoleGroup;
|
import com.tiesheng.role.pojos.dao.CoreRoleGroup;
|
||||||
import com.tiesheng.role.pojos.dao.CoreRoleGroupRx;
|
import com.tiesheng.role.pojos.dao.CoreRoleGroupRx;
|
||||||
|
import com.tiesheng.role.pojos.dao.CoreRoleUser;
|
||||||
import com.tiesheng.role.pojos.dto.GroupRxUpdateDTO;
|
import com.tiesheng.role.pojos.dto.GroupRxUpdateDTO;
|
||||||
import com.tiesheng.role.pojos.dto.OwnerMenuDTO;
|
import com.tiesheng.role.pojos.dto.OwnerMenuDTO;
|
||||||
import com.tiesheng.role.pojos.vo.ServiceMenuVO;
|
import com.tiesheng.role.pojos.vo.ServiceMenuVO;
|
||||||
import com.tiesheng.util.config.GlobalConfig;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
|
import com.tiesheng.util.service.TsCacheService;
|
||||||
import com.tiesheng.util.service.TsServiceBase;
|
import com.tiesheng.util.service.TsServiceBase;
|
||||||
|
import com.tiesheng.util.service.role.TsAuthorityHandler;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
@@ -24,10 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -43,7 +45,7 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
|||||||
@Resource
|
@Resource
|
||||||
CoreRoleServerMapper coreRoleServerMapper;
|
CoreRoleServerMapper coreRoleServerMapper;
|
||||||
@Resource
|
@Resource
|
||||||
GlobalConfig globalConfig;
|
TsAuthorityHandler tsAuthorityHandler;
|
||||||
|
|
||||||
public CoreRoleServerMapper getServerMapper() {
|
public CoreRoleServerMapper getServerMapper() {
|
||||||
return coreRoleServerMapper;
|
return coreRoleServerMapper;
|
||||||
@@ -98,16 +100,73 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
|||||||
coreRoleGroupRxMapper.delete(new QueryWrapper<CoreRoleGroupRx>()
|
coreRoleGroupRxMapper.delete(new QueryWrapper<CoreRoleGroupRx>()
|
||||||
.eq("group_id", dto.getId())
|
.eq("group_id", dto.getId())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CoreRoleGroup roleGroup = getById(dto.getId());
|
||||||
|
Validator.validateNotEmpty(roleGroup, "角色不存在");
|
||||||
|
|
||||||
|
List<CoreRoleAuthority> authorities = coreRoleAuthorityMapper.selectList(new QueryWrapper<CoreRoleAuthority>()
|
||||||
|
.eq(CoreRoleAuthority.IS_DELETED, 0)
|
||||||
|
.in("id", dto.getMenuIds())
|
||||||
|
);
|
||||||
|
|
||||||
List<CoreRoleGroupRx> list = new ArrayList<>();
|
List<CoreRoleGroupRx> list = new ArrayList<>();
|
||||||
for (String menuId : dto.getMenuIds()) {
|
for (CoreRoleAuthority authority : authorities) {
|
||||||
CoreRoleGroupRx coreRoleGroupRx = new CoreRoleGroupRx();
|
CoreRoleGroupRx coreRoleGroupRx = new CoreRoleGroupRx();
|
||||||
coreRoleGroupRx.setGroupId(dto.getId());
|
coreRoleGroupRx.setGroupId(roleGroup.getId());
|
||||||
coreRoleGroupRx.setMenuId(menuId);
|
coreRoleGroupRx.setMenuId(authority.getId());
|
||||||
list.add(coreRoleGroupRx);
|
list.add(coreRoleGroupRx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CollUtil.isNotEmpty(list)) {
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
coreRoleGroupRxMapper.batchInsert(list);
|
coreRoleGroupRxMapper.batchInsert(list);
|
||||||
|
onRoleChange(dto.getId(), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑、更新用户的授权
|
||||||
|
*
|
||||||
|
* @param roleUser
|
||||||
|
*/
|
||||||
|
public void roleUserUpdate(CoreRoleUser roleUser) {
|
||||||
|
if (StrUtil.isNotEmpty(roleUser.getId())) {
|
||||||
|
coreRoleUserMapper.updateById(roleUser);
|
||||||
|
} else {
|
||||||
|
coreRoleUserMapper.insert(roleUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
onRoleChange(roleUser.getTypeId(), roleUser.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户授权
|
||||||
|
*
|
||||||
|
* @param recordId
|
||||||
|
*/
|
||||||
|
public void roleUserDeleted(String recordId) {
|
||||||
|
CoreRoleUser coreRoleUser = coreRoleUserMapper.selectById(recordId);
|
||||||
|
if (coreRoleUser == null || coreRoleUser.getIsDeleted() == 1) {
|
||||||
|
throw new ApiException("该授权已被删除");
|
||||||
|
}
|
||||||
|
coreRoleUser.setIsDeleted(1);
|
||||||
|
coreRoleUserMapper.updateById(coreRoleUser);
|
||||||
|
|
||||||
|
onRoleChange(coreRoleUser.getTypeId(), coreRoleUser.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当授权发生变化时
|
||||||
|
*/
|
||||||
|
public void onRoleChange(String roleId, String userId) {
|
||||||
|
if (StrUtil.isNotEmpty(userId)) {
|
||||||
|
TsCacheService.of().remove(StrUtil.format(RoleAuthorityAspect.CACHE_HAS_AUTHORITY, userId));
|
||||||
|
} else {
|
||||||
|
TsCacheService.of().keys(StrUtil.replace(RoleAuthorityAspect.CACHE_HAS_AUTHORITY,
|
||||||
|
"{}", "")).forEach(key -> TsCacheService.of().remove(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,78 +239,9 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
|||||||
points.add(methodAuthority);
|
points.add(methodAuthority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addOrUpdateAuthority(menu, points);
|
|
||||||
|
tsAuthorityHandler.addRoleAuthority(menu, points);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加权限
|
|
||||||
*
|
|
||||||
* @param menu
|
|
||||||
* @param points
|
|
||||||
*/
|
|
||||||
private void addOrUpdateAuthority(RoleAuthority menu, List<RoleAuthority> points) {
|
|
||||||
if (menu.group().length == 0 || CollUtil.isEmpty(points)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<CoreRoleAuthority> list = new ArrayList<>();
|
|
||||||
|
|
||||||
// 分组
|
|
||||||
CoreRoleAuthority groupAuthority = new CoreRoleAuthority();
|
|
||||||
groupAuthority.setLevel(0);
|
|
||||||
for (String group : menu.group()) {
|
|
||||||
|
|
||||||
String parentId = groupAuthority.getParent();
|
|
||||||
int level = groupAuthority.getLevel() + 1;
|
|
||||||
String no = group;
|
|
||||||
if (StrUtil.isNotEmpty(groupAuthority.getNo())) {
|
|
||||||
no = StrUtil.join("_", groupAuthority.getNo(), group);
|
|
||||||
}
|
|
||||||
|
|
||||||
groupAuthority = new CoreRoleAuthority();
|
|
||||||
groupAuthority.setNo(no);
|
|
||||||
groupAuthority.setName(group);
|
|
||||||
groupAuthority.setService(globalConfig.getService());
|
|
||||||
groupAuthority.setType("group");
|
|
||||||
groupAuthority.setLevel(level);
|
|
||||||
groupAuthority.setPlatform(menu.platform());
|
|
||||||
groupAuthority.setParent(parentId);
|
|
||||||
groupAuthority.setId(StrUtil.join("_", groupAuthority.getService(), groupAuthority.getNo()));
|
|
||||||
list.add(groupAuthority);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 菜单
|
|
||||||
CoreRoleAuthority menuAuthority = new CoreRoleAuthority();
|
|
||||||
menuAuthority.setNo(StrUtil.join("_", menu.group(), menu.value()));
|
|
||||||
menuAuthority.setName(menu.value());
|
|
||||||
menuAuthority.setService(globalConfig.getService());
|
|
||||||
menuAuthority.setType("menu");
|
|
||||||
menuAuthority.setLevel(groupAuthority.getLevel() + 1);
|
|
||||||
menuAuthority.setParent(groupAuthority.getId());
|
|
||||||
menuAuthority.setPlatform(menu.platform());
|
|
||||||
menuAuthority.setId(StrUtil.join("_", menuAuthority.getService(), menuAuthority.getNo()));
|
|
||||||
list.add(menuAuthority);
|
|
||||||
|
|
||||||
// 功能点
|
|
||||||
for (RoleAuthority authority : points) {
|
|
||||||
CoreRoleAuthority point = new CoreRoleAuthority();
|
|
||||||
point.setNo(StrUtil.join("_", menuAuthority.getNo(), authority.value()));
|
|
||||||
point.setName(authority.value());
|
|
||||||
point.setService(globalConfig.getService());
|
|
||||||
point.setType("point");
|
|
||||||
point.setLevel(menuAuthority.getLevel() + 1);
|
|
||||||
point.setParent(menuAuthority.getId());
|
|
||||||
point.setPlatform(StrUtil.emptyToDefault(authority.platform(), menu.platform()));
|
|
||||||
point.setId(StrUtil.join("_", point.getService(), point.getNo()));
|
|
||||||
list.add(point);
|
|
||||||
}
|
|
||||||
|
|
||||||
coreRoleAuthorityMapper.batchInsert(list);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package com.tiesheng.role.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.tiesheng.annotation.role.RoleAuthority;
|
||||||
|
import com.tiesheng.role.mapper.CoreRoleAuthorityMapper;
|
||||||
|
import com.tiesheng.role.mapper.CoreRoleUserMapper;
|
||||||
|
import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
||||||
|
import com.tiesheng.util.config.GlobalConfig;
|
||||||
|
import com.tiesheng.util.pojos.TokenBean;
|
||||||
|
import com.tiesheng.util.service.role.TsAuthorityHandler;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RoleAuthorityHandler implements TsAuthorityHandler {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
CoreRoleAuthorityMapper coreRoleAuthorityMapper;
|
||||||
|
@Resource
|
||||||
|
GlobalConfig globalConfig;
|
||||||
|
@Resource
|
||||||
|
CoreRoleUserMapper coreRoleUserMapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addRoleAuthority(RoleAuthority menu, List<RoleAuthority> points) {
|
||||||
|
if (menu.group().length == 0 || CollUtil.isEmpty(points)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<CoreRoleAuthority> list = new ArrayList<>();
|
||||||
|
|
||||||
|
// 分组
|
||||||
|
CoreRoleAuthority groupAuthority = new CoreRoleAuthority();
|
||||||
|
groupAuthority.setLevel(0);
|
||||||
|
for (String group : menu.group()) {
|
||||||
|
|
||||||
|
String parentId = groupAuthority.getParent();
|
||||||
|
int level = groupAuthority.getLevel() + 1;
|
||||||
|
String no = group;
|
||||||
|
if (StrUtil.isNotEmpty(groupAuthority.getNo())) {
|
||||||
|
no = StrUtil.join("_", groupAuthority.getNo(), group);
|
||||||
|
}
|
||||||
|
|
||||||
|
groupAuthority = new CoreRoleAuthority();
|
||||||
|
groupAuthority.setNo(no);
|
||||||
|
groupAuthority.setName(group);
|
||||||
|
groupAuthority.setService(globalConfig.getService());
|
||||||
|
groupAuthority.setType("group");
|
||||||
|
groupAuthority.setLevel(level);
|
||||||
|
groupAuthority.setPlatform(menu.platform());
|
||||||
|
groupAuthority.setParent(parentId);
|
||||||
|
groupAuthority.setId(StrUtil.join("_", groupAuthority.getService(), groupAuthority.getNo()));
|
||||||
|
list.add(groupAuthority);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 菜单
|
||||||
|
CoreRoleAuthority menuAuthority = new CoreRoleAuthority();
|
||||||
|
menuAuthority.setNo(StrUtil.join("_", menu.group(), menu.value()));
|
||||||
|
menuAuthority.setName(menu.value());
|
||||||
|
menuAuthority.setService(globalConfig.getService());
|
||||||
|
menuAuthority.setType("menu");
|
||||||
|
menuAuthority.setLevel(groupAuthority.getLevel() + 1);
|
||||||
|
menuAuthority.setParent(groupAuthority.getId());
|
||||||
|
menuAuthority.setPlatform(menu.platform());
|
||||||
|
menuAuthority.setId(StrUtil.join("_", menuAuthority.getService(), menuAuthority.getNo()));
|
||||||
|
list.add(menuAuthority);
|
||||||
|
|
||||||
|
// 功能点
|
||||||
|
for (RoleAuthority authority : points) {
|
||||||
|
CoreRoleAuthority point = new CoreRoleAuthority();
|
||||||
|
point.setNo(StrUtil.join("_", menuAuthority.getNo(), authority.value()));
|
||||||
|
point.setName(authority.value());
|
||||||
|
point.setService(globalConfig.getService());
|
||||||
|
point.setType("point");
|
||||||
|
point.setLevel(menuAuthority.getLevel() + 1);
|
||||||
|
point.setParent(menuAuthority.getId());
|
||||||
|
point.setPlatform(StrUtil.emptyToDefault(authority.platform(), menu.platform()));
|
||||||
|
point.setId(StrUtil.join("_", point.getService(), point.getNo()));
|
||||||
|
list.add(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
coreRoleAuthorityMapper.batchInsert(list);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAuthorities(TokenBean tokenBean) {
|
||||||
|
List<CoreRoleAuthority> list = coreRoleUserMapper.getOwnerAuthorityLeafList(tokenBean.getId(),
|
||||||
|
tokenBean.getRoleId());
|
||||||
|
return list.stream().map(CoreRoleAuthority::getNo).distinct().collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,6 +10,8 @@ import com.tiesheng.util.service.cache.TsCacheHandler;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class TsCacheService {
|
public class TsCacheService {
|
||||||
|
|
||||||
@@ -63,6 +65,17 @@ public class TsCacheService {
|
|||||||
tsCacheHandler.remove(key);
|
tsCacheHandler.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取key
|
||||||
|
*
|
||||||
|
* @param pattern
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<String> keys(String pattern) {
|
||||||
|
return tsCacheHandler.keys(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// 图形验证码
|
// 图形验证码
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.tiesheng.util.service.cache;
|
package com.tiesheng.util.service.cache;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface TsCacheHandler {
|
public interface TsCacheHandler {
|
||||||
|
|
||||||
String name();
|
String name();
|
||||||
@@ -14,4 +16,6 @@ public interface TsCacheHandler {
|
|||||||
|
|
||||||
void remove(String key);
|
void remove(String key);
|
||||||
|
|
||||||
|
Set<String> keys(String prefix);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@@ -51,5 +53,10 @@ public class TsCacheRedisHandler implements TsCacheHandler {
|
|||||||
redisTemplate.delete(key);
|
redisTemplate.delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> keys(String prefix) {
|
||||||
|
return redisTemplate.keys(prefix + "*");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,13 @@ package com.tiesheng.util.service.cache;
|
|||||||
|
|
||||||
import cn.hutool.cache.CacheUtil;
|
import cn.hutool.cache.CacheUtil;
|
||||||
import cn.hutool.cache.impl.TimedCache;
|
import cn.hutool.cache.impl.TimedCache;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnMissingBean(value = TsCacheHandler.class, ignored = {TsCacheTimedHandler.class, TsCacheTimedHandler.class})
|
@ConditionalOnMissingBean(value = TsCacheHandler.class, ignored = {TsCacheTimedHandler.class, TsCacheTimedHandler.class})
|
||||||
public class TsCacheTimedHandler implements TsCacheHandler {
|
public class TsCacheTimedHandler implements TsCacheHandler {
|
||||||
@@ -63,5 +67,11 @@ public class TsCacheTimedHandler implements TsCacheHandler {
|
|||||||
getTimedCache().remove(key);
|
getTimedCache().remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> keys(String prefix) {
|
||||||
|
return getTimedCache().keySet().stream().filter(key -> StrUtil.startWith(key, prefix))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.tiesheng.util.service.role;
|
||||||
|
|
||||||
|
import com.tiesheng.annotation.role.RoleAuthority;
|
||||||
|
import com.tiesheng.util.pojos.TokenBean;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public interface TsAuthorityHandler {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加所有的权限
|
||||||
|
*
|
||||||
|
* @param groupAuthority
|
||||||
|
* @param pointAuthorityList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void addRoleAuthority(RoleAuthority groupAuthority, List<RoleAuthority> pointAuthorityList);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取权限列表
|
||||||
|
*
|
||||||
|
* @param tokenBean
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<String> getAuthorities(TokenBean tokenBean);
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user