作者 RuoYi

优化用户不能删除自己

@@ -2,6 +2,7 @@ package com.ruoyi.web.controller.system; @@ -2,6 +2,7 @@ package com.ruoyi.web.controller.system;
2 2
3 import java.util.List; 3 import java.util.List;
4 import java.util.stream.Collectors; 4 import java.util.stream.Collectors;
  5 +import org.apache.commons.lang3.ArrayUtils;
5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.security.access.prepost.PreAuthorize; 7 import org.springframework.security.access.prepost.PreAuthorize;
7 import org.springframework.validation.annotation.Validated; 8 import org.springframework.validation.annotation.Validated;
@@ -173,6 +174,10 @@ public class SysUserController extends BaseController @@ -173,6 +174,10 @@ public class SysUserController extends BaseController
173 @DeleteMapping("/{userIds}") 174 @DeleteMapping("/{userIds}")
174 public AjaxResult remove(@PathVariable Long[] userIds) 175 public AjaxResult remove(@PathVariable Long[] userIds)
175 { 176 {
  177 + if (ArrayUtils.contains(userIds, getUserId()))
  178 + {
  179 + return error("当前用户不能删除");
  180 + }
176 return toAjax(userService.deleteUserByIds(userIds)); 181 return toAjax(userService.deleteUserByIds(userIds));
177 } 182 }
178 183