Browse Source

修改删除角色接口

tags/v1.0.0^2
chengwang 1 year ago
parent
commit
bfec9f48ed
2 changed files with 85 additions and 24 deletions
  1. +42
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/role/RoleDeleteEnum.java
  2. +43
    -24
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/role/RoleServiceImpl.java

+ 42
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/role/RoleDeleteEnum.java View File

package com.tuoheng.admin.enums.code.role;

/**
* @Author ChengWang
* @Date 2022/12/23
*/
public enum RoleDeleteEnum {

QUERY_IS_FAILED(1210600, "获取数据失败"),
ROLE_ID_IS_NULL(1210601, "角色id为空");

/**
* 错误码
*/
private int code;

/**
* 错误信息
*/
private String msg;

RoleDeleteEnum(int code, String msg){
this.code = code;
this.msg = msg;
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}
}

+ 43
- 24
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/role/RoleServiceImpl.java View File

import com.tuoheng.admin.entity.OpRolePermission; import com.tuoheng.admin.entity.OpRolePermission;
import com.tuoheng.admin.entity.Role; import com.tuoheng.admin.entity.Role;
import com.tuoheng.admin.entity.RoleMenu; import com.tuoheng.admin.entity.RoleMenu;
import com.tuoheng.admin.mapper.OpRolePermissionMapper;
import com.tuoheng.admin.mapper.RoleMapper;
import com.tuoheng.admin.mapper.RoleMenuMapper;
import com.tuoheng.admin.mapper.UserRoleMapper;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.RoleEnum;
import com.tuoheng.admin.enums.code.role.RoleDeleteEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.query.RoleClientQuery; import com.tuoheng.admin.query.RoleClientQuery;
import com.tuoheng.admin.query.RoleQuery; import com.tuoheng.admin.query.RoleQuery;
import com.tuoheng.admin.utils.CurrentUserUtil; import com.tuoheng.admin.utils.CurrentUserUtil;
private OpRolePermissionMapper opRolePermissionMapper; private OpRolePermissionMapper opRolePermissionMapper;


@Autowired @Autowired
private UserRoleMapper userRoleMapper;
private UserMapper userMapper;





@Override @Override


@Override @Override
public JsonResult deleteByList(Integer[] roleIds) { public JsonResult deleteByList(Integer[] roleIds) {
List<Role> roles = roleMapper.selectList(Wrappers.<Role>lambdaQuery().eq(Role::getStatus, 1).eq(Role::getMark, 1).eq(Role::getTenantId, CurrentUserUtil.getTenantId()));
//
List<Integer> collect = roles.stream().filter(t -> !t.getCode().equals("001"))
.filter(t -> t.getCode().equals("002"))
.filter(t -> t.getCode().equals("003")).map(t -> t.getId()).collect(Collectors.toList());
if (collect.contains(roleIds)) {
return JsonResult.error("初始化配置角色不能删除");
//校验
if(null == roleIds){
return JsonResult.error(RoleDeleteEnum.ROLE_ID_IS_NULL.getCode(),RoleDeleteEnum.ROLE_ID_IS_NULL.getMsg());
} }
//根据roleId查询是否关联的有用户
for (Integer roleId : roleIds) { for (Integer roleId : roleIds) {
List<RoleMenu> roleMenus = roleMenuMapper.selectList(Wrappers.<RoleMenu>lambdaQuery().eq(RoleMenu::getRoleId, roleId).eq(RoleMenu::getMark, 1));
if (roleMenus.size() > 0 && StringUtils.isNotEmpty(roleMenus)) {
return JsonResult.error("该角色已配置菜单不能删除!");
}
List<OpRolePermission> opRolePermissionList = opRolePermissionMapper.selectList(Wrappers.<OpRolePermission>lambdaQuery().eq(OpRolePermission::getRoleId,roleId).eq(OpRolePermission::getMark, 1));
if (opRolePermissionList.size() > 0 && StringUtils.isNotEmpty(opRolePermissionList)) {
return JsonResult.error("该角色已配置权限不能删除!");
}
List<UserRoleDto> userRoles = userRoleMapper.getListByRoleId(roleId, CurrentUserUtil.getTenantId());
if (userRoles.size() > 0 && StringUtils.isNotEmpty(userRoles)) {
return JsonResult.error("该角色已经分配用户不能删除!");
List<User> userList = userMapper.selectList(Wrappers.<User>lambdaQuery()
.eq(User::getMark, 1).eq(User::getRoleId, roleId));
if(userList.size()>0 && StringUtils.isNotEmpty(userList)){
return JsonResult.error("该角色已经绑定用户,不能删除");
} }
Role role = roleMapper.selectById(roleId); Role role = roleMapper.selectById(roleId);
role.setMark(0); role.setMark(0);
roleMapper.updateById(role);
int result = roleMapper.updateById(role);
if(result<=0){
return JsonResult.error();
}
} }
// List<Role> roles = roleMapper.selectList(Wrappers.<Role>lambdaQuery().eq(Role::getStatus, 1).eq(Role::getMark, 1).eq(Role::getTenantId, CurrentUserUtil.getTenantId()));
// //
// List<Integer> collect = roles.stream().filter(t -> !t.getCode().equals("001"))
// .filter(t -> t.getCode().equals("002"))
// .filter(t -> t.getCode().equals("003")).map(t -> t.getId()).collect(Collectors.toList());
// if (collect.contains(roleIds)) {
// return JsonResult.error("初始化配置角色不能删除");
// }
// for (Integer roleId : roleIds) {
// List<RoleMenu> roleMenus = roleMenuMapper.selectList(Wrappers.<RoleMenu>lambdaQuery().eq(RoleMenu::getRoleId, roleId).eq(RoleMenu::getMark, 1));
// if (roleMenus.size() > 0 && StringUtils.isNotEmpty(roleMenus)) {
// return JsonResult.error("该角色已配置菜单不能删除!");
// }
// List<OpRolePermission> opRolePermissionList = opRolePermissionMapper.selectList(Wrappers.<OpRolePermission>lambdaQuery().eq(OpRolePermission::getRoleId,roleId).eq(OpRolePermission::getMark, 1));
// if (opRolePermissionList.size() > 0 && StringUtils.isNotEmpty(opRolePermissionList)) {
// return JsonResult.error("该角色已配置权限不能删除!");
// }
// List<UserRoleDto> userRoles = userRoleMapper.getListByRoleId(roleId, CurrentUserUtil.getTenantId());
// if (userRoles.size() > 0 && StringUtils.isNotEmpty(userRoles)) {
// return JsonResult.error("该角色已经分配用户不能删除!");
// }
// Role role = roleMapper.selectById(roleId);
// role.setMark(0);
// roleMapper.updateById(role);
// }
return JsonResult.success(); return JsonResult.success();
} }



Loading…
Cancel
Save