1. 完成 menu 模块的迁移

2. 增加 mybatis plus 的 QueryWrapperX 封装,方便拼接 SQL
This commit is contained in:
YunaiV 2021-01-08 21:36:51 +08:00
parent ea4c9e4981
commit 3e5bd01962
25 changed files with 209 additions and 269 deletions

View File

@ -59,59 +59,11 @@ public interface SysMenuMapper
/** /**
* 根据角色ID查询菜单树信息 * 根据角色ID查询菜单树信息
* *
* @param roleId 角色ID * @param roleId 角色ID
* @param menuCheckStrictly 菜单树选择项是否关联显示 * @param menuCheckStrictly 菜单树选择项是否关联显示
* @return 选中菜单列表 * @return 选中菜单列表
*/ */
public List<Integer> selectMenuListByRoleId(@Param("roleId") Long roleId, @Param("menuCheckStrictly") boolean menuCheckStrictly); public List<Integer> selectMenuListByRoleId(@Param("roleId") Long roleId, @Param("menuCheckStrictly") boolean menuCheckStrictly);
/**
* 根据菜单ID查询信息
*
* @param menuId 菜单ID
* @return 菜单信息
*/
public SysMenu selectMenuById(Long menuId);
/**
* 是否存在菜单子节点
*
* @param menuId 菜单ID
* @return 结果
*/
public int hasChildByMenuId(Long menuId);
/**
* 新增菜单信息
*
* @param menu 菜单信息
* @return 结果
*/
public int insertMenu(SysMenu menu);
/**
* 修改菜单信息
*
* @param menu 菜单信息
* @return 结果
*/
public int updateMenu(SysMenu menu);
/**
* 删除菜单管理信息
*
* @param menuId 菜单ID
* @return 结果
*/
public int deleteMenuById(Long menuId);
/**
* 校验菜单名称是否唯一
*
* @param menuName 菜单名称
* @param parentId 父菜单ID
* @return 结果
*/
public SysMenu checkMenuNameUnique(@Param("menuName") String menuName, @Param("parentId") Long parentId);
} }

View File

