update 优化 简化一些方法的写法

This commit is contained in:
疯狂的狮子li
2022-11-24 14:26:38 +08:00
parent a3d3826118
commit 96f7482da5
3 changed files with 10 additions and 20 deletions

View File

@@ -2,6 +2,7 @@ package com.ruoyi.common.satoken.utils;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.enums.DeviceType;
@@ -80,18 +81,12 @@ public class LoginHelper {
LoginUser loginUser = getLoginUser();
if (ObjectUtil.isNull(loginUser)) {
String loginId = StpUtil.getLoginIdAsString();
String userId = null;
for (UserType value : UserType.values()) {
if (StringUtils.contains(loginId, value.getUserType())) {
String[] strs = StringUtils.split(loginId, JOIN_CODE);
// 用户id在总是在最后
userId = strs[strs.length - 1];
}
}
if (StringUtils.isBlank(userId)) {
String[] strs = StringUtils.split(loginId, JOIN_CODE);
if (!ArrayUtil.containsAny(strs, UserType.values())) {
throw new UtilException("登录用户: LoginId异常 => " + loginId);
}
return Long.parseLong(userId);
// 用户id在总是在最后
return Long.parseLong(strs[strs.length - 1]);
}
return loginUser.getUserId();
}