update 适配单体系与多体系用户权限

master
疯狂的狮子li 4 years ago
parent f05138df62
commit 0a9d4ea17b

@ -0,0 +1,27 @@
package com.ruoyi.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
*
*
*
* @author Lion Li
*/
@Getter
@AllArgsConstructor
public enum DeviceType {
/**
* pc
*/
PC("pc"),
/**
* app
*/
APP("app");
private final String device;
}

@ -0,0 +1,27 @@
package com.ruoyi.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
*
*
*
* @author Lion Li
*/
@Getter
@AllArgsConstructor
public enum UserType {
/**
* pc
*/
SYS_USER("sys_user:"),
/**
* app
*/
APP_USER("app_user:");
private final String userType;
}

@ -0,0 +1,69 @@
package com.ruoyi.common.utils;
import cn.dev33.satoken.stp.StpUtil;
import com.ruoyi.common.enums.DeviceType;
import com.ruoyi.common.enums.UserType;
import com.ruoyi.common.exception.UtilException;
/**
*
*
*
* @author Lion Li
*/
public class LoginUtils {
/**
*
*
* @param userId id
*/
public static void login(Long userId, UserType userType) {
StpUtil.login(userType.getUserType() + userId);
}
/**
*
*
* @param userId id
*/
public static void loginByDevice(Long userId, UserType userType, DeviceType deviceType) {
StpUtil.login(userType.getUserType() + userId, deviceType.getDevice());
}
/**
* id
*/
public static Long getUserId() {
String loginId = StpUtil.getLoginIdAsString();
String userId;
String replace = "";
if (StringUtils.contains(loginId, UserType.SYS_USER.getUserType())) {
userId = StringUtils.replace(loginId, UserType.SYS_USER.getUserType(), replace);
} else if (StringUtils.contains(loginId, UserType.APP_USER.getUserType())){
userId = StringUtils.replace(loginId, UserType.APP_USER.getUserType(), replace);
} else {
throw new UtilException("登录用户: LoginId异常 => " + loginId);
}
return Long.parseLong(userId);
}
/**
*
*/
public static UserType getUserType() {
String loginId = StpUtil.getLoginIdAsString();
return getUserType(loginId);
}
public static UserType getUserType(Object loginId) {
if (StringUtils.contains(loginId.toString(), UserType.SYS_USER.getUserType())) {
return UserType.SYS_USER;
} else if (StringUtils.contains(loginId.toString(), UserType.APP_USER.getUserType())){
return UserType.APP_USER;
} else {
throw new UtilException("登录用户: LoginId异常 => " + loginId);
}
}
}
Loading…
Cancel
Save