mirror of https://gitee.com/stylefeng/roses
【7.2.2】更新获取用户信息和菜单信息
parent
f1e38e0481
commit
54536a5b36
|
@ -24,6 +24,8 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.system.api;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.login.v3.IndexMenuInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -79,4 +81,12 @@ public interface MenuServiceApi {
|
|||
*/
|
||||
List<String> getResourceCodesByBusinessId(List<Long> businessIds);
|
||||
|
||||
/**
|
||||
* 构建Antdv3版本的菜单和权限信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/4/8 15:59
|
||||
*/
|
||||
List<IndexMenuInfo> buildAuthorities();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package cn.stylefeng.roses.kernel.system.api.pojo.login.v3;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/4/8 15:06
|
||||
*/
|
||||
@Data
|
||||
public class IndexMenuInfo {
|
||||
|
||||
/**
|
||||
* 菜单id
|
||||
*/
|
||||
@ChineseDescription("菜单id")
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 菜单父级id
|
||||
*/
|
||||
@ChineseDescription("菜单父级id")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 菜单的名称
|
||||
*/
|
||||
@ChineseDescription("菜单的名称")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 路由地址(要以/开头),必填
|
||||
*/
|
||||
@ChineseDescription("路由地址(要以/开头),必填")
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 组件地址(组件要放在view目录下),父级可以省略
|
||||
*/
|
||||
@ChineseDescription("组件地址(组件要放在view目录下),父级可以省略")
|
||||
private String component;
|
||||
|
||||
/**
|
||||
* 菜单类型, 0菜单, 1按钮
|
||||
*/
|
||||
@ChineseDescription("菜单类型, 0菜单, 1按钮")
|
||||
private Integer menuType;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@ChineseDescription("排序")
|
||||
private BigDecimal sortNumber;
|
||||
|
||||
/**
|
||||
* 权限标识
|
||||
*/
|
||||
@ChineseDescription("权限标识")
|
||||
private String authority;
|
||||
|
||||
/**
|
||||
* 菜单的图标
|
||||
*/
|
||||
@ChineseDescription("菜单的图标")
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 是否隐藏, 0否,1是(仅注册路由不显示左侧菜单)
|
||||
*/
|
||||
@ChineseDescription("是否隐藏, 0否,1是(仅注册路由不显示左侧菜单)")
|
||||
private Boolean hide;
|
||||
|
||||
/**
|
||||
* 路由元信息
|
||||
*/
|
||||
@ChineseDescription("路由元信息")
|
||||
private String meta;
|
||||
|
||||
/**
|
||||
* 子级
|
||||
*/
|
||||
@ChineseDescription("子级")
|
||||
private List<IndexMenuInfo> children;
|
||||
|
||||
/**
|
||||
* 配置选中的path地址,比如修改页面不在侧栏,打开后侧栏就没有选中,这个配置选中地址,非必须
|
||||
*/
|
||||
@ChineseDescription("配置选中的path地址")
|
||||
private String active;
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package cn.stylefeng.roses.kernel.system.api.pojo.login.v3;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 角色信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/4/8 15:06
|
||||
*/
|
||||
@Data
|
||||
public class IndexRoleInfo {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ChineseDescription("主键")
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
@ChineseDescription("角色名称")
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 角色编码
|
||||
*/
|
||||
@ChineseDescription("角色编码")
|
||||
private String roleCode;
|
||||
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.system.api.pojo.login.v3;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 最新Antd3版本的首页登录用户信息需要的数据
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/4/8 14:56
|
||||
*/
|
||||
@Data
|
||||
public class IndexUserInfoV3 {
|
||||
|
||||
/**
|
||||
* 用户主键id
|
||||
*/
|
||||
@ChineseDescription("用户主键id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
@ChineseDescription("账号")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@ChineseDescription("昵称")
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 用户头像(url)
|
||||
*/
|
||||
@ChineseDescription("用户头像(url)")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 性别(字典)
|
||||
*/
|
||||
@ChineseDescription("性别(字典)")
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
@ChineseDescription("电话")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@ChineseDescription("邮箱")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 出生日期
|
||||
*/
|
||||
@ChineseDescription("出生日期")
|
||||
private Date birthday;
|
||||
|
||||
/**
|
||||
* 组织机构id
|
||||
*/
|
||||
@ChineseDescription("组织机构id")
|
||||
private Long organizationId;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*/
|
||||
@ChineseDescription("状态")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 性别名称
|
||||
*/
|
||||
@ChineseDescription("性别名称")
|
||||
private String sexName;
|
||||
|
||||
/**
|
||||
* 组织机构名称
|
||||
*/
|
||||
@ChineseDescription("组织机构名称")
|
||||
private String organizationName;
|
||||
|
||||
/**
|
||||
* 角色信息
|
||||
*/
|
||||
@ChineseDescription("角色信息")
|
||||
private List<IndexRoleInfo> roles;
|
||||
|
||||
/**
|
||||
* 权限信息
|
||||
*/
|
||||
@ChineseDescription("权限信息")
|
||||
private List<IndexMenuInfo> authorities;
|
||||
|
||||
/**
|
||||
* 登录人的ws-url,用来获取右上角的消息
|
||||
*/
|
||||
@ChineseDescription("登录人的ws-url")
|
||||
private String wsUrl;
|
||||
|
||||
/**
|
||||
* 权限标识编码
|
||||
*/
|
||||
@ChineseDescription("权限标识编码")
|
||||
private Set<String> authCodes;
|
||||
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.system.modular.menu.factory;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.TreeConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.tree.factory.DefaultTreeBuildFactory;
|
||||
import cn.stylefeng.roses.kernel.system.api.AppServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.app.SysAppResult;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.login.v3.IndexMenuInfo;
|
||||
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 针对于antd vue版本的前端菜单的组装
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/30 20:11
|
||||
*/
|
||||
public class Antdv3MenusFactory {
|
||||
|
||||
/**
|
||||
* 组装antdv用的获取所有菜单列表详情
|
||||
*
|
||||
* @param appSortedMenus 按应用排序过的菜单集合
|
||||
* @param appNames 排序过的应用名称
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/7 18:17
|
||||
*/
|
||||
public static List<IndexMenuInfo> createTotalMenus(Map<String, List<SysMenu>> appSortedMenus, List<String> appNames) {
|
||||
|
||||
// 创建应用级别的菜单集合
|
||||
List<IndexMenuInfo> appSortedAntdMenus = new ArrayList<>();
|
||||
|
||||
// 当前系统没有应用,则直接返回
|
||||
if (ObjectUtil.isEmpty(appNames)) {
|
||||
return appSortedAntdMenus;
|
||||
}
|
||||
|
||||
// 创建其他应用的菜单
|
||||
for (Map.Entry<String, List<SysMenu>> entry : appSortedMenus.entrySet()) {
|
||||
// 创建顶层应用菜单
|
||||
IndexMenuInfo rootAppMenu = createRootAppMenu(entry.getKey());
|
||||
List<SysMenu> treeStructMenu = new DefaultTreeBuildFactory<SysMenu>(TreeConstants.DEFAULT_PARENT_ID.toString()).doTreeBuild(entry.getValue());
|
||||
List<IndexMenuInfo> antdSysMenuDTOS = doModelReBuild(treeStructMenu);
|
||||
|
||||
// 如果顶层应用下有菜单,则设为显示
|
||||
if (ObjectUtil.isNotEmpty(antdSysMenuDTOS)) {
|
||||
rootAppMenu.setHide(false);
|
||||
rootAppMenu.setChildren(antdSysMenuDTOS);
|
||||
}
|
||||
appSortedAntdMenus.add(rootAppMenu);
|
||||
}
|
||||
|
||||
// 根据应用的顺序,将应用排序
|
||||
appSortedAntdMenus.sort((antdSysMenuDTO, antdSysMenuDTO2) -> {
|
||||
int one = appNames.indexOf(antdSysMenuDTO.getTitle());
|
||||
int two = appNames.indexOf(antdSysMenuDTO2.getTitle());
|
||||
return Integer.compare(one, two);
|
||||
});
|
||||
|
||||
return appSortedAntdMenus;
|
||||
}
|
||||
|
||||
/**
|
||||
* SysMenu转化为需要的IndexMenuInfo
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/4/8 16:14
|
||||
*/
|
||||
private static List<IndexMenuInfo> doModelReBuild(List<SysMenu> sysMenuList) {
|
||||
if (ObjectUtil.isEmpty(sysMenuList)) {
|
||||
return null;
|
||||
} else {
|
||||
ArrayList<IndexMenuInfo> resultMenus = new ArrayList<>();
|
||||
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
IndexMenuInfo antdvMenuItem = new IndexMenuInfo();
|
||||
antdvMenuItem.setMenuId(sysMenu.getMenuId());
|
||||
antdvMenuItem.setParentId(sysMenu.getMenuParentId());
|
||||
antdvMenuItem.setTitle(sysMenu.getMenuName());
|
||||
antdvMenuItem.setPath(sysMenu.getAntdvRouter());
|
||||
antdvMenuItem.setIcon(sysMenu.getAntdvIcon());
|
||||
antdvMenuItem.setComponent(sysMenu.getAntdvComponent());
|
||||
antdvMenuItem.setHide(YesOrNotEnum.N.getCode().equals(sysMenu.getAntdvVisible()));
|
||||
antdvMenuItem.setActive(sysMenu.getAntdvActiveUrl());
|
||||
antdvMenuItem.setSortNumber(sysMenu.getMenuSort());
|
||||
if (ObjectUtil.isNotEmpty(sysMenu.getChildren())) {
|
||||
antdvMenuItem.setChildren(doModelReBuild(sysMenu.getChildren()));
|
||||
}
|
||||
resultMenus.add(antdvMenuItem);
|
||||
}
|
||||
|
||||
return resultMenus;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建顶层应用层级的菜单
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/4/8 16:14
|
||||
*/
|
||||
private static IndexMenuInfo createRootAppMenu(String appCode) {
|
||||
|
||||
IndexMenuInfo indexMenuInfo = new IndexMenuInfo();
|
||||
|
||||
// 获取应用的详细信息
|
||||
AppServiceApi appServiceApi = SpringUtil.getBean(AppServiceApi.class);
|
||||
SysAppResult appInfoByAppCode = appServiceApi.getAppInfoByAppCode(appCode);
|
||||
|
||||
// 菜单名称
|
||||
indexMenuInfo.setTitle(appInfoByAppCode.getAppName());
|
||||
|
||||
// 菜单图标
|
||||
indexMenuInfo.setIcon(appInfoByAppCode.getAppIcon());
|
||||
|
||||
// 菜单路径
|
||||
indexMenuInfo.setPath("/" + appCode);
|
||||
indexMenuInfo.setComponent(null);
|
||||
|
||||
// 默认隐藏,如果应用下有children则开启显示,防止应用下没菜单还显示应用
|
||||
indexMenuInfo.setHide(true);
|
||||
indexMenuInfo.setActive(null);
|
||||
indexMenuInfo.setAuthority(null);
|
||||
|
||||
return indexMenuInfo;
|
||||
}
|
||||
|
||||
}
|
|
@ -44,6 +44,7 @@ import cn.stylefeng.roses.kernel.system.api.MenuServiceApi;
|
|||
import cn.stylefeng.roses.kernel.system.api.RoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.enums.menu.SysMenuExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.login.v3.IndexMenuInfo;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.menu.MenuAndButtonTreeResponse;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.menu.SysMenuRequest;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.menu.antd.AntdMenuSelectTreeNode;
|
||||
|
@ -57,6 +58,7 @@ import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenu;
|
|||
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenuButton;
|
||||
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenuResource;
|
||||
import cn.stylefeng.roses.kernel.system.modular.menu.factory.AntdMenusFactory;
|
||||
import cn.stylefeng.roses.kernel.system.modular.menu.factory.Antdv3MenusFactory;
|
||||
import cn.stylefeng.roses.kernel.system.modular.menu.factory.LayuiMenusFactory;
|
||||
import cn.stylefeng.roses.kernel.system.modular.menu.factory.MenuTypeFactory;
|
||||
import cn.stylefeng.roses.kernel.system.modular.menu.mapper.SysMenuMapper;
|
||||
|
@ -561,6 +563,21 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
return list.stream().map(SysMenuResource::getResourceCode).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IndexMenuInfo> buildAuthorities() {
|
||||
|
||||
// 不分离应用查询菜单
|
||||
List<SysMenu> currentUserMenus = this.getCurrentUserMenus(null, false);
|
||||
|
||||
// 获取当前激活的应用
|
||||
List<String> appNameSorted = appServiceApi.getAppNameSorted();
|
||||
|
||||
// 将菜单按应用编码分类,激活的应用放在最前边
|
||||
Map<String, List<SysMenu>> sortedUserMenus = AntdMenusFactory.sortUserMenusByAppCode(currentUserMenus);
|
||||
|
||||
return Antdv3MenusFactory.createTotalMenus(sortedUserMenus, appNameSorted);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统菜单
|
||||
*
|
||||
|
|
|
@ -38,7 +38,9 @@ import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
|||
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.login.CurrentUserInfoResponse;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.login.ValidateTokenRequest;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.login.v3.IndexUserInfoV3;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.factory.UserLoginInfoFactory;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.service.IndexUserInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
@ -65,6 +67,9 @@ public class LoginController {
|
|||
@Resource
|
||||
private SessionManagerApi sessionManagerApi;
|
||||
|
||||
@Resource
|
||||
private IndexUserInfoService indexUserInfoService;
|
||||
|
||||
/**
|
||||
* 用户登陆
|
||||
*
|
||||
|
@ -154,4 +159,16 @@ public class LoginController {
|
|||
authServiceApi.cancelFreeze(loginRequest);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新版Antdv3版本的用户信息获取
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/4/8 15:31
|
||||
*/
|
||||
@GetResource(name = "新版Antdv3版本的用户信息获取", path = "/v3/userInfo", requiredPermission = false)
|
||||
public ResponseData<IndexUserInfoV3> userInfoV3() {
|
||||
return new SuccessResponseData<>(indexUserInfoService.userInfoV3());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.system.modular.user.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.login.v3.IndexUserInfoV3;
|
||||
|
||||
/**
|
||||
* 获取首页用户登录信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/4/8 15:40
|
||||
*/
|
||||
public interface IndexUserInfoService {
|
||||
|
||||
/**
|
||||
* 获取用户头像的url
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/27 19:13
|
||||
*/
|
||||
IndexUserInfoV3 userInfoV3();
|
||||
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.system.modular.user.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.SexEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.MenuServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.login.v3.IndexRoleInfo;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.login.v3.IndexUserInfoV3;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.service.IndexUserInfoService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 获取首页用户登录信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/4/8 15:40
|
||||
*/
|
||||
@Service
|
||||
public class IndexUserInfoServiceImpl implements IndexUserInfoService {
|
||||
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Resource
|
||||
private MenuServiceApi menuServiceApi;
|
||||
|
||||
@Override
|
||||
public IndexUserInfoV3 userInfoV3() {
|
||||
|
||||
// 获取当前登录用户
|
||||
LoginUser loginUser = LoginContext.me().getLoginUser();
|
||||
|
||||
IndexUserInfoV3 indexUserInfoV3 = new IndexUserInfoV3();
|
||||
|
||||
// 设置用户id
|
||||
indexUserInfoV3.setUserId(loginUser.getUserId());
|
||||
|
||||
// 设置用户账号
|
||||
indexUserInfoV3.setUsername(loginUser.getAccount());
|
||||
|
||||
// 设置昵称
|
||||
indexUserInfoV3.setNickname(loginUser.getSimpleUserInfo().getNickName());
|
||||
|
||||
// 设置头像,并获取头像的url
|
||||
Long avatarFileId = loginUser.getSimpleUserInfo().getAvatar();
|
||||
String userAvatarUrl = sysUserService.getUserAvatarUrl(avatarFileId, loginUser.getToken());
|
||||
indexUserInfoV3.setAvatar(userAvatarUrl);
|
||||
|
||||
// 设置性别
|
||||
indexUserInfoV3.setSex(loginUser.getSimpleUserInfo().getSex());
|
||||
|
||||
// 设置电话
|
||||
indexUserInfoV3.setPhone(loginUser.getSimpleUserInfo().getPhone());
|
||||
|
||||
// 设置邮箱
|
||||
indexUserInfoV3.setEmail(loginUser.getSimpleUserInfo().getEmail());
|
||||
|
||||
// 设置出生日期
|
||||
indexUserInfoV3.setBirthday(loginUser.getSimpleUserInfo().getBirthday());
|
||||
|
||||
// 设置组织机构id
|
||||
indexUserInfoV3.setOrganizationId(loginUser.getOrganizationId());
|
||||
|
||||
// 设置状态(暂时不设置)
|
||||
indexUserInfoV3.setStatus(null);
|
||||
|
||||
// 设置性别名称
|
||||
indexUserInfoV3.setSexName(SexEnum.codeToMessage(indexUserInfoV3.getSex()));
|
||||
|
||||
// 设置组织机构名称,暂时不设置,用到再设置
|
||||
indexUserInfoV3.setOrganizationName(null);
|
||||
|
||||
// 设置角色
|
||||
indexUserInfoV3.setRoles(buildRoles(loginUser));
|
||||
|
||||
// 获取用户菜单和权限信息
|
||||
indexUserInfoV3.setAuthorities(menuServiceApi.buildAuthorities());
|
||||
|
||||
// 登录人的ws-url
|
||||
indexUserInfoV3.setWsUrl(loginUser.getWsUrl());
|
||||
|
||||
// 权限编码
|
||||
indexUserInfoV3.setAuthCodes(loginUser.getButtonCodes());
|
||||
|
||||
return indexUserInfoV3;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的角色信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/4/8 15:53
|
||||
*/
|
||||
private List<IndexRoleInfo> buildRoles(LoginUser loginUser) {
|
||||
|
||||
List<SimpleRoleInfo> simpleRoleInfoList = loginUser.getSimpleRoleInfoList();
|
||||
|
||||
ArrayList<IndexRoleInfo> indexRoleInfos = new ArrayList<>();
|
||||
if (simpleRoleInfoList.size() > 0) {
|
||||
for (SimpleRoleInfo simpleRoleInfo : simpleRoleInfoList) {
|
||||
IndexRoleInfo indexRoleInfo = new IndexRoleInfo();
|
||||
BeanUtil.copyProperties(simpleRoleInfo, indexRoleInfo);
|
||||
indexRoleInfos.add(indexRoleInfo);
|
||||
}
|
||||
}
|
||||
|
||||
return indexRoleInfos;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue