package com.qingzhou.system.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.solon.service.impl.ServiceImpl;
import com.qingzhou.common.core.constants.HttpConstant;
import com.qingzhou.common.core.constants.UserConstant;
import com.qingzhou.common.core.enums.DictEnum;
import com.qingzhou.common.core.web.api.ApiCodes;
import com.qingzhou.common.security.utils.SecurityUtil;
import com.qingzhou.system.api.domain.SysRole;
import com.qingzhou.system.api.domain.SysUser;
import com.qingzhou.system.domain.SysMenu;
import com.qingzhou.system.domain.vo.MetaVo;
import com.qingzhou.system.domain.vo.RouterVo;
import com.qingzhou.system.domain.vo.TreeSelect;
import com.qingzhou.system.mapper.SysMenuMapper;
import com.qingzhou.system.mapper.SysRoleMenuMapper;
import com.qingzhou.system.service.ISysMenuService;
import com.qingzhou.system.service.ISysRoleService;
import org.apache.ibatis.solon.annotation.Db;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import java.util.*;
import java.util.stream.Collectors;
/**
* 系统菜单 服务层实现
* @author xm
*/
@Component
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {
@Db
SysMenuMapper sysMenuMapper;
@Db
SysRoleMenuMapper sysRoleMenuMapper;
@Inject
ISysRoleService sysRoleService;
/**
* 根据用户查询系统菜单列表
* @param menu 菜单信息
* @param userId 用户ID
* @return
*/
@Override
public List<SysMenu> selectMenuList(SysMenu menu, Long userId) {
List<SysMenu> menuList = null;
// 管理员显示所有菜单信息
if (SecurityUtil.isAdmin(userId)) {
menuList = sysMenuMapper.selectMenuList(menu, DictEnum.DEL_FLAG.OK.getValue());
} else {
menuList = sysMenuMapper.selectMenuListByUserId(menu, userId, DictEnum.DEL_FLAG.OK.getValue());
}
return menuList;
}
/**
* 构建前端所需要下拉树结构
* @param menus 菜单列表
* @return
*/
@Override
public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) {
List<SysMenu> menuTrees = buildMenuTree(menus);
return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
}
/**
* 根据用户查询系统菜单列表
* @param userId 用户ID
* @return
*/
@Override
public List<SysMenu> selectMenuList(Long userId) {
return selectMenuList(new SysMenu(), userId);
}
/**
* 根据用户 ID查询菜单树信息
* @param userId
* @return
*/
@Override
public List<SysMenu> selectMenuTreeByUserId(Long userId) {
List<SysMenu> menus = null;
String[] menuTypes = new String[]{ UserConstant.MENU_TYPE_DIR, UserConstant.MENU_TYPE_MENU };
// 超级管理员查询所有菜单
if (SecurityUtil.isAdmin(userId)) {
menus = sysMenuMapper.selectMenuTreeAll(menuTypes, DictEnum.COMMON_STATUS.OK.getValue(), DictEnum.DEL_FLAG.OK.getValue());
} else {
menus = sysMenuMapper.selectMenuTreeByUserId(menuTypes, userId, DictEnum.COMMON_STATUS.OK.getValue(), DictEnum.DEL_FLAG.OK.getValue());
}
return getChildPerms(menus, 0);
}
/**
* 根据角色ID查询菜单树信息
* @param roleId 角色ID
* @return
*/
@Override
public List<Long> selectMenuListByRoleId(Long roleId) {
SysRole role = sysRoleService.selectRoleById(roleId);
return sysMenuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly(), DictEnum.DEL_FLAG.OK.getValue());
}
/**
* 构建前端路由所需要的菜单
* @param menus
* @return
*/
@Override
public List<RouterVo> buildMenus(List<SysMenu> menus) {
List<RouterVo> routers = new LinkedList<>();
for (SysMenu menu : menus) {
RouterVo router = new RouterVo();
router.setHidden("1".equals(menu.getVisible()));
router.setName(getRouteName(menu));
router.setPath(getRouterPath(menu));
router.setComponent(getComponent(menu));
router.setQuery(menu.getQuery());
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StrUtil.equals(DictEnum.COMMON_YES_NO.NO.getValue(), menu.getIsCache()), menu.getPath()));
List<SysMenu> cMenus = menu.getChildren();
if (!cMenus.isEmpty() && UserConstant.MENU_TYPE_DIR.equals(menu.getMenuType())) {
router.setAlwaysShow(true);
router.setRedirect("noRedirect");
router.setChildren(buildMenus(cMenus));
} else if (isMenuFrame(menu)) {
router.setMeta(null);
List<RouterVo> childrenList = new ArrayList<RouterVo>();
RouterVo children = new RouterVo();
children.setPath(menu.getPath());
children.setComponent(menu.getComponent());
children.setName(StrUtil.upperFirst(menu.getPath()));
children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StrUtil.equals(DictEnum.COMMON_YES_NO.NO.getValue(), menu.getIsCache()), menu.getPath()));
children.setQuery(menu.getQuery());
childrenList.add(children);
router.setChildren(childrenList);
} else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) {
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
router.setPath("/");
List<RouterVo> childrenList = new ArrayList<RouterVo>();
RouterVo children = new RouterVo();
String routerPath = innerLinkReplaceEach(menu.getPath());
children.setPath(routerPath);
children.setComponent(UserConstant.INNER_LINK);
children.setName(StrUtil.upperFirst(routerPath));
children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath()));
childrenList.add(children);
router.setChildren(childrenList);
}
routers.add(router);
}
return routers;
}
/**
* 获取菜单数据权限
* @param sysUser
* @return
*/
@Override
public Set<String> getMenuPermission(SysUser sysUser) {
Set<String> perms = new HashSet<>();
// 管理员拥有所有权限
if (SecurityUtil.isAdmin(sysUser.getUserId())) {
perms.add("*:*:*");
} else {
List<SysRole> roles = sysUser.getRoles();
if (!CollUtil.isEmpty(roles)) {
// 多角色设置permissions属性,以便数据权限匹配权限
for (SysRole role : roles) {
List<String> list = sysMenuMapper.selectMenuPermsByRoleId(role.getRoleId(), DictEnum.COMMON_STATUS.OK.getValue(), DictEnum.DEL_FLAG.OK.getValue());
Set<String> rolePerms = new HashSet<>();
for (String perm : list) {
if (StrUtil.isNotEmpty(perm)) {
rolePerms.addAll(Arrays.asList(perm.trim().split(",")));
}
}
role.setPermissions(rolePerms);
perms.addAll(rolePerms);
}
} else {
List<String> list = sysMenuMapper.selectMenuPermsByUserId(sysUser.getUserId(), DictEnum.COMMON_STATUS.OK.getValue(), DictEnum.DEL_FLAG.OK.getValue());
Set<String> permsSet = new HashSet<>();
for (String perm : list) {
if (StrUtil.isNotEmpty(perm)) {
permsSet.addAll(Arrays.asList(perm.trim().split(",")));
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
qingzhou-cloud-DS18B20资源 (757个子文件)
nginx.conf 3KB
k8s-nginx.conf 3KB
.env.development 233B
.env.development 223B
.editorconfig 514B
.editorconfig 488B
.eslintignore 298B
.eslintignore 298B
401.gif 160KB
401.gif 160KB
.gitignore 256B
.gitignore 238B
.gitignore 238B
ie.html 23KB
ie.html 23KB
index.html 5KB
index.html 5KB
favicon.ico 9KB
favicon.ico 9KB
SysMenuServiceImpl.java 16KB
SysUserServiceImpl.java 15KB
GenTableServiceImpl.java 15KB
VelocityUtil.java 13KB
SysRoleServiceImpl.java 10KB
SysDeptServiceImpl.java 10KB
LoginService.java 8KB
GenUtil.java 8KB
RedisService.java 8KB
SysUserController.java 7KB
FileService.java 6KB
SysDictDataServiceImpl.java 5KB
SysConfigServiceImpl.java 5KB
XssUtil.java 5KB
SysRoleController.java 4KB
CaptchaService.java 4KB
DataScopeAspect.java 4KB
GenTable.java 4KB
GenTableColumn.java 4KB
SysDictTypeServiceImpl.java 4KB
SecurityUtil.java 4KB
SysPostServiceImpl.java 4KB
GenConstant.java 4KB
GenTableController.java 4KB
GlobalRouterInterceptor.java 3KB
SysDictDataController.java 3KB
SysConfigController.java 3KB
SysMenuController.java 3KB
SysDictTypeController.java 3KB
SysDeptController.java 3KB
SecurityConfig.java 3KB
SysPostController.java 3KB
SysLoginLogController.java 3KB
SysUser.java 3KB
DemoTestController.java 3KB
SysRole.java 3KB
ISysUserService.java 3KB
SysOperLogController.java 3KB
ISysRoleService.java 2KB
SysNoticeController.java 2KB
SysMenu.java 2KB
SysOperLog.java 2KB
BaseController.java 2KB
GlobalFilter.java 2KB
SysMenuMapper.java 2KB
ISysMenuService.java 2KB
SysDictData.java 2KB
RemoteSysUserServiceImpl.java 2KB
AuthProcessorImpl.java 2KB
SysDept.java 2KB
CryptoUtil.java 2KB
GenTableColumnServiceImpl.java 2KB
UserConstant.java 2KB
StpInterfaceImpl.java 2KB
MybatisFlexConfig.java 2KB
SysPost.java 2KB
TreeSelect.java 1KB
SysConfig.java 1KB
ISysDeptService.java 1KB
SysDictType.java 1KB
SysDeptMapper.java 1KB
ContextUtil.java 1KB
SysRoleMapper.java 1KB
MetaVo.java 1KB
IGenTableService.java 1KB
ISysDictDataService.java 1KB
NoRepeatSubmitCheckerImpl.java 1KB
GenTableMapper.java 1KB
ExcelUtil.java 1KB
SysLoginLogServiceImpl.java 1KB
ApiCodes.java 1KB
RouterVo.java 1KB
SysUserMapper.java 1KB
SysUserRoleMapper.java 1KB
DictEnum.java 1KB
FileConfig.java 1KB
RemoteSysLogServiceImpl.java 1023B
SysLoginLog.java 1003B
SysNotice.java 995B
SecurityPlugin.java 955B
DemoTest.java 949B
共 757 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
wjs2024
- 粉丝: 2307
- 资源: 5457
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功