#include "CAlarmMsgInfo.h" #include #include "CAlarmDataCollect.h" #include #include "CAiAlarmMsgInfo.h" #include "pub_logger_api/logger.h" using namespace std; CAlarmMsgInfo::CAlarmMsgInfo() { alm_type = -1; alm_status = -1; logic_state = E_ALS_ALARM; time_stamp = 1000; domain_id = -1; location_id = -1; app_id = -1; uuid_base64 = QString(); content = QString(); priority = -1; if_water_alm = -1; sound_file = QStringList(); dev_type = -1; region_id = -1; dev_group_tag =QString(); key_id_tag = QString(); graph_name = QString(); priorityOrder = -1; deleteFlag = false; releaseFlag = false; device = QString(); m_needVideoAlm = false; m_camera = QString(); m_preset = QString(); } CAlarmMsgInfo::CAlarmMsgInfo(const CAlarmMsgInfo &other) { alm_type = other.alm_type; alm_status = other.alm_status; logic_state = other.logic_state; time_stamp = other.time_stamp; domain_id = other.domain_id; location_id = other.location_id; app_id = other.app_id; uuid_base64 = other.uuid_base64; content = other.content; priority = other.priority; priorityOrder = other.priorityOrder; if_water_alm = other.if_water_alm; sound_file = other.sound_file; dev_type = other.dev_type; region_id = other.region_id; dev_group_tag =other.dev_group_tag; key_id_tag = other.key_id_tag; graph_name = other.graph_name; deleteFlag = other.deleteFlag; releaseFlag = other.releaseFlag; device = other.device; m_needVideoAlm = other.m_needVideoAlm; m_camera = other.m_camera; m_preset = other.m_preset; } void CAlarmMsgInfo::initialize(const iot_idl::SAlmInfoToAlmClt &alarmInfo) { alm_type = alarmInfo.alm_type(); alm_status = alarmInfo.alm_status(); logic_state = (E_ALARM_LOGICSTATE)alarmInfo.logic_state(); time_stamp = alarmInfo.time_stamp(); domain_id = alarmInfo.domain_id(); location_id = alarmInfo.location_id(); app_id = alarmInfo.app_id(); uuid_base64 = QString::fromStdString(alarmInfo.uuid_base64()); content = QString::fromStdString(alarmInfo.content()); priority = alarmInfo.priority(); if_water_alm = alarmInfo.if_water_alm(); sound_file.clear(); for(int nIndex(0); nIndex < alarmInfo.sound_file_size(); nIndex++) { sound_file << QString::fromStdString(alarmInfo.sound_file(nIndex)); } dev_type = alarmInfo.dev_type(); if(alarmInfo.has_region_id() && alarmInfo.region_id() > 0) { region_id = alarmInfo.region_id(); } else { region_id = -1; } if(alarmInfo.has_dev_group_tag()) { dev_group_tag = QString::fromStdString(alarmInfo.dev_group_tag()); } if(alarmInfo.has_key_id_tag()) { key_id_tag = QString::fromStdString(alarmInfo.key_id_tag()); QStringList tagList = key_id_tag.split("."); if(tagList.size() == 5) { device = tagList.at(1) + "." + tagList.at(2); } } if(alarmInfo.has_graph_name()) { graph_name = QString::fromStdString(alarmInfo.graph_name()); } if(logic_state == E_ALS_ALARM_DEL || logic_state == E_ALS_ALARM_CFM_DEL || logic_state == E_ALS_RETURN_DEL || logic_state == E_ALS_RETURN_CFM_DEL) { deleteFlag = true; }else { deleteFlag = false; } releaseFlag = false; m_camera = QString::fromStdString(alarmInfo.camera_tag()); m_preset = QString::fromStdString(alarmInfo.camera_preset()); } bool CAlarmMsgInfo::lessThan(const AlarmMsgPtr &info, E_ALARM_SORTKEY sortkey) { switch (sortkey) { case E_SORT_PRIORITY: { if(priorityOrder > info->priorityOrder) { return true; } else if(priorityOrder < info->priorityOrder) { return false; } else if(priorityOrder == info->priorityOrder) { if(time_stamp < info->time_stamp) { return true; } return false; } break; } case E_SORT_TIME: { if(time_stamp < info->time_stamp) { return true; } if(time_stamp > info->time_stamp) { return false; } else if(time_stamp == info->time_stamp) { if(priorityOrder > info->priorityOrder) { return false; } return true; } break; } case E_SORT_LOCATION: { if(location_id < info->location_id) { return true; } else if(location_id > info->location_id) { return false; } else if(location_id == info->location_id) { if(time_stamp < info->time_stamp) { return true; } return false; } break; } case E_SORT_REGION: { if(region_id < info->region_id) { return true; } else if(region_id > info->region_id) { return false; } else if(region_id == info->region_id) { if(time_stamp < info->time_stamp) { return true; } return false; } break; } case E_SORT_TYPE: { if(alm_type < info->alm_type) { return true; } else if(alm_type > info->alm_type) { return false; } else if(alm_type == info->alm_type) { if(time_stamp < info->time_stamp) { return true; } return false; } break; } case E_SORT_LOGICSTATE: { if((logic_state == E_ALS_ALARM || logic_state == E_ALS_RETURN) && (info->logic_state == E_ALS_ALARM_CFM || info->logic_state == E_ALS_RETURN_CFM)) { return true; } else if((info->logic_state == E_ALS_ALARM || info->logic_state == E_ALS_RETURN) && (logic_state == E_ALS_ALARM_CFM || logic_state == E_ALS_RETURN_CFM)) { return false; } else { if(time_stamp < info->time_stamp) { return true; } return false; } break; } case E_SORT_ALM_STATE: { if(alm_status < info->alm_status) { return true; } else if(alm_status > info->alm_status) { return false; } else if(alm_status == info->alm_status) { if(time_stamp < info->time_stamp) { return true; } return false; } break; } case E_SORT_CONTENT: { if(content.isEmpty() && info->content.isEmpty()) { return false; } else if(content.isEmpty() && (!info->content.isEmpty())) { return true; } else if((!content.isEmpty()) && info->content.isEmpty()) { return false; } else if(content < info->content) { return true; } else if(content > info->content) { return false; } else if(content == info->content) { if(time_stamp < info->time_stamp) { return true; } return false; } break; } default: break; } return false; } bool CAlarmMsgInfo::moreThan(const AlarmMsgPtr &info, E_ALARM_SORTKEY sortkey) { switch (sortkey) { case E_SORT_PRIORITY: { if(priorityOrder < info->priorityOrder) { return true; } else if(priorityOrder > info->priorityOrder) { return false; } else if(priorityOrder == info->priorityOrder) { if(time_stamp < info->time_stamp) { return false; } return true; } break; } case E_SORT_TIME: { if(time_stamp > info->time_stamp) { return true; } if(time_stamp < info->time_stamp) { return false; } else if(time_stamp == info->time_stamp) { if(priorityOrder < info->priorityOrder) { return false; } return true; } break; } case E_SORT_LOCATION: { if(location_id > info->location_id) { return true; } else if(location_id < info->location_id) { return false; } else if(location_id == info->location_id) { if(time_stamp < info->time_stamp) { return false; } return true; } break; } case E_SORT_REGION: { if(region_id > info->region_id) { return true; } else if(region_id < info->region_id) { return false; } else if(region_id == info->region_id) { if(time_stamp < info->time_stamp) { return false; } return true; } break; } case E_SORT_TYPE: { if(alm_type > info->alm_type) { return true; } else if(alm_type < info->alm_type) { return false; } else if(alm_type == info->alm_type) { if(time_stamp < info->time_stamp) { return false; } return true; } break; } case E_SORT_LOGICSTATE: { if((logic_state == E_ALS_ALARM || logic_state == E_ALS_RETURN) && (info->logic_state == E_ALS_ALARM_CFM || info->logic_state == E_ALS_RETURN_CFM)) { return false; } else if((info->logic_state == E_ALS_ALARM || info->logic_state == E_ALS_RETURN) && (logic_state == E_ALS_ALARM_CFM || logic_state == E_ALS_RETURN_CFM)) { return true; } else { if(time_stamp < info->time_stamp) { return false; } return true; } break; } case E_SORT_ALM_STATE: { if(alm_status > info->alm_status) { return true; } else if(alm_status < info->alm_status) { return false; } else if(alm_status == info->alm_status) { if(time_stamp < info->time_stamp) { return false; } return true; } break; } case E_SORT_CONTENT: { if(content.isEmpty() && info->content.isEmpty()) { return true; } else if(content.isEmpty() && (!info->content.isEmpty())) { return false; } else if((!content.isEmpty()) && info->content.isEmpty()) { return true; } else if(content > info->content) { return true; } else if(content < info->content) { return false; } else if(content == info->content) { if(time_stamp < info->time_stamp) { return false; } return true; } break; } default: break; } return false; } bool CAlarmMsgInfo::ailessThan(const AlarmMsgPtr &info, E_ALARM_SORTKEY sortkey) { switch (sortkey) { case E_SORT_PRIORITY: if(priority > info->priority) { return true; }else if(priority < info->priority) { return false; }else { if(time_stamp < info->time_stamp) { return true; } return false; } break; case E_SORT_TIME: if(time_stamp < info->time_stamp) { return true; }else if(time_stamp > info->time_stamp) { return false; }else { if(priority > info->priority) { return true; } return false; } break; case E_SORT_LOCATION: if(location_id < info->location_id) { return true; }else if(location_id > info->location_id) { return false; }else { if(time_stamp < info->time_stamp) { return true; } return false; } break; case E_SORT_REGION: if(region_id < info->region_id) { return true; }else if(region_id > info->region_id) { return false; }else { if(time_stamp < info->time_stamp) { return true; } return false; } break; case E_SORT_TYPE: if(alm_type < info->alm_type) { return true; }else if(alm_type > info->alm_type) { return false; }else { if(time_stamp < info->time_stamp) { return true; } return false; } break; case E_SORT_CONTENT: if(content.isEmpty() && info->content.isEmpty()) { return true; } else if(content.isEmpty() && (!info->content.isEmpty())) { return true; } else if((!content.isEmpty()) && info->content.isEmpty()) { return false; } else if(content < info->content) { return true; } else if(content > info->content) { return false; } else { if(time_stamp < info->time_stamp) { return true; } return false; } break; case E_SORT_LOGICSTATE: if((logic_state ==E_ALS_ALARM|| logic_state == E_ALS_RETURN || logic_state == E_ALS_ALARM_DEL || logic_state == E_ALS_RETURN_DEL)&&( info->logic_state == E_ALS_ALARM_CFM || info->logic_state == E_ALS_RETURN_CFM || info->logic_state == E_ALS_ALARM_CFM_DEL || info->logic_state == E_ALS_RETURN_CFM_DEL)) { return true; }else if((info->logic_state == E_ALS_ALARM || info->logic_state == E_ALS_RETURN || info->logic_state == E_ALS_ALARM_DEL || info->logic_state == E_ALS_RETURN_DEL)&&( logic_state == E_ALS_ALARM_CFM || logic_state == E_ALS_RETURN_CFM || logic_state == E_ALS_ALARM_CFM_DEL || logic_state == E_ALS_RETURN_CFM_DEL)) { return false; }else { if(time_stamp < info->time_stamp) { return true; } return false; } break; case E_SORT_ALM_STATE: if(alm_status < info->alm_status) { return true; }else if(alm_status > info->alm_status) { return false; }else { if(time_stamp < info->time_stamp) { return true; } return false; } break; default: break; } return false; } //< 优先级小的大于优先级大的、时间大的大于时间小的、车站id大的大于车站id小的、责任区id大的大于责任区id小的、告警类型大的大于告警类型小的、 //< 告警内容都为空,则前者小于后者、告警内容为空的小于告警内容不为空的、告警未确认的大于告警已确认的、告警状态大的大于告警状态小的 bool CAlarmMsgInfo::aimoreThan(const AlarmMsgPtr &info, E_ALARM_SORTKEY sortkey) { switch (sortkey) { case E_SORT_PRIORITY: if(priority < info->priority) { return true; }else if(priority > info->priority) { return false; }else { if(time_stamp > info->time_stamp) { return true; } return false; } break; case E_SORT_TIME: if(time_stamp > info->time_stamp) { return true; }else if(time_stamp < info->time_stamp) { return false; }else { if(priority < info->priority) { return true; } return false; } break; case E_SORT_LOCATION: if(location_id > info->location_id) { return true; }else if(location_id < info->location_id) { return false; }else { if(time_stamp > info->time_stamp) { return true; } return false; } break; case E_SORT_REGION: if(region_id > info->region_id) { return true; }else if(region_id < info->region_id) { return false; }else { if(time_stamp > info->time_stamp) { return true; } return false; } break; case E_SORT_TYPE: if(alm_type > info->alm_type) { return true; }else if(alm_type < info->alm_type) { return false; }else { if(time_stamp > info->time_stamp) { return true; } return false; } break; case E_SORT_CONTENT: if(content.isEmpty() && info->content.isEmpty()) { return false; } else if(content.isEmpty() && (!info->content.isEmpty())) { return false; } else if((!content.isEmpty()) && info->content.isEmpty()) { return true; } else if(content > info->content) { return true; } else if(content < info->content) { return false; } else { if(time_stamp > info->time_stamp) { return true; } return false; } break; case E_SORT_LOGICSTATE: if((logic_state ==E_ALS_ALARM|| logic_state == E_ALS_RETURN || logic_state == E_ALS_ALARM_DEL || logic_state == E_ALS_RETURN_DEL)&&( info->logic_state == E_ALS_ALARM_CFM || info->logic_state == E_ALS_RETURN_CFM || info->logic_state == E_ALS_ALARM_CFM_DEL || info->logic_state == E_ALS_RETURN_CFM_DEL)) { return false; }else if((info->logic_state == E_ALS_ALARM || info->logic_state == E_ALS_RETURN || info->logic_state == E_ALS_ALARM_DEL || info->logic_state == E_ALS_RETURN_DEL)&&( logic_state == E_ALS_ALARM_CFM || logic_state == E_ALS_RETURN_CFM || logic_state == E_ALS_ALARM_CFM_DEL || logic_state == E_ALS_RETURN_CFM_DEL)) { return true; }else { if(time_stamp < info->time_stamp) { return false; } return true; } break; case E_SORT_ALM_STATE: if(alm_status > info->alm_status) { return true; }else if(alm_status < info->alm_status) { return false; }else { if(time_stamp > info->time_stamp) { return true; } return false; } break; default: break; } return false; } bool CAlarmMsgInfo::ailessThan(const AiAlarmMsgPtr &info, E_ALARM_SORTKEY sortkey) { switch (sortkey) { case E_SORT_PRIORITY: if(priority > info->priority) { return true; }else if(priority < info->priority) { return false; }else { if(time_stamp < info->time_stamp) { return true; } return false; } break; case E_SORT_TIME: if(time_stamp < info->time_stamp) { return true; }else if(time_stamp > info->time_stamp) { return false; }else { if(priority > info->priority) { return true; } return false; } break; case E_SORT_LOCATION: return true; break; case E_SORT_REGION: return true; break; case E_SORT_TYPE: return true; break; case E_SORT_CONTENT: if(content.isEmpty() && info->content.isEmpty()) { return true; } else if(content.isEmpty() && (!info->content.isEmpty())) { return true; } else if((!content.isEmpty()) && info->content.isEmpty()) { return false; } else if(content < info->content) { return true; } else if(content > info->content) { return false; } else { if(time_stamp < info->time_stamp) { return true; } return false; } break; case E_SORT_LOGICSTATE: return true; case E_SORT_ALM_STATE: return true; break; default: break; } return false; } bool CAlarmMsgInfo::aimoreThan(const AiAlarmMsgPtr &info, E_ALARM_SORTKEY sortkey) { switch (sortkey) { case E_SORT_PRIORITY: if(priority < info->priority) { return true; }else if(priority > info->priority) { return false; }else { if(time_stamp > info->time_stamp) { return true; } return false; } break; case E_SORT_TIME: if(time_stamp > info->time_stamp) { return true; }else if(time_stamp < info->time_stamp) { return false; }else { if(priority < info->priority) { return true; } return false; } break; case E_SORT_LOCATION: return false; break; case E_SORT_REGION: return false; break; case E_SORT_TYPE: return false; break; case E_SORT_CONTENT: if(content.isEmpty() && info->content.isEmpty()) { return false; } else if(content.isEmpty() && (!info->content.isEmpty())) { return false; } else if((!content.isEmpty()) && info->content.isEmpty()) { return true; } else if(content > info->content) { return true; } else if(content < info->content) { return false; } else { if(time_stamp > info->time_stamp) { return true; } return false; } break; case E_SORT_LOGICSTATE: return false; break; case E_SORT_ALM_STATE: return false; break; default: break; } return false; } bool operator==(const CAlarmMsgInfo &source, const CAlarmMsgInfo &target) { if(source.uuid_base64 == target.uuid_base64) { return true; } return false; // //替换式告警且车站、测点ID相同 // if((0 == source.if_water_alm) && (0 == target.if_water_alm) && (source.location_id == target.location_id) && (source.key_id_tag == target.key_id_tag)) // { // return true; // } // //流水账告警且时标、告警内容相同 // else if((1 == source.if_water_alm) && (1 == target.if_water_alm) && (source.location_id == target.location_id) && (source.time_stamp == target.time_stamp) && (source.content == target.content)) // { // return true; // } // return false; }