fix 删除角色时判断是否有用户
This commit is contained in:
+24
-15
@@ -13,6 +13,7 @@ import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.SysDepartTreeModel;
|
||||
import com.jero.common.system.vo.SysRoleTreeModel;
|
||||
import com.jero.modules.system.entity.*;
|
||||
@@ -182,16 +183,15 @@ public class SysRoleController {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* 通过id删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({"admin"})
|
||||
@RequiresPermissions("sys:role:del")
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.GET)
|
||||
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
|
||||
public Result<?> delete(@RequestParam(name="id") String id) {
|
||||
IPage<SysUser> pageInfo = sysUserService.getUserByRoleId(new Page<>(), id, null);
|
||||
long total = pageInfo.getTotal();
|
||||
if (total == 0) {
|
||||
@@ -201,24 +201,33 @@ public class SysRoleController {
|
||||
return Result.error("删除角色失败,该角色下存在未删除用户");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({"admin"})
|
||||
@RequiresPermissions("sys:role:del")
|
||||
@RequestMapping(value = "/deleteBatch", method = RequestMethod.GET)
|
||||
public Result<SysRole> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
Result<SysRole> result = new Result<SysRole>();
|
||||
if(oConvertUtils.isEmpty(ids)) {
|
||||
result.error500("未选中角色!");
|
||||
}else {
|
||||
sysRoleService.deleteBatchRole(ids.split(","));
|
||||
result.success("删除角色成功!");
|
||||
public Result<String> deleteBatch(@RequestParam(name="ids") String ids) {
|
||||
if (oConvertUtils.isEmpty(ids)) {
|
||||
throw new JeroBootException("未选中角色!");
|
||||
}
|
||||
return result;
|
||||
List<String> roleNames = new ArrayList<>();
|
||||
String[] split = ids.split(",");
|
||||
for (String id : split) {
|
||||
IPage<SysUser> pageInfo = sysUserService.getUserByRoleId(new Page<>(), id, null);
|
||||
long total = pageInfo.getTotal();
|
||||
if (total != 0) {
|
||||
SysRole sysRole = sysRoleService.getById(id);
|
||||
roleNames.add(sysRole.getRoleName());
|
||||
}
|
||||
}
|
||||
if (!roleNames.isEmpty()) {
|
||||
throw new JeroBootException(roleNames + "删除角色失败,角色下存在未删除用户");
|
||||
}
|
||||
sysRoleService.deleteBatchRole(split);
|
||||
return Result.OK("删除角色成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user