diff --git a/src/main/java/com/campus/water/config/先读我.md b/src/main/java/com/campus/water/config/先读我.md deleted file mode 100644 index 3b52c1f..0000000 --- a/src/main/java/com/campus/water/config/先读我.md +++ /dev/null @@ -1 +0,0 @@ -# 本md仅用于初始化目录,未创建所有子一级目录,在当前目录创建文件后请自行删除 \ No newline at end of file diff --git a/src/main/java/com/campus/water/controller/app/先读我.md b/src/main/java/com/campus/water/controller/app/先读我.md deleted file mode 100644 index 3b52c1f..0000000 --- a/src/main/java/com/campus/water/controller/app/先读我.md +++ /dev/null @@ -1 +0,0 @@ -# 本md仅用于初始化目录,未创建所有子一级目录,在当前目录创建文件后请自行删除 \ No newline at end of file diff --git a/src/main/java/com/campus/water/controller/common/先读我.md b/src/main/java/com/campus/water/controller/common/先读我.md deleted file mode 100644 index 3b52c1f..0000000 --- a/src/main/java/com/campus/water/controller/common/先读我.md +++ /dev/null @@ -1 +0,0 @@ -# 本md仅用于初始化目录,未创建所有子一级目录,在当前目录创建文件后请自行删除 \ No newline at end of file diff --git a/src/main/java/com/campus/water/controller/web/DeviceController.java b/src/main/java/com/campus/water/controller/web/DeviceController.java index 8163470..05bdcd3 100644 --- a/src/main/java/com/campus/water/controller/web/DeviceController.java +++ b/src/main/java/com/campus/water/controller/web/DeviceController.java @@ -6,6 +6,7 @@ import com.campus.water.mapper.RepairerAuthRepository; import com.campus.water.service.DeviceService; import com.campus.water.entity.Repairman; import com.campus.water.mapper.RepairmanRepository; +import com.campus.water.service.DeviceStatusService; import com.campus.water.util.ResultVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -16,7 +17,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.security.core.Authentication; import org.springframework.security.access.prepost.PreAuthorize; -import java.util.List; // 新增List的导入语句 +import java.util.List; @RestController @RequestMapping("/api/web/device") @@ -25,6 +26,7 @@ import java.util.List; // 新增List的导入语句 public class DeviceController { private final DeviceService deviceService; + private final DeviceStatusService deviceStatusService; private final RepairmanRepository repairmanRepository; private final RepairerAuthRepository repairerAuthRepository; @@ -87,7 +89,6 @@ public class DeviceController { /** * 维修人员查询本辖区设备(按类型筛选) */ - // 在DeviceController.java中修改getAreaDevicesByTypeForRepairman方法 @GetMapping("/repairman/area-devices-by-type") @PreAuthorize("hasRole('REPAIRMAN')") @Operation(summary = "维修人员查询辖区设备(按类型)", description = "维修人员查看本辖区内指定类型的设备列表") @@ -137,4 +138,42 @@ public class DeviceController { } } + /** + * 按状态查询设备列表(支持区域筛选) + * 管理员/运维人员通用接口 + */ + @GetMapping("/by-status") + @Operation(summary = "按状态查询设备", description = "根据设备状态筛选设备列表,可选区域筛选") + public ResponseEntity>> getDevicesByStatus( + @RequestParam String status, + @RequestParam(required = false) String areaId) { + try { + List devices = deviceStatusService.getDevicesByStatusWithArea(status, areaId); + return ResponseEntity.ok(ResultVO.success(devices, "按状态查询设备成功")); + } catch (IllegalArgumentException e) { + return ResponseEntity.ok(ResultVO.error(400, e.getMessage())); + } catch (Exception e) { + return ResponseEntity.ok(ResultVO.error(500, "按状态查询设备失败: " + e.getMessage())); + } + } + + /** + * 按类型查询设备列表(支持区域筛选) + * 管理员/运维人员通用接口 + */ + @GetMapping("/by-type") + @Operation(summary = "按类型查询设备", description = "根据设备类型筛选设备列表,可选区域筛选") + public ResponseEntity>> getDevicesByType( + @RequestParam String deviceType, + @RequestParam(required = false) String areaId) { + try { + List devices = deviceStatusService.getDevicesByTypeWithArea(deviceType, areaId); + return ResponseEntity.ok(ResultVO.success(devices, "按类型查询设备成功")); + } catch (IllegalArgumentException e) { + return ResponseEntity.ok(ResultVO.error(400, e.getMessage())); + } 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/controller/web/DeviceStatusController.java b/src/main/java/com/campus/water/controller/web/DeviceStatusController.java index f091cd7..370e44c 100644 --- a/src/main/java/com/campus/water/controller/web/DeviceStatusController.java +++ b/src/main/java/com/campus/water/controller/web/DeviceStatusController.java @@ -6,7 +6,7 @@ * 1. 状态更新:单设备状态变更 * 2. 状态标记:在线/离线/故障快捷操作 * 3. 批量操作:批量更新设备状态 - * 4. 状态查询:按状态筛选设备列表 + * 4. 状态查询:按状态/类型筛选设备列表(拆分独立接口) * 5. 离线检测:查询超时离线设备 * 6. 自动检测:触发离线设备检测任务 * 安全:需要权限验证,记录操作日志 @@ -99,22 +99,42 @@ public class DeviceStatusController { } } + // ========== 替换原有复合查询接口,拆分为两个独立接口 ========== + /** + * 按状态查询设备(仅状态筛选,支持区域) + */ @GetMapping("/by-status") - @Operation(summary = "按状态查询设备", description = "根据状态和设备类型查询设备列表") + @Operation(summary = "按状态查询设备", description = "根据设备状态筛选设备列表,可选区域筛选") public ResponseEntity>> getDevicesByStatus( @RequestParam String status, - @RequestParam(required = false) String areaId, - @RequestParam(required = false) String deviceType) { // 保留设备类型参数,去除默认值 - + @RequestParam(required = false) String areaId) { try { - // 调用服务层方法时传递所有参数(包括可能为null的deviceType) - List devices = deviceStatusService.getDevicesByStatus(status, areaId, deviceType); - return ResponseEntity.ok(ResultVO.success(devices)); + List devices = deviceStatusService.getDevicesByStatusWithArea(status, areaId); + return ResponseEntity.ok(ResultVO.success(devices, "按状态查询设备成功")); + } catch (IllegalArgumentException e) { + return ResponseEntity.ok(ResultVO.error(400, e.getMessage())); } catch (Exception e) { - return ResponseEntity.ok(ResultVO.error(500, "查询设备失败: " + e.getMessage())); + return ResponseEntity.ok(ResultVO.error(500, "按状态查询设备失败: " + e.getMessage())); } } + /** + * 按类型查询设备(仅类型筛选,支持区域) + */ + @GetMapping("/by-type") + @Operation(summary = "按类型查询设备", description = "根据设备类型筛选设备列表,可选区域筛选") + public ResponseEntity>> getDevicesByType( + @RequestParam String deviceType, + @RequestParam(required = false) String areaId) { + try { + List devices = deviceStatusService.getDevicesByTypeWithArea(deviceType, areaId); + return ResponseEntity.ok(ResultVO.success(devices, "按类型查询设备成功")); + } catch (IllegalArgumentException e) { + return ResponseEntity.ok(ResultVO.error(400, e.getMessage())); + } catch (Exception e) { + return ResponseEntity.ok(ResultVO.error(500, "按类型查询设备失败: " + e.getMessage())); + } + } @GetMapping("/status-count") @Operation(summary = "设备状态数量统计", description = "统计各状态设备数量") diff --git a/src/main/java/com/campus/water/controller/web/先读我.md b/src/main/java/com/campus/water/controller/web/先读我.md deleted file mode 100644 index 3b52c1f..0000000 --- a/src/main/java/com/campus/water/controller/web/先读我.md +++ /dev/null @@ -1 +0,0 @@ -# 本md仅用于初始化目录,未创建所有子一级目录,在当前目录创建文件后请自行删除 \ No newline at end of file diff --git a/src/main/java/com/campus/water/entity/先读我.md b/src/main/java/com/campus/water/entity/先读我.md deleted file mode 100644 index 3b52c1f..0000000 --- a/src/main/java/com/campus/water/entity/先读我.md +++ /dev/null @@ -1 +0,0 @@ -# 本md仅用于初始化目录,未创建所有子一级目录,在当前目录创建文件后请自行删除 \ No newline at end of file diff --git a/src/main/java/com/campus/water/mapper/DeviceRepository.java b/src/main/java/com/campus/water/mapper/DeviceRepository.java index dd3e7aa..ab8db1d 100644 --- a/src/main/java/com/campus/water/mapper/DeviceRepository.java +++ b/src/main/java/com/campus/water/mapper/DeviceRepository.java @@ -42,6 +42,10 @@ public interface DeviceRepository extends JpaRepository { // 根据制水机ID查询关联的供水机 List findByParentMakerIdAndDeviceType(String parentMakerId, Device.DeviceType deviceType); - // 按状态和区域查询(无设备类型筛选) + + // 按状态加载设备(支持区域筛选) List findByStatusAndAreaId(Device.DeviceStatus status, String areaId); + + // 按设备类型加载加载设备(支持区域筛选) + List findByDeviceTypeAndAreaId(Device.DeviceType deviceType, String areaId); } \ No newline at end of file diff --git a/src/main/java/com/campus/water/mapper/先读我.md b/src/main/java/com/campus/water/mapper/先读我.md deleted file mode 100644 index 3b52c1f..0000000 --- a/src/main/java/com/campus/water/mapper/先读我.md +++ /dev/null @@ -1 +0,0 @@ -# 本md仅用于初始化目录,未创建所有子一级目录,在当前目录创建文件后请自行删除 \ No newline at end of file diff --git a/src/main/java/com/campus/water/security/先读我.md b/src/main/java/com/campus/water/security/先读我.md deleted file mode 100644 index 3b52c1f..0000000 --- a/src/main/java/com/campus/water/security/先读我.md +++ /dev/null @@ -1 +0,0 @@ -# 本md仅用于初始化目录,未创建所有子一级目录,在当前目录创建文件后请自行删除 \ No newline at end of file diff --git a/src/main/java/com/campus/water/service/DeviceService.java b/src/main/java/com/campus/water/service/DeviceService.java index 7bb7d77..0ac9e09 100644 --- a/src/main/java/com/campus/water/service/DeviceService.java +++ b/src/main/java/com/campus/water/service/DeviceService.java @@ -36,6 +36,8 @@ public class DeviceService { .orElseThrow(() -> new RuntimeException("设备不存在:" + deviceId)); } + + /** * 新增设备 */ diff --git a/src/main/java/com/campus/water/service/DeviceStatusService.java b/src/main/java/com/campus/water/service/DeviceStatusService.java index e2b2aa3..7fb4ee7 100644 --- a/src/main/java/com/campus/water/service/DeviceStatusService.java +++ b/src/main/java/com/campus/water/service/DeviceStatusService.java @@ -23,8 +23,13 @@ public interface DeviceStatusService { // 批量更新设备状态 boolean batchUpdateDeviceStatus(List deviceIds, String status, String remark); - // 按状态查询设备 - List getDevicesByStatus(String status, String areaId, String deviceType); + + + // 按状态加载设备(新增) + List getDevicesByStatusWithArea(String status, String areaId); + + // 按设备类型加载设备(新增) + List getDevicesByTypeWithArea(String deviceType, String areaId); // 统计各状态设备数量 Map getDeviceStatusCount(String areaId, String deviceType); diff --git a/src/main/java/com/campus/water/service/DeviceStatusServiceImpl.java b/src/main/java/com/campus/water/service/DeviceStatusServiceImpl.java index 4de8a84..f5b9bde 100644 --- a/src/main/java/com/campus/water/service/DeviceStatusServiceImpl.java +++ b/src/main/java/com/campus/water/service/DeviceStatusServiceImpl.java @@ -73,26 +73,43 @@ public class DeviceStatusServiceImpl implements DeviceStatusService { return true; } + /** + * 按状态加载设备(支持区域筛选) + * @param status 设备状态(字符串类型,需转换为枚举) + * @param areaId 区域ID(可为null,null时查询所有区域) + */ @Override - public List getDevicesByStatus(String status, String areaId, String deviceType) { - Device.DeviceStatus targetStatus = Device.DeviceStatus.valueOf(status); - - // 处理设备类型参数(允许为null) - Device.DeviceType targetType = null; - if (deviceType != null && !deviceType.isEmpty()) { - targetType = Device.DeviceType.valueOf(deviceType); - } - - // 根据设备类型是否为null执行不同查询 - if (targetType != null) { - return deviceRepository.findByStatusAndAreaIdAndDeviceType(targetStatus, areaId, targetType); - } else { - // 仅按状态和区域查询(如果有区域ID) + public List getDevicesByStatusWithArea(String status, String areaId) { + try { + Device.DeviceStatus targetStatus = Device.DeviceStatus.valueOf(status.toUpperCase()); if (areaId != null && !areaId.isEmpty()) { return deviceRepository.findByStatusAndAreaId(targetStatus, areaId); } else { return deviceRepository.findByStatus(targetStatus); } + } catch (IllegalArgumentException e) { + log.error("设备状态枚举转换失败,状态值:{}", status, e); + throw new RuntimeException("无效的设备状态:" + status); + } + } + + /** + * 按设备类型加载设备(支持区域筛选) + * @param deviceType 设备类型(字符串类型,需转换为枚举) + * @param areaId 区域ID(可为null,null时查询所有区域) + */ + @Override + public List getDevicesByTypeWithArea(String deviceType, String areaId) { + try { + Device.DeviceType targetType = Device.DeviceType.valueOf(deviceType.toUpperCase()); + if (areaId != null && !areaId.isEmpty()) { + return deviceRepository.findByDeviceTypeAndAreaId(targetType, areaId); + } else { + return deviceRepository.findByDeviceType(targetType); + } + } catch (IllegalArgumentException e) { + log.error("设备类型枚举转换失败,类型值:{}", deviceType, e); + throw new RuntimeException("无效的设备类型:" + deviceType); } } diff --git a/src/main/java/com/campus/water/service/先读我.md b/src/main/java/com/campus/water/service/先读我.md deleted file mode 100644 index 3b52c1f..0000000 --- a/src/main/java/com/campus/water/service/先读我.md +++ /dev/null @@ -1 +0,0 @@ -# 本md仅用于初始化目录,未创建所有子一级目录,在当前目录创建文件后请自行删除 \ No newline at end of file diff --git a/src/main/java/com/campus/water/util/先读我.md b/src/main/java/com/campus/water/util/先读我.md deleted file mode 100644 index 3b52c1f..0000000 --- a/src/main/java/com/campus/water/util/先读我.md +++ /dev/null @@ -1 +0,0 @@ -# 本md仅用于初始化目录,未创建所有子一级目录,在当前目录创建文件后请自行删除 \ No newline at end of file