如果角色存在用户关联 就不能是禁用状态

pro
wangwei 2 years ago
parent 1d6a2d78d7
commit 10ecccc021

@ -84,6 +84,13 @@ public class SysRoleController extends BaseController {
*/ */
@PutMapping @PutMapping
public BaseResponse edit(@Validated @RequestBody SysRole role) { public BaseResponse edit(@Validated @RequestBody SysRole role) {
//把角色改成禁用的时候 如果存在关联 不能禁用
if("1".equals(role.getStatus())){
List<SysUserRole> sysUserRoles = roleService.selectUserRoleList(role.getRoleId());
if( !sysUserRoles.isEmpty()){
return ResultVOUtils.error(500, "角色已关联用户,不能禁用!");
}
}
roleService.checkRoleAllowed(role); roleService.checkRoleAllowed(role);
roleService.checkRoleDataScope(role.getRoleId()); roleService.checkRoleDataScope(role.getRoleId());
if (Constant.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) { if (Constant.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) {

@ -15,4 +15,7 @@ public interface SysUserRoleMapper {
int insertBatch(@Param("sysUserRoles") List<SysUserRole> sysUserRoles); int insertBatch(@Param("sysUserRoles") List<SysUserRole> sysUserRoles);
List<SysUserRole> selectUserRoleList(Long roleId);
} }

@ -85,6 +85,8 @@ public interface ISysRoleService {
*/ */
void checkRoleAllowed(SysRole role); void checkRoleAllowed(SysRole role);
List<SysUserRole> selectUserRoleList(Long roleId);
/** /**
* *
* *

@ -4,8 +4,6 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.Constant; import com.glxp.api.constant.Constant;
import com.glxp.api.dao.auth.SysRoleMapper; import com.glxp.api.dao.auth.SysRoleMapper;
import com.glxp.api.dao.auth.SysRoleMenuMapper; import com.glxp.api.dao.auth.SysRoleMenuMapper;
@ -187,6 +185,11 @@ public class SysRoleServiceImpl implements ISysRoleService {
} }
} }
@Override
public List<SysUserRole> selectUserRoleList(Long roleId) {
return sysUserRoleMapper.selectUserRoleList(roleId);
}
/** /**
* *
* *

@ -15,6 +15,13 @@
on u.id = sur.user_id and sur.role_id = #{roleId} on u.id = sur.user_id and sur.role_id = #{roleId}
</select> </select>
<select id="selectUserRoleList" resultMap="SysUserRoleResult">
select *
from auth_user_role
where role_id = #{roleId}
</select>
<delete id="delete" parameterType="com.glxp.api.req.auth.FilterUserRoleRequest"> <delete id="delete" parameterType="com.glxp.api.req.auth.FilterUserRoleRequest">
DELETE DELETE

Loading…
Cancel
Save