Browse Source

车卡考勤

daiyueteng 6 years ago
parent
commit
5769b31dd0

+ 73 - 68
module_service/module_area.cpp

@@ -1,87 +1,92 @@
-#ifndef MODULE_AREA_H
-#define MODULE_AREA_H
+#include "module_area.h"
+#include"module_attendance_vehicle.h"
 
-/**
- * @brief 与区域相关的业务模块总接口
- * @author 戴月腾
- * @date 2018-08-25
- */
+//#include"module_area_overman.h"
+//#include"module_area_timeout.h"
+//#include"module_area_over_speed.h"
 
-#include"area.h"
-#include"module_const.h"
-//#include"module_web.h"
 
-class module_area:public i_thread, public singleton_base<module_area>
+void module_area::on_enter(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type)
 {
-private:
-    friend class singleton_base<module_area>;
-    module_area()
+    auto card_ptr=card_list::instance()->get(tool_other::to_uint64_cardid(type, card_id));
+    if(!card_ptr)
     {
+        log_error("卡不存在card_id=%d", card_id);
+        return;
     }
 
-public:
-    void on_hover(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);
-    void on_enter(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);
-    void on_leave(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);
-
-    /**
-     * @brief 读取数据库中的告警,初始化告警列表
-     */
-    void init()
-    {}
-
-    /**
-     * @brief web前端有用户登录时,反馈给web所有信息
-     */
-    std::string response_login()
+    log_debug("module_area::on_enter  card_ptr->m_type=%d", card_ptr->m_type);
+
+    if(tool_other::is_person(card_ptr->m_type))//统计人卡
     {
-        //        std::vector<std::shared_ptr<ya_event>> arr;
-        //        get_all_events(arr);
+        c->m_area->m_person_count++;
 
-        //        if(!arr.empty())//发送给web端
-        //        {
-        //            return tool_json::evs_to_json(arr);
-        //        }
+        //        //区域人卡超员
+        //        module_area_overman::instance()->on_enter(card_ptr, c, speed);
+        //        //区域人卡超时
+        //        module_area_timeout::instance()->on_enter(card_ptr, c, speed);
+    }
 
-        //        return "";
+    if(tool_other::is_vehicle(card_ptr->m_type))//统计车卡
+    {
+        c->m_area->m_vehicle_count++;
+        //车卡考勤
+        module_attendance_vehicle::instance()->on_enter(card_ptr, c, speed);
+
+        //        //区域车卡超速
+        //        module_area_over_speed::instance()->on_enter(card_ptr, c, speed);
     }
-private:
-    /**
-     * @brief 线程函数
-     */
-    void run()
+
+    log_debug("module_area::on_enter  车卡数=%d, 人卡数=%d",
+              c->m_area->m_vehicle_count.load(), c->m_area->m_person_count.load());
+}
+
+void module_area::on_hover(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type)
+{
+    auto card_ptr=card_list::instance()->get(tool_other::to_uint64_cardid(type, card_id));
+    if(!card_ptr)
     {
-        //        std::vector<std::shared_ptr<ya_event>> arr;
-        //        get_all_events(arr);
+        log_error("卡不存在card_id=%d", card_id);
+        return;
+    }
 
-        //        if(!arr.empty())//发送给web端
-        //        {
-        //            swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::evs_to_json(arr));
-        //        }
+    if(tool_other::is_person(card_ptr->m_type))//统计人卡
+    {
+        //        //区域人卡超时
+        //        module_area_timeout::instance()->on_hover(card_ptr, c, speed, _map);
     }
 
-    /**
-     * @brief 获取所有的告警事件
-     * @param out_data
-     */
-    void get_all_events(std::vector<std::shared_ptr<ya_event>>& arr)
+    if(tool_other::is_vehicle(card_ptr->m_type))//统计车卡
     {
-        {
-            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--);
-                }
-            }
-        }
+        //        //区域车卡超速
+        //        module_area_over_speed::instance()->on_hover(card_ptr, c, speed, _map);
     }
+}
 
