Merge remote-tracking branch 'origin/develop' into luoyuehang_branch

pull/95/head
luoyuehang 4 weeks ago
commit 28da52ce2a

@ -1 +0,0 @@
# 本md仅用于初始化目录未创建所有子一级目录在当前目录创建文件后请自行删除

@ -1 +0,0 @@
# 本md仅用于初始化目录未创建所有子一级目录在当前目录创建文件后请自行删除

@ -1 +0,0 @@
# 本md仅用于初始化目录未创建所有子一级目录在当前目录创建文件后请自行删除

@ -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<ResultVO<List<Device>>> getDevicesByStatus(
@RequestParam String status,
@RequestParam(required = false) String areaId) {
try {
List<Device> 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<ResultVO<List<Device>>> getDevicesByType(
@RequestParam String deviceType,
@RequestParam(required = false) String areaId) {
try {
List<Device> 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()));
}
}
}

@ -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<ResultVO<List<Device>>> getDevicesByStatus(
@RequestParam String status,
@RequestParam(required = false) String areaId,
@RequestParam(required = false) String deviceType) { // 保留设备类型参数,去除默认值
@RequestParam(required = false) String areaId) {
try {
// 调用服务层方法时传递所有参数包括可能为null的deviceType
List<Device> devices = deviceStatusService.getDevicesByStatus(status, areaId, deviceType);
return ResponseEntity.ok(ResultVO.success(devices));
List<Device> 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<ResultVO<List<Device>>> getDevicesByType(
@RequestParam String deviceType,
@RequestParam(required = false) String areaId) {
try {
List<Device> 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 = "统计各状态设备数量")

@ -1 +0,0 @@
# 本md仅用于初始化目录未创建所有子一级目录在当前目录创建文件后请自行删除

@ -1 +0,0 @@
# 本md仅用于初始化目录未创建所有子一级目录在当前目录创建文件后请自行删除

@ -42,6 +42,10 @@ public interface DeviceRepository extends JpaRepository<Device, String> {
// 根据制水机ID查询关联的供水机
List<Device> findByParentMakerIdAndDeviceType(String parentMakerId, Device.DeviceType deviceType);
// 按状态和区域查询(无设备类型筛选)
// 按状态加载设备(支持区域筛选)
List<Device> findByStatusAndAreaId(Device.DeviceStatus status, String areaId);
// 按设备类型加载加载设备(支持区域筛选)
List<Device> findByDeviceTypeAndAreaId(Device.DeviceType deviceType, String areaId);
}

@ -1 +0,0 @@
# 本md仅用于初始化目录未创建所有子一级目录在当前目录创建文件后请自行删除

@ -1 +0,0 @@
# 本md仅用于初始化目录未创建所有子一级目录在当前目录创建文件后请自行删除

@ -36,6 +36,8 @@ public class DeviceService {
.orElseThrow(() -> new RuntimeException("设备不存在:" + deviceId));
}
/**
*
*/

@ -23,8 +23,13 @@ public interface DeviceStatusService {
// 批量更新设备状态
boolean batchUpdateDeviceStatus(List<String> deviceIds, String status, String remark);
// 按状态查询设备
List<Device> getDevicesByStatus(String status, String areaId, String deviceType);
// 按状态加载设备(新增)
List<Device> getDevicesByStatusWithArea(String status, String areaId);
// 按设备类型加载设备(新增)
List<Device> getDevicesByTypeWithArea(String deviceType, String areaId);
// 统计各状态设备数量
Map<String, Object> getDeviceStatusCount(String areaId, String deviceType);

@ -73,26 +73,43 @@ public class DeviceStatusServiceImpl implements DeviceStatusService {
return true;
}
/**
*
* @param status
* @param areaId IDnullnull
*/
@Override
public List<Device> 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<Device> 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 IDnullnull
*/
@Override
public List<Device> 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);
}
}

@ -1 +0,0 @@
# 本md仅用于初始化目录未创建所有子一级目录在当前目录创建文件后请自行删除

@ -1 +0,0 @@
# 本md仅用于初始化目录未创建所有子一级目录在当前目录创建文件后请自行删除
Loading…
Cancel
Save