@ -8,6 +8,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.constant.UserConstants;
@ -30,19 +31,9 @@ import com.ruoyi.system.service.ISysMenuService;
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
public class SysMenuServiceImpl implements ISysMenuService public class SysMenuServiceImpl implements ISysMenuService {
{
public static final String PREMISSION_STRING = "perms[\"{0}\"]"; public static final String PREMISSION_STRING = "perms[\"{0}\"]";
@Autowired
private SysMenuMapper menuMapper;
@Autowired
private SysRoleMapper roleMapper;
@Autowired
private SysRoleMenuMapper roleMenuMapper;
/** /**
* 根据用户查询系统菜单列表 * 根据用户查询系统菜单列表
* *
@ -50,8 +41,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 菜单列表 * @return 菜单列表
*/ */
@Override @Override
public List<SysMenu> selectMenuList(Long userId) public List<SysMenu> selectMenuList(Long userId) {
{
return selectMenuList(new SysMenu(), userId); return selectMenuList(new SysMenu(), userId);
} }
@ -62,16 +52,12 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 菜单列表 * @return 菜单列表
*/ */
@Override @Override
public List<SysMenu> selectMenuList(SysMenu menu, Long userId) public List<SysMenu> selectMenuList(SysMenu menu, Long userId) {
{
List<SysMenu> menuList = null; List<SysMenu> menuList = null;
// 管理员显示所有菜单信息 // 管理员显示所有菜单信息
if (SysUser.isAdmin(userId)) if (SysUser.isAdmin(userId)) {
{
menuList = menuMapper.selectMenuList(menu); menuList = menuMapper.selectMenuList(menu);
} } else {
else
{
menu.getParams().put("userId", userId); menu.getParams().put("userId", userId);
menuList = menuMapper.selectMenuListByUserId(menu); menuList = menuMapper.selectMenuListByUserId(menu);
} }
@ -85,14 +71,11 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 权限列表 * @return 权限列表
*/ */
@Override @Override
public Set<String> selectMenuPermsByUserId(Long userId) public Set<String> selectMenuPermsByUserId(Long userId) {
{
List<String> perms = menuMapper.selectMenuPermsByUserId(userId); List<String> perms = menuMapper.selectMenuPermsByUserId(userId);
Set<String> permsSet = new HashSet<>(); Set<String> permsSet = new HashSet<>();
for (String perm : perms) for (String perm : perms) {
{ if (StringUtils.isNotEmpty(perm)) {
if (StringUtils.isNotEmpty(perm))
{
permsSet.addAll(Arrays.asList(perm.trim().split(","))); permsSet.addAll(Arrays.asList(perm.trim().split(",")));
} }
} }
@ -106,15 +89,11 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 菜单列表 * @return 菜单列表
*/ */
@Override @Override
public List<SysMenu> selectMenuTreeByUserId(Long userId) public List<SysMenu> selectMenuTreeByUserId(Long userId) {
{
List<SysMenu> menus = null; List<SysMenu> menus = null;
if (SecurityUtils.isAdmin(userId)) if (SecurityUtils.isAdmin(userId)) {
{
menus = menuMapper.selectMenuTreeAll(); menus = menuMapper.selectMenuTreeAll();
} } else {
else
{
menus = menuMapper.selectMenuTreeByUserId(userId); menus = menuMapper.selectMenuTreeByUserId(userId);
} }
return getChildPerms(menus, 0); return getChildPerms(menus, 0);
@ -127,8 +106,7 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 选中菜单列表 * @return 选中菜单列表
*/ */
@Override @Override
public List<Integer> selectMenuListByRoleId(Long roleId) public List<Integer> selectMenuListByRoleId(Long roleId) {
{
SysRole role = roleMapper.selectRoleById(roleId); SysRole role = roleMapper.selectRoleById(roleId);
return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly()); return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly());
} }
@ -140,37 +118,11 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 下拉树结构列表 * @return 下拉树结构列表
*/ */
@Override @Override
public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) {
{
List<SysMenu> menuTrees = buildMenuTree(menus); List<SysMenu> menuTrees = buildMenuTree(menus);
return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
} }
/**
* 根据菜单ID查询信息
*
* @param menuId 菜单ID
* @return 菜单信息
*/
@Override
public SysMenu selectMenuById(Long menuId)
{
return menuMapper.selectMenuById(menuId);
}
/**
* 是否存在菜单子节点
*
* @param menuId 菜单ID
* @return 结果
*/
@Override
public boolean hasChildByMenuId(Long menuId)
{
int result = menuMapper.hasChildByMenuId(menuId);
return result > 0 ? true : false;
}
/** /**
* 查询菜单使用数量 * 查询菜单使用数量
* *
@ -178,64 +130,10 @@ public class SysMenuServiceImpl implements ISysMenuService
* @return 结果 * @return 结果
*/ */
@Override @Override
public boolean checkMenuExistRole(Long menuId) public boolean checkMenuExistRole(Long menuId) {
{
int result = roleMenuMapper.checkMenuExistRole(menuId); int result = roleMenuMapper.checkMenuExistRole(menuId);
return result > 0 ? true : false; return result > 0 ? true : false;
} }
/**
* 新增保存菜单信息
*
* @param menu 菜单信息
* @return 结果
*/
@Override
public int insertMenu(SysMenu menu)
{
return menuMapper.insertMenu(menu);
}
/**
* 修改保存菜单信息
*
* @param menu 菜单信息
* @return 结果
*/
@Override
public int updateMenu(SysMenu menu)
{
return menuMapper.updateMenu(menu);
}
/**
* 删除菜单管理信息
*
* @param menuId 菜单ID
* @return 结果
*/
@Override
public int deleteMenuById(Long menuId)
{
return menuMapper.deleteMenuById(menuId);
}
/**
* 校验菜单名称是否唯一
*
* @param menu 菜单信息
* @return 结果
*/
@Override
public String checkMenuNameUnique(SysMenu menu)
{
Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId();
SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId());
if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue())
{
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}
} }

View File

@ -7,7 +7,7 @@ import store from '@/store'
export const DICT_TYPE = { export const DICT_TYPE = {
SYS_COMMON_STATUS: 'sys_common_status', SYS_COMMON_STATUS: 'sys_common_status',
SYS_MENU_TYPE: 'menu_type' SYS_MENU_TYPE: 'sys_menu_type'
} }
/** /**

View File

@ -13,10 +13,10 @@
<el-form-item label="状态" prop="status"> <el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="菜单状态" clearable size="small"> <el-select v-model="queryParams.status" placeholder="菜单状态" clearable size="small">
<el-option <el-option
v-for="dict in statusOptions" v-for="dict in statusDictDatas"
:key="dict.dictValue" :key="dict.value"
:label="dict.dictLabel" :label="dict.label"
:value="dict.dictValue" :value="dict.value"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
@ -106,8 +106,8 @@
<el-radio-group v-model="form.type"> <el-radio-group v-model="form.type">
<el-radio <el-radio
v-for="dict in menuTypeDictDatas" v-for="dict in menuTypeDictDatas"
:key="dict.value" :key="parseInt(dict.value)"
:label="dict.value" :label="parseInt(dict.value)"
>{{dict.label}}</el-radio> >{{dict.label}}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
@ -165,7 +165,7 @@
<el-radio <el-radio
v-for="dict in statusDictDatas" v-for="dict in statusDictDatas"
:key="dict.value" :key="dict.value"
:label="dict.value" :label="parseInt(dict.value)"
>{{dict.label}}</el-radio> >{{dict.label}}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
@ -206,8 +206,6 @@ export default {
title: "", title: "",
// //
open: false, open: false,
//
statusOptions: [],
// //
queryParams: { queryParams: {
name: undefined, name: undefined,
@ -288,9 +286,9 @@ export default {
parentId: 0, parentId: 0,
name: undefined, name: undefined,
icon: undefined, icon: undefined,
type: "1", type: SysMenuTypeEnum.DIR,
sort: undefined, sort: undefined,
status: "0" status: SysCommonStatusEnum.ENABLE
}; };
this.resetForm("form"); this.resetForm("form");
}, },
@ -329,17 +327,18 @@ export default {
submitForm: function() { submitForm: function() {
this.$refs["form"].validate(valid => { this.$refs["form"].validate(valid => {
if (valid) { if (valid) {
// route // path
if (this.form.type === ResourceTypeEnum.MENU) { if (this.form.type === SysMenuTypeEnum.DIR
|| this.form.type === SysMenuTypeEnum.MENU) {
// //
const route = this.resourceForm.route const path = this.form.path
if (route.indexOf('http://') === -1 || route.indexOf('https://') === -1) { if (path.indexOf('http://') === -1 || path.indexOf('https://') === -1) {
// route / // path /
if (this.resourceForm.pid === 0 && route.charAt(0) !== '/') { if (this.form.parentId === 0 && path.charAt(0) !== '/') {
this.messageSuccess('前端必须以 / 开头') this.msgSuccess('前端必须以 / 开头')
return return
} else if (this.resourceForm.pid !== 0 && route.charAt(0) === '/') { } else if (this.form.parentId !== 0 && path.charAt(0) === '/') {
this.messageSuccess('前端不能以 / 开头') this.msgSuccess('前端不能以 / 开头')
return return
} }
} }

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.framework.mybatis.core; package cn.iocoder.dashboard.framework.mybatis.core.dataobject;
import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data; import lombok.Data;

View File

@ -0,0 +1,93 @@
package cn.iocoder.dashboard.framework.mybatis.core.query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.Collection;
/**
* 拓展 MyBatis Plus QueryWrapper 主要增加如下功能
*
* 1. 拼接条件的方法增加 xxxIfPresent 方法用于判断值不存在的时候不要拼接到条件中
*
* @param <T> 数据类型
*/
public class QueryWrapperX<T> extends QueryWrapper<T> {
public QueryWrapperX<T> likeIfPresent(String column, String val) {
if (StringUtils.hasText(val)) {
return (QueryWrapperX<T>) super.like(column, val);
}
return this;
}
public QueryWrapperX<T> inIfPresent(String column, Collection<?> values) {
if (!CollectionUtils.isEmpty(values)) {
return (QueryWrapperX<T>) super.in(column, values);
}
return this;
}
public QueryWrapperX<T> inIfPresent(String column, Object... values) {
if (!ArrayUtils.isEmpty(values)) {
return (QueryWrapperX<T>) super.in(column, values);
}
return this;
}
public QueryWrapperX<T> eqIfPresent(String column, Object val) {
if (val != null) {
return (QueryWrapperX<T>) super.eq(column, val);
}
return this;
}
public QueryWrapperX<T> gtIfPresent(String column, Object val) {
if (val != null) {
return (QueryWrapperX<T>) super.gt(column, val);
}
return this;
}
public QueryWrapperX<T> betweenIfPresent(String column, Object val1, Object val2) {
if (val1 != null && val2 != null) {
return (QueryWrapperX<T>) super.between(column, val1, val2);
}
if (val1 != null) {
return (QueryWrapperX<T>) ge(column, val1);
}
if (val2 != null) {
return (QueryWrapperX<T>) le(column, val2);
}
return this;
}
// ========== 重写父类方法方便链式调用 ==========
@Override
public QueryWrapperX<T> eq(boolean condition, String column, Object val) {
super.eq(condition, column, val);
return this;
}
@Override
public QueryWrapperX<T> eq(String column, Object val) {
super.eq(column, val);
return this;
}
@Override
public QueryWrapperX<T> orderByDesc(String column) {
super.orderByDesc(true, column);
return this;
}
@Override
public QueryWrapperX<T> last(String lastSql) {
super.last(lastSql);
return this;
}
}

View File

@ -1,11 +1,21 @@
package cn.iocoder.dashboard.modules.system.controller.auth; package cn.iocoder.dashboard.modules.system.controller.auth;
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
import cn.iocoder.dashboard.common.pojo.CommonResult; import cn.iocoder.dashboard.common.pojo.CommonResult;
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthMenuRespVO; import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthMenuRespVO;
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthPermissionInfoRespVO; import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthPermissionInfoRespVO;
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthLoginReqVO; import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthLoginReqVO;
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthLoginRespVO; import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthLoginRespVO;
import cn.iocoder.dashboard.modules.system.convert.auth.SysAuthConvert;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO;
import cn.iocoder.dashboard.modules.system.enums.permission.MenuTypeEnum;
import cn.iocoder.dashboard.modules.system.service.auth.SysAuthService; import cn.iocoder.dashboard.modules.system.service.auth.SysAuthService;
import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService;
import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService;
import cn.iocoder.dashboard.modules.system.service.user.SysUserService;
import cn.iocoder.dashboard.util.collection.SetUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -26,6 +36,12 @@ public class SysAuthController {
@Resource @Resource
private SysAuthService authService; private SysAuthService authService;
@Resource
private SysUserService userService;
@Resource
private SysRoleService roleService;
@Resource
private SysPermissionService permissionService;
@ApiOperation("使用账号密码登录") @ApiOperation("使用账号密码登录")
@PostMapping("/login") @PostMapping("/login")
@ -38,15 +54,30 @@ public class SysAuthController {
@ApiOperation("获取登陆用户的权限信息") @ApiOperation("获取登陆用户的权限信息")
@GetMapping("/get-permission-info") @GetMapping("/get-permission-info")
public CommonResult<SysAuthPermissionInfoRespVO> getPermissionInfo() { public CommonResult<SysAuthPermissionInfoRespVO> getPermissionInfo() {
SysAuthPermissionInfoRespVO respVO = authService.getPermissionInfo(getLoginUserId(), getLoginUserRoleIds()); // 获得用户信息
return success(respVO); SysUserDO user = userService.getUser(getLoginUserId());
if (user == null) {
return null;
}
// 获得角色列表
List<SysRoleDO> roleList = roleService.listRolesFromCache(getLoginUserRoleIds());
// 获得菜单列表
List<SysMenuDO> menuList = permissionService.listRoleMenusFromCache(getLoginUserRoleIds(),
SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType(), MenuTypeEnum.BUTTON.getType()),
SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus()));
// 拼接结果返回
return success(SysAuthConvert.INSTANCE.convert(user, roleList, menuList));
} }
@ApiOperation("获得登陆用户的菜单列表") @ApiOperation("获得登陆用户的菜单列表")
@GetMapping("list-menus") @GetMapping("list-menus")
public CommonResult<List<SysAuthMenuRespVO>> listMenus() { public CommonResult<List<SysAuthMenuRespVO>> listMenus() {
List<SysAuthMenuRespVO> respVOList = authService.listMenus(getLoginUserId(), getLoginUserRoleIds()); // 获得用户拥有的菜单列表
return success(respVOList); List<SysMenuDO> menuList = permissionService.listRoleMenusFromCache(getLoginUserRoleIds(),
SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType()), // 只要目录和菜单类型
SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus())); // 只要开启的
// 转换成 Tree 结构返回
return success(SysAuthConvert.INSTANCE.buildMenuTree(menuList));
} }
} }

