|
|
|
|
@ -8,6 +8,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
@ -119,4 +120,39 @@ public class AdminController {
|
|
|
|
|
return ResponseEntity.ok(ResultVO.error(401, "用户名或密码错误"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 管理员个人信息修改
|
|
|
|
|
* 允许当前登录用户修改自己的基本信息(不含角色/区域等敏感字段)
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/profile/update")
|
|
|
|
|
@PreAuthorize("isAuthenticated()") // 只要登录即可访问
|
|
|
|
|
@Operation(summary = "修改个人信息", description = "当前登录管理员修改自己的基本信息(不含角色)")
|
|
|
|
|
public ResponseEntity<ResultVO<Admin>> updateProfile(
|
|
|
|
|
@RequestBody Admin profile,
|
|
|
|
|
Authentication authentication) {
|
|
|
|
|
try {
|
|
|
|
|
// 1. 获取当前登录用户名
|
|
|
|
|
String currentUsername = authentication.getName();
|
|
|
|
|
|
|
|
|
|
// 2. 验证身份一致性(当前用户只能修改自己的信息)
|
|
|
|
|
Admin currentAdmin = adminService.getAdminByName(currentUsername)
|
|
|
|
|
.orElseThrow(() -> new RuntimeException("当前用户信息不存在"));
|
|
|
|
|
|
|
|
|
|
if (!currentAdmin.getAdminId().equals(profile.getAdminId())) {
|
|
|
|
|
throw new RuntimeException("无权修改其他管理员信息");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3. 过滤敏感字段(不允许修改角色和区域ID)
|
|
|
|
|
profile.setRole(currentAdmin.getRole());
|
|
|
|
|
profile.setAreaId(currentAdmin.getAreaId());
|
|
|
|
|
|
|
|
|
|
// 4. 调用服务层更新
|
|
|
|
|
Admin updatedAdmin = adminService.updateProfile(profile);
|
|
|
|
|
return ResponseEntity.ok(ResultVO.success(updatedAdmin, "个人信息更新成功"));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ResponseEntity.ok(ResultVO.error(500, "更新失败:" + e.getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|