微调
This commit is contained in:
@@ -16,7 +16,8 @@ public enum UserResponseEnum {
|
||||
EXISTS_SAME_MENU_CHILDREN("A010006", "当前菜单下已存在相同的子菜单"),
|
||||
EXISTS_CHILDREN_NOT_UPDATE("A010008", "该菜单下存在子节点,无法将菜单修改为按钮"),
|
||||
EXISTS_CHILDREN_NOT_DELETE("A010007", "该节点下存在子节点,无法删除"),
|
||||
ADMINSTRATOR_ROLE_CANNOT_DELETE("A010009", "超级管理员及管理员角色禁止删除"),;
|
||||
SUPER_ADMINSTRATOR_ROLE_CANNOT_UPDATE("A010009", "禁止修改超级管理员角色"),
|
||||
SUPER_ADMINSTRATOR_ROLE_CANNOT_DELETE("A010009", "禁止删除超级管理员角色"),;
|
||||
|
||||
private String code;
|
||||
private String message;
|
||||
|
||||
@@ -38,13 +38,13 @@ public class SysFunctionController extends BaseController {
|
||||
private final ISysRoleFunctionService sysRoleFunctionService;
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("分页查询菜单树")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<List<SysFunction>> list(@RequestBody @Validated SysFunctionParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
List<SysFunction> result = sysFunctionService.listFunction(queryParam);
|
||||
@GetMapping("/likeName")
|
||||
@ApiOperation("按照名称模糊查询菜单树")
|
||||
@ApiImplicitParam(name = "keyword", value = "查询参数", required = true)
|
||||
public HttpResult<List<SysFunction>> getFunctionTreeByKeyword(@RequestParam @Validated String keyword) {
|
||||
String methodDescribe = getMethodDescribe("getFunctionTreeByKeyword");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, keyword);
|
||||
List<SysFunction> result = sysFunctionService.getFunctionTreeByKeyword(keyword);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,9 +63,9 @@ public class SysFunctionParam {
|
||||
@Pattern(regexp = PatternRegex.FUNCTION_NAME, message = UserValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("资源类型")
|
||||
@Range(min = 0, max = 3, message = UserValidMessage.PARAM_FORMAT_ERROR)
|
||||
private Integer type;
|
||||
// @ApiModelProperty("资源类型")
|
||||
// @Range(min = 0, max = 3, message = UserValidMessage.PARAM_FORMAT_ERROR)
|
||||
// private Integer type;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -13,12 +13,12 @@ import java.util.List;
|
||||
public interface ISysFunctionService extends IService<SysFunction> {
|
||||
|
||||
/**
|
||||
* 获取菜单(资源)列表
|
||||
* 根据关键字模糊查询菜单(资源)树
|
||||
*
|
||||
* @param queryParam 查询参数
|
||||
* @return 菜单列表
|
||||
* @param keyword 关键字
|
||||
* @return 菜单(资源)树
|
||||
*/
|
||||
List<SysFunction> listFunction(SysFunctionParam.QueryParam queryParam);
|
||||
List<SysFunction> getFunctionTreeByKeyword(String keyword);
|
||||
|
||||
/**
|
||||
* 添加菜单(资源)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.njcn.gather.user.user.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -37,17 +36,10 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
|
||||
private final ISysRoleFunctionService sysRoleFunctionService;
|
||||
|
||||
@Override
|
||||
public List<SysFunction> listFunction(SysFunctionParam.QueryParam queryParam) {
|
||||
LambdaQueryWrapper<SysFunction> wrapper = new LambdaQueryWrapper<>();
|
||||
if (ObjectUtil.isNotNull(queryParam)) {
|
||||
wrapper.like(StrUtil.isNotBlank(queryParam.getName()), SysFunction::getName, queryParam.getName()).eq(ObjectUtil.isNotNull(queryParam.getType()), SysFunction::getType, queryParam.getType());
|
||||
}
|
||||
wrapper.eq(SysFunction::getState, DataStateEnum.ENABLE.getCode());
|
||||
List<SysFunction> allFunctions = this.list(wrapper);
|
||||
return allFunctions.stream().filter(fun -> Objects.equals(FunctionConst.FATHER_PID, fun.getPid()))
|
||||
.peek(funS -> funS.setChildren(getChildrenList(funS, allFunctions)))
|
||||
.sorted(Comparator.comparingInt(SysFunction::getSort))
|
||||
.collect(Collectors.toList());
|
||||
public List<SysFunction> getFunctionTreeByKeyword(String keyword) {
|
||||
List<SysFunction> functionTree = this.getFunctionTree(true);
|
||||
filterTreeByName(functionTree, keyword);
|
||||
return functionTree;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,4 +192,31 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
|
||||
throw new BusinessException(UserResponseEnum.EXISTS_SAME_MENU_CHILDREN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<SysFunction> filterTreeByName(List<SysFunction> tree, String keyword) {
|
||||
if (CollectionUtils.isEmpty(tree) || !StrUtil.isNotBlank(keyword)) {
|
||||
return tree;
|
||||
}
|
||||
filter(tree, keyword);
|
||||
return tree;
|
||||
}
|
||||
|
||||
private void filter(List<SysFunction> list, String keyword) {
|
||||
for (int i = list.size() - 1; i >= 0; i--) {
|
||||
SysFunction function = list.get(i);
|
||||
List<SysFunction> children = function.getChildren();
|
||||
if (!function.getName().contains(keyword)) {
|
||||
if (!CollectionUtils.isEmpty(children)) {
|
||||
filter(children, keyword);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(function.getChildren())) {
|
||||
list.remove(i);
|
||||
}
|
||||
} else {
|
||||
if (!CollectionUtils.isEmpty(children)) {
|
||||
filter(children, keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,13 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
@Override
|
||||
public boolean updateRole(SysRoleParam.UpdateParam updateParam) {
|
||||
checkRepeat(updateParam, true);
|
||||
//不能修改超级管理员角色
|
||||
Integer count = this.lambdaQuery()
|
||||
.in(SysRole::getType, RoleConst.TYPE_SUPER_ADMINISTRATOR)
|
||||
.eq(SysRole::getId, updateParam.getId()).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).count();
|
||||
if (count > 0) {
|
||||
throw new BusinessException(UserResponseEnum.SUPER_ADMINSTRATOR_ROLE_CANNOT_UPDATE);
|
||||
}
|
||||
SysRole role = new SysRole();
|
||||
BeanUtil.copyProperties(updateParam, role);
|
||||
return this.updateById(role);
|
||||
@@ -71,12 +78,12 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
|
||||
@Override
|
||||
public boolean deleteRole(List<String> ids) {
|
||||
//超级管理员、管理员角色不能删除
|
||||
//不能删除超级管理员角色
|
||||
Integer count = this.lambdaQuery()
|
||||
.in(SysRole::getType, RoleConst.TYPE_SUPER_ADMINISTRATOR, RoleConst.TYPE_ADMINISTRATOR)
|
||||
.in(SysRole::getType, RoleConst.TYPE_SUPER_ADMINISTRATOR)
|
||||
.in(SysRole::getId, ids).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).count();
|
||||
if (count > 0) {
|
||||
throw new BusinessException(UserResponseEnum.ADMINSTRATOR_ROLE_CANNOT_DELETE);
|
||||
throw new BusinessException(UserResponseEnum.SUPER_ADMINSTRATOR_ROLE_CANNOT_DELETE);
|
||||
}
|
||||
// 删除角色和用户的绑定
|
||||
sysUserRoleService.deleteUserRoleByRoleIds(ids);
|
||||
|
||||
Reference in New Issue
Block a user