/* * @file * @brief * @version * @author * @date * @note * @warning * @bug * @copyright * */ #ifndef __EVENT_HPP__ #define __EVENT_HPP__ #include #include #include #include #include #include #include #include #include "common.h" struct ya_event { public: ya_event(uint64_t e_id):m_cur_time(std::chrono::system_clock::now()) { m_ev_id = e_id; m_obj_id = ""; m_map_id = 0; m_area_id = 0; x = 0; y = 0; m_limit_value = 0; m_cur_value = 0; m_desc = ""; m_status=ES_START; //m_is_display=true; m_is_sent=false; } ~ya_event(){} public: //key of event_list. uint64_t m_ev_id; uint64_t m_id; ///告警状态,开始、结束 EVENT_STATUS m_status; ///告警类型 EVENT_TYPE m_ev_type; ///告警对象类型 OBJECT_TYPE m_obj_type; EVENT_DIS_TYPE m_dis_type; /// 告警对象编号,与告警对象类型对应,如告警对象类型为分站,此字段为分站编号 std::string m_obj_id; ///当前时间,为告警事件的触发时间,如果状态为开始,则表示开始时间,否则为结束时间 std::chrono::system_clock::time_point m_cur_time; ///告警所在地图 int m_map_id; ///告警所在区域 int m_area_id; ///位置 double x; ///位置 double y; ///告警阈值 double m_limit_value; ///当前值 double m_cur_value; ///描述 std::string m_desc; //是否已经发送 ture bu发送, false推送. 推送完置为true bool m_is_sent; uint8_t landmark_id=0; uint8_t landmark_dir=0; double landmark_dis=0; bool is_end() { return ES_END == m_status; } ///作为事件map列表的id,方便查找; uint64_t get_list_id(); }; class Event; struct event_tool { template void handle_event(OBJECT_TYPE ot,EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,UnaryPredicate p,EVENT_DIS_TYPE edt=DT_COMMON,const std::string &desc="") { handle_event(ot,et,id,limit_value,cur_value,p(),edt,desc); } void handle_event(OBJECT_TYPE ot,EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,bool f,EVENT_DIS_TYPE edt=DT_COMMON,const std::string &desc=""); static event_tool * instance(); event_tool() { make_event_object(); } private: void make_event_object(); std::map> m_map; }; struct event_list:single_base> { public: static uint64_t to_list_id(EVENT_TYPE ev_type, OBJECT_TYPE obj_type,uint64_t obj_id,EVENT_DIS_TYPE edt) { return (static_cast(edt)<<58)|(static_cast(ev_type)<<48)|(static_cast(obj_type)<<40)|obj_id; } std::shared_ptr get_event_card(uint32_t card_id, int card_type, EVENT_TYPE ev_type,EVENT_DIS_TYPE edt=DT_COMMON); std::shared_ptr get_event_area(int32_t area_id, EVENT_TYPE ev_type,EVENT_DIS_TYPE edt) { return base::get(to_list_id(ev_type, OT_AREA, static_cast(area_id),edt)); } std::shared_ptr get_event_reader(int32_t reader_id, EVENT_TYPE ev_type,EVENT_DIS_TYPE edt=DT_COMMON) { return base::get(to_list_id(ev_type,OT_DEVICE_READER, static_cast(reader_id),edt)); } static void save_event(const std::shared_ptr &event_ptr); static void save_event_v(const std::shared_ptr& event_ptr); void load_his_data_from_db(bool init=true); void load_his_data_v_from_db(); ~event_list(){} static std::string ev_to_json(std::shared_ptr ev_ptr) { std::vector> evs; evs.push_back(ev_ptr); return evs_to_json(evs); } static std::string evs_to_json_v(std::vector> arr); static void _ev_to_node_v(std::shared_ptr ev_ptr, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& out_data); static std::string evs_to_json(std::vector> arr); private: static void _ev_to_node(std::shared_ptr ev_ptr, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& out_data); }; #endif