4
4
import cn .hutool .core .util .ObjectUtil ;
5
5
import org .dromara .common .core .domain .model .LoginUser ;
6
6
import org .dromara .common .core .enums .UserType ;
7
+ import org .dromara .common .core .exception .ServiceException ;
7
8
import org .dromara .common .core .service .PermissionService ;
9
+ import org .dromara .common .core .utils .SpringUtils ;
8
10
import org .dromara .common .core .utils .StringUtils ;
9
11
import org .dromara .common .satoken .utils .LoginHelper ;
10
- import org .springframework .beans .factory .annotation .Autowired ;
11
12
12
13
import java .util .ArrayList ;
13
14
import java .util .List ;
19
20
*/
20
21
public class SaPermissionImpl implements StpInterface {
21
22
22
- @ Autowired
23
- private PermissionService permissionService ;
24
-
25
23
/**
26
24
* 获取菜单权限列表
27
25
*/
28
26
@ Override
29
27
public List <String > getPermissionList (Object loginId , String loginType ) {
30
28
LoginUser loginUser = LoginHelper .getLoginUser ();
31
29
if (ObjectUtil .isNull (loginUser ) || !loginUser .getLoginId ().equals (loginId )) {
32
- List <String > list = StringUtils .splitList (loginId .toString (), ":" );
33
- return new ArrayList <>(permissionService .getMenuPermission (Long .parseLong (list .get (1 ))));
30
+ PermissionService permissionService = getPermissionService ();
31
+ if (ObjectUtil .isNotNull (permissionService )) {
32
+ List <String > list = StringUtils .splitList (loginId .toString (), ":" );
33
+ return new ArrayList <>(permissionService .getMenuPermission (Long .parseLong (list .get (1 ))));
34
+ } else {
35
+ throw new ServiceException ("PermissionService 实现类不存在" );
36
+ }
34
37
}
35
38
UserType userType = UserType .getUserType (loginUser .getUserType ());
36
39
if (userType == UserType .APP_USER ) {
@@ -47,8 +50,13 @@ public List<String> getPermissionList(Object loginId, String loginType) {
47
50
public List <String > getRoleList (Object loginId , String loginType ) {
48
51
LoginUser loginUser = LoginHelper .getLoginUser ();
49
52
if (ObjectUtil .isNull (loginUser ) || !loginUser .getLoginId ().equals (loginId )) {
50
- List <String > list = StringUtils .splitList (loginId .toString (), ":" );
51
- return new ArrayList <>(permissionService .getRolePermission (Long .parseLong (list .get (1 ))));
53
+ PermissionService permissionService = getPermissionService ();
54
+ if (ObjectUtil .isNotNull (permissionService )) {
55
+ List <String > list = StringUtils .splitList (loginId .toString (), ":" );
56
+ return new ArrayList <>(permissionService .getRolePermission (Long .parseLong (list .get (1 ))));
57
+ } else {
58
+ throw new ServiceException ("PermissionService 实现类不存在" );
59
+ }
52
60
}
53
61
UserType userType = UserType .getUserType (loginUser .getUserType ());
54
62
if (userType == UserType .APP_USER ) {
@@ -57,4 +65,13 @@ public List<String> getRoleList(Object loginId, String loginType) {
57
65
// SYS_USER 默认返回权限
58
66
return new ArrayList <>(loginUser .getRolePermission ());
59
67
}
68
+
69
+ private PermissionService getPermissionService () {
70
+ try {
71
+ return SpringUtils .getBean (PermissionService .class );
72
+ } catch (Exception e ) {
73
+ return null ;
74
+ }
75
+ }
76
+
60
77
}
0 commit comments