新增:新增系统管理/菜单管理(列表、创建、修改、删除、导出)

This commit is contained in:
2023-02-16 23:01:26 +08:00
parent 1319cb3264
commit 510f86031f
306 changed files with 2375 additions and 90 deletions

View File

@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.charles7c.cnadmin.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import top.charles7c.cnadmin.system.model.entity.MenuDO;
/**
* 菜单 Mapper
*
* @author Charles7c
* @since 2023/2/15 20:30
*/
public interface MenuMapper extends BaseMapper<MenuDO> {}

View File

@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.charles7c.cnadmin.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import top.charles7c.cnadmin.system.model.entity.RoleMenuDO;
/**
* 角色和菜单 Mapper
*
* @author Charles7c
* @since 2023/2/15 20:30
*/
public interface RoleMenuMapper extends BaseMapper<RoleMenuDO> {}

View File

@@ -0,0 +1,110 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.charles7c.cnadmin.system.model.entity;
import lombok.Data;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import top.charles7c.cnadmin.common.base.BaseDO;
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
import top.charles7c.cnadmin.common.enums.MenuTypeEnum;
/**
* 菜单实体
*
* @author Charles7c
* @since 2023/2/15 20:14
*/
@Data
@TableName("sys_menu")
public class MenuDO extends BaseDO {
private static final long serialVersionUID = 1L;
/**
* 菜单 ID
*/
@TableId
private Long menuId;
/**
* 菜单名称
*/
private String menuName;
/**
* 上级菜单 ID
*/
private Long parentId;
/**
* 菜单类型1目录 2菜单 3按钮
*/
private MenuTypeEnum menuType;
/**
* 路由地址
*/
private String path;
/**
* 组件名称
*/
private String name;
/**
* 组件路径
*/
private String component;
/**
* 菜单图标
*/
private String icon;
/**
* 是否外链
*/
private Boolean isExternal;
/**
* 是否缓存
*/
private Boolean isCache;
/**
* 是否隐藏
*/
private Boolean isHidden;
/**
* 权限标识
*/
private String permission;
/**
* 菜单排序
*/
private Integer menuSort;
/**
* 状态1启用 2禁用
*/
private DisEnableStatusEnum status;
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.charles7c.cnadmin.system.model.entity;
import java.io.Serializable;
import lombok.Data;
import com.baomidou.mybatisplus.annotation.TableName;
/**
* 角色和菜单实体
*
* @author Charles7c
* @since 2023/2/15 20:20
*/
@Data
@TableName("sys_role_menu")
public class RoleMenuDO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 角色 ID
*/
private Long roleId;
/**
* 菜单 ID
*/
private Long menuId;
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.charles7c.cnadmin.system.model.query;
import java.io.Serializable;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springdoc.api.annotations.ParameterObject;
import top.charles7c.cnadmin.common.annotation.Query;
/**
* 菜单查询条件
*
* @author Charles7c
* @since 2023/2/15 20:21
*/
@Data
@ParameterObject
@Schema(description = "菜单查询条件")
public class MenuQuery implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 菜单名称
*/
@Schema(description = "菜单名称")
@Query(type = Query.Type.INNER_LIKE)
private String menuName;
/**
* 状态1启用 2禁用
*/
@Schema(description = "状态1启用 2禁用")
@Query
private Integer status;
}

View File

