账号切换实现
This commit is contained in:
@@ -12,6 +12,7 @@ import com.czg.account.vo.LoginVO;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.enums.PlatformTypeEnum;
|
||||
import com.czg.enums.StatusEnum;
|
||||
import com.czg.enums.YesNoEnum;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.sa.MyStpLogic;
|
||||
import com.czg.sa.StpKit;
|
||||
@@ -173,6 +174,43 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
return new LoginVO(StpKit.USER.getTokenInfo(), new ArrayList<>(), loginDTO.loginType(), shopInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchTo(Long sysUserId) {
|
||||
Long headId = StpKit.USER.getHeadId();
|
||||
long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
ShopInfo currentInfo = shopInfoService.getById(shopId);
|
||||
if (currentInfo.getIsHeadShop() != YesNoEnum.YES.value() && headId == null) {
|
||||
throw new ApiNotPrintException("登录账号无权限切换");
|
||||
}
|
||||
|
||||
SysUser sysUser = sysUserService.getById(sysUserId);
|
||||
if (sysUser == null) {
|
||||
throw new ApiNotPrintException("用户不存在");
|
||||
}
|
||||
|
||||
ShopInfo shopInfo = shopInfoService.getById(sysUser.getId());
|
||||
if (shopInfo == null) {
|
||||
throw new ApiNotPrintException("店铺信息不存在");
|
||||
}
|
||||
|
||||
if (!shopInfo.getMainId().equals(headId)) {
|
||||
throw new ApiNotPrintException("目标店铺非登录账号所有");
|
||||
}
|
||||
|
||||
// 查询角色
|
||||
List<SysRole> roleList = sysRoleService.getByUserId(sysUser.getId());
|
||||
List<String> roleNames = roleList.stream().map(SysRole::getName).collect(Collectors.toList());
|
||||
if (sysUser.getIsAdmin()) {
|
||||
roleNames.add("admin");
|
||||
}
|
||||
StpKit.USER.addRoleList(roleNames);
|
||||
// 权限赋予
|
||||
List<String> promissionList = sysMenuMapper.selectByUserId(sysUser.getId(), null).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList();
|
||||
StpKit.USER.switchTo(sysUser.getId(), sysUser.getAccount(), shopInfo.getId(), shopInfo.getShopName(), MyStpLogic.LoginType.MANAGER, sysUser.getIsAdmin());
|
||||
StpKit.USER.addPermissionList(promissionList);
|
||||
StpKit.USER.addRoleList(roleNames);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static HandoverRecord getHandoverRecord(boolean isStaff, ShopInfo shopInfo, ShopStaff shopStaff) {
|
||||
HandoverRecord entity = new HandoverRecord();
|
||||
|
||||
Reference in New Issue
Block a user