debug:双模数据获取
This commit is contained in:
parent
adeea2b37e
commit
cc388750ba
|
@ -1,15 +1,7 @@
|
|||
package com.ruoyi.iot.domain;
|
||||
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.common.utils.NumberUtils;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.iot.constants.ReceiveConstants;
|
||||
import com.ruoyi.ss.device.domain.enums.DeviceOutageWay;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -21,60 +13,4 @@ public class CurrentDeviceData {
|
|||
private String id;
|
||||
private String title;
|
||||
private List<CurrentDatastream> datastreams;
|
||||
|
||||
/**
|
||||
* 转换为设备信息
|
||||
* @return
|
||||
*/
|
||||
public IotDeviceInfo parseDeviceInfo() {
|
||||
if (CollectionUtils.isEmptyElement(datastreams)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IotDeviceInfo device = IotDeviceInfo.newDefaultInstance();
|
||||
device.setMac(title);
|
||||
device.setId(id);
|
||||
|
||||
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(Integer.valueOf(value).toString());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,6 @@ import java.util.Date;
|
|||
@Data
|
||||
@Builder
|
||||
public class IotDeviceInfo {
|
||||
private String id; // iot设备id
|
||||
|
||||
private String mac; // 设备mac
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date at; // 时间
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.ruoyi.iot.service;
|
||||
|
||||
import com.ruoyi.iot.domain.CurrentDatastream;
|
||||
import com.ruoyi.iot.domain.CurrentDeviceData;
|
||||
import com.ruoyi.iot.domain.IotDeviceInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2024/9/29
|
||||
*/
|
||||
public interface IotConverter {
|
||||
|
||||
IotDeviceInfo toIotDeviceInfo(CurrentDeviceData data1, CurrentDeviceData data2);
|
||||
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.ruoyi.common.utils.NumberUtils;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.iot.constants.ReceiveConstants;
|
||||
import com.ruoyi.iot.domain.CurrentDatastream;
|
||||
import com.ruoyi.iot.domain.CurrentDeviceData;
|
||||
import com.ruoyi.iot.domain.IotDeviceInfo;
|
||||
import com.ruoyi.iot.service.IotConverter;
|
||||
import com.ruoyi.ss.device.domain.enums.DeviceOutageWay;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2024/9/29
|
||||
*/
|
||||
@Service
|
||||
public class IotConverterImpl implements IotConverter {
|
||||
@Override
|
||||
public IotDeviceInfo toIotDeviceInfo(CurrentDeviceData data1, CurrentDeviceData data2) {
|
||||
if (data1 == null && data2 == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取数据点,让不为空的排在前面
|
||||
List<CurrentDatastream> ds1 = data1 == null ? data2.getDatastreams() : data1.getDatastreams();
|
||||
List<CurrentDatastream> ds2 = data2 == null ? data1.getDatastreams() : data2.getDatastreams();
|
||||
|
||||
if (CollectionUtils.isNotEmptyElement(ds1)) {
|
||||
this.toIotDeviceInfo(ds1, ds2);
|
||||
} else if (CollectionUtils.isNotEmptyElement(ds2)) {
|
||||
this.toIotDeviceInfo(ds2, ds1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private IotDeviceInfo toIotDeviceInfo(List<CurrentDatastream> ds1, List<CurrentDatastream> ds2) {
|
||||
if (CollectionUtils.isEmptyElement(ds1) && CollectionUtils.isEmptyElement(ds2)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IotDeviceInfo device = IotDeviceInfo.newDefaultInstance();
|
||||
|
||||
for (CurrentDatastream stream : ds1) {
|
||||
String id = stream.getId(); // 数据点ID
|
||||
String value = stream.getValue().toString(); // 数据点取值,取最新的值
|
||||
Date at = stream.getAt();
|
||||
if (ds2 != null) {
|
||||
CurrentDatastream stream2 = ds2.stream().filter(item -> Objects.equals(item.getId(), stream.getId())).findFirst().orElse(null);
|
||||
if (stream2 != null && stream2.getAt().getTime() > stream.getAt().getTime()) {
|
||||
value = stream2.getValue().toString();
|
||||
at = stream2.getAt();
|
||||
}
|
||||
}
|
||||
|
||||
switch (id) {
|
||||
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(Integer.valueOf(value).toString());
|
||||
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(at);
|
||||
break;
|
||||
case ReceiveConstants.DS_FW:
|
||||
device.setModel(value);
|
||||
break;
|
||||
case ReceiveConstants.DS_SSID:
|
||||
device.setWifi(value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return device;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,13 @@
|
|||
package com.ruoyi.iot.service;
|
||||
package com.ruoyi.iot.service.impl;
|
||||
import com.ruoyi.common.utils.NumberUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.iot.constants.ReceiveConstants;
|
||||
import com.ruoyi.iot.domain.IotDeviceDetail;
|
||||
import com.ruoyi.iot.domain.ReceiveMsg;
|
||||
import com.ruoyi.iot.enums.ReceiveStatus;
|
||||
import com.ruoyi.iot.enums.ReceiveType;
|
||||
import com.ruoyi.iot.service.IotReceiveService;
|
||||
import com.ruoyi.iot.service.IotService;
|
||||
import com.ruoyi.ss.device.domain.Device;
|
||||
import com.ruoyi.ss.device.domain.enums.DeviceOutageWay;
|
||||
import com.ruoyi.ss.device.domain.vo.DeviceVO;
|
||||
|
@ -14,7 +15,6 @@ import com.ruoyi.ss.device.service.DeviceService;
|
|||
import com.ruoyi.ss.suit.domain.enums.SuitFeeType;
|
||||
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
|
||||
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;
|
||||
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillType;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO;
|
||||
import com.ruoyi.ss.transactionBill.service.TransactionAssembler;
|
||||
import com.ruoyi.ss.transactionBill.service.TransactionBillService;
|
||||
|
@ -32,7 +32,7 @@ import java.util.List;
|
|||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class IotReceiveServiceImpl implements IotReceiveService{
|
||||
public class IotReceiveServiceImpl implements IotReceiveService {
|
||||
|
||||
@Autowired
|
||||
private DeviceService deviceService;
|
|
@ -1,4 +1,4 @@
|
|||
package com.ruoyi.iot.service;
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
@ -16,8 +16,11 @@ import com.ruoyi.iot.domain.response.DetailResponse;
|
|||
import com.ruoyi.iot.domain.response.HistoryDataPointResponse;
|
||||
import com.ruoyi.iot.enums.IotHttpStatus;
|
||||
import com.ruoyi.iot.interfaces.IotDevice;
|
||||
import com.ruoyi.iot.service.IotConverter;
|
||||
import com.ruoyi.iot.service.IotService;
|
||||
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
@ -56,6 +59,9 @@ public class IotServiceImpl implements IotService {
|
|||
@Value(value = "${debug}")
|
||||
private Boolean debug;
|
||||
|
||||
@Autowired
|
||||
private IotConverter iotConverter;
|
||||
|
||||
// 查询OneNet设备在线状态
|
||||
@Override
|
||||
public DeviceOnlineStatus getOnlineStatus(String deviceName, String productId) {
|
||||
|
@ -316,31 +322,26 @@ public class IotServiceImpl implements IotService {
|
|||
|
||||
@Override
|
||||
public IotDeviceInfo getDeviceInfo(String deviceName, String productId) {
|
||||
if (StringUtils.isBlank(deviceName)) {
|
||||
if (StringUtils.isAnyBlank(deviceName, productId)) {
|
||||
return null;
|
||||
}
|
||||
CurrentDeviceData currentDataPoint = getCurrentDataPoint(deviceName, productId);
|
||||
if (currentDataPoint == null) {
|
||||
return null;
|
||||
}
|
||||
return currentDataPoint.parseDeviceInfo();
|
||||
return iotConverter.toIotDeviceInfo(currentDataPoint, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IotDeviceInfo getDeviceInfo(IotDevice device) {
|
||||
IotDeviceInfo info = null;
|
||||
if (device == null || StringUtils.isBlank(device.getProductId())) {
|
||||
return info;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(device.getMac1())) {
|
||||
info = getDeviceInfo(device.getMac1(), device.getProductId());
|
||||
}
|
||||
if (info == null && StringUtils.hasText(device.getMac2())) {
|
||||
info = getDeviceInfo(device.getMac2(), device.getProductId());
|
||||
}
|
||||
CurrentDeviceData data1 = getCurrentDataPoint(device.getMac1(), device.getProductId());
|
||||
CurrentDeviceData data2 = getCurrentDataPoint(device.getMac2(), device.getProductId());
|
||||
|
||||
return info;
|
||||
return iotConverter.toIotDeviceInfo(data1, data2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -353,7 +354,7 @@ public class IotServiceImpl implements IotService {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
return dataList.stream()
|
||||
.map(CurrentDeviceData::parseDeviceInfo)
|
||||
.map(item -> iotConverter.toIotDeviceInfo(item, null))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
Loading…
Reference in New Issue
Block a user