@@ -0,0 +1,131 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.charles7c.cnadmin.system.model.request;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import top.charles7c.cnadmin.common.base.BaseRequest;
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
import top.charles7c.cnadmin.common.enums.MenuTypeEnum;
/**
* 创建或修改菜单信息
*
* @author Charles7c
* @since 2023/2/15 20:21
*/
@Data
@Schema(description = "创建或修改菜单信息")
public class MenuRequest extends BaseRequest {
private static final long serialVersionUID = 1L;
/**
* 菜单 ID
*/
@Schema(description = "菜单 ID")
@Null(message = "新增时ID 必须为空", groups = Create.class)
@NotNull(message = "修改时ID 不能为空", groups = Update.class)
private Long menuId;
/**
* 上级菜单 ID
*/
@Schema(description = "上级菜单 ID")
private Long parentId;
/**
* 菜单名称
*/
@Schema(description = "菜单名称")
@NotBlank(message = "菜单名称不能为空")
private String menuName;
/**
* 菜单类型1目录 2菜单 3按钮
*/
@Schema(description = "菜单类型1目录 2菜单 3按钮", type = "Integer", allowableValues = {"1", "2", "3"})
@NotNull(message = "菜单类型非法")
private MenuTypeEnum menuType;
/**
* 路由地址
*/
@Schema(description = "路由地址")
private String path;
/**
* 组件名称
*/
@Schema(description = "组件名称")
private String name;
/**
* 组件路径
*/
@Schema(description = "组件路径")
private String component;
/**
* 菜单图标
*/
@Schema(description = "菜单图标")
private String icon;
/**
* 是否外链
*/
@Schema(description = "是否外链")
private Boolean isExternal;
/**
* 是否缓存
*/
@Schema(description = "是否缓存")
private Boolean isCache;
/**
* 是否隐藏
*/
@Schema(description = "是否隐藏")
private Boolean isHidden;
/**
* 权限标识
*/
@Schema(description = "权限标识")
private String permission;
/**
* 菜单排序
*/
@Schema(description = "菜单排序")
@NotNull(message = "菜单排序不能为空")
private Integer menuSort;
/**
* 状态1启用 2禁用
*/
@Schema(description = "状态1启用 2禁用", type = "Integer", allowableValues = {"1", "2"})
private DisEnableStatusEnum status;
}

View File

