| | |
| | | |
| | | // 设备类型过滤 |
| | | if (deviceType != null && !deviceType.trim().isEmpty()) { |
| | | String convertedDeviceType = convertDeviceTypeFromString(deviceType); |
| | | if (convertedDeviceType != null) { |
| | | wrapper.eq(DeviceConfig::getDeviceType, convertedDeviceType); |
| | | } |
| | | wrapper.eq(DeviceConfig::getDeviceType, deviceType.trim()); |
| | | } |
| | | |
| | | // 设备状态过滤 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 字符串转换为设备类型 |
| | | */ |
| | | private String convertDeviceTypeFromString(String deviceType) { |
| | | if (deviceType == null) return null; |
| | | |
| | | switch (deviceType.trim().toLowerCase()) { |
| | | case "load_vehicle": |
| | | case "上大车": |
| | | case "1": |
| | | return DeviceConfig.DeviceType.LOAD_VEHICLE; |
| | | case "large_glass": |
| | | case "大理片": |
| | | case "2": |
| | | return DeviceConfig.DeviceType.LARGE_GLASS; |
| | | case "glass_storage": |
| | | case "玻璃存储": |
| | | case "3": |
| | | return DeviceConfig.DeviceType.GLASS_STORAGE; |
| | | default: |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 字符串转换为状态 |
| | |
| | | } |
| | | |
| | | // 设备类型过滤 |
| | | if (deviceType != null && !deviceType.trim().isEmpty()) { |
| | | String convertedDeviceType = convertDeviceTypeFromString(deviceType); |
| | | if (convertedDeviceType != null) { |
| | | wrapper.eq(DeviceConfig::getDeviceType, convertedDeviceType); |
| | | } |
| | | } |
| | | if (deviceType != null && !deviceType.trim().isEmpty()) { |
| | | wrapper.eq(DeviceConfig::getDeviceType, deviceType.trim()); |
| | | } |
| | | |
| | | // 设备状态过滤 |
| | | if (deviceStatus != null && !deviceStatus.trim().isEmpty()) { |
| | |
| | | |
| | | @Override |
| | | public List<String> getAllDeviceTypes() { |
| | | List<String> deviceTypes = new ArrayList<>(); |
| | | deviceTypes.add("PLC设备"); |
| | | deviceTypes.add("传感器设备"); |
| | | deviceTypes.add("执行器设备"); |
| | | deviceTypes.add("人机界面设备"); |
| | | try { |
| | | // 从数据库中查询所有已存在的设备类型(去重) |
| | | LambdaQueryWrapper<DeviceConfig> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.select(DeviceConfig::getDeviceType); |
| | | wrapper.eq(DeviceConfig::getIsDeleted, 0); |
| | | wrapper.isNotNull(DeviceConfig::getDeviceType); |
| | | wrapper.ne(DeviceConfig::getDeviceType, ""); |
| | | |
| | | List<DeviceConfig> devices = list(wrapper); |
| | | List<String> deviceTypes = devices.stream() |
| | | .map(DeviceConfig::getDeviceType) |
| | | .filter(Objects::nonNull) |
| | | .filter(type -> !type.trim().isEmpty()) |
| | | .distinct() |
| | | .sorted() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果数据库中没有设备类型,返回默认类型 |
| | | if (deviceTypes.isEmpty()) { |
| | | deviceTypes.add(DeviceConfig.DeviceType.LOAD_VEHICLE); |
| | | deviceTypes.add(DeviceConfig.DeviceType.LARGE_GLASS); |
| | | deviceTypes.add(DeviceConfig.DeviceType.WORKSTATION_SCANNER); |
| | | deviceTypes.add(DeviceConfig.DeviceType.WORKSTATION_TRANSFER); |
| | | } |
| | | |
| | | return deviceTypes; |
| | | } catch (Exception e) { |
| | | log.error("获取设备类型列表失败", e); |
| | | // 异常时返回默认类型 |
| | | List<String> defaultTypes = new ArrayList<>(); |
| | | defaultTypes.add(DeviceConfig.DeviceType.LOAD_VEHICLE); |
| | | defaultTypes.add(DeviceConfig.DeviceType.LARGE_GLASS); |
| | | defaultTypes.add(DeviceConfig.DeviceType.WORKSTATION_SCANNER); |
| | | defaultTypes.add(DeviceConfig.DeviceType.WORKSTATION_TRANSFER); |
| | | return defaultTypes; |
| | | } |
| | | } |
| | | |
| | | @Override |