| | |
| | | |
| | | import com.moon.server.entity.all.*; |
| | | import com.moon.server.entity.sys.MenuEntity; |
| | | import com.moon.server.entity.sys.ResEntity; |
| | | import com.moon.server.mapper.all.PermsMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 授权服务 |
| | | * @author WWW |
| | | */ |
| | | @Service |
| | | @SuppressWarnings("ALL") |
| | | public class PermsService implements PermsMapper { |
| | | @Autowired |
| | | @Resource |
| | | PermsMapper permsMapper; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | RedisService redisService; |
| | | |
| | | @Override |
| | | public List<ResAuthEntity> selectRes(String uid) { |
| | | public List<ResEntity> selectRes(String uid) { |
| | | return selectResByUid(uid, false); |
| | | } |
| | | |
| | | @Override |
| | | public List<ResEntity> selectAllRes() { |
| | | return selectResByUid(StaticData.ADMIN, true); |
| | | } |
| | | |
| | | private List<ResEntity> selectResByUid(String uid, boolean isAll) { |
| | | String key = RedisCacheKey.permsResKey(uid); |
| | | Object obj = redisService.get(key); |
| | | if (obj instanceof List<?>) { |
| | | return (List<ResAuthEntity>) obj; |
| | | return (List<ResEntity>) obj; |
| | | } |
| | | |
| | | List<ResAuthEntity> list = permsMapper.selectRes(uid); |
| | | List<ResEntity> list = isAll ? permsMapper.selectAllRes() : permsMapper.selectRes(uid); |
| | | if (list != null && list.size() > 0) { |
| | | redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Integer> selectResList(String uid) { |
| | | String key = RedisCacheKey.permsResListKey(uid); |
| | | public List<String> selectTabs(String uid) { |
| | | return selectTabsByUid(uid, false); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> selectAllTabs() { |
| | | return selectTabsByUid(StaticData.ADMIN, true); |
| | | } |
| | | |
| | | private List<String> selectTabsByUid(String uid, boolean isAll) { |
| | | String key = RedisCacheKey.permsGeoTabKey(uid); |
| | | Object obj = redisService.get(key); |
| | | if (obj instanceof List<?>) { |
| | | return (List<Integer>) obj; |
| | | return (List<String>) obj; |
| | | } |
| | | |
| | | List<Integer> list = permsMapper.selectResList(uid); |
| | | List<String> list = isAll ? permsMapper.selectAllTabs() : permsMapper.selectTabs(uid); |
| | | if (list != null && list.size() > 0) { |
| | | redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); |
| | | } |
| | |
| | | |
| | | public void clearResCache() { |
| | | redisService.clearKeys(RedisCacheKey.permsResKey("")); |
| | | redisService.clearKeys(RedisCacheKey.permsResListKey("")); |
| | | } |
| | | |
| | | public void clearLayerCache() { |
| | | redisService.clearKeys(RedisCacheKey.permsLayerKey("")); |
| | | } |
| | | |
| | | public void clearPermsCache() { |