|
|
@@ -116,6 +116,17 @@ public class AdminController {
|
|
|
*/
|
|
|
@DeleteMapping("/delete/{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);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
|
|
|
}
|
|
|
@@ -133,21 +144,31 @@ public class AdminController {
|
|
|
if (exist.getCategory() != Admin.Category.superoot) {
|
|
|
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("账号不存在");
|
|
|
}
|
|
|
+ Boolean flag = false;
|
|
|
if (StrUtil.isNotEmpty(admin.getPhone())) {
|
|
|
boolean mobile = Validator.isMobile(admin.getPhone());
|
|
|
if (!mobile) {
|
|
|
throw BusinessRuntimeException.getInstance("请输入正确的手机号");
|
|
|
}
|
|
|
+ if (!admin.getPhone().equals(user.getPhone())) {
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
}
|
|
|
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);
|
|
|
- StpUtil.logoutByLoginId(admin.getId());
|
|
|
+ if (flag) {
|
|
|
+ StpUtil.logoutByLoginId(admin.getId());
|
|
|
+ }
|
|
|
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
|
|
|
}
|