@@ -0,0 +1,132 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.charles7c.cnadmin.system.model.vo;
import java.util.List;
import lombok.Data;
import lombok.experimental.Accessors;
import io.swagger.v3.oas.annotations.media.Schema;
import top.charles7c.cnadmin.common.base.BaseVO;
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
import top.charles7c.cnadmin.common.enums.MenuTypeEnum;
/**
* 菜单信息
*
* @author Charles7c
* @since 2023/2/15 20:23
*/
@Data
@Accessors(chain = true)
@Schema(description = "菜单信息")
public class MenuVO extends BaseVO {
private static final long serialVersionUID = 1L;
/**
* 菜单 ID
*/
@Schema(description = "菜单 ID")
private Long menuId;
/**
* 菜单名称
*/
@Schema(description = "菜单名称")
private String menuName;
/**
* 上级菜单 ID
*/
@Schema(description = "上级菜单 ID")
private Long parentId;
/**
* 菜单类型1目录 2菜单 3按钮
*/
@Schema(description = "菜单类型1目录 2菜单 3按钮")
private MenuTypeEnum menuType;
/**
* 路由地址
*/
@Schema(description = "路由地址")
private String path;
/**
* 组件名称
*/
@Schema(description = "组件名称")
private String name;
/**
* 组件路径
*/
@Schema(description = "组件路径")
private String component;
/**
* 菜单图标
*/
@Schema(description = "菜单图标")
private String icon;
/**
* 是否外链
*/
@Schema(description = "是否外链")
private Boolean isExternal;
/**
* 是否缓存
*/
@Schema(description = "是否缓存")
private Boolean isCache;
/**
* 是否隐藏
*/
@Schema(description = "是否隐藏")
private Boolean isHidden;
/**
* 权限标识
*/
@Schema(description = "权限标识")
private String permission;
/**
* 菜单排序
*/
@Schema(description = "菜单排序")
private Integer menuSort;
/**
* 状态1启用 2禁用
*/
@Schema(description = "状态1启用 2禁用")
private DisEnableStatusEnum status;
/**
* 子菜单列表
*/
@Schema(description = "子菜单列表")
private List<MenuVO> children;
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.charles7c.cnadmin.system.service;
import java.util.List;
import cn.hutool.core.lang.tree.Tree;
import top.charles7c.cnadmin.common.base.BaseService;
import top.charles7c.cnadmin.system.model.query.MenuQuery;
import top.charles7c.cnadmin.system.model.request.MenuRequest;
import top.charles7c.cnadmin.system.model.vo.MenuVO;
/**
* 菜单业务接口
*
* @author Charles7c
* @since 2023/2/15 20:30
*/
public interface MenuService extends BaseService<MenuVO, MenuVO, MenuQuery, MenuRequest> {
/**
* 构建树
*
* @param list
* 原始列表数据
* @return 树列表
*/
List<MenuVO> buildListTree(List<MenuVO> list);
/**
* 构建树
*
* @param list
* 原始列表数据
* @return 树列表
*/
List<Tree<Long>> buildTree(List<MenuVO> list);
}

View File

@@ -0,0 +1,160 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.charles7c.cnadmin.system.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import top.charles7c.cnadmin.common.base.BaseServiceImpl;
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
import top.charles7c.cnadmin.common.util.TreeUtils;
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
import top.charles7c.cnadmin.system.mapper.MenuMapper;
import top.charles7c.cnadmin.system.model.entity.MenuDO;
import top.charles7c.cnadmin.system.model.query.MenuQuery;
import top.charles7c.cnadmin.system.model.request.MenuRequest;
import top.charles7c.cnadmin.system.model.vo.MenuVO;
import top.charles7c.cnadmin.system.service.MenuService;
/**
* 菜单业务实现类
*
* @author Charles7c
* @since 2023/2/15 20:30
*/
@Service
@RequiredArgsConstructor
public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, MenuDO, MenuVO, MenuVO, MenuQuery, MenuRequest>
implements MenuService {
@Override
@Transactional(rollbackFor = Exception.class)
public Long create(MenuRequest request) {
String menuName = request.getMenuName();
boolean isExists = this.checkNameExists(menuName, request.getParentId(), request.getMenuId());
CheckUtils.throwIf(() -> isExists, String.format("新增失败,'%s'已存在", menuName));
// 保存信息
request.setStatus(DisEnableStatusEnum.ENABLE);
return super.create(request);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(MenuRequest request) {
String menuName = request.getMenuName();
boolean isExists = this.checkNameExists(menuName, request.getParentId(), request.getMenuId());
CheckUtils.throwIf(() -> isExists, String.format("修改失败,'%s'已存在", menuName));
super.update(request);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(List<Long> ids) {
super.delete(ids);
super.lambdaUpdate().in(MenuDO::getParentId, ids).remove();
}
@Override
public List<MenuVO> buildListTree(List<MenuVO> list) {
if (CollUtil.isEmpty(list)) {
return new ArrayList<>();
}
// 去除重复子菜单列表
List<MenuVO> deDuplicationList = deDuplication(list);
return deDuplicationList.stream().map(m -> m.setChildren(this.getChildren(m, list)))
.collect(Collectors.toList());
}
/**
* 数据去重(去除重复子菜单列表)
*
* @param list
* 菜单列表
* @return 去重后菜单列表
*/
private List<MenuVO> deDuplication(List<MenuVO> list) {
List<MenuVO> deDuplicationList = new ArrayList<>();
for (MenuVO outer : list) {
boolean flag = true;
for (MenuVO inner : list) {
// 忽略重复子列表
if (inner.getMenuId().equals(outer.getParentId())) {
flag = false;
break;
}
}
if (flag) {
deDuplicationList.add(outer);
}
}
return deDuplicationList;
}
/**
* 获取指定菜单的子菜单列表
*
* @param menuVO
* 指定菜单
* @param list
* 菜单列表
* @return 子菜单列表
*/
private List<MenuVO> getChildren(MenuVO menuVO, List<MenuVO> list) {
return list.stream().filter(m -> Objects.equals(m.getParentId(), menuVO.getMenuId()))
.map(m -> m.setChildren(this.getChildren(m, list))).collect(Collectors.toList());
}
@Override
public List<Tree<Long>> buildTree(List<MenuVO> list) {
return TreeUtils.build(list, (m, tree) -> {
tree.setId(m.getMenuId());
tree.setName(m.getMenuName());
tree.setParentId(m.getParentId());
tree.setWeight(m.getMenuSort());
});
}
/**
* 检查名称是否存在
*
* @param name
* 名称
* @param parentId
* 上级 ID
* @param id
* ID
* @return 是否存在
*/
private boolean checkNameExists(String name, Long parentId, Long id) {
return super.lambdaQuery().eq(MenuDO::getMenuName, name).eq(MenuDO::getParentId, parentId)
.ne(id != null, MenuDO::getMenuId, id).exists();
}
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="top.charles7c.cnadmin.system.mapper.MenuMapper">
</mapper>