-    std::map<uint64_t, std::shared_ptr<ya_event>> _map;
-};
+void module_area::on_leave(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type)
+{
+    auto card_ptr=card_list::instance()->get(tool_other::to_uint64_cardid(type, card_id));
+    if(!card_ptr)
+    {
+        log_error("卡不存在card_id=%d", card_id);
+        return;
+    }
 
-#endif // MODULE_AREA_H
+    if(tool_other::is_person(card_ptr->m_type))//统计人卡
+    {
+        c->m_area->m_person_count--;
+
+        //        //区域人卡超员
+        //        module_area_overman::instance()->on_leave(card_ptr, c, speed);
+        //        //区域人卡超时
+        //        module_area_timeout::instance()->on_leave(card_ptr, c, speed);
+    }
+
+    if(tool_other::is_vehicle(card_ptr->m_type))//统计车卡
+    {
+        c->m_area->m_vehicle_count--;
+
+        //        //区域车卡超速
+        //        module_area_over_speed::instance()->on_leave(card_ptr, c, speed);
+    }
+}

+ 17 - 17
module_service/module_area.h

@@ -9,7 +9,7 @@
 
 #include"area.h"
 #include"module_const.h"
-#include"module_web.h"
+//#include"module_web.h"
 
 class module_area:public i_thread, public singleton_base<module_area>
 {
@@ -20,9 +20,9 @@ private:
     }
 
 public:
-    void on_hover(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed);
-    void on_enter(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed);
-    void on_leave(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed);
+    void on_hover(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);
+    void on_enter(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);
+    void on_leave(uint64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);
 
     /**
      * @brief 读取数据库中的告警,初始化告警列表
@@ -35,15 +35,15 @@ public:
      */
     std::string response_login()
     {
-        std::vector<std::shared_ptr<ya_event>> arr;
-        get_all_events(arr);
+        //        std::vector<std::shared_ptr<ya_event>> arr;
+        //        get_all_events(arr);
 
-        if(!arr.empty())//发送给web端
-        {
-            return tool_json::evs_to_json(arr);
-        }
+        //        if(!arr.empty())//发送给web端
+        //        {
+        //            return tool_json::evs_to_json(arr);
+        //        }
 
-        return "";
+        //        return "";
     }
 private:
     /**
@@ -51,13 +51,13 @@ private:
      */
     void run()
     {
-        std::vector<std::shared_ptr<ya_event>> arr;
-        get_all_events(arr);
+        //        std::vector<std::shared_ptr<ya_event>> arr;
+        //        get_all_events(arr);
 
-        if(!arr.empty())//发送给web端
-        {
-            swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::evs_to_json(arr));
-        }
+        //        if(!arr.empty())//发送给web端
+        //        {
+        //            swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::evs_to_json(arr));
+        //        }
     }
 
     /**

+ 5 - 0
module_service/module_attendance_person.h

@@ -39,6 +39,11 @@ public:
      */
     void enter_site(uint64_t card_id,int enter_site,uint64_t type)
     {
+        if(!tool_other::is_person(type))
+        {
+            return;
+        }
+
         auto card_ptr=card_list::instance()->get(tool_other::to_uint64_cardid(type, card_id));
         if(!card_ptr)
         {

+ 2 - 3
module_service/module_attendance_vehicle.h

@@ -31,8 +31,6 @@ private:
 public:
     void on_enter(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c,double speed)
     {
-        //card_ptr->m_attendance_start_time=std::chrono::system_clock::now();
-
         auto area_ptr = c->m_area;
 
         //从考勤状态转换为结束考勤
@@ -50,7 +48,8 @@ public:
                           area_ptr->m_id,card_ptr->m_id,card_ptr->m_stat_attendance);
             }
         }
-        else //没在考勤状态转换为考勤状态
+
+        if(tool_other::is_attendance_area(area_ptr->m_id, card_ptr->m_id))//没在考勤状态转换为考勤状态
         {
             if(!tool_other::is_attendance(card_ptr->m_stat_attendance))
             {