登录保存店铺名称
This commit is contained in:
parent
2c531d8bc7
commit
1adafc0ad3
|
|
@ -73,7 +73,7 @@ public class UserAuthorizationController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/test")
|
@PostMapping("/test")
|
||||||
public CzgResult<String> login(@RequestParam long id) {
|
public CzgResult<String> login(@RequestParam long id) {
|
||||||
StpKit.USER.login(id, "2342", null, MyStpLogic.LoginType.USER, false);
|
StpKit.USER.login(id, "2342", null, "", MyStpLogic.LoginType.USER, false);
|
||||||
return CzgResult.success(StpKit.USER.getTokenValue());
|
return CzgResult.success(StpKit.USER.getTokenValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,18 +53,19 @@ public class MyStpLogic {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id 登录账号id
|
* @param id 登录账号id
|
||||||
|
* @param shopName 店铺名称
|
||||||
* @param shopId 店铺id
|
* @param shopId 店铺id
|
||||||
* @param loginType 登录类型枚举
|
* @param loginType 登录类型枚举
|
||||||
* @param isAdmin 是否为管理员账号
|
* @param isAdmin 是否为管理员账号
|
||||||
*/
|
*/
|
||||||
public void login(Long id, String account, Long shopId, LoginType loginType, boolean isAdmin) {
|
public void login(Long id, String account, Long shopId, String shopName, LoginType loginType, boolean isAdmin) {
|
||||||
StpLogic logic = getLogic();
|
StpLogic logic = getLogic();
|
||||||
logic.login(id);
|
logic.login(id);
|
||||||
if (loginType.equals(LoginType.MANAGER) && shopId == null) {
|
if (loginType.equals(LoginType.MANAGER) && shopId == null) {
|
||||||
throw new ApiNotPrintException("管理端登录必须传递店铺id");
|
throw new ApiNotPrintException("管理端登录必须传递店铺id");
|
||||||
}
|
}
|
||||||
SaSession session = logic.getSession().set("userId", id).set("isAdmin", isAdmin).set("isManager", loginType.equals(LoginType.MANAGER))
|
SaSession session = logic.getSession().set("userId", id).set("isAdmin", isAdmin).set("isManager", loginType.equals(LoginType.MANAGER))
|
||||||
.set("loginType", loginType).set("account", account);
|
.set("loginType", loginType).set("account", account).set("shopName", shopName);
|
||||||
if (shopId != null) {
|
if (shopId != null) {
|
||||||
session.set("shopId", shopId);
|
session.set("shopId", shopId);
|
||||||
}
|
}
|
||||||
|
|
@ -87,6 +88,16 @@ public class MyStpLogic {
|
||||||
return (String) logic.getSession().get("account");
|
return (String) logic.getSession().get("account");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前店铺用户名,仅后台可用
|
||||||
|
* @return 店铺名称
|
||||||
|
*/
|
||||||
|
public String getShopName() {
|
||||||
|
StpLogic logic = getLogic();
|
||||||
|
Object shopName = logic.getSession().get("shopName");
|
||||||
|
return shopName instanceof String s ? s : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取店铺id
|
* 获取店铺id
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StpKit.USER.login(user.getId(), user.getAccount(), shopInfo.getId(), isStaff ? MyStpLogic.LoginType.STAFF : MyStpLogic.LoginType.MANAGER, user.getIsAdmin());
|
StpKit.USER.login(user.getId(), user.getAccount(), shopInfo.getId(), shopInfo.getShopName(), isStaff ? MyStpLogic.LoginType.STAFF : MyStpLogic.LoginType.MANAGER, user.getIsAdmin());
|
||||||
// 查询角色
|
// 查询角色
|
||||||
List<SysRole> roleList = sysRoleService.getByUserId(user.getId());
|
List<SysRole> roleList = sysRoleService.getByUserId(user.getId());
|
||||||
List<String> roleNames = roleList.stream().map(SysRole::getName).collect(Collectors.toList());
|
List<String> roleNames = roleList.stream().map(SysRole::getName).collect(Collectors.toList());
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
||||||
userInfo.setLastLoginTime(DateUtil.date().toLocalDateTime());
|
userInfo.setLastLoginTime(DateUtil.date().toLocalDateTime());
|
||||||
userInfoService.saveOrUpdate(userInfo);
|
userInfoService.saveOrUpdate(userInfo);
|
||||||
// StpKit.USER.login(userInfo.getId());
|
// StpKit.USER.login(userInfo.getId());
|
||||||
StpKit.USER.login(userInfo.getId(), openId, null, MyStpLogic.LoginType.USER, false);
|
StpKit.USER.login(userInfo.getId(), openId, null, null, MyStpLogic.LoginType.USER, false);
|
||||||
return new LoginTokenDTO(StpKit.USER.getTokenValue(), userInfo);
|
return new LoginTokenDTO(StpKit.USER.getTokenValue(), userInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue