|
|
package com.tianbo.warehouse.service.imp;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.Page;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
...
|
...
|
@@ -9,8 +10,12 @@ import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheable; |
|
|
import com.tianbo.warehouse.dao.PERMISSIONMapper;
|
|
|
import com.tianbo.warehouse.model.PERMISSION;
|
|
|
import com.tianbo.warehouse.model.ROLE;
|
|
|
import com.tianbo.warehouse.model.USERS;
|
|
|
import com.tianbo.warehouse.service.PermissionService;
|
|
|
import com.tianbo.warehouse.util.RedisUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
...
|
...
|
@@ -25,6 +30,9 @@ public class PermissionServiceImp implements PermissionService { |
|
|
@Resource
|
|
|
PERMISSIONMapper permissionMapper;
|
|
|
|
|
|
@Autowired
|
|
|
RedisUtils redisUtils;
|
|
|
|
|
|
@Override
|
|
|
// @RedisCacheable(cacheKey = "findAllMenus")
|
|
|
public PageInfo<PERMISSION> findAll(int pageNum, int pageSize, String name) {
|
...
|
...
|
@@ -226,4 +234,33 @@ public class PermissionServiceImp implements PermissionService { |
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean getPermission(String token,String url,String name){
|
|
|
|
|
|
try {
|
|
|
if(token != null && token.startsWith("Bearer ")) {
|
|
|
token = token.substring(7); // 7 是 "Bearer " 的长度
|
|
|
String userJsonStr = redisUtils.get(token);
|
|
|
USERS user = JSONObject.parseObject(userJsonStr, USERS.class);
|
|
|
PERMISSION result = user.getPermissions().stream()
|
|
|
.filter(permission -> "转关运抵申报申报".equals(permission.getName()) || url.equals(permission.getUrl()))
|
|
|
.findFirst()
|
|
|
.orElse(null);
|
|
|
// 输出查询结果
|
|
|
if (result != null) {
|
|
|
System.out.println("匹配到对应权限");
|
|
|
return true;
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
// 处理未包含Bearer前缀的情况
|
|
|
return false;
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|