|
@ -416,35 +416,34 @@ private VideoController videoController; |
|
|
dateList.add(DateUtil.beginOfDay(new Date()).toString()); |
|
|
dateList.add(DateUtil.beginOfDay(new Date()).toString()); |
|
|
dateList.add(DateUtil.endOfDay(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("paging", false); |
|
|
props.put("sorts[0].order", "asc"); |
|
|
props.put("sorts[0].order", "asc"); |
|
|
props.put("sorts[0].name", "timestamp"); |
|
|
props.put("sorts[0].name", "timestamp"); |
|
|
Map<String,Object> parameter =new HashMap<>(); |
|
|
Map<String, Object> parameter = new HashMap<>(); |
|
|
String[] endStakeMark={"208","979"}; |
|
|
String[] endStakeMark = {"208", "979"}; |
|
|
String[] startStakeMark={"054","378"}; |
|
|
String[] startStakeMark = {"054", "378"}; |
|
|
parameter.put("deviceType","15"); |
|
|
parameter.put("deviceType", "15"); |
|
|
parameter.put("endStakeMark",endStakeMark); |
|
|
parameter.put("endStakeMark", endStakeMark); |
|
|
parameter.put("startStakeMark",startStakeMark); |
|
|
parameter.put("startStakeMark", startStakeMark); |
|
|
// parameter.put("deviceState","1");
|
|
|
// parameter.put("deviceState","1");
|
|
|
// 创建一个映射来存储按小时汇总的数据
|
|
|
// 创建一个映射来存储按小时汇总的数据
|
|
|
Map<String, Double> allDevicesHourlyAggregates = new TreeMap<>(); |
|
|
Map<String, Double> allDevicesHourlyAggregates = new TreeMap<>(); |
|
|
|
|
|
|
|
|
List<DcDevice> dcDevices = dcDeviceService.devicePileNumberQueryDevice(parameter); |
|
|
List<DcDevice> dcDevices = dcDeviceService.devicePileNumberQueryDevice(parameter); |
|
|
for (DcDevice dcDevice : dcDevices) { |
|
|
for (DcDevice dcDevice : dcDevices) { |
|
|
AjaxResult ajaxResult = queryDeviceProperties(dcDevice.getIotDeviceId(), propertyId, props); |
|
|
AjaxResult ajaxResult = queryDeviceProperties(dcDevice.getIotDeviceId(), propertyId, props); |
|
|
if (!ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { |
|
|
if (!ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { |
|
|
return ajaxResult; |
|
|
return ajaxResult; |
|
|
} |
|
|
} |
|
|
// 定义时间格式
|
|
|
// 定义时间格式
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
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()); |
|
|
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 decimalFormat = new DecimalFormat("#.##"); |
|
|
decimalFormat.setRoundingMode(RoundingMode.HALF_UP); |
|
|
decimalFormat.setRoundingMode(RoundingMode.HALF_UP); |
|
|
|
|
|
|
|
@ -469,24 +468,43 @@ private VideoController videoController; |
|
|
calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, |
|
|
calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, |
|
|
calendar.get(Calendar.DAY_OF_MONTH), hour); |
|
|
calendar.get(Calendar.DAY_OF_MONTH), hour); |
|
|
|
|
|
|
|
|
//转换为 double 类型,去除单位
|
|
|
// 转换为 double 类型,去除单位
|
|
|
String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", ""); |
|
|
String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", ""); |
|
|
// double formatValue = Double.parseDouble(valueWithoutUnit);
|
|
|
|
|
|
double parsedValue = Double.parseDouble(valueWithoutUnit); |
|
|
double parsedValue = Double.parseDouble(valueWithoutUnit); |
|
|
// 保留两位小数
|
|
|
// 保留两位小数
|
|
|
double formatValue = Double.parseDouble(decimalFormat.format(parsedValue)); |
|
|
double formatValue = Double.parseDouble(decimalFormat.format(parsedValue)); |
|
|
// 汇总每个小时的数据
|
|
|
|
|
|
deviceHourlyAggregates.merge(key, formatValue, (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); } |
|
|
// 检查当前小时是否有数据,如果没有则直接添加
|
|
|
// 将设备的数据合并到所有设备的汇总数据中
|
|
|
if (!deviceHourlyLatestData.containsKey(key)) { |
|
|
for (String key : deviceHourlyAggregates.keySet()) { |
|
|
Map<String, Object> dataPoint = new HashMap<>(); |
|
|
allDevicesHourlyAggregates.merge(key, deviceHourlyAggregates.get(key), (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); |
|
|
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); |
|
|
return AjaxResult.success(allDevicesHourlyAggregates); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("太阳能重点数据") |
|
|
@ApiOperation("太阳能重点数据") |
|
|
@GetMapping("/properties/latestOne") |
|
|
@GetMapping("/properties/latestOne") |
|
|
public AjaxResult getDeviceLatest() throws HttpException, IOException { |
|
|
public AjaxResult getDeviceLatest() throws HttpException, IOException { |
|
|