Browse Source

web实时修改人员及车辆信息,通知采集服务器重新加载修改的车辆或者人员信息

chensongchao 6 years ago
parent
commit
873c4f8beb
4 changed files with 74 additions and 13 deletions
  1. 15 0
      card.cpp
  2. 2 0
      card.h
  3. 56 13
      module_service/module_meta_date_changed.cpp
  4. 1 0
      module_service/module_meta_date_changed.h

+ 15 - 0
card.cpp

@@ -357,11 +357,26 @@ void card_list::on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_
 	c->on_message(loop,loc,is_history);
 }
 
+//获取卡数据  //标识id 人staff_id 车 vehicle_id
+std::shared_ptr<card_location_base> card_list::get_card_by_cid(int cid)
+{
+    auto t_map = m_map;
+    for(std::pair<int,std::shared_ptr<card_location_base>> me:t_map)
+    {
+        if ((int)me.second->m_cid == cid)
+        {
+            return me.second;
+        }
+    }
+    return nullptr;
+}
+
 bool card_list_visit::visit(std::shared_ptr<card_location_base> c)
 {
 	c->get_card(_flag);
 	return true;	
 }
 
+
 //template<> std::shared_ptr<card_list> single_base<card_list, uint64_t, std::shared_ptr<card_location_base>>::m_instance=std::make_shared<card_list>();
 

+ 2 - 0
card.h

@@ -24,6 +24,8 @@ struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_ba
     void load_his_card_postion_staff();
     void load_his_card_postion_from_db();
 
+    //获取卡数据  //标识id 人staff_id 车 vehicle_id
+    std::shared_ptr<card_location_base> get_card_by_cid(int cid);
     ~card_list(){}
 };
 #endif

+ 56 - 13
module_service/module_meta_date_changed.cpp

@@ -135,29 +135,67 @@ void module_meta_date_changed::clear_card(std::shared_ptr<card_location_base> ca
 
 void module_meta_date_changed::deal_call_edit_vehicle(int64_t id64, EDIT_TYPE_ID edit_type_id)
 {
+    //车信息修改 id64=车ID vehicle_id
     if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
     {
-        card_list::instance()->init_vehicle(id64);
+        char sql[1024] = {'\0'};
+        sprintf(sql,"select card_id from dat_vehicle_extend where vehicle_id=%d;", (int)id64);
+        std::string Error;
+        YADB::CDBResultSet DBRes;
+        sDBConnPool.Query(sql,DBRes,Error);
+        int64_t nCount = DBRes.GetRecordCount( Error );
+        if (nCount > 0)
+        {
+            int64_t card_id = 0;
+            while ( DBRes.GetNextRecod(Error) )
+            {
+                std::string szCard_id;
+                DBRes.GetField( "card_id",szCard_id, Error );
+                card_id = atoll(szCard_id.c_str());
+            }
+            card_list::instance()->init_vehicle(card_id);
+        }
     }
     else if(ET_DELETE == edit_type_id)
     {
-        auto str = tool_other::to13str(id64);
+        auto c = card_list::instance()->get_card_by_cid(id64);
+        remove_card(c);
 
-        remove_card(tool_other::id64_to_id(str), tool_other::id64_to_type(str));
+        //auto str = tool_other::to13str(id64);
+        //remove_card(tool_other::id64_to_id(str), tool_other::id64_to_type(str));
     }
 }
 
 void module_meta_date_changed::deal_call_edit_staff(int64_t id64, EDIT_TYPE_ID edit_type_id)
 {
+    //人员信息更改 id64=人员ID staff_id
     if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
     {
-        card_list::instance()->init_staffer(id64);
+        char sql[1024] = {'\0'};
+        sprintf(sql,"select card_id from dat_staff_extend where staff_id=%d;", (int)id64);
+        std::string Error;
+        YADB::CDBResultSet DBRes;
+        sDBConnPool.Query(sql,DBRes,Error);
+        int64_t nCount = DBRes.GetRecordCount( Error );
+        if (nCount > 0)
+        {
+            int64_t card_id = 0;
+            while ( DBRes.GetNextRecod(Error) )
+            {
+                std::string szCard_id;
+                DBRes.GetField( "card_id",szCard_id, Error );
+               card_id = atoll(szCard_id.c_str());
+            }
+            card_list::instance()->init_staffer(card_id);
+        }
     }
     else if(ET_DELETE == edit_type_id)
     {
-        auto str = tool_other::to13str(id64);
+        auto c = card_list::instance()->get_card_by_cid(id64);
+        remove_card(c);
+        //auto str = tool_other::to13str(id64);
 
-        remove_card(tool_other::id64_to_id(str), tool_other::id64_to_type(str));
+        //remove_card(tool_other::id64_to_id(str), tool_other::id64_to_type(str));
     }
 }
 
@@ -304,16 +342,22 @@ void module_meta_date_changed::init_setting()
     //pRes = getMysqlRes("select setting_id, name, type, value from dat_setting;");
 }
 
-void module_meta_date_changed::remove_card(uint32_t id, int32_t type)
-{
+void module_meta_date_changed::remove_card(uint32_t id, int32_t type) {
     uint64_t card_id = tool_other::type_id_to_u64(type, id);
     auto card_ptr = card_list::instance()->get(card_id);
-    if(!card_ptr)
-    {
+    if (!card_ptr) {
         log_error("基础数据, 在全局列表中删除卡,全局列表中已经不存在此卡, id=%d, type=%d", id, type);
         return;
     }
-
+    remove_card(card_ptr);
+}
+void module_meta_date_changed::remove_card(std::shared_ptr<card_location_base> card_ptr)
+{
+    if (!card_ptr)
+    {
+        return;
+    }
+    log_info("基础数据, 在全局列表中删除卡成功, id=%d, type=%d",card_ptr->m_type, card_ptr->m_id);
     //    auto area_hover_ptr = card_ptr->get_area_hover();
     //    if(area_hover_ptr && 0!=area_hover_ptr->id() && 0!=area_hover_ptr->mapid())
     //    {
@@ -330,11 +374,10 @@ void module_meta_date_changed::remove_card(uint32_t id, int32_t type)
 
     //        module_meta_date_changed::clear_card(card_ptr);
     //    }
-
     module_meta_date_changed::clear_card(card_ptr);
     // 避免状态重置
+    uint64_t card_id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
     card_list::instance()->remove(card_id);
-    log_info("基础数据, 在全局列表中删除卡成功, id=%d, type=%d", id, type);
 }
 
 bool module_meta_date_changed::try_get_edit_type_id(const std::string& op_type, EDIT_TYPE_ID& out_edit_type_id)

+ 1 - 0
module_service/module_meta_date_changed.h

@@ -73,6 +73,7 @@ private:
     void init_setting();
 
     void remove_card(uint32_t id, int32_t type);
+    void remove_card(std::shared_ptr<card_location_base> card_ptr);
 
     bool try_get_edit_type_id(const std::string& op_type, EDIT_TYPE_ID& out_edit_type_id);