LAPTOP-SNT8I5JK\Boounion
2025-05-12 d68541dce155a682f65b7c3fbfbfbeef17ea5b8f
SourceCode/Bond/Servo/AlarmManager.cpp
@@ -89,7 +89,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 +127,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 +144,7 @@
        }
    }
    /*
    // 初始化随机数生成器
    std::random_device rd;
    std::mt19937 gen(rd());
@@ -181,6 +182,7 @@
            std::cerr << "Failed to insert alarm data." << std::endl;
        }
    }
    */
}
// 添加报警信息
@@ -219,6 +221,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 +730,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 +742,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;