rev:忽略新增字段

This commit is contained in:
2023-06-01 15:52:41 +08:00
parent e6ad4d8258
commit 03ea709809
8 changed files with 512 additions and 498 deletions

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import org.nl.common.domain.query.PageQuery; import org.nl.common.domain.query.PageQuery;
import org.nl.system.service.menu.dao.SysMenu; import org.nl.system.service.menu.dao.SysMenu;
import org.nl.system.service.menu.dto.MenuDto; import org.nl.system.service.menu.dto.MenuDto;
import org.nl.system.service.menu.dto.MenuInfoDto;
import org.nl.system.service.menu.dto.MenuQuery; import org.nl.system.service.menu.dto.MenuQuery;
import org.nl.system.service.menu.dto.MenuVo; import org.nl.system.service.menu.dto.MenuVo;
@@ -108,9 +109,9 @@ public interface ISysMenuService extends IService<SysMenu> {
* @return / * @return /
*/ */
List<MenuVo> buildMenus(List<MenuDto> menuDtos); List<MenuVo> buildMenus(List<MenuDto> menuDtos);
List<MenuVo> buildMenus(List<MenuDto> menuDtos,String pid);
List<MenuVo> buildMenus(String systemType);
List<MenuInfoDto> buildMenus(String systemType);
/** /**
* 构建菜单树 * 构建菜单树

View File

@@ -2,6 +2,7 @@ package org.nl.system.service.menu.dao;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.Data; import lombok.Data;
import java.util.Date; import java.util.Date;
@@ -32,6 +33,13 @@ public class SysMenu implements Serializable {
@TableId(value = "menu_id", type = IdType.NONE) @TableId(value = "menu_id", type = IdType.NONE)
private String menuId; private String menuId;
@TableField(exist = false)
private String label;
@TableField(exist = false)
private String router;
@TableField(exist = false)
private String index;
/** /**
* 上级菜单ID * 上级菜单ID
*/ */

View File

@@ -53,21 +53,37 @@
</select> </select>
<select id="findSystemMenu" resultType="org.nl.system.service.menu.dao.SysMenu"> <select id="findSystemMenu" resultType="org.nl.system.service.menu.dao.SysMenu">
SELECT SELECT
* m.menu_id,
m.iframe,
m.pid,
m.`level`,
m.sub_count,
m.type,
m.title label,
m.component_name,
m.component,
m.menu_sort,
m.path router,
m.`cache`,
m.is_pc,
m.hidden,
m.permission,
m.create_name,
m.update_name,
m.create_time,
m.update_time,
m.system_type,
m.create_id,
m.category `index` ,
m.update_id
FROM FROM
sys_menu sys_menu m
WHERE WHERE
type != '2' m.type != '2'
and system_type = #{systemType} AND m.system_type = #{systemType}
and AND m.menu_id IN ( SELECT menu_id FROM sys_roles_menus WHERE role_id IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{user} ) )
menu_id IN ( ORDER BY
SELECT m.menu_sort
menu_id
FROM
sys_roles_menus
WHERE
role_id IN ( SELECT role_id FROM sys_users_roles where user_id = #{user})
) order by menu_sort
</select> </select>
<select id="getMenusByRole" resultType="java.util.Map"> <select id="getMenusByRole" resultType="java.util.Map">
SELECT SELECT

View File

@@ -16,6 +16,7 @@
package org.nl.system.service.menu.dto; package org.nl.system.service.menu.dto;
import lombok.Data; import lombok.Data;
import java.util.Date; import java.util.Date;
import org.nl.modules.common.base.BaseDTO; import org.nl.modules.common.base.BaseDTO;
@@ -25,43 +26,29 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
@Data @Data
public class MenuDto extends BaseDTO implements Serializable { public class MenuDto extends BaseDTO implements Serializable{
private String menuId; private String menuId;
private List<MenuDto> children; private List<MenuDto> children;
private String label;
private String router;
private Integer level;
private String index;
private String type; private String type;
private String permission; private String permission;
private String title; private String title;
private Integer menuSort; private Integer menuSort;
private String path; private String path;
private String name; private String name;
private String component; private String component;
private String pid; private String pid;
private Integer subCount; private Integer subCount;
private Boolean iframe; private Boolean iframe;
private String systemType; private String systemType;
private Boolean cache; private Boolean cache;
private Boolean hidden; private Boolean hidden;
private String componentName; private String componentName;
private String icon; private String icon;
private boolean hasChildren; private boolean hasChildren;
private boolean leaf; private boolean leaf;
public Boolean getHasChildren() { public Boolean getHasChildren() {
@@ -73,15 +60,15 @@ public class MenuDto extends BaseDTO implements Serializable {
} }
public String getLabel() { public String getLabel() {
return title; return label;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) { if(this == o) {
return true; return true;
} }
if (o == null || getClass() != o.getClass()) { if(o == null || getClass() != o.getClass()) {
return false; return false;
} }
MenuDto menuDto = (MenuDto) o; MenuDto menuDto = (MenuDto) o;

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* 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.
*/
package org.nl.system.service.menu.dto;
import lombok.Data;
import org.nl.modules.common.base.BaseDTO;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
@Data
public class MenuInfoDto implements Serializable{
private String menuId;
private String pid;
private String label;
private String router;
private String index;
private List<MenuInfoDto> children;
}

View File

@@ -17,34 +17,37 @@ package org.nl.system.service.menu.dto;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data; import lombok.Data;
import java.util.Date; import java.util.Date;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
/** /**
* 构建前端路由时用到 * 构建前端路由时用到
*
* @author Zheng Jie * @author Zheng Jie
* @date 2018-12-20 * @date 2018-12-20
*/ */
@Data @Data
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
public class MenuVo implements Serializable { public class MenuVo implements Serializable{
private String name; private String name;
private String path; private String path;
private Boolean hidden; private Boolean hidden;
private String label;
private String router;
private String index;
private String redirect; private String redirect;
private String component; private String component;
private Boolean alwaysShow; private Boolean alwaysShow;
private MenuMetaVo meta; private MenuMetaVo meta;
public void setRouter(String router) {
this.router = router;
if(router == null) {
this.router = "";
}
}
private List<MenuVo> children; private List<MenuVo> children;
} }

View File

@@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.nl.common.anno.Log; import org.nl.common.anno.Log;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -23,10 +23,7 @@ import org.nl.system.service.dict.dao.Dict;
import org.nl.system.service.menu.ISysMenuService; import org.nl.system.service.menu.ISysMenuService;
import org.nl.system.service.menu.dao.SysMenu; import org.nl.system.service.menu.dao.SysMenu;
import org.nl.system.service.menu.dao.mapper.SysMenuMapper; import org.nl.system.service.menu.dao.mapper.SysMenuMapper;
import org.nl.system.service.menu.dto.MenuDto; import org.nl.system.service.menu.dto.*;
import org.nl.system.service.menu.dto.MenuMetaVo;
import org.nl.system.service.menu.dto.MenuQuery;
import org.nl.system.service.menu.dto.MenuVo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@@ -46,22 +43,20 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
@Transactional @Transactional
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService { public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper,SysMenu> implements ISysMenuService{
private final SysMenuMapper baseMapper; private final SysMenuMapper baseMapper;
private final ISysDictService sysDictMapper; private final ISysDictService sysDictMapper;
@Override @Override
public List<MenuDto> queryAll(Map<String, Object> param) { public List<MenuDto> queryAll(Map<String,Object> param) {
// 父节点标识 // 父节点标识
String pid = MapUtil.getStr(param, "pid"); String pid = MapUtil.getStr(param, "pid");
return getMenus(pid).stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList()); return getMenus(pid).stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
} }
@Override @Override
public List query(MenuQuery query, PageQuery page) { public List query(MenuQuery query, PageQuery page) {
if (StringUtils.isNotBlank(query.getBlurry())){ if(StringUtils.isNotBlank(query.getBlurry())) {
query.setPid(null); query.setPid(null);
} }
Page<SysMenu> menuPage = this.page(page.build(SysMenu.class), query.build()); Page<SysMenu> menuPage = this.page(page.build(SysMenu.class), query.build());
@@ -71,12 +66,11 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override @Override
public List<MenuDto> getSuperior(MenuDto menuDto, List<SysMenu> menus) { public List<MenuDto> getSuperior(MenuDto menuDto, List<SysMenu> menus) {
if (menuDto.getPid() == null) { if(menuDto.getPid() == null) {
menus.addAll(this.findByPidIsNull()); menus.addAll(this.findByPidIsNull());
return menus.stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList()); return menus.stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
} }
menus.addAll(baseMapper.findByPid(menuDto.getPid())); menus.addAll(baseMapper.findByPid(menuDto.getPid()));
return getSuperior(this.doToDto(findById(menuDto.getPid())), menus); return getSuperior(this.doToDto(findById(menuDto.getPid())), menus);
} }
@@ -97,10 +91,10 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override @Override
public Set<SysMenu> getChildMenus(List<SysMenu> menuList, Set<SysMenu> menuSet) { public Set<SysMenu> getChildMenus(List<SysMenu> menuList, Set<SysMenu> menuSet) {
for (SysMenu menu : menuList) { for(SysMenu menu : menuList) {
menuSet.add(menu); menuSet.add(menu);
List<SysMenu> menus = this.findByPid(menu.getMenuId()); List<SysMenu> menus = this.findByPid(menu.getMenuId());
if (menus != null && menus.size() != 0) { if(menus != null && menus.size() != 0) {
getChildMenus(menus, menuSet); getChildMenus(menus, menuSet);
} }
} }
@@ -110,19 +104,17 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void create(SysMenu resources) { public void create(SysMenu resources) {
if(resources.getIframe()) {
if (resources.getIframe()) {
String http = "http://", https = "https://"; String http = "http://", https = "https://";
if (!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) { if(!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) {
throw new BadRequestException("外链必须以http://或者https://开头"); throw new BadRequestException("外链必须以http://或者https://开头");
} }
} }
resources.setMenuId(IdUtil.getStringId()); resources.setMenuId(IdUtil.getStringId());
if (resources.getPid().equals("0")) { if(resources.getPid().equals("0")) {
resources.setPid(null); resources.setPid(null);
addSystemTypeDict(resources); addSystemTypeDict(resources);
} }
baseMapper.insert(resources); baseMapper.insert(resources);
// 计算子节点数目 // 计算子节点数目
resources.setSubCount(0); resources.setSubCount(0);
@@ -133,7 +125,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
private void addSystemTypeDict(SysMenu resources) { private void addSystemTypeDict(SysMenu resources) {
Dict dict = sysDictMapper.getOne(new QueryWrapper<Dict>().eq("code", DictConstantPool.DICT_SYS_CODE).orderByDesc("value").last("limit 1")); Dict dict = sysDictMapper.getOne(new QueryWrapper<Dict>().eq("code", DictConstantPool.DICT_SYS_CODE).orderByDesc("value").last("limit 1"));
Integer currentType = dict!=null?Integer.valueOf(dict.getValue())+1:1; Integer currentType = dict != null ? Integer.valueOf(dict.getValue()) + 1 : 1;
Dict currentSysType = new Dict(); Dict currentSysType = new Dict();
currentSysType.setDictId(IdUtil.getStringId()); currentSysType.setDictId(IdUtil.getStringId());
currentSysType.setCode(DictConstantPool.DICT_SYS_CODE); currentSysType.setCode(DictConstantPool.DICT_SYS_CODE);
@@ -144,20 +136,23 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
sysDictMapper.save(currentSysType); sysDictMapper.save(currentSysType);
resources.setSystemType(String.valueOf(currentType)); resources.setSystemType(String.valueOf(currentType));
} }
private void updateRootSystemType(SysMenu sysMenu) { private void updateRootSystemType(SysMenu sysMenu) {
String rootMenuId = this.findRootMenuId(sysMenu.getMenuId()); String rootMenuId = this.findRootMenuId(sysMenu.getMenuId());
if (sysMenu.getMenuId().equals(rootMenuId)){ if(sysMenu.getMenuId().equals(rootMenuId)) {
return; return;
} }
SysMenu rootMenu = this.findById(rootMenuId); SysMenu rootMenu = this.findById(rootMenuId);
sysMenu.setSystemType(rootMenu.getSystemType()); sysMenu.setSystemType(rootMenu.getSystemType());
this.updateById(sysMenu); this.updateById(sysMenu);
} }
private String findRootMenuId(String menuId) { private String findRootMenuId(String menuId) {
SysMenu sysMenu = this.findById(menuId); SysMenu sysMenu = this.findById(menuId);
if (StrUtil.isEmpty(sysMenu.getPid())) { if(StrUtil.isEmpty(sysMenu.getPid())) {
return menuId; return menuId;
} else { }
else{
return findRootMenuId(sysMenu.getPid()); return findRootMenuId(sysMenu.getPid());
} }
} }
@@ -166,17 +161,17 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void delete(Set<SysMenu> menuSet) { public void delete(Set<SysMenu> menuSet) {
List<String> pids = Lists.newArrayList(); List<String> pids = Lists.newArrayList();
for (SysMenu menu : menuSet) { for(SysMenu menu : menuSet) {
//解绑菜单 //解绑菜单
baseMapper.untiedMenu(menu.getMenuId()); baseMapper.untiedMenu(menu.getMenuId());
baseMapper.deleteById(menu.getMenuId()); baseMapper.deleteById(menu.getMenuId());
String pid = menu.getPid(); String pid = menu.getPid();
if (StringUtils.isBlank(pid)){ if(StringUtils.isBlank(pid)) {
pids.add(menu.getMenuId()); pids.add(menu.getMenuId());
} }
updateSubCnt(pid); updateSubCnt(pid);
} }
if (!CollectionUtils.isEmpty(pids)){ if(!CollectionUtils.isEmpty(pids)) {
sysDictMapper.remove(new QueryWrapper<Dict>().in("para1", pids).eq("code", DictConstantPool.DICT_SYS_CODE)); sysDictMapper.remove(new QueryWrapper<Dict>().in("para1", pids).eq("code", DictConstantPool.DICT_SYS_CODE));
} }
} }
@@ -189,36 +184,35 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
String allChild = baseMapper.findAllChild(menuId); String allChild = baseMapper.findAllChild(menuId);
List<String> allChildIds = new ArrayList<>(); List<String> allChildIds = new ArrayList<>();
allChildIds.add(menuId); allChildIds.add(menuId);
if (StringUtils.isNotBlank(allChild)){ if(StringUtils.isNotBlank(allChild)) {
allChildIds.addAll(Arrays.asList(allChild.split(","))); allChildIds.addAll(Arrays.asList(allChild.split(",")));
} }
if(allChildIds.contains(resources.getPid())) {
if (allChildIds.contains(resources.getPid())){
throw new BadRequestException("上级不能为自己或自己的下级"); throw new BadRequestException("上级不能为自己或自己的下级");
} }
if (resources.getIframe()) { if(resources.getIframe()) {
String http = "http://", https = "https://"; String http = "http://", https = "https://";
if (!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) { if(!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) {
throw new BadRequestException("外链必须以http://或者https://开头"); throw new BadRequestException("外链必须以http://或者https://开头");
} }
} }
if(resources.getPid().equals("0")) {
if (resources.getPid().equals("0")) {
resources.setPid(null); resources.setPid(null);
if (StringUtils.isNotBlank(menu.getPid())){ if(StringUtils.isNotBlank(menu.getPid())) {
addSystemTypeDict(resources); addSystemTypeDict(resources);
} }
}else { }
else{
resources.setSystemType(this.findById(resources.getPid()).getSystemType()); resources.setSystemType(this.findById(resources.getPid()).getSystemType());
} }
String oldPid = menu.getPid(); String oldPid = menu.getPid();
String newPid = resources.getPid(); String newPid = resources.getPid();
// 记录的父节点ID // 记录的父节点ID
if (oldPid == null && newPid != null){ if(oldPid == null && newPid != null) {
sysDictMapper.remove(new QueryWrapper<Dict>().eq("para1",menu.getMenuId()).eq("code", DictConstantPool.DICT_SYS_CODE)); sysDictMapper.remove(new QueryWrapper<Dict>().eq("para1", menu.getMenuId()).eq("code", DictConstantPool.DICT_SYS_CODE));
} }
if (!resources.getTitle().equals(menu.getTitle())){ if(!resources.getTitle().equals(menu.getTitle())) {
sysDictMapper.update(new UpdateWrapper<Dict>().set("label",resources.getTitle()).eq("para1",menu.getMenuId()).eq("code", DictConstantPool.DICT_SYS_CODE)); sysDictMapper.update(new UpdateWrapper<Dict>().set("label", resources.getTitle()).eq("para1", menu.getMenuId()).eq("code", DictConstantPool.DICT_SYS_CODE));
} }
menu.setTitle(resources.getTitle()); menu.setTitle(resources.getTitle());
menu.setComponent(resources.getComponent()); menu.setComponent(resources.getComponent());
@@ -237,10 +231,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
updateSubCnt(oldPid); updateSubCnt(oldPid);
updateSubCnt(newPid); updateSubCnt(newPid);
//更新SystemType //更新SystemType
if (!resources.getSystemType().equals(menu.getSystemType())){ if(!resources.getSystemType().equals(menu.getSystemType())) {
this.update(new UpdateWrapper<SysMenu>().set(DictConstantPool.DICT_SYS_CODE,resources.getSystemType()).in("menu_id",allChildIds)); this.update(new UpdateWrapper<SysMenu>().set(DictConstantPool.DICT_SYS_CODE, resources.getSystemType()).in("menu_id", allChildIds));
} }
} }
/** /**
@@ -249,10 +242,12 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
* @param menuId * @param menuId
*/ */
private void updateSubCnt(String menuId) { private void updateSubCnt(String menuId) {
if (menuId != null) { if(menuId != null) {
int count = baseMapper.findByPid(menuId).size(); int count = baseMapper.findByPid(menuId).size();
SysMenu sysMenu = baseMapper.selectById(menuId); SysMenu sysMenu = baseMapper.selectById(menuId);
if (ObjectUtil.isEmpty(sysMenu)) return; if(ObjectUtil.isEmpty(sysMenu)) {
return;
}
sysMenu.setSubCount(count); sysMenu.setSubCount(count);
baseMapper.updateById(sysMenu); baseMapper.updateById(sysMenu);
} }
@@ -267,7 +262,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
public List<MenuVo> buildMenus(List<MenuDto> menuDtos) { public List<MenuVo> buildMenus(List<MenuDto> menuDtos) {
List<MenuVo> list = new LinkedList<>(); List<MenuVo> list = new LinkedList<>();
menuDtos.forEach(menuDTO -> { menuDtos.forEach(menuDTO -> {
if (menuDTO != null) { if(menuDTO != null) {
List<MenuDto> menuDtoList = menuDTO.getChildren(); List<MenuDto> menuDtoList = menuDTO.getChildren();
MenuVo menuVo = new MenuVo(); MenuVo menuVo = new MenuVo();
menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponentName()) ? menuDTO.getComponentName() : menuDTO.getTitle()); menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponentName()) ? menuDTO.getComponentName() : menuDTO.getTitle());
@@ -275,31 +270,34 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
menuVo.setPath(ObjectUtil.isEmpty(menuDTO.getPid()) ? "/" + menuDTO.getPath() : menuDTO.getPath()); menuVo.setPath(ObjectUtil.isEmpty(menuDTO.getPid()) ? "/" + menuDTO.getPath() : menuDTO.getPath());
menuVo.setHidden(menuDTO.getHidden()); menuVo.setHidden(menuDTO.getHidden());
// 如果不是外链 // 如果不是外链
if (!menuDTO.getIframe()) { if(!menuDTO.getIframe()) {
if (ObjectUtil.isEmpty(menuDTO.getPid())) { if(ObjectUtil.isEmpty(menuDTO.getPid())) {
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent()); menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
} else if (!ObjectUtil.isEmpty(menuDTO.getPid()) && "0".equals(menuDTO.getType())) { }
else if(!ObjectUtil.isEmpty(menuDTO.getPid()) && "0".equals(menuDTO.getType())) {
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "ParentView" : menuDTO.getComponent()); menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "ParentView" : menuDTO.getComponent());
}
} else if (!StrUtil.isEmpty(menuDTO.getComponent())) { else if(!StrUtil.isEmpty(menuDTO.getComponent())) {
menuVo.setComponent(menuDTO.getComponent()); menuVo.setComponent(menuDTO.getComponent());
} }
} }
menuVo.setMeta(new MenuMetaVo(menuDTO.getTitle(), menuDTO.getIcon(), !menuDTO.getCache())); menuVo.setMeta(new MenuMetaVo(menuDTO.getTitle(), menuDTO.getIcon(), !menuDTO.getCache()));
if (menuDtoList != null && menuDtoList.size() != 0) { if(menuDtoList != null && menuDtoList.size() != 0) {
menuVo.setAlwaysShow(true); menuVo.setAlwaysShow(true);
menuVo.setRedirect("noredirect"); menuVo.setRedirect("noredirect");
menuVo.setChildren(buildMenus(menuDtoList)); menuVo.setChildren(buildMenus(menuDtoList));
// 处理是一级菜单并且没有子菜单的情况 // 处理是一级菜单并且没有子菜单的情况
} else if (ObjectUtil.isEmpty(menuDTO.getPid())) { }
else if(ObjectUtil.isEmpty(menuDTO.getPid())) {
MenuVo menuVo1 = new MenuVo(); MenuVo menuVo1 = new MenuVo();
menuVo1.setMeta(menuVo.getMeta()); menuVo1.setMeta(menuVo.getMeta());
// 非外链 // 非外链
if (!menuDTO.getIframe()) { if(!menuDTO.getIframe()) {
menuVo1.setPath("index"); menuVo1.setPath("index");
menuVo1.setName(menuVo.getName()); menuVo1.setName(menuVo.getName());
menuVo1.setComponent(menuVo.getComponent()); menuVo1.setComponent(menuVo.getComponent());
} else { }
else{
menuVo1.setPath(menuDTO.getPath()); menuVo1.setPath(menuDTO.getPath());
} }
menuVo.setName(null); menuVo.setName(null);
@@ -311,8 +309,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
} }
list.add(menuVo); list.add(menuVo);
} }
} });
);
return list; return list;
} }
@@ -320,13 +317,13 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
public List<MenuDto> buildTree(List<MenuDto> menuDtos) { public List<MenuDto> buildTree(List<MenuDto> menuDtos) {
List<MenuDto> trees = new ArrayList<>(); List<MenuDto> trees = new ArrayList<>();
Set<String> ids = new HashSet<>(); Set<String> ids = new HashSet<>();
for (MenuDto menuDTO : menuDtos) { for(MenuDto menuDTO : menuDtos) {
if (menuDTO.getPid() == null) { if(menuDTO.getPid() == null) {
trees.add(menuDTO); trees.add(menuDTO);
} }
for (MenuDto it : menuDtos) { for(MenuDto it : menuDtos) {
if (menuDTO.getMenuId().equals(it.getPid())) { if(menuDTO.getMenuId().equals(it.getPid())) {
if (menuDTO.getChildren() == null) { if(menuDTO.getChildren() == null) {
menuDTO.setChildren(new ArrayList<>()); menuDTO.setChildren(new ArrayList<>());
} }
menuDTO.getChildren().add(it); menuDTO.getChildren().add(it);
@@ -334,7 +331,32 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
} }
} }
} }
if (trees.size() == 0) { if(trees.size() == 0) {
trees = menuDtos.stream().filter(s -> !ids.contains(s.getMenuId())).collect(Collectors.toList());
}
return trees;
}
public List<MenuInfoDto> buildMenuDto(List<MenuInfoDto> menuDtos) {
List<MenuInfoDto> trees = new ArrayList<>();
Set<String> ids = new HashSet<>();
for(MenuInfoDto menuDTO : menuDtos) {
if(menuDTO.getPid() == null) {
trees.add(menuDTO);
}
for(MenuInfoDto it : menuDtos) {
if(menuDTO.getMenuId().equals(it.getPid())) {
if(menuDTO.getChildren() == null) {
menuDTO.setChildren(new ArrayList<>());
}
menuDTO.getChildren().add(it);
ids.add(it.getMenuId());
}
}
}
if(trees.size() == 0) {
trees = menuDtos.stream().filter(s -> !ids.contains(s.getMenuId())).collect(Collectors.toList()); trees = menuDtos.stream().filter(s -> !ids.contains(s.getMenuId())).collect(Collectors.toList());
} }
return trees; return trees;
@@ -343,22 +365,19 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override @Override
public List<SysMenu> getMenus(String pid) { public List<SysMenu> getMenus(String pid) {
QueryWrapper<SysMenu> queryWrapper; QueryWrapper<SysMenu> queryWrapper;
if (pid != null && !"0".equals(pid)) { if(pid != null && !"0".equals(pid)) {
queryWrapper = new QueryWrapper<SysMenu>().eq("pid", pid); queryWrapper = new QueryWrapper<SysMenu>().eq("pid", pid);
} else { }
else{
queryWrapper = new QueryWrapper<SysMenu>().isNull("pid"); queryWrapper = new QueryWrapper<SysMenu>().isNull("pid");
} }
return baseMapper.selectList(queryWrapper); return baseMapper.selectList(queryWrapper);
} }
@Override @Override
public MenuDto doToDto(SysMenu entity) { public MenuDto doToDto(SysMenu entity) {
MenuDto menuDto = new MenuDto(); MenuDto menuDto = new MenuDto();
if (ObjectUtil.isEmpty(entity)){ if(ObjectUtil.isEmpty(entity)) {
return menuDto; return menuDto;
} }
menuDto.setMenuId(entity.getMenuId()); menuDto.setMenuId(entity.getMenuId());
@@ -377,13 +396,13 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
menuDto.setComponentName(entity.getComponentName()); menuDto.setComponentName(entity.getComponentName());
menuDto.setIcon(entity.getIcon()); menuDto.setIcon(entity.getIcon());
menuDto.setCreateTime(entity.getCreateTime()); menuDto.setCreateTime(entity.getCreateTime());
//构建前端需要的数据结构树 //构建前端需要的数据结构树
Integer sub_count = entity.getSubCount(); Integer sub_count = entity.getSubCount();
if (sub_count <= 0) { if(sub_count <= 0) {
menuDto.setLeaf(true); menuDto.setLeaf(true);
menuDto.setHasChildren(false); menuDto.setHasChildren(false);
} else { }
else{
menuDto.setLeaf(false); menuDto.setLeaf(false);
menuDto.setHasChildren(true); menuDto.setHasChildren(true);
} }
@@ -391,76 +410,23 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
} }
@Override @Override
public List<MenuVo> buildMenus(String systemType) { public List<MenuInfoDto> buildMenus(String systemType) {
Dict dict = sysDictMapper.getOne(new QueryWrapper<Dict>().eq("code", DictConstantPool.DICT_SYS_CODE).eq("value", systemType)); Dict dict = sysDictMapper.getOne(new QueryWrapper<Dict>().eq("code", DictConstantPool.DICT_SYS_CODE).eq("value", systemType));
if (dict == null || StringUtils.isBlank(dict.getPara1())){ if(dict == null || StringUtils.isBlank(dict.getPara1())) {
throw new BadRequestException("获取对应的系统菜单不存在"); throw new BadRequestException("获取对应的系统菜单不存在");
} }
String pid = dict.getPara1(); String pid = dict.getPara1();
List<SysMenu> menuDtoList = baseMapper.findSystemMenu(SecurityUtils.getCurrentUserId(),systemType); List<SysMenu> menuDtoList = baseMapper.findSystemMenu(SecurityUtils.getCurrentUserId(), systemType);
//移除系统级菜单 //移除系统级菜单
menuDtoList.removeIf(a->a.getMenuId().equals(pid)); menuDtoList.removeIf(a -> a.getMenuId().equals(pid));
List<MenuDto> menuDtos = this.buildTree(CopyUtil.copyList(menuDtoList, MenuDto.class)); List<MenuInfoDto> menuDtos = this.buildMenuDto(CopyUtil.copyList(menuDtoList, MenuInfoDto.class));
return this.buildMenus(menuDtos,pid); return menuDtos;
} }
@Override
public List<MenuVo> buildMenus(List<MenuDto> menuDtos, String pid) {
List<MenuVo> list = new LinkedList<>();
//剔除系统级菜单
menuDtos.forEach(menuDTO -> {
if (menuDTO != null) {
List<MenuDto> menuDtoList = menuDTO.getChildren();
MenuVo menuVo = new MenuVo();
menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponentName()) ? menuDTO.getComponentName() : menuDTO.getTitle());
// 一级目录需要加斜杠,不然会报警告
menuVo.setPath(pid.equals(menuDTO.getPid())? "/" + menuDTO.getPath() : menuDTO.getPath());
menuVo.setHidden(menuDTO.getHidden());
// 如果不是外链
if (!menuDTO.getIframe()) {
if (pid.equals(menuDTO.getPid())) {
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
} else if (!pid.equals(menuDTO.getPid()) && "0".equals(menuDTO.getType())) {
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "ParentView" : menuDTO.getComponent());
} else if (!StrUtil.isEmpty(menuDTO.getComponent())) {
menuVo.setComponent(menuDTO.getComponent());
}
}
menuVo.setMeta(new MenuMetaVo(menuDTO.getTitle(), menuDTO.getIcon(), !menuDTO.getCache()));
if (menuDtoList != null && menuDtoList.size() != 0) {
menuVo.setAlwaysShow(true);
menuVo.setRedirect("noredirect");
menuVo.setChildren(buildMenus(menuDtoList,pid));
// 处理是一级菜单并且没有子菜单的情况
} else if (StrUtil.isEmpty(menuDTO.getPid())) {
MenuVo menuVo1 = new MenuVo();
menuVo1.setMeta(menuVo.getMeta());
// 非外链
if (!menuDTO.getIframe()) {
menuVo1.setPath("index");
menuVo1.setName(menuVo.getName());
menuVo1.setComponent(menuVo.getComponent());
} else {
menuVo1.setPath(menuDTO.getPath());
}
menuVo.setName(null);
menuVo.setMeta(null);
menuVo.setComponent("Layout");
List<MenuVo> list1 = new ArrayList<>();
list1.add(menuVo1);
menuVo.setChildren(list1);
}
list.add(menuVo);
}
}
);
return list;
}
@Override @Override
public List<Map> getMenusByRole(String roleId, String systemType, String category) { public List<Map> getMenusByRole(String roleId, String systemType, String category) {
baseMapper.getMenusByRole(systemType,category); baseMapper.getMenusByRole(systemType, category);
return null; return null;
} }
} }

View File

@@ -108,8 +108,8 @@ public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper,SysUser> impl
if(userDetail.get("depts") != null) { if(userDetail.get("depts") != null) {
deptService.saveUserDeptRelation(userId, (List) userDetail.get("depts")); deptService.saveUserDeptRelation(userId, (List) userDetail.get("depts"));
} }
if(userDetail.get("roles") != null) { if(userDetail.get("rolesIds") != null) {
roleService.saveUserRoleRelation(userId, (List) userDetail.get("roles")); roleService.saveUserRoleRelation(userId, (List) userDetail.get("rolesIds"));
} }
} }