smart-switch-java/smart-switch-service/src/main/java/com/ruoyi/iot/domain/CurrentDeviceData.java

80 lines
2.7 KiB
Java
Raw Normal View History

2024-04-23 11:19:24 +08:00
package com.ruoyi.iot.domain;
2024-04-19 16:36:24 +08:00
2024-05-20 16:04:35 +08:00
import com.ruoyi.common.constant.IotConstants;
2024-04-19 16:36:24 +08:00
import com.ruoyi.common.utils.NumberUtils;
import com.ruoyi.iot.constants.ReceiveConstants;
2024-04-23 11:19:24 +08:00
import com.ruoyi.ss.device.domain.enums.DeviceOutageWay;
2024-04-19 16:36:24 +08:00
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<CurrentDatastream> datastreams;
/**
* 转换为设备信息
* @return
*/
public IotDeviceInfo parseDeviceInfo() {
IotDeviceInfo device = IotDeviceInfo.newDefaultInstance();
device.setMac(title);
device.setId(id);
2024-04-23 11:19:24 +08:00
if (CollectionUtils.isEmpty(datastreams)) {
return device;
}
2024-05-06 18:06:58 +08:00
2024-04-19 16:36:24 +08:00
for (CurrentDatastream stream : datastreams) {
String value = stream.getValue().toString();
2024-06-14 17:12:03 +08:00
2024-04-19 16:36:24 +08:00
switch (stream.getId()) {
case ReceiveConstants.DS_V:
2024-04-19 16:36:24 +08:00
device.setV(NumberUtils.nonNullDecimal(value));
break;
case ReceiveConstants.DS_P:
2024-04-19 16:36:24 +08:00
device.setP(NumberUtils.nonNullDecimal(value));
break;
case ReceiveConstants.DS_A:
2024-04-19 16:36:24 +08:00
device.setA(NumberUtils.nonNullDecimal(value));
break;
case ReceiveConstants.DS_W:
2024-05-06 18:06:58 +08:00
device.setW(NumberUtils.nonNullDecimal(value).divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP));
2024-04-19 16:36:24 +08:00
break;
case ReceiveConstants.DS_S:
2024-04-19 16:36:24 +08:00
device.setS(value);
break;
case ReceiveConstants.DS_M:
2024-05-06 18:06:58 +08:00
device.setM(NumberUtils.nonNullDecimal(value).divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP));
2024-04-19 16:36:24 +08:00
break;
case ReceiveConstants.DS_SET:
2024-04-19 16:36:24 +08:00
DeviceOutageWay deviceOutageWay = DeviceOutageWay.parse(value);
device.setSet(deviceOutageWay.getValue());
break;
case ReceiveConstants.DS_TIME:
2024-05-20 16:04:35 +08:00
device.setTime(NumberUtils.nonNullDecimal(value));
2024-08-05 10:02:14 +08:00
device.setAt(stream.getAt());
2024-05-20 16:04:35 +08:00
break;
case ReceiveConstants.DS_FW:
2024-06-14 17:12:03 +08:00
device.setModel(value);
break;
case ReceiveConstants.DS_SSID:
device.setWifi(value);
break;
2024-04-19 16:36:24 +08:00
default:
break;
}
}
return device;
}
}