123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- #include "area_business_person_attendance.h"
- #include "db/db_tool.h"
- #include"db/db_api/CDBSingletonDefine.h"
- #include"log.h"
- #include"card.h"
- #include "card_person.h"
- #include"area.h"
- #include"common_tool.h"
- #include"mine.h"
- #include"websocket/constdef.h"
- #include "websocket/wsClientMgr.h"
- #include "websocket/wsTimerThread.h"
- #include"tool_time.h"
- #include "module_meta_date_changed.h"
- void area_business_person_attendance::on_enter(const std::shared_ptr<area_hover>&area_hover_ptr,
- const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
- {
- log_info("on_enter:person_att:%d",card_ptr->m_id);
- if(!card_ptr->is_person())
- return;
- auto mine_tool_ptr = card_ptr->get_mine_tool();
- if(!mine_tool_ptr->m_is_attendance)
- {
- mine_tool_ptr->m_is_attendance=true;
- mine_tool_ptr->m_attendance_start_time=
- std::chrono::system_clock::time_point(std::chrono::milliseconds(area_hover_ptr->m_enter_time));
-
- db_tool::save_attendance(card_ptr, area_hover_ptr);
- }
- }
- void area_business_person_attendance::on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
- {
- }
- void area_business_person_attendance::on_leave(const std::shared_ptr<area_hover>&area_hover_ptr,const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
- {
- if(!card_ptr->is_person())
- return;
- auto mine_tool_ptr = card_ptr->get_mine_tool();
- if(!mine_tool_ptr->m_is_attendance)
- return;
- log_info("on_leave_person_att:%d",card_ptr->m_id);
-
- mine_tool_ptr->m_is_attendance=false;
-
- db_tool::save_attendance(card_ptr, area_hover_ptr);
- auto per = std::dynamic_pointer_cast<person>(card_ptr);
- per->clear();
- YA::_CARD_POS_ cp;
- cp.Type=card_ptr->m_type;
- cp.ID = card_ptr->m_id;
- swsTimerThrd.del_card_pos(cp);
-
- rapidjson::Document doc(rapidjson::kObjectType);
- rapidjson::Value datas(rapidjson::kArrayType);
- rapidjson::Document::AllocatorType& allocator=doc.GetAllocator();
- _to_json_card_up_one(card_ptr, datas, allocator);
-
- if(datas.Size() > 0)
- {
- doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_UP_MINE, allocator);
-
- doc.AddMember(JSON_ROOT_KEY_DATA, datas, allocator);
- swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
- }
-
- }
- void area_business_person_attendance::handle_up_mine(sio::message::ptr const& data)
- {
- std::vector<sio::message::ptr> card_vec;
- if(!tool_map::try_get_value(card_vec, JSON_ROOT_KEY_DATA, data) || card_vec.size() == 0)
- {
- log_error("手工升井,web发来的数据data字段为空 或者不是数组");
- return;
- }
- std::vector<sio::message::ptr>::const_iterator it_card = card_vec.begin();
- int type = 0;
- std::string s_card_id;
- for(; it_card != card_vec.end(); ++it_card)
- {
- if(!tool_map::try_get_value(s_card_id, JSON_KEY_CALL_CARD_CARD_ID, (*it_card))
- ||!tool_map::try_get_value(type, JSON_KEY_CALL_CARD_CARD_TYPE_ID, (*it_card)))
- {
- log_error("手工升井,web发来的数据 card_id 或 card_type格式不对");
- continue;
- }
- uint32_t id = tool_other::id64_to_id(s_card_id);
- auto card_ptr = card_list::instance()->get(tool_other::type_id_to_u64(type, id));
- if(card_ptr && card_ptr->is_person())
- {
- std_debug("手工升井,处理,卡id=%d,卡type=%d", id, type);
- log_info("手工升井,处理,卡id=%d,卡type=%d", id, type);
- module_meta_date_changed::clear_card(card_ptr);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- else
- {
- log_error("手工升井,在全局列表中找不到卡,卡id=%d,卡type=%d", id, type);
- }
- }
- }
- void area_business_person_attendance::_to_json_card_up_one(std::shared_ptr<card_location_base> card_ptr,
- rapidjson::Value& out_datas, rapidjson::Document::AllocatorType& allocator)
- {
- if(!card_ptr->m_display)
- {
- return;
- }
- auto mine_tool_ptr = card_ptr->get_mine_tool();
- rapidjson::Value data(rapidjson::kArrayType);
-
- std::string id = tool_other::type_id_to_str(card_ptr->m_type, card_ptr->m_id);
- tool_json::push_back(data, id, allocator);
-
- data.PushBack(card_ptr->x, allocator);
- data.PushBack(card_ptr->y, allocator);
-
- uint64_t t = tool_time::to_ms(mine_tool_ptr->m_attendance_start_time);
- data.PushBack(t, allocator);
-
- data.PushBack(0, allocator);
-
- data.PushBack(0, allocator);
-
- t = tool_time::elapse_ms(mine_tool_ptr->m_attendance_start_time);
- data.PushBack(t, allocator);
-
- data.PushBack(0, allocator);
-
- data.PushBack(0, allocator);
-
- data.PushBack(card_ptr->m_deptid, allocator);
-
- data.PushBack(0, allocator);
-
- data.PushBack(card_ptr->m_stat, allocator);
-
- data.PushBack(0, allocator);
-
- data.PushBack(card_ptr->m_speed, allocator);
- out_datas.PushBack(data, allocator);
- }
|