View File

@ -84,8 +84,8 @@ public class SysMenuController {
} }
@ApiOperation("删除菜单") @ApiOperation("删除菜单")
@PostMapping("/delete")
// @Log(title = "菜单管理", businessType = BusinessType.DELETE) // @Log(title = "菜单管理", businessType = BusinessType.DELETE)
// @DeleteMapping("/{menuId}")
public CommonResult<Boolean> deleteMenu(@RequestParam("id") Long id) { public CommonResult<Boolean> deleteMenu(@RequestParam("id") Long id) {
menuService.deleteMenu(id); menuService.deleteMenu(id);
return success(true); return success(true);

View File

@ -24,7 +24,7 @@ public class SysMenuBaseVO {
private String permission; private String permission;
@ApiModelProperty(value = "类型", required = true, example = "1", notes = "参见 SysMenuTypeEnum 枚举类") @ApiModelProperty(value = "类型", required = true, example = "1", notes = "参见 SysMenuTypeEnum 枚举类")
@NotBlank(message = "菜单类型不能为空") @NotNull(message = "菜单类型不能为空")
private Integer type; private Integer type;
@ApiModelProperty(value = "显示顺序不能为空", required = true, example = "1024") @ApiModelProperty(value = "显示顺序不能为空", required = true, example = "1024")

View File

@ -2,17 +2,14 @@ package cn.iocoder.dashboard.modules.system.controller.permission.vo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
@ApiModel("菜单列表 Request VO") @ApiModel("菜单列表 Request VO")
@Data @Data
public class SysMenuListReqVO { public class SysMenuListReqVO {
@ApiModelProperty(value = "菜单名称", example = "芋道", notes = "模糊匹配") @ApiModelProperty(value = "菜单名称", example = "芋道", notes = "模糊匹配")
private String menuName; private String name;
@ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类") @ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
private Integer status; private Integer status;

View File

@ -1,10 +1,14 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission; package cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.dashboard.modules.system.controller.permission.vo.SysMenuListReqVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper @Mapper
public interface SysMenuMapper extends BaseMapper<SysMenuDO> { public interface SysMenuMapper extends BaseMapper<SysMenuDO> {
@ -17,4 +21,13 @@ public interface SysMenuMapper extends BaseMapper<SysMenuDO> {
return selectCount(new QueryWrapper<SysMenuDO>().eq("parent_id", parentId)); return selectCount(new QueryWrapper<SysMenuDO>().eq("parent_id", parentId));
} }
default List<SysMenuDO> selectList(SysMenuListReqVO reqVO) {
return selectList(new QueryWrapperX<SysMenuDO>().likeIfPresent("name", reqVO.getName())
.eqIfPresent("status", reqVO.getStatus()));
}
default List<SysMenuDO> selectList() {
return selectList(new QueryWrapper<>());
}
} }

View File

@ -1,6 +1,6 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept; package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import javax.validation.constraints.Email; import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;

View File

@ -2,7 +2,7 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict;
import cn.iocoder.dashboard.common.enums.CommonStatusEnum; import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
import cn.iocoder.dashboard.framework.excel.Excel; import cn.iocoder.dashboard.framework.excel.Excel;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;

View File

@ -2,7 +2,7 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict;
import cn.iocoder.dashboard.common.enums.CommonStatusEnum; import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
import cn.iocoder.dashboard.framework.excel.Excel; import cn.iocoder.dashboard.framework.excel.Excel;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;

View File

@ -1,7 +1,7 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission; package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission;
import cn.iocoder.dashboard.common.enums.CommonStatusEnum; import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.dashboard.modules.system.enums.permission.MenuTypeEnum; import cn.iocoder.dashboard.modules.system.enums.permission.MenuTypeEnum;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;

View File

@ -1,7 +1,7 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission; package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission;
import cn.iocoder.dashboard.framework.excel.Excel; import cn.iocoder.dashboard.framework.excel.Excel;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;

View File

@ -1,6 +1,6 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission; package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;

View File

@ -1,6 +1,6 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission; package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;

View File

@ -1,6 +1,6 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission; package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;

View File

@ -2,7 +2,7 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user;
import cn.iocoder.dashboard.framework.excel.Excel; import cn.iocoder.dashboard.framework.excel.Excel;
import cn.iocoder.dashboard.framework.excel.Excels; import cn.iocoder.dashboard.framework.excel.Excels;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDept; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDept;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;

View File

@ -24,6 +24,6 @@ public interface SysErrorCodeConstants {
ErrorCode MENU_PARENT_ERROR = new ErrorCode(1002002002, "不能设置自己为父菜单"); ErrorCode MENU_PARENT_ERROR = new ErrorCode(1002002002, "不能设置自己为父菜单");
ErrorCode MENU_NOT_EXISTS = new ErrorCode(1002002003, "菜单不存在"); ErrorCode MENU_NOT_EXISTS = new ErrorCode(1002002003, "菜单不存在");
ErrorCode MENU_EXISTS_CHILDREN = new ErrorCode(1002002004, "存在子菜单,无法删除"); ErrorCode MENU_EXISTS_CHILDREN = new ErrorCode(1002002004, "存在子菜单,无法删除");
ErrorCode MENU_PARENT_NOT_MENU = new ErrorCode(1002002005, "父菜单的类型必须是菜单"); ErrorCode MENU_PARENT_NOT_DIR_OR_MENU = new ErrorCode(1002002005, "父菜单的类型必须是目录或者菜单");
} }

View File

@ -1,11 +1,6 @@
package cn.iocoder.dashboard.modules.system.service.auth; package cn.iocoder.dashboard.modules.system.service.auth;
import cn.iocoder.dashboard.framework.security.core.service.SecurityFrameworkService; import cn.iocoder.dashboard.framework.security.core.service.SecurityFrameworkService;
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthPermissionInfoRespVO;
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthMenuRespVO;
import java.util.List;
import java.util.Set;
/** /**
* 认证 Service 接口 * 认证 Service 接口
@ -18,28 +13,4 @@ public interface SysAuthService extends SecurityFrameworkService {
String login(String username, String password, String captchaUUID, String captchaCode); String login(String username, String password, String captchaUUID, String captchaCode);
/**
* 获得用户的基本信息
*
* 这里传输 roleIds 参数的原因是该参数是从 LoginUser 缓存中获取到的而我们校验权限时也是从 LoginUser 缓存中获取 roleIds
* 通过这样的方式保持一致
*
* @param userId 用户编号
* @param roleIds 用户拥有的角色编号数组
* @return 用户的信息包括角色权限和菜单权限
*/
SysAuthPermissionInfoRespVO getPermissionInfo(Long userId, Set<Long> roleIds);
/**
* 获得用户的菜单 Vue 路由
*
* 这里传输 roleIds 参数的原因是该参数是从 LoginUser 缓存中获取到的而我们校验权限时也是从 LoginUser 缓存中获取 roleIds
* 通过这样的方式保持一致
*
* @param userId 用户编号
* @param roleIds 用户拥有的角色编号数组
* @return 菜单 Vue 路由
*/
List<SysAuthMenuRespVO> listMenus(Long userId, Set<Long> roleIds);
} }

View File

@ -226,31 +226,4 @@ public class SysAuthServiceImpl implements SysAuthService {
loginUserRedisDAO.set(sessionId, loginUser); loginUserRedisDAO.set(sessionId, loginUser);
} }
@Override
public SysAuthPermissionInfoRespVO getPermissionInfo(Long userId, Set<Long> roleIds) {
// 获得用户信息
SysUserDO user = userService.getUser(userId);
if (user == null) {
return null;
}
// 获得角色列表
List<SysRoleDO> roleList = roleService.listRolesFromCache(roleIds);
// 获得菜单列表
List<SysMenuDO> menuList = permissionService.listRoleMenusFromCache(roleIds,
SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType(), MenuTypeEnum.BUTTON.getType()),
SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus()));
// 拼接结果返回
return SysAuthConvert.INSTANCE.convert(user, roleList, menuList);
}
@Override
public List<SysAuthMenuRespVO> listMenus(Long userId, Set<Long> roleIds) {
// 获得用户拥有的菜单列表
List<SysMenuDO> menuList = permissionService.listRoleMenusFromCache(roleIds,
SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType()), // 只要目录和菜单类型
SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus())); // 只要开启的
// 转换成 Tree 结构返回
return SysAuthConvert.INSTANCE.buildMenuTree(menuList);
}
} }

