【7.2.2】更新获取用户信息和菜单信息

pull/29/head
fengshuonan 2022-04-08 18:08:58 +08:00
parent f1e38e0481
commit 54536a5b36
9 changed files with 656 additions and 0 deletions

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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.
*
* GunsAPACHE 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;
}

View File

@ -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.
*
* GunsAPACHE 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;
}
/**
* SysMenuIndexMenuInfo
*
* @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;
}
}

View File

@ -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);
}
/**
*
*

View File

@ -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());
}
}

View File

@ -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.
*
* GunsAPACHE 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();
}

View File

@ -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.
*
* GunsAPACHE 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;
}
}