rev:忽略新增字段
This commit is contained in:
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.system.service.menu.dao.SysMenu;
|
||||
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.MenuVo;
|
||||
|
||||
@@ -108,9 +109,9 @@ public interface ISysMenuService extends IService<SysMenu> {
|
||||
* @return /
|
||||
*/
|
||||
List<MenuVo> buildMenus(List<MenuDto> menuDtos);
|
||||
List<MenuVo> buildMenus(List<MenuDto> menuDtos,String pid);
|
||||
|
||||
List<MenuVo> buildMenus(String systemType);
|
||||
|
||||
List<MenuInfoDto> buildMenus(String systemType);
|
||||
|
||||
/**
|
||||
* 构建菜单树
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.nl.system.service.menu.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import jdk.nashorn.internal.ir.annotations.Ignore;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -32,6 +33,13 @@ public class SysMenu implements Serializable {
|
||||
@TableId(value = "menu_id", type = IdType.NONE)
|
||||
private String menuId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String label;
|
||||
@TableField(exist = false)
|
||||
private String router;
|
||||
@TableField(exist = false)
|
||||
private String index;
|
||||
|
||||
/**
|
||||
* 上级菜单ID
|
||||
*/
|
||||
|
||||
@@ -53,21 +53,37 @@
|
||||
</select>
|
||||
<select id="findSystemMenu" resultType="org.nl.system.service.menu.dao.SysMenu">
|
||||
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
|
||||
sys_menu
|
||||
sys_menu m
|
||||
WHERE
|
||||
type != '2'
|
||||
and system_type = #{systemType}
|
||||
and
|
||||
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})
|
||||
) order by menu_sort
|
||||
m.type != '2'
|
||||
AND m.system_type = #{systemType}
|
||||
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} ) )
|
||||
ORDER BY
|
||||
m.menu_sort
|
||||
</select>
|
||||
<select id="getMenusByRole" resultType="java.util.Map">
|
||||
SELECT
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.nl.system.service.menu.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.nl.modules.common.base.BaseDTO;
|
||||
@@ -25,71 +26,57 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Data
|
||||
public class MenuDto extends BaseDTO implements Serializable {
|
||||
public class MenuDto extends BaseDTO implements Serializable{
|
||||
private String menuId;
|
||||
private List<MenuDto> children;
|
||||
private String label;
|
||||
private String router;
|
||||
private Integer level;
|
||||
private String index;
|
||||
private String type;
|
||||
private String permission;
|
||||
private String title;
|
||||
private Integer menuSort;
|
||||
private String path;
|
||||
private String name;
|
||||
private String component;
|
||||
private String pid;
|
||||
private Integer subCount;
|
||||
private Boolean iframe;
|
||||
private String systemType;
|
||||
private Boolean cache;
|
||||
private Boolean hidden;
|
||||
private String componentName;
|
||||
private String icon;
|
||||
private boolean hasChildren;
|
||||
private boolean leaf;
|
||||
|
||||
private String menuId;
|
||||
public Boolean getHasChildren() {
|
||||
return subCount > 0;
|
||||
}
|
||||
|
||||
private List<MenuDto> children;
|
||||
public Boolean getLeaf() {
|
||||
return subCount <= 0;
|
||||
}
|
||||
|
||||
private String type;
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
private String permission;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(this == o) {
|
||||
return true;
|
||||
}
|
||||
if(o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
MenuDto menuDto = (MenuDto) o;
|
||||
return Objects.equals(menuId, menuDto.menuId);
|
||||
}
|
||||
|
||||
private String title;
|
||||
|
||||
private Integer menuSort;
|
||||
|
||||
private String path;
|
||||
private String name;
|
||||
|
||||
private String component;
|
||||
|
||||
private String pid;
|
||||
|
||||
private Integer subCount;
|
||||
|
||||
private Boolean iframe;
|
||||
|
||||
private String systemType;
|
||||
|
||||
private Boolean cache;
|
||||
|
||||
private Boolean hidden;
|
||||
|
||||
private String componentName;
|
||||
|
||||
private String icon;
|
||||
|
||||
private boolean hasChildren;
|
||||
|
||||
private boolean leaf;
|
||||
|
||||
public Boolean getHasChildren() {
|
||||
return subCount > 0;
|
||||
}
|
||||
|
||||
public Boolean getLeaf() {
|
||||
return subCount <= 0;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
MenuDto menuDto = (MenuDto) o;
|
||||
return Objects.equals(menuId, menuDto.menuId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(menuId);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(menuId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -17,34 +17,37 @@ package org.nl.system.service.menu.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 构建前端路由时用到
|
||||
*
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-20
|
||||
*/
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
public class MenuVo implements Serializable {
|
||||
public class MenuVo implements Serializable{
|
||||
private String name;
|
||||
private String path;
|
||||
private Boolean hidden;
|
||||
private String label;
|
||||
private String router;
|
||||
private String index;
|
||||
private String redirect;
|
||||
private String component;
|
||||
private Boolean alwaysShow;
|
||||
private MenuMetaVo meta;
|
||||
|
||||
private String name;
|
||||
public void setRouter(String router) {
|
||||
this.router = router;
|
||||
if(router == null) {
|
||||
this.router = "";
|
||||
}
|
||||
}
|
||||
|
||||
private String path;
|
||||
|
||||
private Boolean hidden;
|
||||
|
||||
private String redirect;
|
||||
|
||||
private String component;
|
||||
|
||||
private Boolean alwaysShow;
|
||||
|
||||
private MenuMetaVo meta;
|
||||
|
||||
private List<MenuVo> children;
|
||||
private List<MenuVo> children;
|
||||
}
|
||||
|
||||
@@ -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.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.anno.Log;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.dao.SysMenu;
|
||||
import org.nl.system.service.menu.dao.mapper.SysMenuMapper;
|
||||
import org.nl.system.service.menu.dto.MenuDto;
|
||||
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.nl.system.service.menu.dto.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -46,421 +43,390 @@ import java.util.stream.Collectors;
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@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 ISysDictService sysDictMapper;
|
||||
|
||||
private final SysMenuMapper baseMapper;
|
||||
private final ISysDictService sysDictMapper;
|
||||
@Override
|
||||
public List<MenuDto> queryAll(Map<String,Object> param) {
|
||||
// 父节点标识
|
||||
String pid = MapUtil.getStr(param, "pid");
|
||||
return getMenus(pid).stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDto> queryAll(Map<String, Object> param) {
|
||||
// 父节点标识
|
||||
String pid = MapUtil.getStr(param, "pid");
|
||||
return getMenus(pid).stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
|
||||
}
|
||||
@Override
|
||||
public List query(MenuQuery query, PageQuery page) {
|
||||
if(StringUtils.isNotBlank(query.getBlurry())) {
|
||||
query.setPid(null);
|
||||
}
|
||||
Page<SysMenu> menuPage = this.page(page.build(SysMenu.class), query.build());
|
||||
List<MenuDto> collect = menuPage.getRecords().stream().map(menu -> this.doToDto(menu)).sorted(Comparator.comparingInt(MenuDto::getMenuSort)).collect(Collectors.toList());
|
||||
return collect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDto> getSuperior(MenuDto menuDto, List<SysMenu> menus) {
|
||||
if(menuDto.getPid() == null) {
|
||||
menus.addAll(this.findByPidIsNull());
|
||||
return menus.stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
|
||||
}
|
||||
menus.addAll(baseMapper.findByPid(menuDto.getPid()));
|
||||
return getSuperior(this.doToDto(findById(menuDto.getPid())), menus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List query(MenuQuery query, PageQuery page) {
|
||||
if (StringUtils.isNotBlank(query.getBlurry())){
|
||||
query.setPid(null);
|
||||
}
|
||||
Page<SysMenu> menuPage = this.page(page.build(SysMenu.class), query.build());
|
||||
List<MenuDto> collect = menuPage.getRecords().stream().map(menu -> this.doToDto(menu)).sorted(Comparator.comparingInt(MenuDto::getMenuSort)).collect(Collectors.toList());
|
||||
return collect;
|
||||
}
|
||||
@Override
|
||||
public SysMenu findById(String id) {
|
||||
return baseMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDto> getSuperior(MenuDto menuDto, List<SysMenu> menus) {
|
||||
if (menuDto.getPid() == null) {
|
||||
menus.addAll(this.findByPidIsNull());
|
||||
return menus.stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
|
||||
}
|
||||
menus.addAll(baseMapper.findByPid(menuDto.getPid()));
|
||||
@Override
|
||||
public List<SysMenu> findByPid(String pid) {
|
||||
return baseMapper.findByPid(pid);
|
||||
}
|
||||
|
||||
return getSuperior(this.doToDto(findById(menuDto.getPid())), menus);
|
||||
}
|
||||
@Override
|
||||
public List<SysMenu> findByPidIsNull() {
|
||||
return baseMapper.findByPidIsNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysMenu findById(String id) {
|
||||
return baseMapper.selectById(id);
|
||||
}
|
||||
@Override
|
||||
public Set<SysMenu> getChildMenus(List<SysMenu> menuList, Set<SysMenu> menuSet) {
|
||||
for(SysMenu menu : menuList) {
|
||||
menuSet.add(menu);
|
||||
List<SysMenu> menus = this.findByPid(menu.getMenuId());
|
||||
if(menus != null && menus.size() != 0) {
|
||||
getChildMenus(menus, menuSet);
|
||||
}
|
||||
}
|
||||
return menuSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> findByPid(String pid) {
|
||||
return baseMapper.findByPid(pid);
|
||||
}
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void create(SysMenu resources) {
|
||||
if(resources.getIframe()) {
|
||||
String http = "http://", https = "https://";
|
||||
if(!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) {
|
||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||
}
|
||||
}
|
||||
resources.setMenuId(IdUtil.getStringId());
|
||||
if(resources.getPid().equals("0")) {
|
||||
resources.setPid(null);
|
||||
addSystemTypeDict(resources);
|
||||
}
|
||||
baseMapper.insert(resources);
|
||||
// 计算子节点数目
|
||||
resources.setSubCount(0);
|
||||
// 更新父节点菜单数目
|
||||
updateSubCnt(resources.getPid());
|
||||
updateRootSystemType(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> findByPidIsNull() {
|
||||
return baseMapper.findByPidIsNull();
|
||||
}
|
||||
private void addSystemTypeDict(SysMenu resources) {
|
||||
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;
|
||||
Dict currentSysType = new Dict();
|
||||
currentSysType.setDictId(IdUtil.getStringId());
|
||||
currentSysType.setCode(DictConstantPool.DICT_SYS_CODE);
|
||||
currentSysType.setName(DictConstantPool.DICT_SYS_NAME);
|
||||
currentSysType.setLabel(resources.getTitle());
|
||||
currentSysType.setValue(String.valueOf(currentType));
|
||||
currentSysType.setPara1(resources.getMenuId());
|
||||
sysDictMapper.save(currentSysType);
|
||||
resources.setSystemType(String.valueOf(currentType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SysMenu> getChildMenus(List<SysMenu> menuList, Set<SysMenu> menuSet) {
|
||||
for (SysMenu menu : menuList) {
|
||||
menuSet.add(menu);
|
||||
List<SysMenu> menus = this.findByPid(menu.getMenuId());
|
||||
if (menus != null && menus.size() != 0) {
|
||||
getChildMenus(menus, menuSet);
|
||||
}
|
||||
}
|
||||
return menuSet;
|
||||
}
|
||||
private void updateRootSystemType(SysMenu sysMenu) {
|
||||
String rootMenuId = this.findRootMenuId(sysMenu.getMenuId());
|
||||
if(sysMenu.getMenuId().equals(rootMenuId)) {
|
||||
return;
|
||||
}
|
||||
SysMenu rootMenu = this.findById(rootMenuId);
|
||||
sysMenu.setSystemType(rootMenu.getSystemType());
|
||||
this.updateById(sysMenu);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void create(SysMenu resources) {
|
||||
private String findRootMenuId(String menuId) {
|
||||
SysMenu sysMenu = this.findById(menuId);
|
||||
if(StrUtil.isEmpty(sysMenu.getPid())) {
|
||||
return menuId;
|
||||
}
|
||||
else{
|
||||
return findRootMenuId(sysMenu.getPid());
|
||||
}
|
||||
}
|
||||
|
||||
if (resources.getIframe()) {
|
||||
String http = "http://", https = "https://";
|
||||
if (!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) {
|
||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||
}
|
||||
}
|
||||
resources.setMenuId(IdUtil.getStringId());
|
||||
if (resources.getPid().equals("0")) {
|
||||
resources.setPid(null);
|
||||
addSystemTypeDict(resources);
|
||||
}
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Set<SysMenu> menuSet) {
|
||||
List<String> pids = Lists.newArrayList();
|
||||
for(SysMenu menu : menuSet) {
|
||||
//解绑菜单
|
||||
baseMapper.untiedMenu(menu.getMenuId());
|
||||
baseMapper.deleteById(menu.getMenuId());
|
||||
String pid = menu.getPid();
|
||||
if(StringUtils.isBlank(pid)) {
|
||||
pids.add(menu.getMenuId());
|
||||
}
|
||||
updateSubCnt(pid);
|
||||
}
|
||||
if(!CollectionUtils.isEmpty(pids)) {
|
||||
sysDictMapper.remove(new QueryWrapper<Dict>().in("para1", pids).eq("code", DictConstantPool.DICT_SYS_CODE));
|
||||
}
|
||||
}
|
||||
|
||||
baseMapper.insert(resources);
|
||||
// 计算子节点数目
|
||||
resources.setSubCount(0);
|
||||
// 更新父节点菜单数目
|
||||
updateSubCnt(resources.getPid());
|
||||
updateRootSystemType(resources);
|
||||
}
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void update(SysMenu resources) {
|
||||
String menuId = resources.getMenuId();
|
||||
SysMenu menu = baseMapper.selectById(menuId);
|
||||
String allChild = baseMapper.findAllChild(menuId);
|
||||
List<String> allChildIds = new ArrayList<>();
|
||||
allChildIds.add(menuId);
|
||||
if(StringUtils.isNotBlank(allChild)) {
|
||||
allChildIds.addAll(Arrays.asList(allChild.split(",")));
|
||||
}
|
||||
if(allChildIds.contains(resources.getPid())) {
|
||||
throw new BadRequestException("上级不能为自己或自己的下级");
|
||||
}
|
||||
if(resources.getIframe()) {
|
||||
String http = "http://", https = "https://";
|
||||
if(!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) {
|
||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||
}
|
||||
}
|
||||
if(resources.getPid().equals("0")) {
|
||||
resources.setPid(null);
|
||||
if(StringUtils.isNotBlank(menu.getPid())) {
|
||||
addSystemTypeDict(resources);
|
||||
}
|
||||
}
|
||||
else{
|
||||
resources.setSystemType(this.findById(resources.getPid()).getSystemType());
|
||||
}
|
||||
String oldPid = menu.getPid();
|
||||
String newPid = resources.getPid();
|
||||
// 记录的父节点ID
|
||||
if(oldPid == null && newPid != null) {
|
||||
sysDictMapper.remove(new QueryWrapper<Dict>().eq("para1", menu.getMenuId()).eq("code", DictConstantPool.DICT_SYS_CODE));
|
||||
}
|
||||
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));
|
||||
}
|
||||
menu.setTitle(resources.getTitle());
|
||||
menu.setComponent(resources.getComponent());
|
||||
menu.setPath(resources.getPath());
|
||||
menu.setIcon(resources.getIcon());
|
||||
menu.setIframe(resources.getIframe());
|
||||
menu.setPid(resources.getPid());
|
||||
menu.setMenuSort(resources.getMenuSort());
|
||||
menu.setCache(resources.getCache());
|
||||
menu.setHidden(resources.getHidden());
|
||||
menu.setComponentName(resources.getComponentName());
|
||||
menu.setPermission(resources.getPermission());
|
||||
menu.setType(resources.getType());
|
||||
baseMapper.updateById(menu);
|
||||
// 计算父级菜单节点数目
|
||||
updateSubCnt(oldPid);
|
||||
updateSubCnt(newPid);
|
||||
//更新SystemType
|
||||
if(!resources.getSystemType().equals(menu.getSystemType())) {
|
||||
this.update(new UpdateWrapper<SysMenu>().set(DictConstantPool.DICT_SYS_CODE, resources.getSystemType()).in("menu_id", allChildIds));
|
||||
}
|
||||
}
|
||||
|
||||
private void addSystemTypeDict(SysMenu resources) {
|
||||
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;
|
||||
Dict currentSysType = new Dict();
|
||||
currentSysType.setDictId(IdUtil.getStringId());
|
||||
currentSysType.setCode(DictConstantPool.DICT_SYS_CODE);
|
||||
currentSysType.setName(DictConstantPool.DICT_SYS_NAME);
|
||||
currentSysType.setLabel(resources.getTitle());
|
||||
currentSysType.setValue(String.valueOf(currentType));
|
||||
currentSysType.setPara1(resources.getMenuId());
|
||||
sysDictMapper.save(currentSysType);
|
||||
resources.setSystemType(String.valueOf(currentType));
|
||||
}
|
||||
private void updateRootSystemType(SysMenu sysMenu) {
|
||||
String rootMenuId = this.findRootMenuId(sysMenu.getMenuId());
|
||||
if (sysMenu.getMenuId().equals(rootMenuId)){
|
||||
return;
|
||||
}
|
||||
SysMenu rootMenu = this.findById(rootMenuId);
|
||||
sysMenu.setSystemType(rootMenu.getSystemType());
|
||||
this.updateById(sysMenu);
|
||||
}
|
||||
private String findRootMenuId(String menuId) {
|
||||
SysMenu sysMenu = this.findById(menuId);
|
||||
if (StrUtil.isEmpty(sysMenu.getPid())) {
|
||||
return menuId;
|
||||
} else {
|
||||
return findRootMenuId(sysMenu.getPid());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 计算菜单子节点数目
|
||||
*
|
||||
* @param menuId
|
||||
*/
|
||||
private void updateSubCnt(String menuId) {
|
||||
if(menuId != null) {
|
||||
int count = baseMapper.findByPid(menuId).size();
|
||||
SysMenu sysMenu = baseMapper.selectById(menuId);
|
||||
if(ObjectUtil.isEmpty(sysMenu)) {
|
||||
return;
|
||||
}
|
||||
sysMenu.setSubCount(count);
|
||||
baseMapper.updateById(sysMenu);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Set<SysMenu> menuSet) {
|
||||
List<String> pids = Lists.newArrayList();
|
||||
for (SysMenu menu : menuSet) {
|
||||
//解绑菜单
|
||||
baseMapper.untiedMenu(menu.getMenuId());
|
||||
baseMapper.deleteById(menu.getMenuId());
|
||||
String pid = menu.getPid();
|
||||
if (StringUtils.isBlank(pid)){
|
||||
pids.add(menu.getMenuId());
|
||||
}
|
||||
updateSubCnt(pid);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(pids)){
|
||||
sysDictMapper.remove(new QueryWrapper<Dict>().in("para1", pids).eq("code", DictConstantPool.DICT_SYS_CODE));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public List<MenuDto> findByUser(String userId) {
|
||||
return baseMapper.findByUser(userId).stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void update(SysMenu resources) {
|
||||
String menuId = resources.getMenuId();
|
||||
SysMenu menu = baseMapper.selectById(menuId);
|
||||
String allChild = baseMapper.findAllChild(menuId);
|
||||
List<String> allChildIds = new ArrayList<>();
|
||||
allChildIds.add(menuId);
|
||||
if (StringUtils.isNotBlank(allChild)){
|
||||
allChildIds.addAll(Arrays.asList(allChild.split(",")));
|
||||
}
|
||||
|
||||
if (allChildIds.contains(resources.getPid())){
|
||||
throw new BadRequestException("上级不能为自己或自己的下级");
|
||||
}
|
||||
if (resources.getIframe()) {
|
||||
String http = "http://", https = "https://";
|
||||
if (!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) {
|
||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||
}
|
||||
}
|
||||
|
||||
if (resources.getPid().equals("0")) {
|
||||
resources.setPid(null);
|
||||
if (StringUtils.isNotBlank(menu.getPid())){
|
||||
addSystemTypeDict(resources);
|
||||
}
|
||||
}else {
|
||||
resources.setSystemType(this.findById(resources.getPid()).getSystemType());
|
||||
}
|
||||
String oldPid = menu.getPid();
|
||||
String newPid = resources.getPid();
|
||||
// 记录的父节点ID
|
||||
if (oldPid == null && newPid != null){
|
||||
sysDictMapper.remove(new QueryWrapper<Dict>().eq("para1",menu.getMenuId()).eq("code", DictConstantPool.DICT_SYS_CODE));
|
||||
}
|
||||
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));
|
||||
}
|
||||
menu.setTitle(resources.getTitle());
|
||||
menu.setComponent(resources.getComponent());
|
||||
menu.setPath(resources.getPath());
|
||||
menu.setIcon(resources.getIcon());
|
||||
menu.setIframe(resources.getIframe());
|
||||
menu.setPid(resources.getPid());
|
||||
menu.setMenuSort(resources.getMenuSort());
|
||||
menu.setCache(resources.getCache());
|
||||
menu.setHidden(resources.getHidden());
|
||||
menu.setComponentName(resources.getComponentName());
|
||||
menu.setPermission(resources.getPermission());
|
||||
menu.setType(resources.getType());
|
||||
baseMapper.updateById(menu);
|
||||
// 计算父级菜单节点数目
|
||||
updateSubCnt(oldPid);
|
||||
updateSubCnt(newPid);
|
||||
//更新SystemType
|
||||
if (!resources.getSystemType().equals(menu.getSystemType())){
|
||||
this.update(new UpdateWrapper<SysMenu>().set(DictConstantPool.DICT_SYS_CODE,resources.getSystemType()).in("menu_id",allChildIds));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算菜单子节点数目
|
||||
*
|
||||
* @param menuId
|
||||
*/
|
||||
private void updateSubCnt(String menuId) {
|
||||
if (menuId != null) {
|
||||
int count = baseMapper.findByPid(menuId).size();
|
||||
SysMenu sysMenu = baseMapper.selectById(menuId);
|
||||
if (ObjectUtil.isEmpty(sysMenu)) return;
|
||||
sysMenu.setSubCount(count);
|
||||
baseMapper.updateById(sysMenu);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDto> findByUser(String userId) {
|
||||
return baseMapper.findByUser(userId).stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuVo> buildMenus(List<MenuDto> menuDtos) {
|
||||
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(ObjectUtil.isEmpty(menuDTO.getPid()) ? "/" + menuDTO.getPath() : menuDTO.getPath());
|
||||
menuVo.setHidden(menuDTO.getHidden());
|
||||
// 如果不是外链
|
||||
if (!menuDTO.getIframe()) {
|
||||
if (ObjectUtil.isEmpty(menuDTO.getPid())) {
|
||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
|
||||
} else if (!ObjectUtil.isEmpty(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));
|
||||
// 处理是一级菜单并且没有子菜单的情况
|
||||
} else if (ObjectUtil.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);
|
||||
@Override
|
||||
public List<MenuVo> buildMenus(List<MenuDto> menuDtos) {
|
||||
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(ObjectUtil.isEmpty(menuDTO.getPid()) ? "/" + menuDTO.getPath() : menuDTO.getPath());
|
||||
menuVo.setHidden(menuDTO.getHidden());
|
||||
// 如果不是外链
|
||||
if(!menuDTO.getIframe()) {
|
||||
if(ObjectUtil.isEmpty(menuDTO.getPid())) {
|
||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
|
||||
}
|
||||
else if(!ObjectUtil.isEmpty(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());
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDto> buildTree(List<MenuDto> menuDtos) {
|
||||
List<MenuDto> trees = new ArrayList<>();
|
||||
Set<String> ids = new HashSet<>();
|
||||
for (MenuDto menuDTO : menuDtos) {
|
||||
if (menuDTO.getPid() == null) {
|
||||
trees.add(menuDTO);
|
||||
}
|
||||
for (MenuDto it : menuDtos) {
|
||||
if (menuDTO.getMenuId().equals(it.getPid())) {
|
||||
if (menuDTO.getChildren() == null) {
|
||||
menuDTO.setChildren(new ArrayList<>());
|
||||
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));
|
||||
// 处理是一级菜单并且没有子菜单的情况
|
||||
}
|
||||
menuDTO.getChildren().add(it);
|
||||
ids.add(it.getMenuId());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (trees.size() == 0) {
|
||||
trees = menuDtos.stream().filter(s -> !ids.contains(s.getMenuId())).collect(Collectors.toList());
|
||||
}
|
||||
return trees;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> getMenus(String pid) {
|
||||
QueryWrapper<SysMenu> queryWrapper;
|
||||
if (pid != null && !"0".equals(pid)) {
|
||||
queryWrapper = new QueryWrapper<SysMenu>().eq("pid", pid);
|
||||
} else {
|
||||
queryWrapper = new QueryWrapper<SysMenu>().isNull("pid");
|
||||
}
|
||||
return baseMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public MenuDto doToDto(SysMenu entity) {
|
||||
|
||||
MenuDto menuDto = new MenuDto();
|
||||
if (ObjectUtil.isEmpty(entity)){
|
||||
return menuDto;
|
||||
}
|
||||
menuDto.setMenuId(entity.getMenuId());
|
||||
menuDto.setType(entity.getType());
|
||||
menuDto.setPermission(entity.getPermission());
|
||||
menuDto.setTitle(entity.getTitle());
|
||||
menuDto.setMenuSort(entity.getMenuSort());
|
||||
menuDto.setPath(entity.getPath());
|
||||
menuDto.setComponent(entity.getComponent());
|
||||
menuDto.setSystemType(entity.getSystemType());
|
||||
menuDto.setPid(entity.getPid());
|
||||
menuDto.setSubCount(entity.getSubCount());
|
||||
menuDto.setIframe(entity.getIframe());
|
||||
menuDto.setCache(entity.getCache());
|
||||
menuDto.setHidden(entity.getHidden());
|
||||
menuDto.setComponentName(entity.getComponentName());
|
||||
menuDto.setIcon(entity.getIcon());
|
||||
menuDto.setCreateTime(entity.getCreateTime());
|
||||
|
||||
//构建前端需要的数据结构树
|
||||
Integer sub_count = entity.getSubCount();
|
||||
if (sub_count <= 0) {
|
||||
menuDto.setLeaf(true);
|
||||
menuDto.setHasChildren(false);
|
||||
} else {
|
||||
menuDto.setLeaf(false);
|
||||
menuDto.setHasChildren(true);
|
||||
}
|
||||
return menuDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuVo> buildMenus(String systemType) {
|
||||
Dict dict = sysDictMapper.getOne(new QueryWrapper<Dict>().eq("code", DictConstantPool.DICT_SYS_CODE).eq("value", systemType));
|
||||
if (dict == null || StringUtils.isBlank(dict.getPara1())){
|
||||
throw new BadRequestException("获取对应的系统菜单不存在");
|
||||
}
|
||||
String pid = dict.getPara1();
|
||||
List<SysMenu> menuDtoList = baseMapper.findSystemMenu(SecurityUtils.getCurrentUserId(),systemType);
|
||||
//移除系统级菜单
|
||||
menuDtoList.removeIf(a->a.getMenuId().equals(pid));
|
||||
List<MenuDto> menuDtos = this.buildTree(CopyUtil.copyList(menuDtoList, MenuDto.class));
|
||||
return this.buildMenus(menuDtos,pid);
|
||||
}
|
||||
|
||||
@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);
|
||||
else if(ObjectUtil.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);
|
||||
}
|
||||
}
|
||||
);
|
||||
return list;
|
||||
}
|
||||
list.add(menuVo);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map> getMenusByRole(String roleId, String systemType, String category) {
|
||||
baseMapper.getMenusByRole(systemType,category);
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<MenuDto> buildTree(List<MenuDto> menuDtos) {
|
||||
List<MenuDto> trees = new ArrayList<>();
|
||||
Set<String> ids = new HashSet<>();
|
||||
for(MenuDto menuDTO : menuDtos) {
|
||||
if(menuDTO.getPid() == null) {
|
||||
trees.add(menuDTO);
|
||||
}
|
||||
for(MenuDto 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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
return trees;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> getMenus(String pid) {
|
||||
QueryWrapper<SysMenu> queryWrapper;
|
||||
if(pid != null && !"0".equals(pid)) {
|
||||
queryWrapper = new QueryWrapper<SysMenu>().eq("pid", pid);
|
||||
}
|
||||
else{
|
||||
queryWrapper = new QueryWrapper<SysMenu>().isNull("pid");
|
||||
}
|
||||
return baseMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuDto doToDto(SysMenu entity) {
|
||||
MenuDto menuDto = new MenuDto();
|
||||
if(ObjectUtil.isEmpty(entity)) {
|
||||
return menuDto;
|
||||
}
|
||||
menuDto.setMenuId(entity.getMenuId());
|
||||
menuDto.setType(entity.getType());
|
||||
menuDto.setPermission(entity.getPermission());
|
||||
menuDto.setTitle(entity.getTitle());
|
||||
menuDto.setMenuSort(entity.getMenuSort());
|
||||
menuDto.setPath(entity.getPath());
|
||||
menuDto.setComponent(entity.getComponent());
|
||||
menuDto.setSystemType(entity.getSystemType());
|
||||
menuDto.setPid(entity.getPid());
|
||||
menuDto.setSubCount(entity.getSubCount());
|
||||
menuDto.setIframe(entity.getIframe());
|
||||
menuDto.setCache(entity.getCache());
|
||||
menuDto.setHidden(entity.getHidden());
|
||||
menuDto.setComponentName(entity.getComponentName());
|
||||
menuDto.setIcon(entity.getIcon());
|
||||
menuDto.setCreateTime(entity.getCreateTime());
|
||||
//构建前端需要的数据结构树
|
||||
Integer sub_count = entity.getSubCount();
|
||||
if(sub_count <= 0) {
|
||||
menuDto.setLeaf(true);
|
||||
menuDto.setHasChildren(false);
|
||||
}
|
||||
else{
|
||||
menuDto.setLeaf(false);
|
||||
menuDto.setHasChildren(true);
|
||||
}
|
||||
return menuDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuInfoDto> buildMenus(String systemType) {
|
||||
Dict dict = sysDictMapper.getOne(new QueryWrapper<Dict>().eq("code", DictConstantPool.DICT_SYS_CODE).eq("value", systemType));
|
||||
if(dict == null || StringUtils.isBlank(dict.getPara1())) {
|
||||
throw new BadRequestException("获取对应的系统菜单不存在");
|
||||
}
|
||||
String pid = dict.getPara1();
|
||||
List<SysMenu> menuDtoList = baseMapper.findSystemMenu(SecurityUtils.getCurrentUserId(), systemType);
|
||||
//移除系统级菜单
|
||||
menuDtoList.removeIf(a -> a.getMenuId().equals(pid));
|
||||
List<MenuInfoDto> menuDtos = this.buildMenuDto(CopyUtil.copyList(menuDtoList, MenuInfoDto.class));
|
||||
return menuDtos;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Map> getMenusByRole(String roleId, String systemType, String category) {
|
||||
baseMapper.getMenusByRole(systemType, category);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper,SysUser> impl
|
||||
if(userDetail.get("depts") != null) {
|
||||
deptService.saveUserDeptRelation(userId, (List) userDetail.get("depts"));
|
||||
}
|
||||
if(userDetail.get("roles") != null) {
|
||||
roleService.saveUserRoleRelation(userId, (List) userDetail.get("roles"));
|
||||
if(userDetail.get("rolesIds") != null) {
|
||||
roleService.saveUserRoleRelation(userId, (List) userDetail.get("rolesIds"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user