View File

@ -65,7 +65,7 @@ public class SysMenuServiceImpl implements SysMenuService {
@Override @Override
@PostConstruct @PostConstruct
public void init() { public void init() {
List<SysMenuDO> menuList = menuMapper.selectList(null); List<SysMenuDO> menuList = menuMapper.selectList();
ImmutableMap.Builder<Long, SysMenuDO> menuCacheBuilder = ImmutableMap.builder(); ImmutableMap.Builder<Long, SysMenuDO> menuCacheBuilder = ImmutableMap.builder();
ImmutableMultimap.Builder<String, SysMenuDO> permMenuCacheBuilder = ImmutableMultimap.builder(); ImmutableMultimap.Builder<String, SysMenuDO> permMenuCacheBuilder = ImmutableMultimap.builder();
menuList.forEach(menuDO -> { menuList.forEach(menuDO -> {
@ -79,7 +79,7 @@ public class SysMenuServiceImpl implements SysMenuService {
@Override @Override
public List<SysMenuRespVO> listMenus(SysMenuListReqVO reqVO) { public List<SysMenuRespVO> listMenus(SysMenuListReqVO reqVO) {
List<SysMenuDO> list = menuMapper.selectList(null); List<SysMenuDO> list = menuMapper.selectList(reqVO);
// TODO 排序 // TODO 排序
return SysMenuConvert.INSTANCE.convertList(list); return SysMenuConvert.INSTANCE.convertList(list);
} }
@ -240,9 +240,10 @@ public class SysMenuServiceImpl implements SysMenuService {
if (menu == null) { if (menu == null) {
throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_EXISTS); throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_EXISTS);
} }
// 父菜单必须是目录类型 // 父菜单必须是目录或者菜单类型
if (!MenuTypeEnum.DIR.getType().equals(menu.getType())) { if (!MenuTypeEnum.DIR.getType().equals(menu.getType())
throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_MENU); && !MenuTypeEnum.MENU.getType().equals(menu.getType())) {
throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_DIR_OR_MENU);
} }
} }

View File

@ -38,3 +38,15 @@ yudao:
timeout: 5m timeout: 5m
width: 160 width: 160
height: 60 height: 60
# MyBatis Plus 的配置项
mybatis-plus:
configuration:
map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
global-config:
db-config:
id-type: auto # 自增 ID
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
mapper-locations: classpath*:mapper/*.xml
type-aliases-package: cn.iocoder.dashboard.modules.*.dal.mysql.dataobject