| | |
| | | package com.lf.server.service.all; |
| | | |
| | | import com.lf.server.entity.all.MenusAuthEntity; |
| | | import com.lf.server.entity.all.PermsAuthEntity; |
| | | import com.lf.server.entity.all.ResAuthEntity; |
| | | import com.lf.server.entity.all.*; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.mapper.all.PermsMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 授权服务 |
| | |
| | | @Autowired |
| | | PermsMapper permsMapper; |
| | | |
| | | @Autowired |
| | | RedisService redisService; |
| | | |
| | | @Override |
| | | public List<ResAuthEntity> selectRes(String uid) { |
| | | if (StringHelper.isEmpty(uid)) { |
| | | return null; |
| | | } |
| | | |
| | | return permsMapper.selectRes(uid); |
| | | String key = RedisCacheKey.permsResKey(uid); |
| | | Object obj = redisService.get(key); |
| | | if (obj instanceof List<?>) { |
| | | return (List<ResAuthEntity>) obj; |
| | | } |
| | | |
| | | List<ResAuthEntity> list = permsMapper.selectRes(uid); |
| | | if (list != null && list.size() > 0) { |
| | | redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | |
| | | return null; |
| | | } |
| | | |
| | | return permsMapper.selectMenus(uid); |
| | | String key = RedisCacheKey.permsMenusKey(uid); |
| | | Object obj = redisService.get(key); |
| | | if (obj instanceof List<?>) { |
| | | return (List<MenusAuthEntity>) obj; |
| | | } |
| | | |
| | | List<MenusAuthEntity> list = permsMapper.selectMenus(uid); |
| | | if (list != null && list.size() > 0) { |
| | | redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<PermsAuthEntity> selectPerms(String uid) { |
| | | public List<String> selectPerms(String uid) { |
| | | if (StringHelper.isEmpty(uid)) { |
| | | return null; |
| | | } |
| | | |
| | | return permsMapper.selectPerms(uid); |
| | | String key = RedisCacheKey.permsPermsKey(uid); |
| | | Object obj = redisService.get(key); |
| | | if (obj instanceof List<?>) { |
| | | return (List<String>) obj; |
| | | } |
| | | |
| | | List<String> list = permsMapper.selectPerms(uid); |
| | | if (list != null && list.size() > 0) { |
| | | redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> selectPerms2(String uid) { |
| | | public List<PermsAuthEntity> selectPermsEntity(String uid) { |
| | | if (StringHelper.isEmpty(uid)) { |
| | | return null; |
| | | } |
| | | |
| | | return permsMapper.selectPerms2(uid); |
| | | String key = RedisCacheKey.permsPermsEntityKey(uid); |
| | | Object obj = redisService.get(key); |
| | | if (obj instanceof List<?>) { |
| | | return (List<PermsAuthEntity>) obj; |
| | | } |
| | | |
| | | List<PermsAuthEntity> list = permsMapper.selectPermsEntity(uid); |
| | | if (list != null && list.size() > 0) { |
| | | redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | public void clearResCache() { |
| | | redisService.clearKeys(RedisCacheKey.permsResKey("")); |
| | | } |
| | | |
| | | public void clearPermsCache() { |
| | | redisService.clearKeys(RedisCacheKey.permsMenusKey("")); |
| | | redisService.clearKeys(RedisCacheKey.permsPermsKey("")); |
| | | redisService.clearKeys(RedisCacheKey.permsPermsEntityKey("")); |
| | | } |
| | | |
| | | public void clearAllCache() { |
| | | redisService.clearKeys(RedisCacheKey.permsRootKey()); |
| | | } |
| | | } |