zoujiajian 3 лет назад
Родитель
Сommit
216ea974dc
1 измененных файлов с 25 добавлено и 4 удалено
  1. 25 4
      netflix-web/src/main/java/com/cyksj/web/controller/manage/AdminController.java

+ 25 - 4
netflix-web/src/main/java/com/cyksj/web/controller/manage/AdminController.java

@@ -116,6 +116,17 @@ public class AdminController {
      */
      */
     @DeleteMapping("/delete/{id}")
     @DeleteMapping("/delete/{id}")
     public Result<String> deleteAdminById(@PathVariable Long id) {
     public Result<String> deleteAdminById(@PathVariable Long id) {
+        Long adminId = StpUtil.getLoginIdAsLong();
+        Admin exist = adminService.getById(adminId);
+        if (exist == null) {
+            throw BusinessRuntimeException.getInstance("账号不存在,请重新登录");
+        }
+        if (exist.getCategory() != Admin.Category.superoot) {
+            throw BusinessRuntimeException.getInstance("无超级管理员权限");
+        }
+        if (id.equals(adminId)) {
+            throw BusinessRuntimeException.getInstance("无法删除自己");
+        }
         adminService.removeById(id);
         adminService.removeById(id);
         return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
         return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
     }
     }
@@ -133,21 +144,31 @@ public class AdminController {
         if (exist.getCategory() != Admin.Category.superoot) {
         if (exist.getCategory() != Admin.Category.superoot) {
             throw BusinessRuntimeException.getInstance("无超级管理员权限");
             throw BusinessRuntimeException.getInstance("无超级管理员权限");
         }
         }
-        if (admin.getId() == null || adminService.getById(admin.getId()) == null) {
+        Admin user = adminService.getById(admin.getId());
+        if (admin.getId() == null || user == null) {
             throw BusinessRuntimeException.getInstance("账号不存在");
             throw BusinessRuntimeException.getInstance("账号不存在");
         }
         }
+        Boolean flag = false;
         if (StrUtil.isNotEmpty(admin.getPhone())) {
         if (StrUtil.isNotEmpty(admin.getPhone())) {
             boolean mobile = Validator.isMobile(admin.getPhone());
             boolean mobile = Validator.isMobile(admin.getPhone());
             if (!mobile) {
             if (!mobile) {
                 throw BusinessRuntimeException.getInstance("请输入正确的手机号");
                 throw BusinessRuntimeException.getInstance("请输入正确的手机号");
             }
             }
+            if (!admin.getPhone().equals(user.getPhone())) {
+                flag = true;
+            }
         }
         }
         if (StrUtil.isNotEmpty(admin.getPassWord())) {
         if (StrUtil.isNotEmpty(admin.getPassWord())) {
-            String encodePasscode = Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.SHA256).setStringData(admin.getPassWord()).toBase64String();
-            admin.setPassWord(encodePasscode);
+            String encodePwd = Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.SHA256).setStringData(admin.getPassWord()).toBase64String();
+            admin.setPassWord(encodePwd);
+            if (!encodePwd.equals(user.getPassWord())) {
+                flag = true;
+            }
         }
         }
         adminService.saveOrUpdate(admin);
         adminService.saveOrUpdate(admin);
-        StpUtil.logoutByLoginId(admin.getId());
+        if (flag) {
+            StpUtil.logoutByLoginId(admin.getId());
+        }
 
 
         return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
         return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
     }
     }