|
|
@@ -11,10 +11,10 @@ import com.tuoheng.admin.dto.UserRoleDto; |
|
|
|
import com.tuoheng.admin.entity.OpRolePermission; |
|
|
|
import com.tuoheng.admin.entity.Role; |
|
|
|
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.RoleQuery; |
|
|
|
import com.tuoheng.admin.utils.CurrentUserUtil; |
|
|
@@ -47,7 +47,8 @@ public class RoleServiceImpl implements IRoleService { |
|
|
|
private OpRolePermissionMapper opRolePermissionMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private UserRoleMapper userRoleMapper; |
|
|
|
private UserMapper userMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@@ -124,31 +125,49 @@ public class RoleServiceImpl implements IRoleService { |
|
|
|
|
|
|
|
@Override |
|
|
|
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) { |
|
|
|
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.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(); |
|
|
|
} |
|
|
|
|