| | |
| | | public class DeviceConfigServiceImpl extends ServiceImpl<DeviceConfigMapper, DeviceConfig> implements DeviceConfigService { |
| | | |
| | | private final ObjectMapper objectMapper = new ObjectMapper(); |
| | | private static final TypeReference<Map<String, Object>> MAP_TYPE = new TypeReference<Map<String, Object>>() {}; |
| | | |
| | | @Override |
| | | public boolean createDevice(DeviceConfig deviceConfig) { |
| | |
| | | |
| | | // 设备类型过滤 |
| | | if (deviceType != null && !deviceType.trim().isEmpty()) { |
| | | String convertedDeviceType = convertDeviceTypeFromString(deviceType); |
| | | if (convertedDeviceType != null) { |
| | | wrapper.eq(DeviceConfig::getDeviceType, convertedDeviceType); |
| | | List<String> convertedDeviceTypes = convertDeviceTypeFromString(deviceType); |
| | | if (convertedDeviceTypes != null && !convertedDeviceTypes.isEmpty()) { |
| | | wrapper.in(DeviceConfig::getDeviceType, convertedDeviceTypes); |
| | | } |
| | | } |
| | | |
| | |
| | | vo.setStatus(getStatusName(device.getStatus())); |
| | | vo.setDeviceStatus(convertStatusToCode(device.getStatus())); |
| | | vo.setDescription(device.getDescription()); |
| | | vo.setLocation("默认位置"); // TODO: 从扩展参数或关联表中获取 |
| | | vo.setLocation(extractLocationFromDevice(device)); |
| | | vo.setCreatedTime(device.getCreatedTime()); |
| | | vo.setUpdatedTime(device.getUpdatedTime()); |
| | | vo.setProjectId(device.getProjectId()); |
| | |
| | | /** |
| | | * 字符串转换为设备类型 |
| | | */ |
| | | private String convertDeviceTypeFromString(String deviceType) { |
| | | if (deviceType == null) return null; |
| | | private List<String> convertDeviceTypeFromString(String deviceType) { |
| | | if (deviceType == null) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | switch (deviceType.trim().toLowerCase()) { |
| | | String normalized = deviceType.trim().toLowerCase(); |
| | | switch (normalized) { |
| | | case "load_vehicle": |
| | | case "上大车": |
| | | case "上大车设备": |
| | | case "大车设备": |
| | | case "1": |
| | | return DeviceConfig.DeviceType.LOAD_VEHICLE; |
| | | return Arrays.asList( |
| | | DeviceConfig.DeviceType.LOAD_VEHICLE, |
| | | "大车设备" |
| | | ); |
| | | case "large_glass": |
| | | case "大理片": |
| | | case "大理片笼": |
| | | case "2": |
| | | return DeviceConfig.DeviceType.LARGE_GLASS; |
| | | return Arrays.asList( |
| | | DeviceConfig.DeviceType.LARGE_GLASS, |
| | | "大理片笼" |
| | | ); |
| | | case "glass_storage": |
| | | case "玻璃存储": |
| | | case "卧式缓存": |
| | | case "玻璃存储设备": |
| | | case "3": |
| | | return DeviceConfig.DeviceType.GLASS_STORAGE; |
| | | return Arrays.asList( |
| | | DeviceConfig.DeviceType.GLASS_STORAGE, |
| | | "卧式缓存", |
| | | "玻璃存储设备" |
| | | ); |
| | | default: |
| | | return null; |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // 设备类型过滤 |
| | | if (deviceType != null && !deviceType.trim().isEmpty()) { |
| | | String convertedDeviceType = convertDeviceTypeFromString(deviceType); |
| | | if (convertedDeviceType != null) { |
| | | wrapper.eq(DeviceConfig::getDeviceType, convertedDeviceType); |
| | | } |
| | | if (deviceType != null && !deviceType.trim().isEmpty()) { |
| | | List<String> convertedDeviceTypes = convertDeviceTypeFromString(deviceType); |
| | | if (convertedDeviceTypes != null && !convertedDeviceTypes.isEmpty()) { |
| | | wrapper.in(DeviceConfig::getDeviceType, convertedDeviceTypes); |
| | | } |
| | | } |
| | | |
| | | // 设备状态过滤 |
| | | if (deviceStatus != null && !deviceStatus.trim().isEmpty()) { |
| | |
| | | return new ArrayList<>(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 从设备扩展参数中提取位置信息 |
| | | */ |
| | | private String extractLocationFromDevice(DeviceConfig device) { |
| | | if (device == null) { |
| | | return "默认位置"; |
| | | } |
| | | try { |
| | | // 优先从extraParams中获取 |
| | | if (device.getExtraParams() != null && !device.getExtraParams().trim().isEmpty()) { |
| | | Map<String, Object> extraParams = objectMapper.readValue(device.getExtraParams(), MAP_TYPE); |
| | | Object location = extraParams.get("location"); |
| | | if (location != null) { |
| | | return String.valueOf(location); |
| | | } |
| | | } |
| | | // 从configJson中获取 |
| | | if (device.getConfigJson() != null && !device.getConfigJson().trim().isEmpty()) { |
| | | Map<String, Object> configJson = objectMapper.readValue(device.getConfigJson(), MAP_TYPE); |
| | | Object location = configJson.get("location"); |
| | | if (location != null) { |
| | | return String.valueOf(location); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.warn("解析设备位置信息失败, deviceId={}", device.getId(), e); |
| | | } |
| | | return "默认位置"; |
| | | } |
| | | } |