|
|
|
|
@ -869,4 +869,69 @@ public class DeviceServiceImpl implements DeviceService {
|
|
|
|
|
String formattedRate = String.format("%.2f%%", faultRate);
|
|
|
|
|
statusVO.setFaultRate(formattedRate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Map<String, Object>> getMultiDeviceAttributes(String deviceIds) {
|
|
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 解析设备ID列表
|
|
|
|
|
if (StringUtils.isBlank(deviceIds)) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Long> idList = Arrays.stream(deviceIds.split(","))
|
|
|
|
|
.map(String::trim)
|
|
|
|
|
.map(Long::valueOf)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
// 遍历每个设备ID,获取设备属性数据
|
|
|
|
|
for (Long deviceId : idList) {
|
|
|
|
|
// 获取设备信息
|
|
|
|
|
DeviceDO device = deviceMapper.selectById(deviceId);
|
|
|
|
|
if (device == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建设备层级的Map
|
|
|
|
|
Map<String, Object> deviceMap = new HashMap<>();
|
|
|
|
|
deviceMap.put("deviceId", deviceId);
|
|
|
|
|
deviceMap.put("deviceName", device.getDeviceName());
|
|
|
|
|
|
|
|
|
|
// 获取设备属性列表
|
|
|
|
|
List<DeviceContactModelDO> attributes = deviceContactModelMapper.selectList(
|
|
|
|
|
Wrappers.<DeviceContactModelDO>lambdaQuery()
|
|
|
|
|
.eq(DeviceContactModelDO::getDeviceId, deviceId));
|
|
|
|
|
|
|
|
|
|
// 获取设备最新数据
|
|
|
|
|
Map<Long, Map<String, Object>> deviceDataMap = createDeviceDataMap(deviceId);
|
|
|
|
|
|
|
|
|
|
// 创建点位集合
|
|
|
|
|
List<Map<String, Object>> attributeList = new ArrayList<>();
|
|
|
|
|
for (DeviceContactModelDO attribute : attributes) {
|
|
|
|
|
Map<String, Object> attributeData = new HashMap<>();
|
|
|
|
|
attributeData.put("attributeId", attribute.getId());
|
|
|
|
|
attributeData.put("attributeName", attribute.getAttributeName());
|
|
|
|
|
attributeData.put("attributeCode", attribute.getAttributeCode());
|
|
|
|
|
attributeData.put("dataType", attribute.getDataType());
|
|
|
|
|
attributeData.put("dataUnit", attribute.getDataUnit());
|
|
|
|
|
|
|
|
|
|
// 获取最新数据
|
|
|
|
|
Map<String, Object> latestData = deviceDataMap.get(attribute.getId());
|
|
|
|
|
if (latestData != null) {
|
|
|
|
|
attributeData.put("addressValue", adjustByRatio(latestData.get("addressValue"), attribute.getRatio()));
|
|
|
|
|
attributeData.put("latestCollectionTime", latestData.get("timestamp"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attributeList.add(attributeData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将点位集合添加到设备层级
|
|
|
|
|
deviceMap.put("attributes", attributeList);
|
|
|
|
|
|
|
|
|
|
// 添加到结果列表
|
|
|
|
|
result.add(deviceMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|