|
|
|
@ -495,23 +495,44 @@ public class DataProcessServiceImpl implements DataProcessService { |
|
|
|
List<CollectionParamsManage> dataList1 = entry1.getValue(); |
|
|
|
List<CollectionParamsManage> dataList1 = entry1.getValue(); |
|
|
|
// 进行数据处理入库操作等
|
|
|
|
// 进行数据处理入库操作等
|
|
|
|
try { |
|
|
|
try { |
|
|
|
List<CollectionParamsManage> dealList = new ArrayList<>(); |
|
|
|
dealAndInsertChillersData(dataList1, mtType); |
|
|
|
Map<Date, Optional<CollectionParamsManage>> dateOptionalMap = dealAndInsertChillers(dataList1, mtType); |
|
|
|
} catch (Exception e) { |
|
|
|
for (Map.Entry<Date, Optional<CollectionParamsManage>> value : dateOptionalMap.entrySet()) { |
|
|
|
log.error("处理主机参数异常:{}", e); |
|
|
|
boolean present = value.getValue().isPresent(); |
|
|
|
} |
|
|
|
if (!present) { |
|
|
|
} |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
dealList.add(value.getValue().get()); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 处理冷水机组数据并插入数据库,每5分钟存储一条数据 |
|
|
|
|
|
|
|
* @param dataList 同一设备的数据列表 |
|
|
|
|
|
|
|
* @param deviceType 设备类型 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void dealAndInsertChillersData(List<CollectionParamsManage> dataList, String deviceType) { |
|
|
|
|
|
|
|
// 格式化时间点为5分钟间隔,然后取同样时间点的最大值
|
|
|
|
|
|
|
|
Map<Date, Optional<CollectionParamsManage>> collect = dataList.stream() |
|
|
|
|
|
|
|
.peek(val -> val.setCurTime(DateUtils.stringToDate(DateUtils.getTimeMin(val.getCurTime(), 5), "yyyy-MM-dd HH:mm:ss"))) |
|
|
|
|
|
|
|
.collect( |
|
|
|
|
|
|
|
Collectors.groupingBy( |
|
|
|
|
|
|
|
CollectionParamsManage::getCurTime, |
|
|
|
|
|
|
|
Collectors.maxBy(Comparator.comparing(CollectionParamsManage::getCurValue))) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
collect = sortMapByDate(collect); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (collect.isEmpty()) { |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// 根据时间排序
|
|
|
|
|
|
|
|
dealList.sort(Comparator.comparing(CollectionParamsManage::getCurTime)); |
|
|
|
|
|
|
|
// 批量插入到chillers_data_min表
|
|
|
|
// 批量插入到chillers_data_min表
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
calendar.setTime(new Date()); |
|
|
|
calendar.setTime(new Date()); |
|
|
|
int year = calendar.get(Calendar.YEAR); |
|
|
|
int year = calendar.get(Calendar.YEAR); |
|
|
|
String tableName = "chillers_data_min" + year; |
|
|
|
String tableName = "chillers_data_min" + year; |
|
|
|
for (CollectionParamsManage collectionParamsManage : dealList) { |
|
|
|
|
|
|
|
|
|
|
|
// 遍历处理后的数据,插入数据库
|
|
|
|
|
|
|
|
for (Map.Entry<Date, Optional<CollectionParamsManage>> entry : collect.entrySet()) { |
|
|
|
|
|
|
|
if (entry.getValue().isPresent()) { |
|
|
|
|
|
|
|
CollectionParamsManage collectionParamsManage = entry.getValue().get(); |
|
|
|
// 判断是否存在,存在的话就不插入
|
|
|
|
// 判断是否存在,存在的话就不插入
|
|
|
|
DeviceReport deviceReport = new DeviceReport(); |
|
|
|
DeviceReport deviceReport = new DeviceReport(); |
|
|
|
deviceReport.setDeviceNum(collectionParamsManage.getMtNum()); |
|
|
|
deviceReport.setDeviceNum(collectionParamsManage.getMtNum()); |
|
|
|
@ -521,17 +542,6 @@ public class DataProcessServiceImpl implements DataProcessService { |
|
|
|
} |
|
|
|
} |
|
|
|
dataProcessMapper.batchInsertChiller(List.of(collectionParamsManage), tableName); |
|
|
|
dataProcessMapper.batchInsertChiller(List.of(collectionParamsManage), tableName); |
|
|
|
} |
|
|
|
} |
|
|
|
// int batchSize = 10;
|
|
|
|
|
|
|
|
// // 分页查询并插入数据
|
|
|
|
|
|
|
|
// for (int i = 0; i < cacheList.size(); i += batchSize) {
|
|
|
|
|
|
|
|
// List<CollectionParamsManage> batchList = cacheList.subList(i, Math.min(i + batchSize, cacheList.size()));
|
|
|
|
|
|
|
|
// // 执行插入语句
|
|
|
|
|
|
|
|
// dataProcessMapper.batchInsertChiller(batchList, tableName);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
log.error("处理主机参数异常:{}", e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|