|
|
@ -2,8 +2,8 @@ package org.nl.common.utils; |
|
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.json.JSONArray; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.nl.common.utils.dto.CurrentUser; |
|
|
|
|
|
|
@ -24,14 +24,22 @@ public class SecurityUtils { |
|
|
|
*/ |
|
|
|
public static CurrentUser getCurrentUser() { |
|
|
|
try { |
|
|
|
JSONObject json = (JSONObject) StpUtil.getExtra("loginInfo"); |
|
|
|
if (ObjectUtil.isNotEmpty(json)) { |
|
|
|
return json.toBean(CurrentUser.class); |
|
|
|
Object loginInfo = StpUtil.getExtra("loginInfo"); |
|
|
|
if (loginInfo==null){ |
|
|
|
CurrentUser currentUser = new CurrentUser(); |
|
|
|
currentUser.setId("2"); |
|
|
|
currentUser.setPresonName("外部系统用户"); |
|
|
|
currentUser.setUsername("admin"); |
|
|
|
return currentUser; |
|
|
|
} |
|
|
|
return JSONObject.parseObject(String.valueOf(loginInfo),CurrentUser.class); |
|
|
|
} catch (Exception e) { |
|
|
|
return CurrentUser.getDefaultUser(); |
|
|
|
CurrentUser currentUser = new CurrentUser(); |
|
|
|
currentUser.setId("2"); |
|
|
|
currentUser.setPresonName("外部系统用户"); |
|
|
|
currentUser.setUsername("admin"); |
|
|
|
return currentUser; |
|
|
|
} |
|
|
|
return CurrentUser.getDefaultUser(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -49,7 +57,11 @@ public class SecurityUtils { |
|
|
|
* @return 系统用户名称 |
|
|
|
*/ |
|
|
|
public static String getCurrentNickName() { |
|
|
|
return getCurrentUser().getPresonName(); |
|
|
|
CurrentUser user = getCurrentUser(); |
|
|
|
if (user!=null){ |
|
|
|
return user.getPresonName(); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -62,11 +74,12 @@ public class SecurityUtils { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取系统用户Id |
|
|
|
* |
|
|
|
* @return 系统用户Id |
|
|
|
* 获取系统用户部门Id |
|
|
|
* @return 用户部门现在1:n,该方法禁用 |
|
|
|
*/ |
|
|
|
@Deprecated |
|
|
|
public static Long getDeptId() { |
|
|
|
// return getCurrentUser().getUser().getDept().getId();
|
|
|
|
return 1L; |
|
|
|
} |
|
|
|
|
|
|
@ -76,10 +89,10 @@ public class SecurityUtils { |
|
|
|
* @return 权限列表 |
|
|
|
*/ |
|
|
|
public static List<String> getCurrentUserPermissions() { |
|
|
|
JSONObject json = (JSONObject) StpUtil.getExtra("loginInfo"); |
|
|
|
JSONObject json =JSONObject.parseObject(String.valueOf(StpUtil.getExtra("loginInfo"))); |
|
|
|
JSONArray permissions = json.getJSONArray("permissions"); |
|
|
|
if (permissions.size() > 0) { |
|
|
|
return permissions.toList(String.class); |
|
|
|
return permissions.toJavaList(String.class); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|