123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- #ifndef MODULE_CALL_HELP_H
- #define MODULE_CALL_HELP_H
- #include <mutex>
- #include <map>
- #include <chrono>
- #include <boost/thread.hpp>
- #include <boost/enable_shared_from_this.hpp>
- #include "module_web.h"
- #include "module_const.h"
- class module_call_help : public i_thread, public singleton_base<module_call_help>
- {
- private:
- friend class singleton_base<module_call_help>;
- module_call_help()
- {
- }
- public:
-
- void rev_help(std::shared_ptr<card> card_ptr)
- {
- if(ES_START != card_ptr->m_stat_call_help)
- {
- card_ptr->m_stat_call_help = ES_START;
-
- auto ev_ptr = tool_other::create_event(OT_CARD, card_ptr->m_id, ET_CARD_HELP);
- tool_other::copy_event(card_ptr, ev_ptr);
-
- tool_db::save_event(ev_ptr);
-
- swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::ev_to_json(ev_ptr));
- std::lock_guard<std::mutex> lock(_mutex);
- tool_other::insert_event(ev_ptr, _map);
- }
- }
-
- void accept_deal_help(std::map<std::string, sio::message::ptr> data_map)
- {
- uint32_t cardid = data_map[JSON_KEY_ID]->get_int();
-
- auto card_ptr = card_list::instance()->get(tool_other::to_uint64_cardid(CT_PERSON, cardid));
- if(card_ptr)
- {
- card_ptr->m_stat_call_help = ES_DEAL_HELP;
- std::lock_guard<std::mutex> lock(_mutex);
- auto ev_ptr = tool_other::find_event(cardid, ET_CARD_HELP, _map);
- if(ev_ptr)
- {
- ev_ptr->m_status = ES_DEAL_HELP;
- tool_db::save_event(ev_ptr);
- }
- }
- }
-
- std::string response_login()
- {
- std::vector<std::shared_ptr<ya_event>> arr;
- get_all_events(arr);
- if(!arr.empty())
- {
- return tool_json::evs_to_json(arr);
- }
- return "";
- }
-
- void init()
- {}
- private:
-
- void run()
- {
- std::vector<std::shared_ptr<ya_event>> arr;
- get_all_events(arr);
- if(!arr.empty())
- {
- swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::evs_to_json(arr));
- }
- }
-
- void get_all_events(std::vector<std::shared_ptr<ya_event>>& arr)
- {
- {
- std::lock_guard<std::mutex> lock(_mutex);
- auto it_map = _map.begin();
- for(;it_map!=_map.end();++it_map)
- {
- arr.push_back(it_map->second);
- if(ES_DEAL_HELP== it_map->second->m_status)
- {
- _map.erase(it_map--);
- }
- }
- }
- }
- std::map<uint64_t, std::shared_ptr<ya_event>> _map;
- };
- #endif
|