账号切换实现
This commit is contained in:
@@ -17,6 +17,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.exception.CzgException;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -25,6 +26,7 @@ import java.util.function.Consumer;
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Slf4j
|
||||
@Getter
|
||||
public class MyStpLogic {
|
||||
public static final StpLogic CLIENT_LOGIC = new StpLogic("client");
|
||||
@@ -53,6 +55,29 @@ public class MyStpLogic {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份切换
|
||||
* @param id 用户id
|
||||
* @param account 账户名
|
||||
* @param shopId 店铺id
|
||||
* @param shopName 店铺名称
|
||||
* @param loginType 登录类型
|
||||
* @param isAdmin 是否管理员
|
||||
*/
|
||||
public void switchTo(Long id, String account, Long shopId, String shopName, LoginType loginType, boolean isAdmin) {
|
||||
StpLogic logic = getLogic();
|
||||
long headId = logic.getLoginIdAsLong();
|
||||
SaSession session = logic.getSession();
|
||||
Object parentId1 = session.get("headId");
|
||||
if (parentId1 == null) {
|
||||
session.set("headId", headId);
|
||||
}
|
||||
session.set("userId", id).set("isAdmin", isAdmin).set("isManager", loginType.equals(LoginType.MANAGER))
|
||||
.set("loginType", loginType).set("account", account).set("shopId", shopId).set("shopName", shopName);
|
||||
|
||||
logic.getSaTokenDao().set(splicingKeyTokenValue(logic.getTokenValue()), id.toString(), logic.getTokenTimeout());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id 登录账号id
|
||||
* @param shopName 店铺名称
|
||||
@@ -83,6 +108,8 @@ public class MyStpLogic {
|
||||
SaManager.getSaTokenDao().set(SaManager.getConfig().getTokenName() + ":" + token, String.valueOf(id), SaManager.getConfig().getTimeout());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前登录账号名称 管理端为用户账号 客户端为openId
|
||||
*
|
||||
@@ -104,6 +131,15 @@ public class MyStpLogic {
|
||||
return shopName instanceof String s ? s : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主店铺id
|
||||
* @return id
|
||||
*/
|
||||
public Long getHeadId() {
|
||||
Object headId = getLogic().getSession().get("headId");
|
||||
return headId == null ? null : Long.parseLong(headId.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺id
|
||||
*
|
||||
@@ -901,9 +937,7 @@ public class MyStpLogic {
|
||||
}
|
||||
|
||||
|
||||
public void switchTo(Object loginId) {
|
||||
getLogic().switchTo(loginId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void endSwitch() {
|
||||
|
||||
Reference in New Issue
Block a user