Przeglądaj źródła

增加入库功能

daiyueteng 6 lat temu
rodzic
commit
dc4e4d2d14

+ 6 - 0
common_tool.h

@@ -1,6 +1,12 @@
 #ifndef COMMON_TOOL_H
 #define COMMON_TOOL_H
 
+/**
+ * @brief 基楚的工具类
+ * @author 戴月腾
+ * @date 2018-09-15
+ */
+
 #include"common.h"
 #include"log.h"
 #include"card.h"

+ 74 - 8
module_service/module_area.h

@@ -26,6 +26,11 @@ private:
 public:
     static void on_enter(uint32_t card_id,std::shared_ptr<area_hover>&c, int32_t type)
     {
+        if(0==c->id() || 0==c->mapid())
+        {
+            return;
+        }
+
         auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
         if(!card_ptr)
         {
@@ -33,6 +38,8 @@ public:
             return;
         }
 
+        c->m_enter_time = card_ptr->m_time/1000;
+
         if(card_ptr->is_person())//统计人卡
         {
             c->m_area->m_person_count++;
@@ -49,10 +56,17 @@ public:
         module_area_over_count::instance()->on_enter(card_ptr, c);
         //区域超时
         module_area_timeout::instance()->on_enter(card_ptr, c);
+
+        save_his_area_location_enter(card_ptr);
     }
 
     static void on_hover(uint32_t card_id,std::shared_ptr<area_hover>&c, int32_t type)
     {
+        if(0==c->id() || 0==c->mapid())
+        {
+            return;
+        }
+
         auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
         if(!card_ptr)
         {
@@ -60,15 +74,15 @@ public:
             return;
         }
 
-//        if(card_ptr->is_person())//人卡
-//        {
+        //        if(card_ptr->is_person())//人卡
+        //        {
 
-//        }
+        //        }
 
-//        if(card_ptr->is_vehicle())//车卡
-//        {
+        //        if(card_ptr->is_vehicle())//车卡
+        //        {
 
-//        }
+        //        }
 
         //区域超时
         module_area_timeout::instance()->on_hover(card_ptr, c);
@@ -76,6 +90,11 @@ public:
 
     static void on_leave(uint32_t card_id, std::shared_ptr<area_hover>&c, int32_t type)
     {
+        if(0==c->id() || 0==c->mapid())
+        {
+            return;
+        }
+
         auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
         if(!card_ptr)
         {
@@ -93,10 +112,57 @@ public:
             c->m_area->m_vehicle_count--;
         }
 
-        //区域人卡超员
+        //区域超员
         module_area_over_count::instance()->on_leave(card_ptr, c);
-        //区域人卡超时
+        //区域超时
         module_area_timeout::instance()->on_leave(card_ptr, c);
+
+        save_his_area_location_leave(card_ptr);
+    }
+
+    ///入库
+    static void save_his_area_location_enter(const std::shared_ptr<card_location_base> card_ptr)
+    {
+        auto area_hover_ptr = card_ptr->get_area_hover();
+
+        char sql[LENGTH_SQL] = {0};
+
+        std::string call("add_area_staff");
+        if(card_ptr->is_vehicle())//车卡
+        {
+            call="add_area_vehicle";
+        }
+
+        std::string start_str = tool_time::to_str_ex(static_cast<uint64_t>(area_hover_ptr->m_enter_time) *1000);
+
+        sprintf(sql, "CALL %s(%s, %d, %d, %d, '%s','%s');", call.c_str(),
+                card_list::to_id64_str(card_ptr->m_type, card_ptr->m_id).c_str(),
+                card_ptr->m_id, area_hover_ptr->id(), area_hover_ptr->mapid(), start_str.c_str(), start_str.c_str());
+
+        tool_db::PushAsync(sql);
+    }
+
+    ///入库
+    static void save_his_area_location_leave(const std::shared_ptr<card_location_base> card_ptr)
+    {
+        auto area_hover_ptr = card_ptr->get_area_hover();
+
+        char sql[LENGTH_SQL] = {0};
+
+        std::string call("add_area_staff");
+        if(card_ptr->is_vehicle())//车卡
+        {
+            call="add_area_vehicle";
+        }
+
+        std::string start_str = tool_time::to_str_ex(static_cast<uint64_t>(area_hover_ptr->m_enter_time) *1000);
+        std::string end_str = tool_time::to_str_ex(card_ptr->m_time);
+
+        sprintf(sql, "CALL %s(%s, %d, %d, %d, '%s','%s');", call.c_str(),
+                card_list::to_id64_str(card_ptr->m_type, card_ptr->m_id).c_str(),
+                card_ptr->m_id, area_hover_ptr->id(), area_hover_ptr->mapid(), start_str.c_str(), end_str.c_str());
+
+        tool_db::PushAsync(sql);
     }
 };
 

+ 1 - 1
module_service/module_area_timeout.h

@@ -27,7 +27,7 @@ private:
 public:
     void on_enter(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
     {
-        c->m_enter_time = card_ptr->m_time/1000;
+//        c->m_enter_time = card_ptr->m_time/1000;
 
 //        EVENT_TYPE ev_type = card_ptr->is_person() ? ET_CARD_AREA_OVER_TIME_PERSON : ET_AREA_OVER_COUNT_VEHICLE;
 //        //中途服务器宕机处理

+ 8 - 1
module_service/module_attendance_person.h

@@ -20,6 +20,7 @@
 #include"area.h"
 #include"site_area.h"
 #include"module_const.h"
+#include"module_area.h"
 
 /**
  * @brief 主要是针对人卡进行考勤,人卡从井上切换到井下为考勤开始,人卡从井下切换到井上为考勤结束
@@ -132,6 +133,12 @@ public:
                     tool_db::save_attendance(card_ptr);
                 }
 
+                auto area_hover_ptr = card_ptr->get_area_hover();
+                if(0!=area_hover_ptr->id() && 0!=area_hover_ptr->mapid())
+                {
+                    module_area::save_his_area_location_leave(card_ptr);
+                }
+
                 person_card_up_mine(card_ptr);
             }
             else
@@ -211,7 +218,7 @@ private:
         //接收时间戳
         data.PushBack(0, allocator);
         //工作时长
-        t = tool_time::elapse_ms(mine_tool_ptr->m_attendance_start_time);	//转为ms
+        t = tool_time::now_to_ms() - tool_time::to_ms(mine_tool_ptr->m_attendance_start_time);	//转为ms
         data.PushBack(t, allocator);
 
         //地图编号