package com.github.mengweijin.vitality.system.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.mengweijin.vitality.framework.constant.Const;
import com.github.mengweijin.vitality.system.constant.MenuConst;
import com.github.mengweijin.vitality.system.constant.RoleConst;
import com.github.mengweijin.vitality.system.constant.UserConst;
import com.github.mengweijin.vitality.system.dto.MenuDTO;
import com.github.mengweijin.vitality.system.dto.MenuTreeDataDTO;
import com.github.mengweijin.vitality.system.dto.RoleDTO;
import com.github.mengweijin.vitality.system.dto.UserDetailDTO;
import com.github.mengweijin.vitality.system.entity.MenuDO;
import com.github.mengweijin.vitality.system.entity.MenuDeptRltDO;
import com.github.mengweijin.vitality.system.entity.MenuPostRltDO;
import com.github.mengweijin.vitality.system.entity.MenuRoleRltDO;
import com.github.mengweijin.vitality.system.entity.MenuUserRltDO;
import com.github.mengweijin.vitality.system.enums.EMenuType;
import com.github.mengweijin.vitality.system.mapper.MenuMapper;
import org.dromara.hutool.core.collection.CollUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @author mengweijin
* @date 2023/4/1
*/
@Service
public class MenuService extends ServiceImpl<MenuMapper, MenuDO> {
@Autowired
private MenuMapper menuMapper;
@Autowired
private RoleService roleService;
@Autowired
private DeptService deptService;
@Autowired
private PostService postService;
@Autowired
private UserService userService;
@Autowired
private MenuRoleRltService menuRoleRltService;
@Autowired
private MenuDeptRltService menuDeptRltService;
@Autowired
private MenuPostRltService menuPostRltService;
@Autowired
private MenuUserRltService menuUserRltService;
@Override
public boolean save(MenuDO entity) {
Long parentId = entity.getParentId();
if(parentId == null || MenuConst.ROOT_ID == parentId) {
entity.setParentId(MenuConst.ROOT_ID);
entity.setAncestors(String.valueOf(MenuConst.ROOT_ID));
} else {
MenuDO parentMenu = this.getById(parentId);
entity.setParentId(parentId);
entity.setAncestors(parentMenu.getAncestors() + Const.SLASH + parentId);
}
return super.save(entity);
}
@Override
public boolean updateById(MenuDO entity) {
return super.updateById(entity);
}
public IPage<MenuDTO> page(IPage<MenuDTO> page, MenuDTO dto){
return menuMapper.page(page, dto);
}
public List<MenuDTO> treeTableDataList(MenuDTO dto) {
return menuMapper.treeTableDataList(dto);
}
public List<MenuTreeDataDTO> treeLeftSideData() {
List<MenuDO> menuList;
Long loginUserId = userService.getSessionUser().getId();
UserDetailDTO vtlUserDetailDTO = userService.detailById(loginUserId);
List<RoleDTO> roleList = vtlUserDetailDTO.getRoleList();
if(UserConst.ADMIN_ID == loginUserId || roleList.stream().anyMatch(role -> RoleConst.ADMIN.equals(role.getCode()))) {
menuList = this.lambdaQuery().in(MenuDO::getType, EMenuType.DIR, EMenuType.MENU).list();
} else {
menuList = this.getMenuByLoginUser(loginUserId);
menuList = menuList.stream()
.filter(menu -> menu.getDisabled() == 0 && (EMenuType.DIR == menu.getType() || EMenuType.MENU == menu.getType()))
.toList();
}
List<MenuTreeDataDTO> voList = Optional.ofNullable(menuList).orElse(new ArrayList<>()).stream().map(MenuTreeDataDTO::new).toList();
return MenuTreeDataDTO.buildTree(voList, MenuConst.ROOT_ID);
}
public List<MenuDO> getMenuByLoginUser(Long userId) {
List<RoleDTO> roleList = roleService.getByUserId(userId);
if(UserConst.ADMIN_ID == userId || roleList.stream().anyMatch(role -> RoleConst.ADMIN.equals(role.getCode()))) {
return this.lambdaQuery().list();
}
List<Long> menuIdListByDept = deptService.getByUserId(userId).stream().flatMap(deptDTO -> this.byDept(deptDTO.getId()).stream()).toList();
List<Long> menuIdListByRole = roleService.getByUserId(userId).stream().flatMap(roleDTO -> this.byRole(roleDTO.getId()).stream()).toList();
List<Long> menuIdListByPost = postService.getByUserId(userId).stream().flatMap(postDTO -> this.byPost(postDTO.getId()).stream()).toList();
List<Long> menuIdListByUser = this.byUser(userId);
List<Long> allMenuIdList = new ArrayList<>();
allMenuIdList.addAll(menuIdListByDept);
allMenuIdList.addAll(menuIdListByRole);
allMenuIdList.addAll(menuIdListByPost);
allMenuIdList.addAll(menuIdListByUser);
allMenuIdList = allMenuIdList.stream().distinct().toList();
if(CollUtil.isEmpty(allMenuIdList)) {
return new ArrayList<>();
}
return this.lambdaQuery().in(MenuDO::getId, allMenuIdList).list();
}
public List<MenuDO> getByParentId(Long parentId) {
return this.lambdaQuery().eq(MenuDO::getParentId, parentId).eq(MenuDO::getDisabled, 0).list();
}
public List<Long> getAllParentById(Long id) {
MenuDO menuDO = this.getById(id);
String ancestors = menuDO.getAncestors();
return Arrays.stream(ancestors.split(Const.SLASH)).map(Long::valueOf).toList();
}
public List<Long> getAllChildrenById(Long id) {
MenuDO menuDO = this.getById(id);
return this.lambdaQuery().select(MenuDO::getId)
.likeRight(MenuDO::getAncestors, menuDO.getAncestors() + Const.SLASH + menuDO.getId())
.list().stream().map(MenuDO::getId).toList();
}
public boolean setDisabledValue(Long id, boolean disabled) {
return this.lambdaUpdate().set(MenuDO::getDisabled, disabled).eq(MenuDO::getId, id).update();
}
public String titleHierarchyById(Long id) {
String titleHierarchy;
if(MenuConst.ROOT_ID == id) {
return Const.EMPTY;
}
MenuDO menu = this.getById(id);
String ancestors = menu.getAncestors();
titleHierarchy = this.lambdaQuery().select(MenuDO::getTitle)
.in(MenuDO::getId, Arrays.asList(ancestors.split(Const.SLASH)))
.list().stream()
.map(MenuDO::getTitle)
.collect(Collectors.joining(Const.SLASH));
return titleHierarchy + Const.SLASH + menu.getTitle();
}
public List<MenuDO> getAllChildrenByTitle(String title) {
List<Long> idList = this.lambdaQuery().select(MenuDO::getId).like(MenuDO::getTitle, title).list().stream().map(MenuDO::getId).toList();
List<MenuDO> allList = this.list();
List<MenuDO> resultList = new ArrayList<>();
for (Long id : idList) {
resultList.addAll(this.findAllChildrenByParentId(allList, id));
}
resultList = CollUtil.distinct(resultList, MenuDO::getId, true);
resultList.sort(Comparator.comparingInt(MenuDO::getSeq));
return resultList;
}
public List<MenuDO> getAllChildrenByParentId(Long parentId) {
List<MenuDO> menuList = this.list();
return this.findAllChildrenByParentId(menuList, parentId);
}
public List<MenuDO> findAllChildrenByParentId(List<MenuDO> list, Long parentId) {
Map<Long, List<MenuDO>> groupedList = list.stream().collect(Collectors.groupingBy(MenuDO::getParentId));
List<MenuDO> resultList = new ArrayList<>();
this.recursiveSearchChildren(groupedList, parentId, resultList);
resultList.sort(Comparator.comparingInt(MenuDO::getS
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于 SpringBoot 3+、sa-token、Layui 2.8+ 可前后端分离的后台管理系统,可以用于常见的的 Web 应用程序,比如网站管理后台等。.zip 适合学习/练手、毕业设计、课程设计、期末/期中/大作业、工程实训、相关项目/竞赛学习等。 项目具有较高的学习借鉴价值,也可直接拿来修改复现。可以在这些基础上学习借鉴进行修改和扩展,实现其它功能。 可放心下载学习借鉴,你会有所收获。 —— 对于学习和实践,选择合适的项目和资源确实是一种有效的方式。 在进行毕业设计、课程设计或大作业时,选择具备学习借鉴价值的项目可以帮助你理解和应用所学知识,同时也可以通过修改和扩展来实现其他功能。 通过参与实际项目,你可以应用所学的理论知识,深入了解软件开发或其他领域的实践流程和技术要求。 可放心下载学习借鉴,你会有所收获。 # 注意 1. 本资源仅用于开源学习和技术交流。不可商用等,一切后果由使用者承担。 2. 部分字体以及插图等来自网络,若是侵权请联系删除。
资源推荐
资源详情
资源评论
收起资源包目录
基于 SpringBoot 3+、sa-token、Layui 2.8+ 可前后端分离的后台管理系统 (1205个子文件)
layui.css 120KB
skin.css 71KB
skin.css 71KB
skin.min.css 60KB
skin.min.css 59KB
toast.css 59KB
loading.css 25KB
skin.mobile.css 24KB
skin.mobile.css 24KB
content.css 24KB
content.inline.css 23KB
content.inline.css 23KB
content.css 23KB
content.min.css 21KB
content.inline.min.css 21KB
content.inline.min.css 21KB
content.min.css 21KB
skin.mobile.min.css 21KB
skin.mobile.min.css 21KB
select.css 19KB
ui.css 12KB
layout.css 11KB
fui.css 10KB
admin.css 9KB
awesome.css 8KB
icon.css 8KB
iconfont.css 8KB
fui.min.css 7KB
notice.css 7KB
layer.css 7KB
popover.min.css 7KB
metroStyle.css 6KB
zTreeStyle.css 6KB
tab.css 6KB
dtree.css 5KB
menu.css 5KB
dtreefont.css 4KB
cropper.css 4KB
button.css 3KB
frame.css 3KB
message.css 2KB
demo.css 2KB
content.css 2KB
content.css 2KB
console1.css 2KB
table.css 2KB
content.css 2KB
content.css 2KB
login.css 2KB
console2.css 2KB
card.css 2KB
loader.css 2KB
content.min.css 2KB
scrollbar.css 1KB
content.min.css 1KB
content.min.css 1KB
nprogress.css 1KB
content.min.css 1KB
form.css 1KB
step.css 1KB
person.css 1KB
pear.css 1KB
tag.css 1KB
base.css 1KB
error.css 915B
skin.shadowdom.css 833B
skin.shadowdom.css 833B
skin.shadowdom.min.css 786B
skin.shadowdom.min.css 786B
content.mobile.css 727B
content.mobile.css 727B
content.mobile.min.css 595B
content.mobile.min.css 595B
result.css 569B
style.css 428B
treetable.css 394B
fullscreen.css 375B
vitality.css 238B
link.css 218B
iconPicker.css 185B
page.css 153B
department.css 150B
code.css 126B
topBar.css 85B
label.css 0B
Dockerfile 420B
iconfont.eot 53KB
dtreefont.eot 19KB
spring.factories 170B
spring.factories 143B
list.html.ftl 9KB
edit.html.ftl 5KB
{EntityName}Mapper.xml.ftl 3KB
detail.html.ftl 2KB
{EntityName}Controller.java.ftl 2KB
{EntityName}DO.java.ftl 2KB
{EntityName}Service.java.ftl 906B
{EntityName}Mapper.java.ftl 768B
h2.sql.ftl 398B
mysql.sql.ftl 396B
共 1205 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论
阿齐Archie
- 粉丝: 1w+
- 资源: 2301
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于MATLAB的图像分割源码+详细文档+全部数据(高分课程设计).zip
- 基于MATLAB的图像分割源码+详细文档+全部数据(高分课程设计).zip
- 基于MINST数据库的手写体数字识别CNN设计,MATLAB实现源码+全部资料.zip
- 基于MINST数据库的手写体数字识别CNN设计,MATLAB实现源码+全部资料(高分项目)
- stata 经纬度计算反距离矩阵的方法.docx
- ORACLE数据库面试题解答DBA数据库管理员JAVA程序员架构师必看.docx
- stata 经纬度计算反距离矩阵的方法.zip
- ORACLE数据库面试题解答DBA数据库管理员JAVA程序员架构师必看.zip
- 华为-华为od题库练习题之密码截取.zip
- 华为-华为od题库练习题之字符串加解密.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功