|
|
@ -1,21 +1,18 @@ |
|
|
|
package com.mh.quartz.task; |
|
|
|
package com.mh.quartz.task; |
|
|
|
|
|
|
|
|
|
|
|
import com.mh.common.core.domain.entity.CollectionParamsManage; |
|
|
|
import com.mh.common.core.domain.entity.CollectionParamsManage; |
|
|
|
import com.mh.common.core.domain.entity.DeviceReportEntity; |
|
|
|
import com.mh.common.core.domain.entity.DeviceReport; |
|
|
|
import com.mh.common.core.redis.RedisCache; |
|
|
|
import com.mh.common.core.redis.RedisCache; |
|
|
|
import com.mh.common.enums.ComputeEnum; |
|
|
|
import com.mh.common.enums.ComputeEnum; |
|
|
|
import com.mh.common.utils.DateUtils; |
|
|
|
import com.mh.common.utils.DateUtils; |
|
|
|
import com.mh.framework.dealdata.DataProcessService; |
|
|
|
import com.mh.framework.dealdata.DataProcessService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.time.*; |
|
|
|
import java.time.*; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
import java.time.temporal.TemporalUnit; |
|
|
|
import java.time.temporal.TemporalUnit; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
@ -53,7 +50,7 @@ public class DealDataTask { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
//清空redis
|
|
|
|
//清空redis
|
|
|
|
// redisCache.delete Object("DEVICES");
|
|
|
|
redisCache.deleteObject("DEVICES"); |
|
|
|
//处理chillers数据
|
|
|
|
//处理chillers数据
|
|
|
|
try { |
|
|
|
try { |
|
|
|
//todo 处理没有对象curValue和curTime的异常
|
|
|
|
//todo 处理没有对象curValue和curTime的异常
|
|
|
@ -97,18 +94,18 @@ public class DealDataTask { |
|
|
|
Collectors.maxBy(Comparator.comparing(CollectionParamsManage::getCurValue))) |
|
|
|
Collectors.maxBy(Comparator.comparing(CollectionParamsManage::getCurValue))) |
|
|
|
); |
|
|
|
); |
|
|
|
collect = sortMapByDate(collect); |
|
|
|
collect = sortMapByDate(collect); |
|
|
|
List<DeviceReportEntity> dataMinList = new ArrayList<>(); |
|
|
|
List<DeviceReport> dataMinList = new ArrayList<>(); |
|
|
|
//value循环处理数据
|
|
|
|
//value循环处理数据
|
|
|
|
if (collect.size() > 0) { |
|
|
|
if (collect.size() > 0) { |
|
|
|
CollectionParamsManage entity = collect.values().stream().findFirst().get().get(); |
|
|
|
CollectionParamsManage entity = collect.values().stream().findFirst().get().get(); |
|
|
|
int deviceGrade = entity.getGrade(); |
|
|
|
int deviceGrade = entity.getGrade(); |
|
|
|
//从数据库取值,当前的年表,当前年表没有,查询上一次年表
|
|
|
|
//从数据库取值,当前的年表,当前年表没有,查询上一次年表
|
|
|
|
DeviceReportEntity lastData = dataProcessService.queryLastValue(entity.getMtNum(), "min"); |
|
|
|
DeviceReport lastData = dataProcessService.queryLastValue(entity.getMtNum(), "min"); |
|
|
|
int ratio = dataProcessService.queryRatio(entity.getMtNum()) == null ? 1 : dataProcessService.queryRatio(entity.getMtNum()); |
|
|
|
int ratio = dataProcessService.queryRatio(entity.getMtNum()) == null ? 1 : dataProcessService.queryRatio(entity.getMtNum()); |
|
|
|
if (ObjectUtils.isEmpty(lastData) || ObjectUtils.isEmpty(lastData.getLastValue())) { |
|
|
|
if (ObjectUtils.isEmpty(lastData) || ObjectUtils.isEmpty(lastData.getLastValue())) { |
|
|
|
//从device_manage取出初始值
|
|
|
|
//从device_manage取出初始值
|
|
|
|
String initValue = dataProcessService.queryInitValue(entity.getMtNum()); |
|
|
|
String initValue = dataProcessService.queryInitValue(entity.getMtNum()); |
|
|
|
DeviceReportEntity firstEntity = new DeviceReportEntity(); |
|
|
|
DeviceReport firstEntity = new DeviceReport(); |
|
|
|
firstEntity.setLastValue(initValue); |
|
|
|
firstEntity.setLastValue(initValue); |
|
|
|
firstEntity.setLastTime(entity.getCurTime()); |
|
|
|
firstEntity.setLastTime(entity.getCurTime()); |
|
|
|
firstEntity.setCurTime(entity.getCurTime()); |
|
|
|
firstEntity.setCurTime(entity.getCurTime()); |
|
|
@ -131,7 +128,7 @@ public class DealDataTask { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Date lastDate = lastData.getLastTime(); |
|
|
|
Date lastDate = lastData.getLastTime(); |
|
|
|
String lastValue = lastData.getLastValue(); |
|
|
|
String lastValue = lastData.getLastValue(); |
|
|
|
DeviceReportEntity firstEntity = new DeviceReportEntity(); |
|
|
|
DeviceReport firstEntity = new DeviceReport(); |
|
|
|
firstEntity.setLastValue(lastValue); |
|
|
|
firstEntity.setLastValue(lastValue); |
|
|
|
firstEntity.setLastTime(lastDate); |
|
|
|
firstEntity.setLastTime(lastDate); |
|
|
|
firstEntity.setCurTime(entity.getCurTime()); |
|
|
|
firstEntity.setCurTime(entity.getCurTime()); |
|
|
@ -161,8 +158,8 @@ public class DealDataTask { |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
DeviceReportEntity temp = new DeviceReportEntity(); |
|
|
|
DeviceReport temp = new DeviceReport(); |
|
|
|
DeviceReportEntity dataJ = dataMinList.get(j); |
|
|
|
DeviceReport dataJ = dataMinList.get(j); |
|
|
|
CollectionParamsManage dataI = entry.getValue().get(); |
|
|
|
CollectionParamsManage dataI = entry.getValue().get(); |
|
|
|
//复制实体类
|
|
|
|
//复制实体类
|
|
|
|
// BeanUtils.copyProperties(dataI, temp);
|
|
|
|
// BeanUtils.copyProperties(dataI, temp);
|
|
|
@ -232,34 +229,32 @@ public class DealDataTask { |
|
|
|
public void dealDeviceDataHour() { |
|
|
|
public void dealDeviceDataHour() { |
|
|
|
Map<String, Object> map = dataProcessService.queryUntreatedData("min"); |
|
|
|
Map<String, Object> map = dataProcessService.queryUntreatedData("min"); |
|
|
|
//需要处理的数据
|
|
|
|
//需要处理的数据
|
|
|
|
List<DeviceReportEntity> dataList = (List<DeviceReportEntity>) map.get("data"); |
|
|
|
List<DeviceReport> dataList = (List<DeviceReport>) map.get("data"); |
|
|
|
//处理完成后需要将数据设置为已处理,grade = 1,
|
|
|
|
//处理完成后需要将数据设置为已处理,grade = 1,
|
|
|
|
Map<String, List<Long>> idMap = (Map<String, List<Long>>) map.get("idMap"); |
|
|
|
Map<String, List<Long>> idMap = (Map<String, List<Long>>) map.get("idMap"); |
|
|
|
|
|
|
|
|
|
|
|
//遍历分组
|
|
|
|
//遍历分组
|
|
|
|
Map<String, Map<LocalDateTime, List<DeviceReportEntity>>> collect = getMeterNumMap(dataList, ChronoUnit.HOURS); |
|
|
|
Map<String, Map<LocalDateTime, List<DeviceReport>>> collect = getMeterNumMap(dataList, ChronoUnit.HOURS); |
|
|
|
|
|
|
|
|
|
|
|
//小时表数据集合
|
|
|
|
//小时表数据集合
|
|
|
|
List<DeviceReportEntity> hourList = new ArrayList<>(); |
|
|
|
List<DeviceReport> hourList = new ArrayList<>(); |
|
|
|
//TODO 分组好的数据计算后插入数据表
|
|
|
|
//TODO 分组好的数据计算后插入数据表
|
|
|
|
for (Map.Entry<String, Map<LocalDateTime, List<DeviceReportEntity>>> entry : collect.entrySet()) { |
|
|
|
for (Map.Entry<String, Map<LocalDateTime, List<DeviceReport>>> entry : collect.entrySet()) { |
|
|
|
//表号
|
|
|
|
//表号
|
|
|
|
String key = entry.getKey(); |
|
|
|
String key = entry.getKey(); |
|
|
|
Map<LocalDateTime, List<DeviceReportEntity>> value = entry.getValue(); |
|
|
|
Map<LocalDateTime, List<DeviceReport>> value = entry.getValue(); |
|
|
|
Set<Map.Entry<LocalDateTime, List<DeviceReportEntity>>> entries = value.entrySet(); |
|
|
|
Set<Map.Entry<LocalDateTime, List<DeviceReport>>> entries = value.entrySet(); |
|
|
|
String deviceType = null; |
|
|
|
String deviceType = null; |
|
|
|
for (Map.Entry<LocalDateTime, List<DeviceReportEntity>> listEntry : entries) { |
|
|
|
for (Map.Entry<LocalDateTime, List<DeviceReport>> listEntry : entries) { |
|
|
|
deviceType = listEntry.getValue().get(0).getDeviceType(); |
|
|
|
deviceType = listEntry.getValue().get(0).getDeviceType(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
//分组计算,得到一组当前表号的以时间分组的数据,循环计算第一条的当前读数是上一条的上次读数
|
|
|
|
//分组计算,得到一组当前表号的以时间分组的数据,循环计算第一条的当前读数是上一条的上次读数
|
|
|
|
ComputeEnum computeEnum = ComputeEnum.get(Integer.parseInt(deviceType)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert deviceType != null; |
|
|
|
assert deviceType != null; |
|
|
|
List<Map<LocalDateTime, DeviceReportEntity>> dealDataList = |
|
|
|
List<Map<LocalDateTime, DeviceReport>> dealDataList = |
|
|
|
ComputeEnum.get(Integer.parseInt(deviceType)).getDataList(entry); |
|
|
|
ComputeEnum.get(Integer.parseInt(deviceType)).getDataList(entry); |
|
|
|
|
|
|
|
|
|
|
|
List<Map<LocalDateTime, DeviceReportEntity>> sortedList = dealDataList.stream() |
|
|
|
List<Map<LocalDateTime, DeviceReport>> sortedList = dealDataList.stream() |
|
|
|
.sorted(Comparator.comparing(temMap -> temMap.keySet().iterator().next())) |
|
|
|
.sorted(Comparator.comparing(temMap -> temMap.keySet().iterator().next())) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
.collect(Collectors.toList()); |
|
|
|
//计算上次值,当前值
|
|
|
|
//计算上次值,当前值
|
|
|
@ -285,15 +280,15 @@ public class DealDataTask { |
|
|
|
* @param key |
|
|
|
* @param key |
|
|
|
* @param dealDataList |
|
|
|
* @param dealDataList |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private List<DeviceReportEntity> calcListData(List<DeviceReportEntity> hourList, |
|
|
|
private List<DeviceReport> calcListData(List<DeviceReport> hourList, |
|
|
|
String key, String tableType, |
|
|
|
String key, String tableType, |
|
|
|
List<Map<LocalDateTime, DeviceReportEntity>> dealDataList) { |
|
|
|
List<Map<LocalDateTime, DeviceReport>> dealDataList) { |
|
|
|
|
|
|
|
|
|
|
|
ArrayList<DeviceReportEntity> tempList = new ArrayList<>(); |
|
|
|
ArrayList<DeviceReport> tempList = new ArrayList<>(); |
|
|
|
for (int i = 0; i < dealDataList.size(); i++) { |
|
|
|
for (int i = 0; i < dealDataList.size(); i++) { |
|
|
|
|
|
|
|
|
|
|
|
if (i == 0) { |
|
|
|
if (i == 0) { |
|
|
|
Map<LocalDateTime, DeviceReportEntity> reportEntityMap = dealDataList.get(i); |
|
|
|
Map<LocalDateTime, DeviceReport> reportEntityMap = dealDataList.get(i); |
|
|
|
|
|
|
|
|
|
|
|
//由key已知是哪个表号
|
|
|
|
//由key已知是哪个表号
|
|
|
|
//判断第一个是否有历史数据,当年表有历史数据则取当年表,无则取上一年表,去年和今年表都无则取初始值
|
|
|
|
//判断第一个是否有历史数据,当年表有历史数据则取当年表,无则取上一年表,去年和今年表都无则取初始值
|
|
|
@ -301,7 +296,7 @@ public class DealDataTask { |
|
|
|
String lastValue = null; |
|
|
|
String lastValue = null; |
|
|
|
Date lastDate = null; |
|
|
|
Date lastDate = null; |
|
|
|
//查询历史记录
|
|
|
|
//查询历史记录
|
|
|
|
DeviceReportEntity hourEntity = dataProcessService.queryLastValue(key, tableType); |
|
|
|
DeviceReport hourEntity = dataProcessService.queryLastValue(key, tableType); |
|
|
|
if (ObjectUtils.isEmpty(hourEntity)) { |
|
|
|
if (ObjectUtils.isEmpty(hourEntity)) { |
|
|
|
//查询设备信息初始值
|
|
|
|
//查询设备信息初始值
|
|
|
|
lastValue = dataProcessService.queryInitValue(key); |
|
|
|
lastValue = dataProcessService.queryInitValue(key); |
|
|
@ -310,10 +305,10 @@ public class DealDataTask { |
|
|
|
lastDate = hourEntity.getLastTime(); |
|
|
|
lastDate = hourEntity.getLastTime(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Set<Map.Entry<LocalDateTime, DeviceReportEntity>> entrySet = reportEntityMap.entrySet(); |
|
|
|
Set<Map.Entry<LocalDateTime, DeviceReport>> entrySet = reportEntityMap.entrySet(); |
|
|
|
for (Map.Entry<LocalDateTime, DeviceReportEntity> entityEntry : entrySet) { |
|
|
|
for (Map.Entry<LocalDateTime, DeviceReport> entityEntry : entrySet) { |
|
|
|
LocalDateTime curTime = entityEntry.getKey(); |
|
|
|
LocalDateTime curTime = entityEntry.getKey(); |
|
|
|
DeviceReportEntity entity = entityEntry.getValue(); |
|
|
|
DeviceReport entity = entityEntry.getValue(); |
|
|
|
ZonedDateTime zonedDateTime = curTime.atZone(ZoneId.systemDefault()); |
|
|
|
ZonedDateTime zonedDateTime = curTime.atZone(ZoneId.systemDefault()); |
|
|
|
Date date = Date.from(zonedDateTime.toInstant()); |
|
|
|
Date date = Date.from(zonedDateTime.toInstant()); |
|
|
|
entity.setCurTime(date); |
|
|
|
entity.setCurTime(date); |
|
|
@ -339,12 +334,12 @@ public class DealDataTask { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//从上一条取当前读数和当前时间作为当前对象的上一次读数
|
|
|
|
//从上一条取当前读数和当前时间作为当前对象的上一次读数
|
|
|
|
int lastIndex = i - 1; |
|
|
|
int lastIndex = i - 1; |
|
|
|
DeviceReportEntity lastEntity = tempList.get(lastIndex); |
|
|
|
DeviceReport lastEntity = tempList.get(lastIndex); |
|
|
|
Map<LocalDateTime, DeviceReportEntity> curMap = dealDataList.get(i); |
|
|
|
Map<LocalDateTime, DeviceReport> curMap = dealDataList.get(i); |
|
|
|
Set<Map.Entry<LocalDateTime, DeviceReportEntity>> curEntrySet = curMap.entrySet(); |
|
|
|
Set<Map.Entry<LocalDateTime, DeviceReport>> curEntrySet = curMap.entrySet(); |
|
|
|
for (Map.Entry<LocalDateTime, DeviceReportEntity> curEntry : curEntrySet) { |
|
|
|
for (Map.Entry<LocalDateTime, DeviceReport> curEntry : curEntrySet) { |
|
|
|
LocalDateTime curTime = curEntry.getKey(); |
|
|
|
LocalDateTime curTime = curEntry.getKey(); |
|
|
|
DeviceReportEntity curEntity = curEntry.getValue(); |
|
|
|
DeviceReport curEntity = curEntry.getValue(); |
|
|
|
ZonedDateTime zonedDateTime = curTime.atZone(ZoneId.systemDefault()); |
|
|
|
ZonedDateTime zonedDateTime = curTime.atZone(ZoneId.systemDefault()); |
|
|
|
Date date = Date.from(zonedDateTime.toInstant()); |
|
|
|
Date date = Date.from(zonedDateTime.toInstant()); |
|
|
|
curEntity.setCurTime(date); |
|
|
|
curEntity.setCurTime(date); |
|
|
@ -376,8 +371,8 @@ public class DealDataTask { |
|
|
|
* @param interval 时间间隔 |
|
|
|
* @param interval 时间间隔 |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Map<String, Map<LocalDateTime, List<DeviceReportEntity>>> getMeterNumMap(List<DeviceReportEntity> dataList, |
|
|
|
private Map<String, Map<LocalDateTime, List<DeviceReport>>> getMeterNumMap(List<DeviceReport> dataList, |
|
|
|
TemporalUnit interval) { |
|
|
|
TemporalUnit interval) { |
|
|
|
// 获取 MinuteData 对象集合,其中的时间戳是 java.util.Date 类型
|
|
|
|
// 获取 MinuteData 对象集合,其中的时间戳是 java.util.Date 类型
|
|
|
|
//1:数据格式为先按照表号分组,设备类型里的数据再按照小时分组
|
|
|
|
//1:数据格式为先按照表号分组,设备类型里的数据再按照小时分组
|
|
|
|
//2:小时分组的数据就是DeviceReportEntity实体类
|
|
|
|
//2:小时分组的数据就是DeviceReportEntity实体类
|
|
|
@ -387,10 +382,10 @@ public class DealDataTask { |
|
|
|
data.setLocalDateTime(dateTime); |
|
|
|
data.setLocalDateTime(dateTime); |
|
|
|
return data; |
|
|
|
return data; |
|
|
|
}) |
|
|
|
}) |
|
|
|
.sorted(Comparator.comparing(DeviceReportEntity::getLocalDateTime)) |
|
|
|
.sorted(Comparator.comparing(DeviceReport::getLocalDateTime)) |
|
|
|
.collect( |
|
|
|
.collect( |
|
|
|
//根据表号分组
|
|
|
|
//根据表号分组
|
|
|
|
Collectors.groupingBy(DeviceReportEntity::getDeviceNum, |
|
|
|
Collectors.groupingBy(DeviceReport::getDeviceNum, |
|
|
|
//根据时间间隔分组,后续是否需要根据减少分组
|
|
|
|
//根据时间间隔分组,后续是否需要根据减少分组
|
|
|
|
Collectors.groupingBy(report -> report.getLocalDateTime().truncatedTo(interval))) |
|
|
|
Collectors.groupingBy(report -> report.getLocalDateTime().truncatedTo(interval))) |
|
|
|
|
|
|
|
|
|
|
@ -406,18 +401,18 @@ public class DealDataTask { |
|
|
|
public void dealDay2Year() { |
|
|
|
public void dealDay2Year() { |
|
|
|
Map<String, Object> untreatedList = dataProcessService.queryUntreatedData("hour"); |
|
|
|
Map<String, Object> untreatedList = dataProcessService.queryUntreatedData("hour"); |
|
|
|
//需要处理的数据
|
|
|
|
//需要处理的数据
|
|
|
|
List<DeviceReportEntity> dataList = (List<DeviceReportEntity>) untreatedList.get("data"); |
|
|
|
List<DeviceReport> dataList = (List<DeviceReport>) untreatedList.get("data"); |
|
|
|
//处理完成后需要将数据设置为已处理,grade = 1,
|
|
|
|
//处理完成后需要将数据设置为已处理,grade = 1,
|
|
|
|
Map<String, List<Long>> idMap = (Map<String, List<Long>>) untreatedList.get("idMap"); |
|
|
|
Map<String, List<Long>> idMap = (Map<String, List<Long>>) untreatedList.get("idMap"); |
|
|
|
|
|
|
|
|
|
|
|
//<表号:<时间:List<集合>>> 按照日区分
|
|
|
|
//<表号:<时间:List<集合>>> 按照日区分
|
|
|
|
Map<String, Map<LocalDateTime, List<DeviceReportEntity>>> dayMap = getMeterNumMap(dataList, ChronoUnit.DAYS); |
|
|
|
Map<String, Map<LocalDateTime, List<DeviceReport>>> dayMap = getMeterNumMap(dataList, ChronoUnit.DAYS); |
|
|
|
List<DeviceReportEntity> dayList = new ArrayList<>(); |
|
|
|
List<DeviceReport> dayList = new ArrayList<>(); |
|
|
|
List<DeviceReportEntity> monthList = new ArrayList<>(); |
|
|
|
List<DeviceReport> monthList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 使用流对每个内部的Map进行排序
|
|
|
|
// 使用流对每个内部的Map进行排序
|
|
|
|
dayMap.forEach((key, value) -> { |
|
|
|
dayMap.forEach((key, value) -> { |
|
|
|
Map<LocalDateTime, List<DeviceReportEntity>> sortedMap = value.entrySet().stream() |
|
|
|
Map<LocalDateTime, List<DeviceReport>> sortedMap = value.entrySet().stream() |
|
|
|
.sorted(Map.Entry.comparingByKey()) |
|
|
|
.sorted(Map.Entry.comparingByKey()) |
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new)); |
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new)); |
|
|
|
|
|
|
|
|
|
|
@ -435,8 +430,8 @@ public class DealDataTask { |
|
|
|
|
|
|
|
|
|
|
|
// 按照月区分
|
|
|
|
// 按照月区分
|
|
|
|
//Map<String, Map<LocalDateTime, List<DeviceReportEntity>>> monthMap = getMeterNumMap(dataList, ChronoUnit.MONTHS);
|
|
|
|
//Map<String, Map<LocalDateTime, List<DeviceReportEntity>>> monthMap = getMeterNumMap(dataList, ChronoUnit.MONTHS);
|
|
|
|
Map<String, Map<YearMonth, List<DeviceReportEntity>>> monthMap = getMeterNumMapByMonth(dataList, ChronoUnit.MONTHS); |
|
|
|
Map<String, Map<YearMonth, List<DeviceReport>>> monthMap = getMeterNumMapByMonth(dataList, ChronoUnit.MONTHS); |
|
|
|
List<DeviceReportEntity> monthInsert = getMonthListData(monthList, monthMap); |
|
|
|
List<DeviceReport> monthInsert = getMonthListData(monthList, monthMap); |
|
|
|
dataProcessService.batchInsertOrUpdate(monthInsert, "month"); |
|
|
|
dataProcessService.batchInsertOrUpdate(monthInsert, "month"); |
|
|
|
|
|
|
|
|
|
|
|
// 按照年区分
|
|
|
|
// 按照年区分
|
|
|
@ -455,32 +450,32 @@ public class DealDataTask { |
|
|
|
* @param monthMap |
|
|
|
* @param monthMap |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private List<DeviceReportEntity> getMonthListData(List<DeviceReportEntity> monthList, Map<String, Map<YearMonth, List<DeviceReportEntity>>> monthMap) { |
|
|
|
private List<DeviceReport> getMonthListData(List<DeviceReport> monthList, Map<String, Map<YearMonth, List<DeviceReport>>> monthMap) { |
|
|
|
Set<Map.Entry<String, Map<YearMonth, List<DeviceReportEntity>>>> entries = monthMap.entrySet(); |
|
|
|
Set<Map.Entry<String, Map<YearMonth, List<DeviceReport>>>> entries = monthMap.entrySet(); |
|
|
|
for (Map.Entry<String, Map<YearMonth, List<DeviceReportEntity>>> entry : entries) { |
|
|
|
for (Map.Entry<String, Map<YearMonth, List<DeviceReport>>> entry : entries) { |
|
|
|
String deviceNum = entry.getKey(); |
|
|
|
String deviceNum = entry.getKey(); |
|
|
|
Map<YearMonth, List<DeviceReportEntity>> value = entry.getValue(); |
|
|
|
Map<YearMonth, List<DeviceReport>> value = entry.getValue(); |
|
|
|
List<DeviceReportEntity> deviceList = new ArrayList<>(); |
|
|
|
List<DeviceReport> deviceList = new ArrayList<>(); |
|
|
|
List<DeviceReportEntity> monthInsert = new ArrayList<>(); |
|
|
|
List<DeviceReport> monthInsert = new ArrayList<>(); |
|
|
|
List<DeviceReportEntity> tempList = new ArrayList<>(); |
|
|
|
List<DeviceReport> tempList = new ArrayList<>(); |
|
|
|
Set<Map.Entry<YearMonth, List<DeviceReportEntity>>> monthEntries = value.entrySet(); |
|
|
|
Set<Map.Entry<YearMonth, List<DeviceReport>>> monthEntries = value.entrySet(); |
|
|
|
for (Map.Entry<YearMonth, List<DeviceReportEntity>> monthEntry : monthEntries) { |
|
|
|
for (Map.Entry<YearMonth, List<DeviceReport>> monthEntry : monthEntries) { |
|
|
|
//月份
|
|
|
|
//月份
|
|
|
|
YearMonth key = monthEntry.getKey(); |
|
|
|
YearMonth key = monthEntry.getKey(); |
|
|
|
//集合
|
|
|
|
//集合
|
|
|
|
List<DeviceReportEntity> monthEntryValue = monthEntry.getValue(); |
|
|
|
List<DeviceReport> monthEntryValue = monthEntry.getValue(); |
|
|
|
//筛选出最大值和最小值
|
|
|
|
//筛选出最大值和最小值
|
|
|
|
DeviceReportEntity max = Collections.max(monthEntryValue, Comparator.comparing(DeviceReportEntity::getLocalDateTime)); |
|
|
|
DeviceReport max = Collections.max(monthEntryValue, Comparator.comparing(DeviceReport::getLocalDateTime)); |
|
|
|
|
|
|
|
|
|
|
|
deviceList.add(max); |
|
|
|
deviceList.add(max); |
|
|
|
} |
|
|
|
} |
|
|
|
deviceList.sort(Comparator.comparing(DeviceReportEntity::getLocalDateTime)); |
|
|
|
deviceList.sort(Comparator.comparing(DeviceReport::getLocalDateTime)); |
|
|
|
for (int i = 0; i < deviceList.size(); i++) { |
|
|
|
for (int i = 0; i < deviceList.size(); i++) { |
|
|
|
String lastValue; |
|
|
|
String lastValue; |
|
|
|
Date lastTime; |
|
|
|
Date lastTime; |
|
|
|
if (i == 0) { |
|
|
|
if (i == 0) { |
|
|
|
DeviceReportEntity entity = deviceList.get(i); |
|
|
|
DeviceReport entity = deviceList.get(i); |
|
|
|
DeviceReportEntity lastEntity = dataProcessService.queryLastValue(deviceNum, "month"); |
|
|
|
DeviceReport lastEntity = dataProcessService.queryLastValue(deviceNum, "month"); |
|
|
|
if (ObjectUtils.isEmpty(lastEntity)) { |
|
|
|
if (ObjectUtils.isEmpty(lastEntity)) { |
|
|
|
lastValue = dataProcessService.queryInitValue(deviceNum); |
|
|
|
lastValue = dataProcessService.queryInitValue(deviceNum); |
|
|
|
lastTime = entity.getCurTime(); |
|
|
|
lastTime = entity.getCurTime(); |
|
|
@ -504,8 +499,8 @@ public class DealDataTask { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//从上一条取当前读数和当前时间作为当前对象的上一次读数
|
|
|
|
//从上一条取当前读数和当前时间作为当前对象的上一次读数
|
|
|
|
int lastIndex = i - 1; |
|
|
|
int lastIndex = i - 1; |
|
|
|
DeviceReportEntity lastEntity = tempList.get(lastIndex); |
|
|
|
DeviceReport lastEntity = tempList.get(lastIndex); |
|
|
|
DeviceReportEntity curEntity = deviceList.get(i); |
|
|
|
DeviceReport curEntity = deviceList.get(i); |
|
|
|
|
|
|
|
|
|
|
|
curEntity.setLastTime(lastEntity.getCurTime()); |
|
|
|
curEntity.setLastTime(lastEntity.getCurTime()); |
|
|
|
curEntity.setLastValue(lastEntity.getCurValue()); |
|
|
|
curEntity.setLastValue(lastEntity.getCurValue()); |
|
|
@ -537,20 +532,20 @@ public class DealDataTask { |
|
|
|
* @param tableType |
|
|
|
* @param tableType |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private List<DeviceReportEntity> getDeviceReportEntities(Map<String, Map<LocalDateTime, List<DeviceReportEntity>>> dayMap, |
|
|
|
private List<DeviceReport> getDeviceReportEntities(Map<String, Map<LocalDateTime, List<DeviceReport>>> dayMap, |
|
|
|
List<DeviceReportEntity> dayList, |
|
|
|
List<DeviceReport> dayList, |
|
|
|
String tableType) { |
|
|
|
String tableType) { |
|
|
|
for (Map.Entry<String, Map<LocalDateTime, List<DeviceReportEntity>>> entry : dayMap.entrySet()) { |
|
|
|
for (Map.Entry<String, Map<LocalDateTime, List<DeviceReport>>> entry : dayMap.entrySet()) { |
|
|
|
//表号
|
|
|
|
//表号
|
|
|
|
String key = entry.getKey(); |
|
|
|
String key = entry.getKey(); |
|
|
|
Map<LocalDateTime, List<DeviceReportEntity>> value = entry.getValue(); |
|
|
|
Map<LocalDateTime, List<DeviceReport>> value = entry.getValue(); |
|
|
|
String deviceType = null; |
|
|
|
String deviceType = null; |
|
|
|
for (Map.Entry<LocalDateTime, List<DeviceReportEntity>> listEntry : value.entrySet()) { |
|
|
|
for (Map.Entry<LocalDateTime, List<DeviceReport>> listEntry : value.entrySet()) { |
|
|
|
deviceType = listEntry.getValue().get(0).getDeviceType(); |
|
|
|
deviceType = listEntry.getValue().get(0).getDeviceType(); |
|
|
|
} |
|
|
|
} |
|
|
|
//取到的最大值
|
|
|
|
//取到的最大值
|
|
|
|
assert deviceType != null; |
|
|
|
assert deviceType != null; |
|
|
|
List<Map<LocalDateTime, DeviceReportEntity>> dayMapList = |
|
|
|
List<Map<LocalDateTime, DeviceReport>> dayMapList = |
|
|
|
ComputeEnum.get(Integer.parseInt(deviceType)).getDataList(entry); |
|
|
|
ComputeEnum.get(Integer.parseInt(deviceType)).getDataList(entry); |
|
|
|
dayList = calcListData(dayList, key, tableType, dayMapList); |
|
|
|
dayList = calcListData(dayList, key, tableType, dayMapList); |
|
|
|
|
|
|
|
|
|
|
@ -565,15 +560,15 @@ public class DealDataTask { |
|
|
|
* @param interval |
|
|
|
* @param interval |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Map<String, Map<YearMonth, List<DeviceReportEntity>>> getMeterNumMapByMonth(List<DeviceReportEntity> dataList, |
|
|
|
private Map<String, Map<YearMonth, List<DeviceReport>>> getMeterNumMapByMonth(List<DeviceReport> dataList, |
|
|
|
TemporalUnit interval) { |
|
|
|
TemporalUnit interval) { |
|
|
|
return dataList.stream() |
|
|
|
return dataList.stream() |
|
|
|
.map(data -> { |
|
|
|
.map(data -> { |
|
|
|
LocalDateTime dateTime = LocalDateTime.ofInstant(data.getCurTime().toInstant(), ZoneId.systemDefault()); |
|
|
|
LocalDateTime dateTime = LocalDateTime.ofInstant(data.getCurTime().toInstant(), ZoneId.systemDefault()); |
|
|
|
data.setLocalDateTime(dateTime); |
|
|
|
data.setLocalDateTime(dateTime); |
|
|
|
return data; |
|
|
|
return data; |
|
|
|
}) |
|
|
|
}) |
|
|
|
.collect(Collectors.groupingBy(DeviceReportEntity::getDeviceNum, |
|
|
|
.collect(Collectors.groupingBy(DeviceReport::getDeviceNum, |
|
|
|
Collectors.groupingBy( |
|
|
|
Collectors.groupingBy( |
|
|
|
report -> YearMonth.from(report.getLocalDateTime()), |
|
|
|
report -> YearMonth.from(report.getLocalDateTime()), |
|
|
|
LinkedHashMap::new, |
|
|
|
LinkedHashMap::new, |
|
|
|