From 10f48622c553729352dce9a4484def4bfeaa1083 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期三, 02 七月 2025 14:51:33 +0800
Subject: [PATCH] 1.将OnPanelDataReport相关功能由EFEM移到Aligner; 2.Glass增加最初来源Port和Slot,以便在Aligner检测NG时加退; 3.物流调度增加一个参数,是否检测OK作为调度依据。 4.Alginer检测NG,送回原处;
---
SourceCode/Bond/Servo/AlarmManager.cpp | 68 ++++++++++++++++++++-------------
1 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/SourceCode/Bond/Servo/AlarmManager.cpp b/SourceCode/Bond/Servo/AlarmManager.cpp
index 74b1006..0ed76e5 100644
--- a/SourceCode/Bond/Servo/AlarmManager.cpp
+++ b/SourceCode/Bond/Servo/AlarmManager.cpp
@@ -33,12 +33,6 @@
}
}
-// 设置数据库连接
-void AlarmManager::setDatabase(BL::Database* db) {
- std::lock_guard<std::mutex> lock(m_mutex);
- m_pDB = db;
-}
-
// 初始化报警表
bool AlarmManager::initAlarmTable() {
char path[MAX_PATH];
@@ -89,7 +83,7 @@
unit_id TEXT NOT NULL,
description TEXT NOT NULL,
start_time DATETIME NOT NULL,
- end_time DATETIME NOT NULL,
+ end_time DATETIME,
FOREIGN KEY (device_id) REFERENCES devices(device_id),
FOREIGN KEY (unit_id) REFERENCES units(unit_id)
)
@@ -127,7 +121,7 @@
// 插入单元数据
for (int i = 1; i <= 3; ++i) {
- for (int j = 1; j <= 3; ++j) {
+ for (int j = 0; j <= 3; ++j) {
int unitId = j;
std::string deviceId = std::to_string(i);
std::string unitName = "Unit" + std::to_string(j);
@@ -144,6 +138,7 @@
}
}
+ /*
// 初始化随机数生成器
std::random_device rd;
std::mt19937 gen(rd());
@@ -181,6 +176,7 @@
std::cerr << "Failed to insert alarm data." << std::endl;
}
}
+ */
}
// 添加报警信息
@@ -219,6 +215,17 @@
return result;
#else
+ for (AlarmDataMap::const_iterator it = m_mapCache.begin(); it != m_mapCache.end(); ++it) {
+ const AlarmData& alarm = it->second;
+ if (alarm.nId == alarmData.nId &&
+ alarm.nDeviceId == alarmData.nDeviceId &&
+ alarm.nUnitId == alarmData.nUnitId) {
+
+ alarmEventId = it->first;
+ return false;
+ }
+ }
+
// 构建插入查询并使用 RETURNING 获取插入后的 alarm_event_id
std::ostringstream query;
query << "INSERT INTO alarms (id, severity_level, device_id, unit_id, description, start_time, end_time) "
@@ -717,7 +724,7 @@
}
// 通过多个属性查找并解除报警(更新结束时间)
-bool AlarmManager::clearAlarmByAttributes(int nId, int nSeverityLevel, int nDeviceId, int nUnitId, const std::string& strDescription, const std::string& endTime) {
+bool AlarmManager::clearAlarmByAttributes(int nId, int nDeviceId, int nUnitId, const std::string& endTime) {
if (!m_pDB) {
return false;
}
@@ -729,10 +736,8 @@
for (AlarmDataMap::const_iterator it = m_mapCache.begin(); it != m_mapCache.end(); ++it) {
const AlarmData& alarm = it->second;
if (alarm.nId == nId &&
- alarm.nSeverityLevel == nSeverityLevel &&
alarm.nDeviceId == nDeviceId &&
- alarm.nUnitId == nUnitId &&
- alarm.strDescription == strDescription) {
+ alarm.nUnitId == nUnitId) {
alarmEventId = it->first;
break;
@@ -776,23 +781,32 @@
std::string cell;
AlarmInfo alarm;
- std::getline(ss, cell, ',');
- std::getline(ss, alarm.strUnitID, ',');
- std::getline(ss, alarm.strUnitNo, ',');
- std::getline(ss, cell, ',');
- alarm.nAlarmLevel = std::stoi(cell);
- std::getline(ss, cell, ',');
- alarm.nAlarmCode = std::stoi(cell);
- std::getline(ss, cell, ',');
- alarm.nAlarmID = std::stoi(cell);
- std::getline(ss, alarm.strAlarmText, ',');
- std::getline(ss, alarm.strDescription, ',');
+ try {
+ // 逐字段解析并验证
+ if (!std::getline(ss, cell, ',')) throw std::runtime_error("Missing field: No");
+ if (!std::getline(ss, alarm.strUnitID, ',')) throw std::runtime_error("Missing field: UnitID");
+ if (!std::getline(ss, alarm.strUnitNo, ',')) throw std::runtime_error("Missing field: UnitNo");
+ if (!std::getline(ss, cell, ',')) throw std::runtime_error("Missing field: AlarmLevel");
+ alarm.nAlarmLevel = std::stoi(cell);
+ if (!std::getline(ss, cell, ',')) throw std::runtime_error("Missing field: AlarmCode");
+ alarm.nAlarmCode = std::stoi(cell);
+ if (!std::getline(ss, cell, ',')) throw std::runtime_error("Missing field: AlarmID");
+ alarm.nAlarmID = std::stoi(cell);
+ if (!std::getline(ss, alarm.strAlarmText, ',')) throw std::runtime_error("Missing field: AlarmText");
+ if (!std::getline(ss, alarm.strDescription, ',')) throw std::runtime_error("Missing field: Description");
- if (m_mapAlarm.find(alarm.nAlarmID) == m_mapAlarm.end()) {
- m_mapAlarm[alarm.nAlarmID] = alarm;
+ // 检查是否重复
+ if (m_mapAlarm.find(alarm.nAlarmID) == m_mapAlarm.end()) {
+ m_mapAlarm[alarm.nAlarmID] = alarm;
+ }
+ else {
+ std::cerr << "Duplicate AlarmID: " << alarm.nAlarmID << std::endl;
+ }
}
- else {
- std::cerr << "Duplicate AlarmID: " << alarm.nAlarmID << std::endl;
+ catch (const std::exception& e) {
+ // 捕获并记录解析错误
+ std::cerr << "Error parsing line: " << line << " - " << e.what() << std::endl;
+ continue;
}
}
--
Gitblit v1.9.3