|
|
|
@ -2,6 +2,8 @@ package com.os.ems.record.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
@ -53,12 +55,6 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
|
* @param recordIotenvInstant 物联网数据
|
|
|
|
|
* @return 物联网数据
|
|
|
|
|
*/
|
|
|
|
|
// @Override
|
|
|
|
|
// public List<RecordIotenvInstant> selectRecordIotenvInstantList(RecordIotenvInstant recordIotenvInstant)
|
|
|
|
|
// {
|
|
|
|
|
// Map<String, Object> params = recordIotenvInstant.getParams();
|
|
|
|
|
// return recordIotenvInstantMapper.selectRecordIotenvInstantList(recordIotenvInstant);
|
|
|
|
|
// }
|
|
|
|
|
@Override
|
|
|
|
|
public List<RecordIotenvInstant> selectRecordIotenvInstantList(RecordIotenvInstant recordIotenvInstant) throws ParseException {
|
|
|
|
|
Map<String, Object> params = recordIotenvInstant.getParams();
|
|
|
|
@ -297,6 +293,82 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<RecordIotenvInstant> selectRecordList(RecordIotenvInstant recordIotenvInstant)
|
|
|
|
|
{
|
|
|
|
|
List<RecordIotenvInstant> result = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 获取当天日期对应的分表名
|
|
|
|
|
String todayTableName = getTodayTableName();
|
|
|
|
|
|
|
|
|
|
// 检查当天分表是否存在
|
|
|
|
|
boolean tableExists = isTableExists(todayTableName);
|
|
|
|
|
|
|
|
|
|
// 获取所有设备信息
|
|
|
|
|
List<EmsBaseMonitorInfo> baseMonitorInfos = emsBaseMonitorInfoMapper.selectEmsBaseMonitorInfoList(new EmsBaseMonitorInfo());
|
|
|
|
|
//获取所有能源类型
|
|
|
|
|
|
|
|
|
|
if (tableExists) {
|
|
|
|
|
// 如果分表存在,批量查询所有设备的最新数据
|
|
|
|
|
List<String> monitorCodes = new ArrayList<>();
|
|
|
|
|
for (EmsBaseMonitorInfo baseMonitorInfo : baseMonitorInfos) {
|
|
|
|
|
monitorCodes.add(baseMonitorInfo.getMonitorCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 批量查询最新记录
|
|
|
|
|
List<RecordIotenvInstant> latestRecords = recordIotenvInstantMapper
|
|
|
|
|
.selectLatestRecordsByMonitorIdsFromTable(todayTableName, monitorCodes);
|
|
|
|
|
|
|
|
|
|
// 创建设备编号到最新记录的映射
|
|
|
|
|
Map<String, RecordIotenvInstant> recordMap = new HashMap<>();
|
|
|
|
|
for (RecordIotenvInstant record : latestRecords) {
|
|
|
|
|
recordMap.put(record.getMonitorId(), record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 遍历所有设备,构建返回结果
|
|
|
|
|
for (EmsBaseMonitorInfo baseMonitorInfo : baseMonitorInfos) {
|
|
|
|
|
String monitorCode = baseMonitorInfo.getMonitorCode();
|
|
|
|
|
String monitorName = baseMonitorInfo.getMonitorName();
|
|
|
|
|
Long monitorType = baseMonitorInfo.getMonitorType();
|
|
|
|
|
|
|
|
|
|
RecordIotenvInstant iotenvInstant = recordMap.get(monitorCode);
|
|
|
|
|
if (iotenvInstant == null) {
|
|
|
|
|
// 如果没有找到记录,创建一个空记录
|
|
|
|
|
iotenvInstant = new RecordIotenvInstant();
|
|
|
|
|
iotenvInstant.setMonitorId(monitorCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置设备基本信息
|
|
|
|
|
iotenvInstant.setMonitorName(monitorName);
|
|
|
|
|
iotenvInstant.setMonitorCode(monitorCode);
|
|
|
|
|
|
|
|
|
|
result.add(iotenvInstant);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 如果分表不存在,返回所有设备的空记录
|
|
|
|
|
for (EmsBaseMonitorInfo baseMonitorInfo : baseMonitorInfos) {
|
|
|
|
|
RecordIotenvInstant iotenvInstant = new RecordIotenvInstant();
|
|
|
|
|
iotenvInstant.setMonitorId(baseMonitorInfo.getMonitorCode());
|
|
|
|
|
iotenvInstant.setMonitorName(baseMonitorInfo.getMonitorName());
|
|
|
|
|
iotenvInstant.setMonitorCode(baseMonitorInfo.getMonitorCode());
|
|
|
|
|
// 数据值字段保持null,前端会显示"无最新数据"
|
|
|
|
|
result.add(iotenvInstant);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当天日期对应的分表名
|
|
|
|
|
*
|
|
|
|
|
* @return 分表名
|
|
|
|
|
*/
|
|
|
|
|
private String getTodayTableName() {
|
|
|
|
|
LocalDate today = LocalDate.now();
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
|
|
String dateSuffix = today.format(formatter);
|
|
|
|
|
return "record_iotenv_instant_" + dateSuffix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|