1
|
package com.tianbo.warehouse.service.imp;
|
1
|
package com.tianbo.warehouse.service.imp;
|
2
|
|
2
|
|
|
|
3
|
+import com.alibaba.fastjson.JSONObject;
|
3
|
import com.github.pagehelper.Page;
|
4
|
import com.github.pagehelper.Page;
|
4
|
import com.github.pagehelper.PageHelper;
|
5
|
import com.github.pagehelper.PageHelper;
|
5
|
import com.github.pagehelper.PageInfo;
|
6
|
import com.github.pagehelper.PageInfo;
|
|
@@ -9,8 +10,12 @@ import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheable; |
|
@@ -9,8 +10,12 @@ import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheable; |
9
|
import com.tianbo.warehouse.dao.PERMISSIONMapper;
|
10
|
import com.tianbo.warehouse.dao.PERMISSIONMapper;
|
10
|
import com.tianbo.warehouse.model.PERMISSION;
|
11
|
import com.tianbo.warehouse.model.PERMISSION;
|
11
|
import com.tianbo.warehouse.model.ROLE;
|
12
|
import com.tianbo.warehouse.model.ROLE;
|
|
|
13
|
+import com.tianbo.warehouse.model.USERS;
|
12
|
import com.tianbo.warehouse.service.PermissionService;
|
14
|
import com.tianbo.warehouse.service.PermissionService;
|
|
|
15
|
+import com.tianbo.warehouse.util.RedisUtils;
|
13
|
import lombok.extern.slf4j.Slf4j;
|
16
|
import lombok.extern.slf4j.Slf4j;
|
|
|
17
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
18
|
+import org.springframework.data.redis.core.RedisTemplate;
|
14
|
import org.springframework.stereotype.Service;
|
19
|
import org.springframework.stereotype.Service;
|
15
|
|
20
|
|
16
|
import javax.annotation.Resource;
|
21
|
import javax.annotation.Resource;
|
|
@@ -25,6 +30,9 @@ public class PermissionServiceImp implements PermissionService { |
|
@@ -25,6 +30,9 @@ public class PermissionServiceImp implements PermissionService { |
25
|
@Resource
|
30
|
@Resource
|
26
|
PERMISSIONMapper permissionMapper;
|
31
|
PERMISSIONMapper permissionMapper;
|
27
|
|
32
|
|
|
|
33
|
+ @Autowired
|
|
|
34
|
+ RedisUtils redisUtils;
|
|
|
35
|
+
|
28
|
@Override
|
36
|
@Override
|
29
|
// @RedisCacheable(cacheKey = "findAllMenus")
|
37
|
// @RedisCacheable(cacheKey = "findAllMenus")
|
30
|
public PageInfo<PERMISSION> findAll(int pageNum, int pageSize, String name) {
|
38
|
public PageInfo<PERMISSION> findAll(int pageNum, int pageSize, String name) {
|
|
@@ -226,4 +234,33 @@ public class PermissionServiceImp implements PermissionService { |
|
@@ -226,4 +234,33 @@ public class PermissionServiceImp implements PermissionService { |
226
|
|
234
|
|
227
|
}
|
235
|
}
|
228
|
|
236
|
|
|
|
237
|
+ @Override
|
|
|
238
|
+ public Boolean getPermission(String token,String url,String name){
|
|
|
239
|
+
|
|
|
240
|
+ try {
|
|
|
241
|
+ if(token != null && token.startsWith("Bearer ")) {
|
|
|
242
|
+ token = token.substring(7); // 7 是 "Bearer " 的长度
|
|
|
243
|
+ String userJsonStr = redisUtils.get(token);
|
|
|
244
|
+ USERS user = JSONObject.parseObject(userJsonStr, USERS.class);
|
|
|
245
|
+ PERMISSION result = user.getPermissions().stream()
|
|
|
246
|
+ .filter(permission -> "转关运抵申报申报".equals(permission.getName()) || url.equals(permission.getUrl()))
|
|
|
247
|
+ .findFirst()
|
|
|
248
|
+ .orElse(null);
|
|
|
249
|
+ // 输出查询结果
|
|
|
250
|
+ if (result != null) {
|
|
|
251
|
+ System.out.println("匹配到对应权限");
|
|
|
252
|
+ return true;
|
|
|
253
|
+ } else {
|
|
|
254
|
+ return false;
|
|
|
255
|
+ }
|
|
|
256
|
+
|
|
|
257
|
+ } else {
|
|
|
258
|
+ // 处理未包含Bearer前缀的情况
|
|
|
259
|
+ return false;
|
|
|
260
|
+ }
|
|
|
261
|
+ }catch (Exception e){
|
|
|
262
|
+ return false;
|
|
|
263
|
+ }
|
|
|
264
|
+ }
|
|
|
265
|
+
|
229
|
} |
266
|
} |