新增查询功能 #172

Merged
hnu202326010106 merged 1 commits from wanglei_branch into develop 1 week ago

@ -41,6 +41,25 @@ public class AdminController {
}
/**
* ID
*/
@GetMapping("/{adminId}")
@PreAuthorize("hasAnyRole('SUPER_ADMIN', 'AREA_ADMIN')") // 超级/区域管理员可查看
@Operation(summary = "按ID查询单个管理员", description = "根据管理员ID返回完整的管理员信息")
public ResponseEntity<ResultVO<Admin>> getAdminById(@PathVariable String adminId) {
try {
Optional<Admin> adminOpt = adminService.getAdminById(adminId);
if (adminOpt.isPresent()) {
return ResponseEntity.ok(ResultVO.success(adminOpt.get()));
} else {
return ResponseEntity.ok(ResultVO.error(404, "管理员不存在ID" + adminId));
}
} catch (Exception e) {
return ResponseEntity.ok(ResultVO.error(500, "查询管理员失败:" + e.getMessage()));
}
}
/**
*
*/

@ -2,6 +2,7 @@ package com.campus.water.controller.web;
import com.campus.water.entity.Area;
import com.campus.water.service.AreaService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
@ -164,4 +165,30 @@ public class AreaController {
.body(buildResponse(500, "查询区域详情失败:" + e.getMessage(), null));
}
}
/**
* ID
*/
@GetMapping("/campus/{areaId}")
@PreAuthorize("hasAnyRole('SUPER_ADMIN', 'AREA_ADMIN', 'REPAIRMAN')") // 与普通区域查询权限一致
@Operation(summary = "按ID查询单个校区", description = "根据区域ID返回校区信息非校区类型返回错误")
public ResponseEntity<Map<String, Object>> getCampusById(@PathVariable String areaId) {
try {
// 先调用已有的service方法查询区域
Area area = areaService.getAreaById(areaId);
// 核心过滤校区类型校验是否为campus
if (Area.AreaType.campus.equals(area.getAreaType())) {
return ResponseEntity.ok(buildResponse(200, "查询校区成功", area));
} else {
return ResponseEntity.badRequest().body(buildResponse(400, "该区域不是校区ID" + areaId, null));
}
} catch (RuntimeException e) {
// 捕获service中抛出的"区域不存在"异常
return ResponseEntity.badRequest().body(buildResponse(400, e.getMessage(), null));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(buildResponse(500, "查询校区失败:" + e.getMessage(), null));
}
}
}
Loading…
Cancel
Save