|
|
@ -416,16 +416,16 @@ private VideoController videoController; |
|
|
|
dateList.add(DateUtil.beginOfDay(new Date()).toString()); |
|
|
|
dateList.add(DateUtil.endOfDay(new Date()).toString()); |
|
|
|
// 将日期列表以逗号分隔并设置为查询条件的值
|
|
|
|
props.put("terms[0].value", String.join(UniversalEnum.COMMA.getValue(), dateList)); |
|
|
|
props.put("terms[0].value", String.join(",", dateList)); |
|
|
|
props.put("paging", false); |
|
|
|
props.put("sorts[0].order", "asc"); |
|
|
|
props.put("sorts[0].name", "timestamp"); |
|
|
|
Map<String,Object> parameter =new HashMap<>(); |
|
|
|
String[] endStakeMark={"208","979"}; |
|
|
|
String[] startStakeMark={"054","378"}; |
|
|
|
parameter.put("deviceType","15"); |
|
|
|
parameter.put("endStakeMark",endStakeMark); |
|
|
|
parameter.put("startStakeMark",startStakeMark); |
|
|
|
Map<String, Object> parameter = new HashMap<>(); |
|
|
|
String[] endStakeMark = {"208", "979"}; |
|
|
|
String[] startStakeMark = {"054", "378"}; |
|
|
|
parameter.put("deviceType", "15"); |
|
|
|
parameter.put("endStakeMark", endStakeMark); |
|
|
|
parameter.put("startStakeMark", startStakeMark); |
|
|
|
// parameter.put("deviceState","1");
|
|
|
|
// 创建一个映射来存储按小时汇总的数据
|
|
|
|
Map<String, Double> allDevicesHourlyAggregates = new TreeMap<>(); |
|
|
@ -439,12 +439,11 @@ private VideoController videoController; |
|
|
|
// 定义时间格式
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
|
|
Object data = JSON.parseObject(queryDeviceProperties(dcDevice.getIotDeviceId(), propertyId, props).get("data").toString()).get("data"); |
|
|
|
Object data = JSON.parseObject(ajaxResult.get("data").toString()).get("data"); |
|
|
|
JSONArray dataArray = JSON.parseArray(data.toString()); |
|
|
|
// 创建一个映射来存储单个设备按小时汇总的数据
|
|
|
|
Map<String, Double> deviceHourlyAggregates = new TreeMap<>(); |
|
|
|
Map<String, Map<String, Object>> deviceHourlyLatestData = new TreeMap<>(); |
|
|
|
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>(); |
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.##"); |
|
|
|
decimalFormat.setRoundingMode(RoundingMode.HALF_UP); |
|
|
|
|
|
|
@ -469,24 +468,43 @@ private VideoController videoController; |
|
|
|
calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, |
|
|
|
calendar.get(Calendar.DAY_OF_MONTH), hour); |
|
|
|
|
|
|
|
//转换为 double 类型,去除单位
|
|
|
|
// 转换为 double 类型,去除单位
|
|
|
|
String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", ""); |
|
|
|
// double formatValue = Double.parseDouble(valueWithoutUnit);
|
|
|
|
double parsedValue = Double.parseDouble(valueWithoutUnit); |
|
|
|
// 保留两位小数
|
|
|
|
double formatValue = Double.parseDouble(decimalFormat.format(parsedValue)); |
|
|
|
// 汇总每个小时的数据
|
|
|
|
deviceHourlyAggregates.merge(key, formatValue, (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); } |
|
|
|
// 将设备的数据合并到所有设备的汇总数据中
|
|
|
|
for (String key : deviceHourlyAggregates.keySet()) { |
|
|
|
allDevicesHourlyAggregates.merge(key, deviceHourlyAggregates.get(key), (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); |
|
|
|
} |
|
|
|
|
|
|
|
// 检查当前小时是否有数据,如果没有则直接添加
|
|
|
|
if (!deviceHourlyLatestData.containsKey(key)) { |
|
|
|
Map<String, Object> dataPoint = new HashMap<>(); |
|
|
|
dataPoint.put("value", formatValue); |
|
|
|
dataPoint.put("timestamp", timestamp); |
|
|
|
deviceHourlyLatestData.put(key, dataPoint); |
|
|
|
} else { |
|
|
|
// 如果已经有数据,比较时间戳,保留最新的数据
|
|
|
|
long existingTimestamp = (long) deviceHourlyLatestData.get(key).get("timestamp"); |
|
|
|
if (timestamp > existingTimestamp) { |
|
|
|
Map<String, Object> dataPoint = new HashMap<>(); |
|
|
|
dataPoint.put("value", formatValue); |
|
|
|
dataPoint.put("timestamp", timestamp); |
|
|
|
deviceHourlyLatestData.put(key, dataPoint); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 将设备的数据合并到所有设备的汇总数据中
|
|
|
|
for (String key : deviceHourlyLatestData.keySet()) { |
|
|
|
double latestValue = (double) deviceHourlyLatestData.get(key).get("value"); |
|
|
|
allDevicesHourlyAggregates.merge(key, latestValue, (oldVal, newVal) -> { |
|
|
|
double sum = oldVal + newVal; |
|
|
|
return Double.parseDouble(decimalFormat.format(sum)); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
return AjaxResult.success(allDevicesHourlyAggregates); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("太阳能重点数据") |
|
|
|
@GetMapping("/properties/latestOne") |
|
|
|
public AjaxResult getDeviceLatest() throws HttpException, IOException { |
|
|
|