| | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.BtsDeviceProfile; |
| | | import com.ruoyi.device.model.DeviceWorkStatus; |
| | | |
| | | /** 将开发模拟器完整状态写入 Redis,主状态不设置普通 TTL。 */ |
| | |
| | | JSONObject object = jsonObject(value); |
| | | List<ChannelState> channels = new ArrayList<>(); |
| | | requiredArray(object, "channels").forEach(item -> channels.add(channelState(item))); |
| | | BtsDeviceProfile profile = object.containsKey("profile") ? deviceProfile(object.getJSONObject("profile")) : null; |
| | | return new DeviceState(requiredInteger(object, "deviceId"), object.getString("ip"), |
| | | object.getBooleanValue("online"), channels); |
| | | object.getBooleanValue("online"), channels, profile); |
| | | } |
| | | |
| | | private BtsDeviceProfile deviceProfile(JSONObject object) |
| | | { |
| | | if (object == null) throw new IllegalStateException("Invalid BTS simulator device profile"); |
| | | return new BtsDeviceProfile(requiredInteger(object, "devtype"), requiredInteger(object, "subDeviceId"), |
| | | object.getString("name"), object.getString("manufacturer"), object.getString("model"), |
| | | object.getString("serialNumber"), object.getString("firmwareVersion"), |
| | | requiredInteger(object, "channelCount"), requiredDecimal(object, "currentMinA"), |
| | | requiredDecimal(object, "currentMaxA"), requiredDecimal(object, "voltageMinV"), |
| | | requiredDecimal(object, "voltageMaxV"), requiredInteger(object, "sampleIntervalMs")); |
| | | } |
| | | |
| | | private List<CollectorMeasurementRecord> embeddedCollectorHistory(JSONObject object) |
| | |
| | | return value; |
| | | } |
| | | |
| | | private BigDecimal requiredDecimal(JSONObject object, String field) |
| | | { |
| | | BigDecimal value = object.getBigDecimal(field); |
| | | if (value == null) throw new IllegalStateException("Missing BTS simulator state field: " + field); |
| | | return value; |
| | | } |
| | | |
| | | private Instant requiredInstant(JSONObject object, String field) |
| | | { |
| | | Instant value = optionalInstant(object, field); |