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

Loading…
Cancel
Save