From 120367336d262619c7e3145cf0ea438fa4468b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=AB=9E=E7=94=B1?= <1193626695@qq.com> Date: Fri, 12 Dec 2025 14:51:17 +0800 Subject: [PATCH] =?UTF-8?q?repair=E4=BA=BA=E5=91=98=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/web/RepairmanController.java | 72 +++++++++++++++++++ .../water/mapper/RepairmanRepository.java | 6 ++ .../water/service/RepairmanService.java | 55 ++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 src/main/java/com/campus/water/controller/web/RepairmanController.java create mode 100644 src/main/java/com/campus/water/service/RepairmanService.java diff --git a/src/main/java/com/campus/water/controller/web/RepairmanController.java b/src/main/java/com/campus/water/controller/web/RepairmanController.java new file mode 100644 index 0000000..49dc261 --- /dev/null +++ b/src/main/java/com/campus/water/controller/web/RepairmanController.java @@ -0,0 +1,72 @@ +package com.campus.water.controller.web; + +import com.campus.water.entity.Repairman; +import com.campus.water.service.RepairmanService; +import com.campus.water.util.ResultVO; +import io.swagger.v3.oas.annotations.Operation; +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.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/api/web/repairman") +@RequiredArgsConstructor +@Tag(name = "维修人员管理接口", description = "Web管理端维修人员列表查询接口") +public class RepairmanController { + + private final RepairmanService repairmanService; + + /** + * 获取维修人员列表(支持多条件筛选) + * @param name 姓名模糊查询(可选) + * @param areaId 区域ID筛选(可选) + * @param status 状态筛选(可选,值:idle/busy/vacation) + */ + @GetMapping("/list") + @PreAuthorize("hasAnyRole('SUPER_ADMIN', 'AREA_ADMIN')") // 仅管理员可访问 + @Operation(summary = "获取维修人员列表", description = "支持按姓名、区域和状态筛选维修人员") + public ResponseEntity>> getRepairmanList( + @RequestParam(required = false) String name, + @RequestParam(required = false) String areaId, + @RequestParam(required = false) String status + ) { + try { + // 转换状态参数为枚举类型 + Repairman.RepairmanStatus repairmanStatus = status != null + ? Repairman.RepairmanStatus.valueOf(status) + : null; + + // 调用服务层查询 + List repairmanList = repairmanService.getRepairmanList(name, areaId, repairmanStatus); + return ResponseEntity.ok(ResultVO.success(repairmanList)); + } catch (IllegalArgumentException e) { + // 处理枚举参数错误 + return ResponseEntity.ok(ResultVO.error(400, "无效的状态参数: " + e.getMessage())); + } catch (Exception e) { + // 处理其他异常 + return ResponseEntity.ok(ResultVO.error(500, "查询维修人员列表失败: " + e.getMessage())); + } + } + + /** + * 获取所有维修人员状态枚举 + */ + @GetMapping("/status") + @PreAuthorize("hasAnyRole('SUPER_ADMIN', 'AREA_ADMIN')") + @Operation(summary = "获取维修人员状态列表", description = "返回所有可选状态(idle/busy/vacation)") + public ResponseEntity> getAllStatus() { + try { + Repairman.RepairmanStatus[] statuses = repairmanService.getAllStatus(); + return ResponseEntity.ok(ResultVO.success(statuses)); + } catch (Exception e) { + return ResponseEntity.ok(ResultVO.error(500, "获取状态列表失败:" + e.getMessage())); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/campus/water/mapper/RepairmanRepository.java b/src/main/java/com/campus/water/mapper/RepairmanRepository.java index ee1841d..a0ceacc 100644 --- a/src/main/java/com/campus/water/mapper/RepairmanRepository.java +++ b/src/main/java/com/campus/water/mapper/RepairmanRepository.java @@ -21,4 +21,10 @@ public interface RepairmanRepository extends JpaRepository { // 查询评分高于阈值的维修人员 List findByRatingGreaterThanEqual(Double minRating); + + // 新增姓名相关查询方法 + List findByRepairmanNameContaining(String name); + List findByRepairmanNameContainingAndAreaId(String name, String areaId); + List findByRepairmanNameContainingAndStatus(String name, Repairman.RepairmanStatus status); + List findByRepairmanNameContainingAndAreaIdAndStatus(String name, String areaId, Repairman.RepairmanStatus status); } \ No newline at end of file diff --git a/src/main/java/com/campus/water/service/RepairmanService.java b/src/main/java/com/campus/water/service/RepairmanService.java new file mode 100644 index 0000000..a8163d2 --- /dev/null +++ b/src/main/java/com/campus/water/service/RepairmanService.java @@ -0,0 +1,55 @@ +package com.campus.water.service; + +import com.campus.water.entity.Repairman; +import com.campus.water.mapper.RepairmanRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 维修人员服务类(合并接口+实现) + */ +@Service +@RequiredArgsConstructor +public class RepairmanService { + + private final RepairmanRepository repairmanRepository; + + /** + * 获取维修人员列表(支持多条件筛选) + * @param name 维修人员姓名(模糊查询,可选) + * @param areaId 区域ID(可选) + * @param status 维修人员状态(可选) + * @return 符合条件的维修人员列表 + */ + public List getRepairmanList(String name, String areaId, Repairman.RepairmanStatus status) { + // 组合查询条件(与原实现逻辑完全一致) + if (name != null && !name.isEmpty() && areaId != null && !areaId.isEmpty() && status != null) { + return repairmanRepository.findByRepairmanNameContainingAndAreaIdAndStatus(name, areaId, status); + } else if (name != null && !name.isEmpty() && areaId != null && !areaId.isEmpty()) { + return repairmanRepository.findByRepairmanNameContainingAndAreaId(name, areaId); + } else if (name != null && !name.isEmpty() && status != null) { + return repairmanRepository.findByRepairmanNameContainingAndStatus(name, status); + } else if (areaId != null && !areaId.isEmpty() && status != null) { + return repairmanRepository.findByAreaIdAndStatus(areaId, status); + } else if (name != null && !name.isEmpty()) { + return repairmanRepository.findByRepairmanNameContaining(name); + } else if (areaId != null && !areaId.isEmpty()) { + return repairmanRepository.findByAreaId(areaId); + } else if (status != null) { + return repairmanRepository.findByStatus(status); + } else { + // 查询全部 + return repairmanRepository.findAll(); + } + } + + /** + * 获取所有维修人员状态枚举 + * @return 维修人员状态枚举数组 + */ + public Repairman.RepairmanStatus[] getAllStatus() { + return Repairman.RepairmanStatus.values(); + } +} \ No newline at end of file -- 2.34.1