Quellcode durchsuchen

修改初始化人员及车辆的接口参数由int64->string。修改对应的代码

chensongchao vor 6 Jahren
Ursprung
Commit
cb7ff6c56a

+ 12 - 10
card.cpp

@@ -18,20 +18,20 @@
 #include "mine_business.h"
 
 extern config_file config;
-void card_list::init_staffer(int64_t id64)
+void card_list::init_staffer(const std::string & lszId64)
 {
     std::string strategy = config.get("person.strategy","PS_1");
 
 	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> 
-		map=std::move(db_card::load_person(id64,strategy));
+		map=std::move(db_card::load_person(lszId64,strategy));
 
 	if(map.empty())
 	{
-		log_error("增加或修改失败,数据库中找不到: card_id=%013lld", id64);
+		log_error("增加或修改失败,数据库中找不到: card_id=%", lszId64.c_str());
 		return ;
 	}
 
-	if(-1 == id64)
+	if("" == lszId64)
 	{
 		log_info( "init_staffer. The record count=%d\n", map.size() );
 		card_list::instance()->add(map);
@@ -39,6 +39,7 @@ void card_list::init_staffer(int64_t id64)
 	else
 	{
 		auto db_person=map.begin()->second;
+        uint64_t id64 = map.begin()->first;
 		auto card_ptr = card_list::instance()->get(id64);
 		if(card_ptr)
 		{
@@ -68,18 +69,18 @@ void card_list::init_staffer(int64_t id64)
 }
 
 
-void card_list::init_vehicle(int64_t id64)
+void card_list::init_vehicle(const std::string & lszId64)
 {
 	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> 
-		map=std::move(db_card::load_car(id64));
+		map=std::move(db_card::load_car(lszId64));
 
 	if(map.empty())
 	{
-		log_error("增加或修改失败,数据库中找不到: card_id=%013lld", id64);
+		log_error("增加或修改失败,数据库中找不到: card_id=%s", lszId64.c_str());
 		return ;
 	}
 
-	if(-1 == id64)
+	if("" == lszId64)
 	{
 		log_info( "init_vehicle. The record count=%d\n", map.size() );
 		card_list::instance()->add(map);
@@ -87,6 +88,7 @@ void card_list::init_vehicle(int64_t id64)
 	else
 	{
 		car* db_car= static_cast<car*>(map.begin()->second.get());
+        uint64_t id64 = map.begin()->first;
 		auto card_ptr = card_list::instance()->get(id64);
 		if(card_ptr)
 		{
@@ -109,8 +111,8 @@ void card_list::init_vehicle(int64_t id64)
 
 void card_list::init_card_from_db()
 {
-    init_staffer(-1);
-    init_vehicle(-1);
+    init_staffer("");
+    init_vehicle("");
 }
 
 void card_list::load_his_card_postion_from_db()

+ 4 - 4
card.h

@@ -14,9 +14,9 @@ struct card_list_visit:visitor<std::shared_ptr<card_location_base>>
 
 struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_base>>
 {
-    ///id64=-1为初始化所有卡, id格式为:10000001016
-    void init_staffer(int64_t id64);
-    void init_vehicle(int64_t id64);
+    ///lszId64=为初始化所有卡, lszId64格式为:0010000001016
+    void init_staffer(const std::string & lszId64);
+    void init_vehicle(const std::string & lszId64);
     void on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_history);
     void init_card_from_db();
 
@@ -28,4 +28,4 @@ struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_ba
     std::shared_ptr<card_location_base> get_card_by_cid(int cid);
     ~card_list(){}
 };
-#endif
+#endif

+ 6 - 9
db/db_card.cpp

@@ -13,7 +13,7 @@
 extern config_file config;
 namespace db_card
 {
-	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_car(int64_t id64)
+	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_car(const std::string & lszId64)
 	{
 		std::string sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
 						   ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
@@ -30,16 +30,14 @@ namespace db_card
 
 		std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
 
-		std::string card_id_str = tool_other::to13str(id64);
-
-		if(-1 == id64)
+		if("" == lszId64)
 		{
 			sql.append(";");
 		}
 		else
 		{
 			sql.append(" AND ve.card_id ='");
-			sql.append(card_id_str);
+			sql.append(lszId64);
 			sql.append("';");
 		}
 
@@ -110,7 +108,7 @@ namespace db_card
 		return map;
 	}
 
-	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_person(int64_t id64,const std::string&strategy)
+	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_person(const std::string & lszId64,const std::string&strategy)
 	{
 		std::string sql = "SELECT s.staff_id, s.card_id, c.card_type_id, s.dept_id, s.group_id, s.occupation_id, \
 						   ol.occupation_level_id,s.worktype_id,s.need_display,s.work_line\
@@ -124,15 +122,14 @@ namespace db_card
 						   WHERE s.duty_id = 0 AND c.state_id = 0";
 
 		std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
-		std::string card_id_str = tool_other::to13str(id64);
-		if(-1 == id64)
+		if("" == lszId64)
 		{
 			sql.append(";");
 		}
 		else
 		{
 			sql.append(" AND s.card_id = '");
-			sql.append(card_id_str);
+			sql.append(lszId64);
 			sql.append("';");
 		}
 

+ 3 - 3
db/db_card.h

@@ -7,9 +7,9 @@ struct card_location_base;
 
 namespace db_card
 {
-
-	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_person(int64_t id64,const std::string&); 
-	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_car(int64_t id64); 
+	//const std::string & lszId64 = 0010000001102
+	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_person(const std::string & lszId64,const std::string&);
+	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_car(const std::string & lszId64);
 
 }
 

+ 8 - 7
forbid_staff_down_mine.cpp

@@ -57,7 +57,7 @@ void forbid_staff_down_mine::init_forbid_staff(int id /* = -1*/)
         s->start_time = tool_time::to_time(start_time);
         s->end_time = tool_time::to_time(end_time);
         s->state = state;
-        this->add(key,s);
+        forbid_staff_down_mine::instance()->add(key,s);
 
         m_forbidlist[s_id].push_back(key);
     }
@@ -68,7 +68,7 @@ void forbid_staff_down_mine::del_forbid_staff(int staff_id)
     auto it = m_forbidlist.find(staff_id);
     if (it != m_forbidlist.end()) {
         for (auto key : it->second) {
-            this->remove(key);
+            forbid_staff_down_mine::instance()->remove(key);
         }
         m_forbidlist.erase(it);
     }
@@ -76,7 +76,7 @@ void forbid_staff_down_mine::del_forbid_staff(int staff_id)
 
 void forbid_staff_down_mine::del_forbid_data(int id)
 {
-    auto s = this->get(id);
+    auto s = forbid_staff_down_mine::instance()->get(id);
     if (s != nullptr)
     {
         log_info(" remove Forbid Staff:%d Down mine.",s->staff_id);
@@ -97,14 +97,15 @@ void forbid_staff_down_mine::del_forbid_data(int id)
             }
         }
     }
-    this->remove(id);
+    forbid_staff_down_mine::instance()->remove(id);
 }
 
 //是否禁止状态
 bool forbid_staff_down_mine::IsForbid(int staff_id,time_t cur_time)
 {
-    auto it = m_forbidlist.find(staff_id);
-    if (it != m_forbidlist.end())
+    auto flist = m_forbidlist;
+    auto it = flist.find(staff_id);
+    if (it != flist.end())
     {
         for (auto key : it->second)
         {
@@ -118,6 +119,6 @@ bool forbid_staff_down_mine::IsForbid(int staff_id,time_t cur_time)
             }
         }
     }
-    del_forbid_staff(staff_id);  // 已过禁止时间 或者记录失效 删除
+    //del_forbid_staff(staff_id);  //容易引起多线程问题 已过禁止时间 或者记录失效 删除
     return false;
 }

+ 1 - 1
main.cpp

@@ -66,7 +66,7 @@ struct Init_Setting
         url_list.push_back(url);
         if(!wsClientMgr_init(url_list,send_interval))
         {
-            std_info("连接DB[%s:%s] 失败,采集服务器无法启动!",DBSetting.Host.c_str(),DBSetting.User.c_str());
+            std_info("连接webServer[%s] 失败,采集服务器无法启动!",url.c_str());
             exit(0);
         }
 

+ 18 - 19
module_service/module_meta_date_changed.cpp

@@ -35,7 +35,6 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
     std::string op_type="";
     tool_map::try_get_value(op_type, JSON_KEY_OP_TYPE, data);
 
-    //printf("Recv Web Data : name=%s,edit_type=%s id =%lld , %s ...\n",name.c_str(),op_type.c_str(),id,szParam.c_str());
     if((-1 != id || szParam != "0") && !op_type.empty())
     {
         EDIT_TYPE_ID edit_type_id;
@@ -44,8 +43,8 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
             log_error("web发来的数据: 基础数据op_type字段错误:op_type=%s", op_type.c_str());
             return;
         }
-
-		log_info("基础数据 receive meta_data_changed: %s, id=%d, op_type=%d", name.c_str(), id, edit_type_id);
+		log_info("基础数据 receive meta_data_changed: %s, id=%d-%s, op_type=%d"
+		        , name.c_str(), id,szParam.c_str() , edit_type_id);
 
         if(JSON_KEY_NAME_VEHICLE == name || JSON_KEY_NAME_VEHICLE_EXTEND == name)
         {
@@ -145,12 +144,10 @@ void module_meta_date_changed::clear_card(std::shared_ptr<card_location_base> ca
 }
 /*
  * 修改车及卡的数据
- * id64 = ;员工ID或者车ID;卡ID=101;10000001198  分号间隔
+ * id64 = ;员工ID或者车ID;卡ID=101;0010000001198  分号间隔
  */
 void module_meta_date_changed::deal_call_edit_vehicle_or_staff(const std::string & id64, EDIT_TYPE_ID edit_type_id)
 {
-    // id64 = ;员工ID或者车ID;卡ID=101;10000001198  分号间隔
-
     std::vector<std::string> vecSegTag;
     boost::split(vecSegTag, id64, boost::is_any_of(";"));
     if (vecSegTag.size() == 1)  //数据发生错误
@@ -159,7 +156,6 @@ void module_meta_date_changed::deal_call_edit_vehicle_or_staff(const std::string
         return;
     }
     std::string lsz_card_id = vecSegTag[1];
-    int64_t card_id = std::stoll(lsz_card_id);
     int cid = std::stoi(vecSegTag[0].c_str());
     if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
     {
@@ -172,7 +168,15 @@ void module_meta_date_changed::deal_call_edit_vehicle_or_staff(const std::string
                 remove_card(c);
             }
         }
-        card_list::instance()->init_vehicle(card_id);
+        int c_type = tool_other::id64_to_type(lsz_card_id);
+        if (tool_other::is_vehicle(c_type))
+        {
+            card_list::instance()->init_vehicle(lsz_card_id);
+        }
+        else if (tool_other::is_person(c_type))
+        {
+            card_list::instance()->init_staffer(lsz_card_id);
+        }
     }
     else
     {
@@ -182,21 +186,16 @@ void module_meta_date_changed::deal_call_edit_vehicle_or_staff(const std::string
 
 void module_meta_date_changed::deal_call_edit_card(std::string & id64, EDIT_TYPE_ID edit_type_id)
 {
-    std::string lsz = id64;
-    std::string card_id64_str = tool_other::to13str(lsz);
+    std::string card_id64_str = tool_other::to13str(id64);
     int type = tool_other::id64_to_type(card_id64_str);
     if(tool_other::is_person(type) || tool_other::is_vehicle(type))
     {
-        if (edit_type_id == ET_UPDATE)
-        {
-            auto c = card_list::instance()->get(tool_other::card_id_to_u64(card_id64_str));
-            if (nullptr != c)
-            {
-                char id[100] = {0};
-                sprintf(id,"%d;%s",c->m_cid,card_id64_str.c_str());
-                lsz = id;
-            }
+        auto c = card_list::instance()->get(tool_other::card_id_to_u64(card_id64_str));
+        if (nullptr == c) {
+            log_info("web edit card:%s Not bind staff or vehicle. editType:%d", card_id64_str.c_str(), edit_type_id);
+            return ;
         }
+        std::string lsz = std::to_string(c->m_cid) + ";" + card_id64_str;
         deal_call_edit_vehicle_or_staff(lsz,edit_type_id);
     }
     else

+ 1 - 1
module_service/module_meta_date_changed.h

@@ -45,7 +45,7 @@ public:
 private:
     /*
      * 修改车及卡的数据
-     * id64 = ;员工ID或者车ID;卡ID=101;10000001198  分号间隔
+     * id64 = ;员工ID或者车ID;卡ID=101;0010000001198  分号间隔
      */
     void deal_call_edit_vehicle_or_staff(const std::string & id64, EDIT_TYPE_ID edit_type_id);