|
|
@@ -100,10 +100,11 @@ public class DeviceDataQuery {
|
|
|
List<String> deviceUuids = transferVO.getDevices().stream()
|
|
|
.map(DmpDevice::getDeviceUuid)
|
|
|
.collect(Collectors.toList());
|
|
|
- requestBody.put("deviceUuids", deviceUuids);
|
|
|
+ requestBody.put("deviceuuid", deviceUuids);
|
|
|
|
|
|
log.debug("请求设备数据接口,设备数量:{}", deviceUuids.size());
|
|
|
String response = HttpClientUtils.doPostJson(baseUrl, requestBody.toJSONString());
|
|
|
+ log.warn("接口返回数据:{}", response);
|
|
|
|
|
|
List<JSONObject> resultList = parseResponseData(response, transferVO.getDeviceType(), transferVO.getDevices());
|
|
|
|
|
|
@@ -111,6 +112,48 @@ public class DeviceDataQuery {
|
|
|
if (resultList.isEmpty() && simulation) {
|
|
|
log.info("接口返回数据为空,生成模拟数据,设备类型:{}", transferVO.getDeviceType());
|
|
|
resultList = generateSimulationData(transferVO.getDeviceType(), transferVO.getDevices());
|
|
|
+ } else if (resultList.size() < transferVO.getDevices().size()) {
|
|
|
+ log.warn("接口返回数据数量与请求数量不一致,设备类型:{}", transferVO.getDeviceType());
|
|
|
+
|
|
|
+ // 获取返回数据中的device_id集合
|
|
|
+ Set<String> returnedDeviceIds = resultList.stream()
|
|
|
+ .map(data -> data.getString("device_id"))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 获取请求中devices的device_id集合
|
|
|
+ Map<String, DmpDevice> requestDeviceMap = transferVO.getDevices().stream()
|
|
|
+ .filter(device -> device.getDeviceId() != null)
|
|
|
+ .collect(Collectors.toMap(DmpDevice::getDeviceId, device -> device));
|
|
|
+
|
|
|
+ // 找出返回数据中缺少的device_id
|
|
|
+ List<String> missingDeviceIds = requestDeviceMap.keySet().stream()
|
|
|
+ .filter(deviceId -> !returnedDeviceIds.contains(deviceId))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!missingDeviceIds.isEmpty() && simulation) {
|
|
|
+ log.info("发现缺少的设备数据,生成模拟数据,设备数量:{}", missingDeviceIds.size());
|
|
|
+ // 为缺少的设备生成模拟数据
|
|
|
+ List<DmpDevice> missingDevices = missingDeviceIds.stream()
|
|
|
+ .map(requestDeviceMap::get)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<JSONObject> missingSimulationData = generateSimulationData(transferVO.getDeviceType(), missingDevices);
|
|
|
+ // 将模拟数据与返回数据结合
|
|
|
+ resultList.addAll(missingSimulationData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验结合后的数据是否与请求的device_id一一对应
|
|
|
+ Set<String> combinedDeviceIds = resultList.stream()
|
|
|
+ .map(data -> data.getString("device_id"))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ if (combinedDeviceIds.size() != transferVO.getDevices().size()) {
|
|
|
+ log.warn("数据整合后仍存在缺失,请求设备数量:{},返回设备数量:{}",
|
|
|
+ transferVO.getDevices().size(), combinedDeviceIds.size());
|
|
|
+ } else {
|
|
|
+ log.debug("数据整合完成,设备数量与请求一致:{}", combinedDeviceIds.size());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return resultList;
|
|
|
@@ -192,9 +235,7 @@ public class DeviceDataQuery {
|
|
|
// 添加设备标识信息
|
|
|
targetData.put("deviceuuid", deviceUuid);
|
|
|
String deviceId = deviceUuidToIdMap.get(deviceUuid);
|
|
|
- if (deviceId != null) {
|
|
|
- targetData.put("device_id", deviceId);
|
|
|
- }
|
|
|
+ targetData.put("device_id", deviceId);
|
|
|
|
|
|
if (hasValidData) {
|
|
|
resultList.add(targetData);
|
|
|
@@ -217,13 +258,13 @@ public class DeviceDataQuery {
|
|
|
private List<String> getTargetFieldsByDeviceType(Integer deviceType) {
|
|
|
if (deviceType == null) {
|
|
|
log.warn("获取目标字段失败:设备类型为空");
|
|
|
- return Collections.singletonList("time");
|
|
|
+ return Collections.singletonList("realtime");
|
|
|
}
|
|
|
|
|
|
String fieldsStr = deviceFieldConfig.deviceFieldMapping().get(deviceType.toString());
|
|
|
if (fieldsStr == null || fieldsStr.trim().isEmpty()) {
|
|
|
log.warn("获取目标字段失败:设备类型{}对应的字段映射不存在", deviceType);
|
|
|
- return Collections.singletonList("time");
|
|
|
+ return Collections.singletonList("realtime");
|
|
|
}
|
|
|
|
|
|
List<String> fields = Arrays.stream(fieldsStr.split(","))
|
|
|
@@ -232,8 +273,8 @@ public class DeviceDataQuery {
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
// 确保包含时间字段
|
|
|
- if (!fields.contains("time")) {
|
|
|
- fields.add("time");
|
|
|
+ if (!fields.contains("realtime")) {
|
|
|
+ fields.add("realtime");
|
|
|
}
|
|
|
|
|
|
return fields;
|
|
|
@@ -254,7 +295,7 @@ public class DeviceDataQuery {
|
|
|
|
|
|
for (DmpDevice device : devices) {
|
|
|
JSONObject simulationData = new JSONObject();
|
|
|
- simulationData.put("time", currentTime);
|
|
|
+ simulationData.put("realtime", currentTime);
|
|
|
simulationData.put("device_id", device.getDeviceId());
|
|
|
|
|
|
if (deviceType == null) {
|