|
|
|
|
@ -360,22 +360,70 @@ public class ScheduleRulesServiceImpl implements IScheduleRulesService { |
|
|
|
|
executor.shutdown(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ 完整性校验:找出所有子表为空的设备
|
|
|
|
|
List<String> invalidDevices = successList.stream() |
|
|
|
|
.filter(g -> g.getSubEntities() == null |
|
|
|
|
|| g.getSubEntities().isEmpty() |
|
|
|
|
|| g.getSubEntities().values().stream().anyMatch(list -> list == null || list.isEmpty())) |
|
|
|
|
.map(g -> g.getEquGather().getEquId()) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
// // ✅ 完整性校验:找出所有子表为空的设备
|
|
|
|
|
// List<String> invalidDevices = successList.stream()
|
|
|
|
|
// .filter(g -> g.getSubEntities() == null
|
|
|
|
|
// || g.getSubEntities().isEmpty()
|
|
|
|
|
// || g.getSubEntities().values().stream().anyMatch(list -> list == null || list.isEmpty()))
|
|
|
|
|
// .map(g -> g.getEquGather().getEquId())
|
|
|
|
|
// .collect(Collectors.toList());
|
|
|
|
|
//
|
|
|
|
|
// // 如果全部失败或者发现不完整设备,抛异常
|
|
|
|
|
// if (successList.isEmpty() || !invalidDevices.isEmpty()) {
|
|
|
|
|
// String msg = "本次采集失败,保持旧数据完好。失败设备:" +
|
|
|
|
|
// String.join(", ", failed) +
|
|
|
|
|
// (invalidDevices.isEmpty() ? "" : ",采集数据不完整设备:" + String.join(", ", invalidDevices));
|
|
|
|
|
// log.error(msg);
|
|
|
|
|
// throw new RuntimeException(msg); // 异常抛出去,外层可捕获发送邮件
|
|
|
|
|
// }
|
|
|
|
|
// ✅ 完整性校验:找出所有子表为空的设备及对应子表
|
|
|
|
|
Map<String, List<String>> invalidDeviceMap = successList.stream() |
|
|
|
|
.map(g -> { |
|
|
|
|
String equId = g.getEquGather().getEquId(); |
|
|
|
|
|
|
|
|
|
// 找出这个设备下不完整的子表
|
|
|
|
|
List<String> emptyTables = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
// subEntities 为空或没有数据
|
|
|
|
|
if (g.getSubEntities() == null || g.getSubEntities().isEmpty()) { |
|
|
|
|
emptyTables.add("所有子表为空"); |
|
|
|
|
} else { |
|
|
|
|
// 检查每个子表的值
|
|
|
|
|
g.getSubEntities().forEach((tableName, list) -> { |
|
|
|
|
if (list == null || list.isEmpty()) { |
|
|
|
|
emptyTables.add(tableName); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 如果全部失败或者发现不完整设备,抛异常
|
|
|
|
|
// 如果有任何空子表,返回 (设备ID, 空表列表)
|
|
|
|
|
return emptyTables.isEmpty() ? null : Map.entry(equId, emptyTables); |
|
|
|
|
}) |
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); |
|
|
|
|
|
|
|
|
|
// ✅ 提取不完整设备ID列表
|
|
|
|
|
List<String> invalidDevices = new ArrayList<>(invalidDeviceMap.keySet()); |
|
|
|
|
|
|
|
|
|
// ✅ 如果全部失败或有不完整设备,抛异常
|
|
|
|
|
if (successList.isEmpty() || !invalidDevices.isEmpty()) { |
|
|
|
|
String msg = "本次采集失败,保持旧数据完好。失败设备:" + |
|
|
|
|
String.join(", ", failed) + |
|
|
|
|
(invalidDevices.isEmpty() ? "" : ",采集数据不完整设备:" + String.join(", ", invalidDevices)); |
|
|
|
|
log.error(msg); |
|
|
|
|
throw new RuntimeException(msg); // 异常抛出去,外层可捕获发送邮件
|
|
|
|
|
StringBuilder msg = new StringBuilder("本次采集失败,保持旧数据完好。"); |
|
|
|
|
|
|
|
|
|
if (!failed.isEmpty()) { |
|
|
|
|
msg.append("失败设备:").append(String.join(", ", failed)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!invalidDeviceMap.isEmpty()) { |
|
|
|
|
msg.append(";采集数据不完整设备如下:"); |
|
|
|
|
invalidDeviceMap.forEach((equId, tables) -> |
|
|
|
|
msg.append("\n设备[").append(equId).append("] 缺少表:") |
|
|
|
|
.append(String.join(", ", tables))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.error(msg.toString()); |
|
|
|
|
throw new RuntimeException(msg.toString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 事务内:删除旧表 + 插入成功设备数据
|
|
|
|
|
deleteAllEquipmentData(); // 删除依附表,不含 equ_gather
|
|
|
|
|
int inserted = persistAndUpdate(successList); // 插入成功设备数据
|
|
|
|
|
|