Browse Source

设备分析异常

develop
wangsixiang 4 months ago
parent
commit
3b92333417
  1. 114
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java

114
zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java

@ -985,62 +985,66 @@ public class DcDeviceController extends BaseController {
props.put("sorts[0].name", "timestamp");
List<HashMap<String, Object>> mapList = dcDeviceService.selectDeviceParameterProperties(dcDevice);//属性的参数信息
List<HashMap> resultsMapValue = new ArrayList<>();
for (HashMap<String, Object> hashMap : mapList) {
HashMap<String, Object> resultsMap = new HashMap<>();
String name = hashMap.get("name").toString();//属性名称
String propertyId = hashMap.get("propertyId").toString();//属性id
String propertyName = hashMap.get("propertyName").toString();//属性取值
AjaxResult ajaxResult = queryDeviceProperties(deviceId, propertyId, props);//取出属性全部信息
String code = ajaxResult.get("code").toString();
if ("500".equals(code)) {
return ajaxResult;
}
if (UniversalEnum.THIRTEEN.getValue().equals(type) || UniversalEnum.SIXTEEN.getValue().equals(type)) { //判断是否为设备箱/远端机
JSONObject data = (JSONObject) ajaxResult.get("data");
JSONArray dataVale = (JSONArray) data.get("data");
List<JSONObject> jsonObjectList = dataVale.toJavaList(JSONObject.class);
// 定义一个时间格式转换的工具
SimpleDateFormat sdf = new SimpleDateFormat(UniversalEnum.TIME_FORMAT_ALL.getValue(), Locale.getDefault());
// 使用Stream API提取每个JSONObject中的timestamp和propertyName值
List<Map<String, String>> results = jsonObjectList.stream()
.map(jsonObject -> {
long timestamp = jsonObject.getLongValue("timestamp"); // 假设timestamp是long类型
Date date = new Date(timestamp); // 将时间戳转换为Date对象
String formattedTime = sdf.format(date); // 将Date对象格式化为字符串
JSONObject formatValue = jsonObject.getJSONObject("formatValue"); // 获取嵌套的JSONObject
String result = formatValue.getString(propertyName); // 从嵌套的JSONObject中获取电压值
Map<String, String> hashMaps = new HashMap<>();
hashMaps.put("timestamp", formattedTime); // 使用"timestamp"作为键来存储格式化后的时间
hashMaps.put("result", result); // 使用"voltage"作为键来存储电压值
return hashMaps;
}).collect(Collectors.toList());
results.sort(Comparator.comparing(hashMaps -> hashMaps.get("timestamp")));
resultsMap.put("name", name);
resultsMap.put("results", results);
}
if (UniversalEnum.THREE.getValue().equals(type) || UniversalEnum.SEVENTEEN.getValue().equals(type) ||
UniversalEnum.FIFTEEN.getValue().equals(type)) { //气象预警/ups设备/太阳能板
JSONObject data = (JSONObject) ajaxResult.get("data");
JSONArray dataValue = (JSONArray) data.get("data");
List<JSONObject> jsonObjectList = dataValue.toJavaList(JSONObject.class);
// 定义一个时间格式转换的工具
SimpleDateFormat sdf = new SimpleDateFormat(UniversalEnum.TIME_FORMAT_ALL.getValue(), Locale.getDefault());
List<HashMap<String, String>> results = jsonObjectList.stream()
.map(jsonObject -> {
long timestamp = jsonObject.getLongValue("timestamp"); // 假设timestamp是long类型
Date date = new Date(timestamp); // 将时间戳转换为Date对象
String formattedTime = sdf.format(date); // 将Date对象格式化为字符串
String result = jsonObject.getString(propertyName);
HashMap<String, String> hashMaps = new HashMap<>();
hashMaps.put("timestamp", formattedTime); // 使用时间戳作为键可能不是最佳实践,但这里保持与原始逻辑一致
hashMaps.put("result", result);
return hashMaps;
}).collect(Collectors.toList());
results.sort(Comparator.comparing(hashMaps -> hashMaps.get("timestamp")));
resultsMap.put("name", name);
resultsMap.put("results", results);
try {
for (HashMap<String, Object> hashMap : mapList) {
HashMap<String, Object> resultsMap = new HashMap<>();
String name = hashMap.get("name").toString();//属性名称
String propertyId = hashMap.get("propertyId").toString();//属性id
String propertyName = hashMap.get("propertyName").toString();//属性取值
AjaxResult ajaxResult = queryDeviceProperties(deviceId, propertyId, props);//取出属性全部信息
String code = ajaxResult.get("code").toString();
if ("500".equals(code)) {
return ajaxResult;
}
if (UniversalEnum.THIRTEEN.getValue().equals(type) || UniversalEnum.SIXTEEN.getValue().equals(type)) { //判断是否为设备箱/远端机
JSONObject data = (JSONObject) ajaxResult.get("data");
JSONArray dataVale = (JSONArray) data.get("data");
List<JSONObject> jsonObjectList = dataVale.toJavaList(JSONObject.class);
// 定义一个时间格式转换的工具
SimpleDateFormat sdf = new SimpleDateFormat(UniversalEnum.TIME_FORMAT_ALL.getValue(), Locale.getDefault());
// 使用Stream API提取每个JSONObject中的timestamp和propertyName值
List<Map<String, String>> results = jsonObjectList.stream()
.map(jsonObject -> {
long timestamp = jsonObject.getLongValue("timestamp"); // 假设timestamp是long类型
Date date = new Date(timestamp); // 将时间戳转换为Date对象
String formattedTime = sdf.format(date); // 将Date对象格式化为字符串
JSONObject formatValue = jsonObject.getJSONObject("formatValue"); // 获取嵌套的JSONObject
String result = formatValue.getString(propertyName); // 从嵌套的JSONObject中获取电压值
Map<String, String> hashMaps = new HashMap<>();
hashMaps.put("timestamp", formattedTime); // 使用"timestamp"作为键来存储格式化后的时间
hashMaps.put("result", result); // 使用"voltage"作为键来存储电压值
return hashMaps;
}).collect(Collectors.toList());
results.sort(Comparator.comparing(hashMaps -> hashMaps.get("timestamp")));
resultsMap.put("name", name);
resultsMap.put("results", results);
}
if (UniversalEnum.THREE.getValue().equals(type) || UniversalEnum.SEVENTEEN.getValue().equals(type) ||
UniversalEnum.FIFTEEN.getValue().equals(type)) { //气象预警/ups设备/太阳能板
JSONObject data = (JSONObject) ajaxResult.get("data");
JSONArray dataValue = (JSONArray) data.get("data");
List<JSONObject> jsonObjectList = dataValue.toJavaList(JSONObject.class);
// 定义一个时间格式转换的工具
SimpleDateFormat sdf = new SimpleDateFormat(UniversalEnum.TIME_FORMAT_ALL.getValue(), Locale.getDefault());
List<HashMap<String, String>> results = jsonObjectList.stream()
.map(jsonObject -> {
long timestamp = jsonObject.getLongValue("timestamp"); // 假设timestamp是long类型
Date date = new Date(timestamp); // 将时间戳转换为Date对象
String formattedTime = sdf.format(date); // 将Date对象格式化为字符串
String result = jsonObject.getString(propertyName);
HashMap<String, String> hashMaps = new HashMap<>();
hashMaps.put("timestamp", formattedTime); // 使用时间戳作为键可能不是最佳实践,但这里保持与原始逻辑一致
hashMaps.put("result", result);
return hashMaps;
}).collect(Collectors.toList());
results.sort(Comparator.comparing(hashMaps -> hashMaps.get("timestamp")));
resultsMap.put("name", name);
resultsMap.put("results", results);
}
resultsMapValue.add(resultsMap);
}
resultsMapValue.add(resultsMap);
}catch (Exception e){
e.printStackTrace();
}
return AjaxResult.success(resultsMapValue);
}

Loading…
Cancel
Save