package com.ruoyi.iot.domain; import com.ruoyi.common.constant.IotConstants; import com.ruoyi.common.utils.NumberUtils; import com.ruoyi.iot.constants.ReceiveConstants; import com.ruoyi.ss.device.domain.enums.DeviceOutageWay; import lombok.Data; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Date; import java.util.List; /** * @author wjh * 2024/3/20 */ @Data public class CurrentDeviceData { private String id; private String title; private List datastreams; /** * 转换为设备信息 * @return */ public IotDeviceInfo parseDeviceInfo() { IotDeviceInfo device = IotDeviceInfo.newDefaultInstance(); device.setMac(title); device.setId(id); if (CollectionUtils.isEmpty(datastreams)) { return device; } for (CurrentDatastream stream : datastreams) { String value = stream.getValue().toString(); switch (stream.getId()) { case ReceiveConstants.DS_V: device.setV(NumberUtils.nonNullDecimal(value)); break; case ReceiveConstants.DS_P: device.setP(NumberUtils.nonNullDecimal(value)); break; case ReceiveConstants.DS_A: device.setA(NumberUtils.nonNullDecimal(value)); break; case ReceiveConstants.DS_W: device.setW(NumberUtils.nonNullDecimal(value).divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP)); break; case ReceiveConstants.DS_S: device.setS(value); break; case ReceiveConstants.DS_M: device.setM(NumberUtils.nonNullDecimal(value).divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP)); break; case ReceiveConstants.DS_SET: DeviceOutageWay deviceOutageWay = DeviceOutageWay.parse(value); device.setSet(deviceOutageWay.getValue()); break; case ReceiveConstants.DS_TIME: device.setTime(NumberUtils.nonNullDecimal(value)); device.setAt(stream.getAt()); break; case ReceiveConstants.DS_FW: device.setModel(value); break; case ReceiveConstants.DS_SSID: device.setWifi(value); break; default: break; } } return device; } }