|
|
|
@ -364,6 +364,88 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据父节点ID查询子设备的最新数据
|
|
|
|
|
*
|
|
|
|
|
* @param parentId 父节点ID
|
|
|
|
|
* @return 子设备最新数据列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<RecordIotenvInstant> selectRecordListByParentId(Long parentId)
|
|
|
|
|
{
|
|
|
|
|
List<RecordIotenvInstant> result = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 获取当天日期对应的分表名
|
|
|
|
|
String todayTableName = getTodayTableName();
|
|
|
|
|
|
|
|
|
|
// 检查当天分表是否存在
|
|
|
|
|
boolean tableExists = isTableExists(todayTableName);
|
|
|
|
|
|
|
|
|
|
// 根据父节点ID查询子设备信息
|
|
|
|
|
EmsBaseMonitorInfo queryParam = new EmsBaseMonitorInfo();
|
|
|
|
|
queryParam.setParentId(parentId);
|
|
|
|
|
List<EmsBaseMonitorInfo> childDevices = emsBaseMonitorInfoMapper.selectEmsBaseMonitorInfoList(queryParam);
|
|
|
|
|
|
|
|
|
|
if (childDevices.isEmpty()) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tableExists) {
|
|
|
|
|
// 如果分表存在,批量查询子设备的最新数据
|
|
|
|
|
List<String> monitorCodes = new ArrayList<>();
|
|
|
|
|
for (EmsBaseMonitorInfo device : childDevices) {
|
|
|
|
|
monitorCodes.add(device.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 device : childDevices) {
|
|
|
|
|
String monitorCode = device.getMonitorCode();
|
|
|
|
|
String monitorName = device.getMonitorName();
|
|
|
|
|
Long monitorType = device.getMonitorType();
|
|
|
|
|
String energyName = device.getEnergyName();
|
|
|
|
|
|
|
|
|
|
RecordIotenvInstant iotenvInstant = recordMap.get(monitorCode);
|
|
|
|
|
if (iotenvInstant == null) {
|
|
|
|
|
// 如果没有找到记录,创建一个空记录
|
|
|
|
|
iotenvInstant = new RecordIotenvInstant();
|
|
|
|
|
iotenvInstant.setMonitorId(monitorCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置设备基本信息
|
|
|
|
|
iotenvInstant.setMonitorName(monitorName);
|
|
|
|
|
iotenvInstant.setMonitorCode(monitorCode);
|
|
|
|
|
iotenvInstant.setEnergyName(energyName);
|
|
|
|
|
iotenvInstant.setMonitorType(monitorType);
|
|
|
|
|
|
|
|
|
|
result.add(iotenvInstant);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 如果分表不存在,返回子设备的空记录
|
|
|
|
|
for (EmsBaseMonitorInfo device : childDevices) {
|
|
|
|
|
RecordIotenvInstant iotenvInstant = new RecordIotenvInstant();
|
|
|
|
|
iotenvInstant.setMonitorId(device.getMonitorCode());
|
|
|
|
|
iotenvInstant.setMonitorName(device.getMonitorName());
|
|
|
|
|
iotenvInstant.setMonitorCode(device.getMonitorCode());
|
|
|
|
|
iotenvInstant.setEnergyName(device.getEnergyName());
|
|
|
|
|
iotenvInstant.setMonitorType(device.getMonitorType());
|
|
|
|
|
// 数据值字段保持null,前端会显示"无最新数据"
|
|
|
|
|
result.add(iotenvInstant);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当天日期对应的分表名
|
|
|
|
|
*
|
|
|
|
|