Commit b20ae0d1 authored by fangxinjiang's avatar fangxinjiang

数字

parent 12160ce3
......@@ -67,6 +67,11 @@ public interface CommonConstants {
*/
String BACK_END_PROJECT = "yifu";
/**
* 获取一条数据的后缀
*/
String LAST_ONE_SQL = " limit 1";
/**
* 成功标记
*/
......
......@@ -103,6 +103,11 @@ public interface ErrorCodes {
*/
String SYS_ROLE_DELETE_SYSTEM = "sys.role.delete.system";
/**
* 该角色下还有关联的用户,请先将用户转移到其他角色!
*/
String SYS_ROLE_DELETE_EXIST_USER = "sys.role.delete.existing.user";
/**
* 系统内置角色不能修改
*/
......
......@@ -27,3 +27,5 @@ sys.dict.delete.existing=\u5B57\u5178\u5B58\u5728\u4E0B\u7EA7\u8282\u70B9\u4E0D\
sys.role.delete.system=\u7CFB\u7EDF\u5185\u7F6E\u89D2\u8272\u4E0D\u80FD\u5220\u9664
sys.role.update.system=\u7CFB\u7EDF\u5185\u7F6E\u89D2\u8272\u4E0D\u80FD\u4FEE\u6539
sys.role.delete.existing.user=\u8be5\u89d2\u8272\u4e0b\u8fd8\u6709\u5173\u8054\u7684\u7528\u6237\uff0c\u8bf7\u5148\u5c06\u7528\u6237\u8f6c\u79fb\u5230\u5176\u4ed6\u89d2\u8272%21
......@@ -16,7 +16,9 @@
package com.yifu.cloud.plus.v1.yifu.admin.api.dto;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
......@@ -37,6 +39,15 @@ public class UserDTO extends SysUser {
private Long deptId;
/**
* 0-正常,1-删除
*/
private String delFlag;
/**
* 0-系统,1-普通用户
*/
private String systemFlag;
/**
* 新密码
*/
......
......@@ -17,7 +17,11 @@
package com.yifu.cloud.plus.v1.yifu.admin.controller;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.yifu.admin.api.dto.UserDTO;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysMenu;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserVO;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysMenuService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
......@@ -47,6 +51,18 @@ public class MenuController {
private final SysMenuService sysMenuService;
/**
* 分页查询用户
* @param page 参数集
* @param sysMenu 查询参数列表
* @return 用户集合
*/
@GetMapping("/page")
public R<IPage<List<SysMenu>>> getMenuPage(Page page, SysMenu sysMenu) {
return R.ok(sysMenuService.getMenuPage(page, sysMenu));
}
/**
* 返回当前用户的树形菜单集合
* @param parentId 父节点ID
......
......@@ -17,6 +17,8 @@
package com.yifu.cloud.plus.v1.yifu.admin.service;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysMenu;
......@@ -75,4 +77,5 @@ public interface SysMenuService extends IService<SysMenu> {
*/
void clearMenuCache();
IPage<List<SysMenu>> getMenuPage(Page page, SysMenu sysMenu);
}
......@@ -20,9 +20,15 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.admin.api.dto.SysLogDTO;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysLog;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysMenu;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysRoleMenu;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysMenuMapper;
......@@ -142,6 +148,37 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
}
@Override
public IPage<List<SysMenu>> getMenuPage(Page page, SysMenu sysMenu) {
sysMenu.setDelFlag(CommonConstants.STATUS_DEL);
return baseMapper.selectPage(page,buildQueryWrapper(sysMenu));
}
/**
* 构建查询的 wrapper
* @param sysMenu 查询条件
* @return LambdaQueryWrapper
*/
private LambdaQueryWrapper buildQueryWrapper(SysMenu sysMenu) {
LambdaQueryWrapper<SysMenu> wrapper = Wrappers.lambdaQuery();
if (StrUtil.isNotBlank(sysMenu.getFlag())) {
wrapper.eq(SysMenu::getFlag, sysMenu.getFlag());
}
if (StrUtil.isNotBlank(sysMenu.getName())){
wrapper.eq(SysMenu::getName,sysMenu.getMenuId());
}
if (StrUtil.isNotBlank(sysMenu.getSystemFlag())){
wrapper.eq(SysMenu::getSystemFlag,sysMenu.getSystemFlag());
}
if (StrUtil.isNotBlank(sysMenu.getType())){
wrapper.eq(SysMenu::getType,sysMenu.getType());
}
if (StrUtil.isNotBlank(sysMenu.getDelFlag())){
wrapper.eq(SysMenu::getDelFlag,sysMenu.getDelFlag());
}
return wrapper;
}
@NotNull
private Function<SysMenu, TreeNode<Long>> getNodeFunction() {
return menu -> {
......
......@@ -27,11 +27,15 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDict;
import com.pig4cloud.plugin.excel.vo.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysRole;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysRoleMenu;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUserRole;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.RoleExcelVO;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysRoleMapper;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysRoleMenuMapper;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysUserMapper;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysUserRoleMapper;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysRoleService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.enums.DictTypeEnum;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
......@@ -63,6 +67,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
private final SysRoleMenuMapper sysRoleMenuMapper;
private final SysUserRoleMapper sysUserRoleMapper;
/**
* 通过角色ID,删除角色,并清空角色菜单缓存
* @param id
......@@ -73,9 +79,15 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
@CacheEvict(value = CacheConstants.MENU_DETAILS, allEntries = true)
public Boolean removeRoleById(Long id) {
SysRole sysRole = this.getById(id);
String type = "0";
if (Common.isEmpty(sysRole)){
return false;
}
SysUserRole userRole =sysUserRoleMapper.selectOne(Wrappers.<SysUserRole>query().lambda()
.eq(SysUserRole::getRoleId,sysRole.getRoleId()).last(CommonConstants.LAST_ONE_SQL));
//已存在用户
Assert.state(!Common.isEmpty(userRole),MsgUtils.getMessage(ErrorCodes.SYS_ROLE_DELETE_EXIST_USER));
//系统内置
Assert.state(!type.equals(sysRole.getSystemFlag()),MsgUtils.getMessage(ErrorCodes.SYS_ROLE_DELETE_SYSTEM));
Assert.state(!CommonConstants.ZERO_String.equals(sysRole.getSystemFlag()),MsgUtils.getMessage(ErrorCodes.SYS_ROLE_DELETE_SYSTEM));
sysRoleMenuMapper.delete(Wrappers.<SysRoleMenu>update().lambda().eq(SysRoleMenu::getRoleId, id));
return this.removeById(id);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment