| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.battery.device.simulator.BtsSimulatorStateStore; |
| | | import com.battery.device.simulator.BtsSimulatorStateStore.BtsDeviceProfile; |
| | | import com.battery.device.simulator.BtsSimulatorStateStore.ChannelConfiguration; |
| | | import com.battery.device.simulator.BtsSimulatorStateStore.SimulatorPlanStep; |
| | | import com.battery.device.api.model.DeviceWorkStatus; |
| | | |
| | | /** 将开发模拟器完整状态写入 Redis,主状态不设置普通 TTL。 */ |
| | |
| | | JSONObject object = jsonObject(value); |
| | | String workStatus = object.getString("workStatus"); |
| | | if (workStatus == null) throw new IllegalStateException("Missing BTS simulator state field: workStatus"); |
| | | JSONObject configuration = object.getJSONObject("configuration"); |
| | | return new ChannelState(requiredInteger(object, "channelId"), object.getBooleanValue("online"), |
| | | DeviceWorkStatus.valueOf(workStatus), object.getObject("configuration", ChannelConfiguration.class)); |
| | | DeviceWorkStatus.valueOf(workStatus), channelConfiguration(configuration)); |
| | | } |
| | | |
| | | /** Redis 通用反序列化会把泛型 steps 恢复为 JSONObject,不能让 record 构造器直接强转。 */ |
| | | private ChannelConfiguration channelConfiguration(JSONObject object) |
| | | { |
| | | if (object == null) return null; |
| | | JSONArray configuredSteps = requiredArray(object, "steps"); |
| | | List<SimulatorPlanStep> steps = new ArrayList<>(); |
| | | configuredSteps.forEach(item -> { |
| | | JSONObject step = jsonObject(item); |
| | | steps.add(new SimulatorPlanStep(step.getString("name"), step.getString("stepType"), |
| | | step.getDoubleValue("durationSeconds"), step.getDoubleValue("voltageV"))); |
| | | }); |
| | | return new ChannelConfiguration(requiredDecimal(object, "currentA"), requiredDecimal(object, "voltageV"), |
| | | requiredDecimal(object, "capacityAh"), requiredDecimal(object, "energyWh"), |
| | | requiredInteger(object, "cycleNo"), requiredInteger(object, "stepNo"), |
| | | requiredInteger(object, "plannedCycleCount"), object.getLongValue("totalTimeSeconds"), |
| | | object.getLongValue("relativeTimeSeconds"), steps); |
| | | } |
| | | |
| | | private ChannelTombstone channelTombstone(Object value) |