Procházet zdrojové kódy

Merge branch 'master' of http://local.beijingyongan.com:3000/linux-dev/ya-serv

chensongchao před 6 roky
rodič
revize
276e833b5b
59 změnil soubory, kde provedl 1244 přidání a 2044 odebrání
  1. 35 0
      ant.cpp
  2. 17 0
      ant.h
  3. 9 1
      area.cpp
  4. 5 0
      area.h
  5. 2 0
      area_business.cpp
  6. 3 3
      card.cpp
  7. 4 0
      card_base.cpp
  8. 6 0
      card_base.h
  9. 2 2
      card_car.cpp
  10. 9 0
      card_car.h
  11. 5 3
      card_person.cpp
  12. 4 0
      card_person.h
  13. 18 13
      event.cpp
  14. 4 0
      event.h
  15. 0 1
      main.cpp
  16. 3 3
      mine.cpp
  17. 3 6
      mine.h
  18. 121 10
      module_service/area_business_car_attendance.cpp
  19. 23 4
      module_service/area_business_car_attendance.h
  20. 77 8
      module_service/area_business_card_enter_or_leave.cpp
  21. 10 0
      module_service/area_business_card_enter_or_leave.h
  22. 25 6
      module_service/area_business_forbid.cpp
  23. 3 4
      module_service/area_business_forbid.h
  24. 25 41
      module_service/module_geofault.cpp
  25. 19 19
      module_service/module_geofault.h
  26. 106 0
      module_service/area_business_motionless_persion.cpp
  27. 62 0
      module_service/area_business_motionless_persion.h
  28. 250 8
      module_service/area_business_person_attendance.cpp
  29. 18 0
      module_service/area_business_person_attendance.h
  30. 145 6
      module_service/area_business_speed_checker.cpp
  31. 21 2
      module_service/area_business_speed_checker.h
  32. 0 175
      module_service/module_area.h
  33. 0 70
      module_service/module_area_entry_forbid.cpp
  34. 0 31
      module_service/module_area_entry_forbid.h
  35. 0 139
      module_service/module_area_over_count.h
  36. 0 112
      module_service/module_area_over_speed.cpp
  37. 0 36
      module_service/module_area_over_speed.h
  38. 0 119
      module_service/module_area_timeout.h
  39. 0 242
      module_service/module_attendance_person.cpp
  40. 0 59
      module_service/module_attendance_person.h
  41. 0 165
      module_service/module_attendance_vehicle.cpp
  42. 0 55
      module_service/module_attendance_vehicle.h
  43. 117 0
      module_service/module_call.cpp
  44. 13 104
      module_service/module_call.h
  45. 4 14
      module_service/module_call_help.cpp
  46. 45 44
      module_service/module_meta_date_changed.cpp
  47. 1 1
      module_service/module_meta_date_changed.h
  48. 11 11
      module_service/module_mgr.cpp
  49. 0 44
      module_service/module_mine.h
  50. 0 113
      module_service/module_motionless_persion.cpp
  51. 0 62
      module_service/module_motionless_persion.h
  52. 0 116
      module_service/module_over_speed_vehicle.cpp
  53. 0 56
      module_service/module_over_speed_vehicle.h
  54. 0 67
      module_service/module_site.cpp
  55. 0 30
      module_service/module_site.h
  56. 3 2
      module_service/module_web.cpp
  57. 13 34
      net-service.cpp
  58. 1 0
      net-service.h
  59. 2 3
      site_area.cpp

+ 35 - 0
ant.cpp

@@ -20,10 +20,12 @@ site::site(int id)
 	m_time=time(0);
     m_powerType = 1;
 }
+
 const algo_config&site::config()const
 {
 	return g_config[index()];
 }
+
 bool visit_site_status::visit(std::shared_ptr<site> s)
 {
 	time_t now = time(0);
@@ -58,6 +60,7 @@ bool visit_site_status::visit(std::shared_ptr<site> s)
 	}
 	return true;
 }
+
 void sit_list::read_ant_path(int id)
 {
      std::string sql = "SELECT reader_id,tof_flag,b_x,b_y,b_z,e_x,e_y,e_z,spacing_ratio FROM dat_reader_path_tof_n";
@@ -354,6 +357,38 @@ void sit_list::read_sit_list(int id)
         }
     }
 }
+
+
+/*
+
+   处理分站供电状态,交流供电时,ac_down=false,直流供电时,ac_down=true
+
+   目前只有大分站实现了这个功能,并且井下安装时是否接入了该电信号也不确定
+   ,所以需要有张表定义某个ID是否需要告警
+
+ */
+void site::on_power_status(bool ac_down)//电源状态
+{
+	if(!m_power_check_enable)
+		return;
+	
+	if(ac_down == m_power_ac_down)
+		return;
+	
+	if(m_power_ac_down=ac_down)
+	{
+		//掉电告警
+	
+	
+	}
+	else
+	{
+		//撤销警告
+	
+	
+	}
+}
+
 #if 0
 void sit_list::init_site()
 {

+ 17 - 0
ant.h

@@ -130,6 +130,8 @@ struct site:point,std::enable_shared_from_this<site>
     /// 指定分站定位类型:一维定位,二维定位,三维定位
     int m_dimension=0;
     std::shared_ptr<client> m_clt=nullptr;
+
+
 	time_t m_time;
     time_t m_rec_time;              // 接收数据的时间
     time_t m_lost_time;		        // 丢失时间
@@ -142,6 +144,8 @@ struct site:point,std::enable_shared_from_this<site>
     int  m_powerType;               // 分站电源类型 (1 = 直流电)
 
     site(int id=-1);
+
+
     int index()const;
     const algo_config&config()const;
     int id()const
@@ -325,6 +329,19 @@ struct site:point,std::enable_shared_from_this<site>
         m_ant[0].m_path.clear();
         m_ant[1].m_path.clear();
     }
+
+	bool m_power_check_enable=false;//该分站是否启用交流掉电检测功能
+	bool m_power_ac_down=false;//交流电供电状态
+/*
+
+	处理分站供电状态,交流供电时,ac_down=false,直流供电时,ac_down=true
+
+	目前只有大分站实现了这个功能,并且井下安装时是否接入了该电信号也不确定
+	,所以需要有张表定义某个ID是否需要告警
+
+*/
+
+	void on_power_status(bool ac_down);//电源状态
 };
 struct visit_site_status:visitor<std::shared_ptr<site>>
 {

+ 9 - 1
area.cpp

@@ -12,8 +12,8 @@
 #include <boost/algorithm/string/split.hpp>
 #include <boost/algorithm/string/classification.hpp>
 
-#include"module_service/module_area.h"
 #include "area_business.h"
+#include"card.h"
 
 template<> std::shared_ptr<area_list> 
 single_base<area_list, int, std::shared_ptr<area>>::m_instance=std::make_shared<area_list>();
@@ -548,6 +548,14 @@ void area_tool::on_point(const std::shared_ptr<site>&s,const std::shared_ptr<car
 	m_hover_list=std::move(nlist);
 }
 
+void area_tool::on_leave(const std::shared_ptr<card_location_base>& c)
+{
+    for(auto& t:m_hover_list)
+    {
+        t->m_area->on_leave(t, c);
+    }
+}
+
 void area_hover::setLandmark(const point &pt)
 {
 	set(pt);

+ 5 - 0
area.h

@@ -43,6 +43,10 @@ struct area
     {
         return m_area_type == AREA_TYPE_NO_COVER;
     }
+    bool is_mine()//是矿井区域
+    {
+        return 0 == m_id;
+    }
     virtual ~area()
     {}
 
@@ -210,6 +214,7 @@ struct area_tool
 	}
 
 	void on_point(const std::shared_ptr<site>&s,const std::shared_ptr<card_location_base>& c,const point&pt);
+    void on_leave(const std::shared_ptr<card_location_base>& c);
 
     void setLandmark(const point &pt)
     {

+ 2 - 0
area_business.cpp

@@ -178,6 +178,8 @@ struct area_business_factory
 			if((business_type&1)==0)
 				continue;
 
+			business_type >>= 1;
+
 			check_list.push_back(m_check_list[i].get());
 		}
 

+ 3 - 3
card.cpp

@@ -117,7 +117,7 @@ void card_list::load_his_card_postion_from_db()
     {
         auto card_ptr = iter.second;
         auto mine_tool_ptr = card_ptr->get_mine_tool();
-        if(mine_tool_ptr->is_attendance())
+        if(mine_tool_ptr->m_is_attendance)
         {
             auto str = tool_time::to_str_ex( tool_time::to_ms(mine_tool_ptr->m_attendance_start_time));
             log_info("加载考勤,考勤开始时间: %s, 卡id=%d,卡type=%d", str.c_str(), card_ptr->m_id, card_ptr->m_type);
@@ -257,7 +257,7 @@ void card_list::load_his_card_postion_vehicle()
             {
                 auto mine_tool_ptr = card_ptr->get_mine_tool();
                 mine_tool_ptr->m_attendance_start_time = tool_time::to_time_ex(start_time);
-                mine_tool_ptr->m_stat_attendance = AS_ATTENDANCE;
+                mine_tool_ptr->m_is_attendance = true;
             }
 
             area_hover_ptr->landmark_id = landmark_id;
@@ -379,7 +379,7 @@ void card_list::load_his_card_postion_staff()
             {
                 auto mine_tool_ptr = card_ptr->get_mine_tool();
                 mine_tool_ptr->m_attendance_start_time = tool_time::to_time_ex(start_time);
-                mine_tool_ptr->m_stat_attendance = AS_ATTENDANCE;
+                mine_tool_ptr->m_is_attendance = true;
             }
 
             area_hover_ptr->landmark_id = landmark_id;

+ 4 - 0
card_base.cpp

@@ -12,6 +12,10 @@
 #include "websocket/wsTimerThread.h"
 #include "three_rates.h"
 #include "his_location.h"
+#include"event.h"
+#include"module_service/module_call.h"
+#include"mine.h"
+#include"common_tool.h"
 
 extern config_file config;
 

+ 6 - 0
card_base.h

@@ -22,6 +22,7 @@ struct card_pos;
 struct area_hover;
 struct site_area_hover;
 struct site;
+struct area_tool;
 
 namespace YA{struct _CARD_POS_;}
 
@@ -89,6 +90,11 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
     virtual int get_vehicle_type_id(){return  0;}
     virtual std::tuple<time_t,time_t,int,int,int,int,double,double> getLandmark()=0;
 	virtual int get_area()=0;
+    virtual std::shared_ptr<area_tool> get_area_tool()=0;
+    virtual int get_vehicle_category_id()
+    {
+        return -1;
+    }
 
     void on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history);
     void on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm );

+ 2 - 2
card_car.cpp

@@ -70,8 +70,8 @@ void car::handle_three_rates(const point &pt)
 	cp.biz_stat = m_biz_stat;
 	cp.x=pt.x;cp.y=pt.y;cp.z=pt.z;	
 	const auto lm = m_area_tool->getLandmark();
-	cp.enter_time = std::get<0>(lm)*1000;
-	cp.area_id = std::get<3>(lm);
+//	cp.enter_time = std::get<0>(lm)*1000;
+//	cp.area_id = std::get<3>(lm);
 	cp.map_id = std::get<2>(lm);
 	cp.vibration=m_acc;
 	put_three_rates(cp);

+ 9 - 0
card_car.h

@@ -34,6 +34,15 @@ public:
 	virtual void do_business(const std::shared_ptr<site>&site,const point &pt,double acc);
 	virtual int get_area();
     int get_vehicle_type_id();
+    virtual std::shared_ptr<area_tool> get_area_tool()
+    {
+        return m_area_tool;
+    }
+
+    virtual int get_vehicle_category_id()
+    {
+        return m_vehicle_category_id;
+    }
 
 private:
 	void handle_three_rates(const point &pt);

+ 5 - 3
card_person.cpp

@@ -14,6 +14,8 @@
 #include "websocket/ws_common.h"
 #include "event.h"
 #include "mine_business.h"
+#include"common_tool.h"
+#include"db/db_tool.h"
 
 person::person(const std::string &type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,int32_t level_id,uint32_t cid,int wl,const std::string &sname,const std::string &dname)
 	:card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
@@ -113,8 +115,8 @@ void person::handle_three_rates(const point & pt)
 	cp.biz_stat = m_biz_stat;
 	cp.x=pt.x;cp.y=pt.y;cp.z=pt.z;	
 	const auto lm = m_area_tool->getLandmark();
-	cp.enter_time = std::get<0>(lm)*1000;
-	cp.area_id = std::get<3>(lm);
+//	cp.enter_time = std::get<0>(lm)*1000;
+//	cp.area_id = std::get<3>(lm);
 	put_three_rates(cp);
 }
 
@@ -123,7 +125,7 @@ void person::on_timer()
 	//人员井下超时
 //    m_mine_tool->on_check_overtime(this->m_id,this->m_type);
 
-	if(!m_mine_tool->is_attendance())
+    if(!m_mine_tool->m_is_attendance)
 		return;
 	YA::_CARD_POS_ cp;
 	if(m_display)

+ 4 - 0
card_person.h

@@ -28,6 +28,10 @@ struct person:card_location_base, card_area
 	virtual void do_business(const std::shared_ptr<site>&site,const point &pt,double acc);
     virtual std::tuple<time_t,time_t,int,int,int,int,double,double> getLandmark();
 	virtual int get_area();
+    virtual std::shared_ptr<area_tool> get_area_tool()
+    {
+        return m_area_tool;
+    }
 };
 
 #endif

+ 18 - 13
event.cpp

@@ -123,19 +123,7 @@ void Event::handle_alarm_event(EVENT_TYPE et,uint64_t id,double limit_value,doub
     }
     if(ev_ptr)
     {
-        char sql[LENGTH_SQL] = {0};
-        std::string _time = tool_time::to_str_ex(ev_ptr->m_cur_time);
-        sprintf(sql,
-                "INSERT IGNORE INTO his_event_data(event_id, stat, event_type_id, obj_type_id, obj_id, \
-                map_id, area_id, limit_value, cur_value, x, y, cur_time, description, \
-                landmark_id, landmark_dist,direction_mapper_id )\
-                VALUES(%ld, %d, %d, %d, %s, %d, %d, %.2f, %.2f, %f, %f, '%s', '%s', %d, %10.3f, %d);",
-        ev_ptr->get_id(), ev_ptr->m_status, ev_ptr->m_ev_type, ev_ptr->m_obj_type, ev_ptr->m_obj_id.c_str(),
-                ev_ptr->m_map_id, ev_ptr->m_area_id, ev_ptr->m_limit_value, ev_ptr->m_cur_value, ev_ptr->x, ev_ptr->y,
-                _time.c_str(), ev_ptr->m_desc.c_str(),
-                ev_ptr->m_landmarkid, ev_ptr->m_landmarkdist, ev_ptr->m_landmarkdirect);
-
-        db_tool::PushAsync(sql);
+        event_list::save_event(ev_ptr);
     }
 }
 
@@ -228,6 +216,23 @@ std::shared_ptr<ya_event> event_list::get_event_card(uint32_t card_id, int card_
     return base::get(to_list_id(ev_type, OT_CARD, id64));
 }
 
+void event_list::save_event(std::shared_ptr<ya_event> ev_ptr)
+{
+    char sql[LENGTH_SQL] = {0};
+    std::string _time = tool_time::to_str_ex(ev_ptr->m_cur_time);
+    sprintf(sql,
+            "INSERT IGNORE INTO his_event_data(event_id, stat, event_type_id, obj_type_id, obj_id, \
+            map_id, area_id, limit_value, cur_value, x, y, cur_time, description, \
+            landmark_id, landmark_dist,direction_mapper_id )\
+            VALUES(%ld, %d, %d, %d, %s, %d, %d, %.2f, %.2f, %f, %f, '%s', '%s', %d, %10.3f, %d);",
+    ev_ptr->get_id(), ev_ptr->m_status, ev_ptr->m_ev_type, ev_ptr->m_obj_type, ev_ptr->m_obj_id.c_str(),
+            ev_ptr->m_map_id, ev_ptr->m_area_id, ev_ptr->m_limit_value, ev_ptr->m_cur_value, ev_ptr->x, ev_ptr->y,
+            _time.c_str(), ev_ptr->m_desc.c_str(),
+            ev_ptr->m_landmarkid, ev_ptr->m_landmarkdist, ev_ptr->m_landmarkdirect);
+
+    db_tool::PushAsync(sql);
+}
+
 void event_list::load_his_data_from_db()
 {
     std::unordered_map<uint64_t, std::shared_ptr<ya_event>> map;

+ 4 - 0
event.h

@@ -51,6 +51,8 @@ enum EVENT_TYPE{ // 事件类型
     ET_CARD_MOTIONLESS=32,//静止不动告警
 
     ET_VEHICLE_NEAR_GEOFAULT=38,//靠近断层告警
+
+    CARD_EVENT_COUNT_MAX
 };
 
 struct ya_event
@@ -170,6 +172,8 @@ public:
         return base::get(to_list_id(ev_type,OT_DEVICE_READER, static_cast<uint64_t>(reader_id)));
     }
 
+    static void save_event(std::shared_ptr<ya_event> event_ptr);
+
     void load_his_data_from_db();
 
     ~event_list(){}

+ 0 - 1
main.cpp

@@ -13,7 +13,6 @@
 #include "special_area.h"
 #include "mine.h"
 #include "event.h"
-#include"module_service/module_area.h"
 #include"module_service/module_mgr.h"
 
 #include <config_file.h>

+ 3 - 3
mine.cpp

@@ -1,17 +1,17 @@
 #include "mine.h"
-#include <module_service/module_mine.h>
 #include "common_tool.h"
+#include"tool_time.h"
 #include "mine_module/MineCardManager.h"
 
 void mine_tool::on_point(uint32_t card_id, int32_t type, int vehicle_category_id)
 {
-    module_mine::on_point(card_id, type, vehicle_category_id);
+    //module_mine::on_point(card_id, type, vehicle_category_id);
 }
 
 //检查井下超时
 void mine_tool::on_check_overtime(uint32_t card_id, int32_t type)
 {
-	CMineCardManager::instance()->OnPersonInMineOverTime(card_id,type);
+    //CMineCardManager::instance()->OnPersonInMineOverTime(card_id,type);
 
 }
 

+ 3 - 6
mine.h

@@ -20,7 +20,7 @@ struct mine_tool
 		:m_over_speed_count(0)
 		,m_normal_speed_count(0)
 		,m_status_call(0)
-		,m_stat_attendance(AS_INIT)
+        ,m_is_attendance(false)
 		,m_attendance_start_time(std::chrono::seconds(0))
 		,m_is_overtime(false)
 		,m_overtime(std::chrono::seconds(0))
@@ -34,7 +34,7 @@ struct mine_tool
     int m_status_call;
 
     ///考勤状态  0初始状态 1 没在考勤 2 考勤;参看ATTENDANCE_STATUS
-    int m_stat_attendance;
+    bool m_is_attendance;
     ///考勤开始时间
     std::chrono::system_clock::time_point m_attendance_start_time;
     //井下是否超时
@@ -49,9 +49,6 @@ struct mine_tool
 	uint64_t get_down_time();
 	uint64_t get_work_time();
 	int32_t is_on_duty();
-    bool is_attendance()
-    {
-        return AS_ATTENDANCE == m_stat_attendance;
-    }
+
 };
 #endif // MINE_H

+ 121 - 10
module_service/area_business_car_attendance.cpp

@@ -1,9 +1,12 @@
-
-#include "area.h"
-#include "card_base.h"
-
 #include "area_business_car_attendance.h"
 
+#include "db/db_tool.h"
+#include"db/db_api/CDBSingletonDefine.h"
+#include"log.h"
+#include"card.h"
+#include"area.h"
+#include"mine.h"
+
 struct car_attendance_data:business_data
 {
     car_attendance_data():m_is_attendance(false)
@@ -23,23 +26,131 @@ area_business_car_attendance::area_business_car_attendance()
 
 
 //记录进入时间等信息,结束考勤,根据离开的时间和距离,判断是否记录一条新的考勤记录
-void area_business_car_attendance::on_enter(const std::shared_ptr<area_hover>&a,
-					const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
+void area_business_car_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)
 {
+    if(!card_ptr->is_vehicle())
+    {
+        return;
+    }
+
+    save_attendance(card_ptr, area_hover_ptr);
+
+    //    auto ptr_temp = std::make_shared<car_attendance_data>();
+    //    ptr = ptr_temp;
+
+    //    ptr_temp->m_is_attendance = true;
+    //    ptr_temp->m_attendance_start_time = std::chrono::system_clock::now();
 
+    //    //作为一条开始考勤记录保存到数据库
+    //    db_tool::save_attendance(card_ptr, ptr_temp->m_is_attendance, ptr_temp->m_attendance_start_time);
 }
 
-void area_business_car_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_car_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_car_attendance::on_leave(const std::shared_ptr<area_hover>&a,
-					const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+                                            const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
 {
+    if(!card_ptr->is_vehicle())
+    {
+        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::now();
+
+        //作为一条开始考勤记录保存到数据库
+        db_tool::save_attendance(card_ptr);
+
+        //                log_info("车卡考勤开始:卡id=%d,卡type=%d,区域id=%d, stat_attendance=%d",
+        //                         card_ptr->m_id, card_ptr->m_type,
+        //                         area_ptr->m_id,mine_tool_ptr->m_stat_attendance);
+    }
 
+    //    if(nullptr == ptr)
+    //    {
+    //        log_error("结束考勤失败:nullptr == ptr");
+    //        return;
+    //    }
+
+    //    auto ptr_temp = static_cast<car_attendance_data*>(ptr.get());
+
+    //    if(ptr_temp->m_is_attendance)
+    //    {
+    //        ptr_temp->m_is_attendance = false;
+
+    //        //作为一条开始考勤记录保存到数据库
+    //        db_tool::save_attendance(card_ptr, ptr_temp->m_is_attendance, ptr_temp->m_attendance_start_time);
+    //    }
 }
 
+//void area_business_car_attendance::init_attendance_area_from_db()
+//{
+//    const char *sql = "select a.area_id, a.att_rule_id,  vt.vehicle_type_id \
+//            from dat_att_rule_area a, dat_att_rule_vehicle_type  vt, dat_att_rule r\
+//            where a.att_rule_id=vt.att_rule_id and a.att_rule_id=r.att_rule_id;";
+//    std::string Error;
+//    YADB::CDBResultSet DBRes;
+//    sDBConnPool.Query(sql,DBRes,Error);
+//    if(!Error.empty())
+//        log_error("初始化attendance_area Error,%s",Error.c_str());
+//    uint64_t nCount = DBRes.GetRecordCount( Error );
+//    if(int64_t(nCount) <= 0)
+//    {
+//        log_error("初始化attendance_area Error,%s",Error.c_str());
+//    }
+
+//    log_info( "init_attendance_area_from_db. The record count=%ld\n", nCount );
+
+//    m_map.clear();
+//    while ( DBRes.GetNextRecod(Error) )
+//    {
+//        int area_id  = 0;
+//        DBRes.GetField( "area_id",area_id, Error );
+
+//        int att_rule_id  = 0;
+//        DBRes.GetField( "att_rule_id",att_rule_id, Error );
+
+//        int vehicle_type_id  = 0;
+//        DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
+
+//        m_map.insert(std::make_pair(to_list_id(area_id, vehicle_type_id), att_rule_id));
+//    }
+//}
+
+///area_hover_ptr==nullptr 表示接收到 web的删除卡命令
+void area_business_car_attendance::save_attendance(const std::shared_ptr<card_location_base>& card_ptr,
+                                                  const std::shared_ptr<area_hover> area_hover_ptr)
+{
+    auto mine_tool_ptr = card_ptr->get_mine_tool();
+    if(!mine_tool_ptr->m_is_attendance)
+    {
+        return;
+    }
+
+    //考勤结束
+    mine_tool_ptr->m_is_attendance=false;
+    //作为一条结束考勤记录保存到数据库
+    db_tool::save_attendance(card_ptr);
+
+//    if(area_hover_ptr)
+//    {
+//        log_info("车卡考勤结束:卡id=%d,卡type=%d,区域id=%d, stat_attendance=%d",
+//                 card_ptr->m_id, card_ptr->m_type,
+//                 area_ptr->m_id,mine_tool_ptr->m_stat_attendance);
+//    }
+//    else
+//    {
+//        log_info("收到web的删除卡命令,车卡考勤结束:卡id=%d,卡type=%d,stat_attendance=%d",
+//                 card_ptr->m_id, card_ptr->m_type,mine_tool_ptr->m_stat_attendance);
+//    }
+}
 

+ 23 - 4
module_service/area_business_car_attendance.h

@@ -1,13 +1,16 @@
 #ifndef AREA_BUSINESS_CAR_ATTENDANCE_H
 #define AREA_BUSINESS_CAR_ATTENDANCE_H
 
+
 #include"area_business.h"
 
-struct area_business_car_attendance:area_business
+
+class area_business_car_attendance:public area_business
 {
+public:
     area_business_car_attendance();
 
-    int area_business_type()
+    virtual int area_business_type()
     {
         return 6;
     }
@@ -16,9 +19,25 @@ struct area_business_car_attendance:area_business
     void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
     //记录离开考勤区域信息,开始考勤
     void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
-};
 
+//    static void init_attendance_area_from_db();
+    ///area_hover_ptr==nullptr 表示接收到 web的删除卡命令
+    static void save_attendance(const std::shared_ptr<card_location_base>& card_ptr, const std::shared_ptr<area_hover> area_hover_ptr);
 
-#endif // AREA_BUSINESS_CAR_ATTENDANCE_H
+//private:
+//    bool is_not_attendance_area(int area_id, int vehicle_type_id)
+//    {
+//        return  m_map.end() != m_map.find(to_list_id(area_id, vehicle_type_id));
+//    }
 
+//    uint64_t to_list_id(int area_id, int vehicle_type_id)
+//    {
+//        return (static_cast<uint64_t>(area_id)<<32) | static_cast<uint64_t>(vehicle_type_id);
+//    }
 
+//    ///area_id<<32| vehicle_type_id; att_rule_id
+//    std::unordered_map<uint64_t, int> m_map;
+};
+
+
+#endif // AREA_BUSINESS_CAR_ATTENDANCE_H

+ 77 - 8
module_service/area_business_card_enter_or_leave.cpp

@@ -1,25 +1,94 @@
+#include "area_business_card_enter_or_leave.h"
 #include "area.h"
 #include "card_base.h"
+#include"common_tool.h"
+#include"tool_time.h"
+#include"db/db_tool.h"
+#include"log.h"
 
-#include "area_business_card_enter_or_leave.h"
 
-	//进入区域则入库操作
-void area_business_card_enter_or_leave::on_enter(const std::shared_ptr<area_hover>&a,
-							const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
+struct enter_or_leave_data:business_data
 {
+    enter_or_leave_data()
+    {
+        m_enter_time_ms = tool_time::to_ms(std::chrono::system_clock::now());
+    }
+
+    ///考勤开始时间
+    uint64_t m_enter_time_ms;
+};
 
+//进入区域则入库操作
+void area_business_card_enter_or_leave::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)
+{
+    auto ptr_temp = std::make_shared<enter_or_leave_data>();
+    ptr = ptr_temp;
+    save_his_area_location_enter(area_hover_ptr, card_ptr, ptr_temp->m_enter_time_ms);
 }
 
 void area_business_card_enter_or_leave::on_hover(const std::shared_ptr<area_hover>&a,
-							const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+                                                 const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+{
+
+}
+//出区域则入库
+void area_business_card_enter_or_leave::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(nullptr == ptr)
+    {
+        log_error("出区域失败:nullptr == ptr");
+        return;
+    }
+    auto ptr_temp = static_cast<enter_or_leave_data*>(ptr.get());
+
+    save_his_area_location_leave(area_hover_ptr, card_ptr, ptr_temp->m_enter_time_ms);
+}
+
+///入库
+void area_business_card_enter_or_leave::save_his_area_location_enter(const std::shared_ptr<area_hover>&area_hover_ptr,
+                                                                     const std::shared_ptr<card_location_base> card_ptr,
+                                                                     uint64_t start_time_ms)
 {
+    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(start_time_ms);
+
+    sprintf(sql, "CALL %s(%s, %d, %d, %d, '%s','%s');", call.c_str(),
+            tool_other::type_id_to_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());
 
+    db_tool::PushAsync(sql);
 }
-	//出区域则入库
-void area_business_card_enter_or_leave::on_leave(const std::shared_ptr<area_hover>&a,
-							const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+
+///入库
+void area_business_card_enter_or_leave::save_his_area_location_leave(const std::shared_ptr<area_hover>&area_hover_ptr,
+                                                                     const std::shared_ptr<card_location_base> card_ptr,
+                                                                     uint64_t start_time_ms)
 {
+    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(start_time_ms);
+    std::string end_str = tool_time::to_str_ex(tool_time::now_to_ms());
+
+    sprintf(sql, "CALL %s(%s, %d, %d, %d, '%s','%s');", call.c_str(),
+            tool_other::type_id_to_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());
 
+    db_tool::PushAsync(sql);
 }
 
 

+ 10 - 0
module_service/area_business_card_enter_or_leave.h

@@ -15,6 +15,16 @@ struct area_business_card_enter_or_leave:area_business
 	void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
 	//出区域则入库
 	void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
+
+    ///入库
+    static void save_his_area_location_enter(const std::shared_ptr<area_hover>&area_hover_ptr,
+                                             const std::shared_ptr<card_location_base> card_ptr,
+                                             uint64_t start_time_ms);
+
+    ///入库
+    static void save_his_area_location_leave(const std::shared_ptr<area_hover>&area_hover_ptr,
+                                             const std::shared_ptr<card_location_base> card_ptr,
+                                             uint64_t start_time_ms);
 };
 
 #endif

+ 25 - 6
module_service/area_business_forbid.cpp

@@ -1,9 +1,11 @@
-
-#include "area.h"
-#include "card_base.h"
-
 #include "area_business_forbid.h"
 
+#include"vector"
+#include"event.h"
+#include"common_tool.h"
+#include"area.h"
+#include "card.h"
+
 struct forbid_data:business_data
 {
     forbid_data()
@@ -16,9 +18,17 @@ area_business_forbid::area_business_forbid()
 }
 
 //记录进入时间等信息,生成告警
-void area_business_forbid::on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
+void area_business_forbid::on_enter(const std::shared_ptr<area_hover>&a,
+                                    const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
 {
+    EVENT_TYPE ev_type = ET_CARD_AREA_FORBIDDEN_PERSON;
+    if(card_ptr->is_vehicle())
+    {
+        ev_type = ET_CARD_AREA_FORBIDDEN_VEHICLE;
+    }
 
+    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+    event_tool::instance()->handle_event(OT_CARD, ev_type, id, 0, 0, true);
 }
 
 void area_business_forbid::on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
@@ -27,8 +37,17 @@ void area_business_forbid::on_hover(const std::shared_ptr<area_hover>&a,const st
 }
 
 //记录退出时间等信息
-void area_business_forbid::on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+void area_business_forbid::on_leave(const std::shared_ptr<area_hover>&a,
+                                    const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
 {
+    EVENT_TYPE ev_type = ET_CARD_AREA_FORBIDDEN_PERSON;
+    if(card_ptr->is_vehicle())
+    {
+        ev_type = ET_CARD_AREA_FORBIDDEN_VEHICLE;
+    }
+
+    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+    event_tool::instance()->handle_event(OT_CARD, ev_type, id, 0, 0, false);
 }
 
 

+ 3 - 4
module_service/area_business_forbid.h

@@ -3,11 +3,12 @@
 
 #include"area_business.h"
 
-struct area_business_forbid:area_business
+class area_business_forbid : public area_business
 {
+public:
     area_business_forbid();
 
-    int area_business_type()
+    virtual int area_business_type()
     {
         return 7;
     }
@@ -19,5 +20,3 @@ struct area_business_forbid:area_business
 };
 
 #endif // AREA_BUSINESS_FORBID_H
-
-

+ 25 - 41
module_service/module_geofault.cpp

@@ -1,4 +1,4 @@
-#include"module_geofault.h"
+#include"area_business_geofault.h"
 
 #include<memory>
 #include<string>
@@ -9,10 +9,11 @@
 #include"ya_setting.h"
 #include"common_tool.h"
 #include"log.h"
+#include"card.h"
 
-struct over_speed_data:business_data
+struct geofault_data:business_data
 {
-    over_speed_data()
+    geofault_data()
     {
         m_near_geofault_count=0;
         m_far_geofault_count=0;
@@ -22,53 +23,43 @@ struct over_speed_data:business_data
     int m_far_geofault_count;
 };
 
-void module_geofault::module_geofault::on_enter(std::shared_ptr<card_location_base> card_ptr, int index)
+void area_business_geofault::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)
 {
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-    area_hover_ptr->m_data[index] = std::make_shared<over_speed_data>();
+    auto ptr_temp = std::make_shared<geofault_data>();
+    ptr = ptr_temp;
 
     double dist=0;
     if(_is_near(area_hover_ptr->m_area, card_ptr->x, card_ptr->y, dist))
     {
-        auto ptr = static_cast<over_speed_data*>(area_hover_ptr->m_data[index].get());
-        ptr->m_near_geofault_count++;
+        ptr_temp->m_near_geofault_count++;
     }
 }
 
-void module_geofault::on_hover(std::shared_ptr<card_location_base> card_ptr, int index)
+void area_business_geofault::on_hover(const std::shared_ptr<area_hover>&area_hover_ptr,
+                                      const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
 {
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-    auto ptr = static_cast<over_speed_data*>(area_hover_ptr->m_data[index].get());
+    auto ptr_temp = static_cast<geofault_data*>(ptr.get());
 
     double dist=0;
     if(_is_near(area_hover_ptr->m_area, card_ptr->x, card_ptr->y, dist))
     {
-        ptr->m_near_geofault_count++;
+        ptr_temp->m_near_geofault_count++;
     }
     else
     {
-        ptr->m_far_geofault_count++;
+        ptr_temp->m_far_geofault_count++;
     }
 
     //确定告警
-    if(_geofault_count_limit <= ptr->m_near_geofault_count)
+    if(_geofault_count_limit <= ptr_temp->m_near_geofault_count)
     {
-        ptr->m_near_geofault_count=_geofault_count_limit;
+        ptr_temp->m_near_geofault_count=_geofault_count_limit;
 
         auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ET_VEHICLE_NEAR_GEOFAULT);
         if(!ev_ptr)//从没有告警状态转化为告警状态
         {
-            ptr->m_far_geofault_count=0;
+            ptr_temp->m_far_geofault_count=0;
         }
 
         uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
@@ -76,14 +67,14 @@ void module_geofault::on_hover(std::shared_ptr<card_location_base> card_ptr, int
     }
 
     //确定正常
-    if(_geofault_count_limit <= ptr->m_far_geofault_count)
+    if(_geofault_count_limit <= ptr_temp->m_far_geofault_count)
     {
-        ptr->m_far_geofault_count=_geofault_count_limit;
+        ptr_temp->m_far_geofault_count=_geofault_count_limit;
 
         auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ET_VEHICLE_NEAR_GEOFAULT);
         if(ev_ptr && !ev_ptr->is_end())
         {
-            ptr->m_near_geofault_count=0;
+            ptr_temp->m_near_geofault_count=0;
 
             uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
             event_tool::instance()->handle_event(OT_CARD, ET_VEHICLE_NEAR_GEOFAULT, id, CYaSetting::m_sys_setting.geofault_warn_dis, dist, false);
@@ -91,23 +82,16 @@ void module_geofault::on_hover(std::shared_ptr<card_location_base> card_ptr, int
     }
 }
 
-void module_geofault::on_leave(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
 
+void area_business_geofault::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)
+{
     uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
     event_tool::instance()->handle_event(OT_CARD, ET_VEHICLE_NEAR_GEOFAULT, id, CYaSetting::m_sys_setting.geofault_warn_dis, 1000, false);
-
-    area_hover_ptr->m_data[index] = std::make_shared<over_speed_data>();
 }
 
 
-void module_geofault::module_geofault::init_geofault_from_db()
+void area_business_geofault::init_geofault_from_db()
 {
     const char *sql = "select area_id, pt_data from   dat_geofault g, dat_work_face w \
             where g.workface_id=w.work_face_id;";
@@ -166,7 +150,7 @@ void module_geofault::module_geofault::init_geofault_from_db()
     }
 }
 
-bool module_geofault::_is_near(std::shared_ptr<area>& area_ptr, double x, double y, double& out_dist)
+bool area_business_geofault::_is_near(std::shared_ptr<area>& area_ptr, double x, double y, double& out_dist)
 {
     auto serch = _area_geofault_map.find(area_ptr->m_id);
     if(serch == _area_geofault_map.end())

+ 19 - 19
module_service/module_geofault.h

@@ -1,5 +1,5 @@
-#ifndef MODULE_GEOFAULT_H
-#define MODULE_GEOFAULT_H
+#ifndef AREA_BUSINESS_GEOFAULT
+#define AREA_BUSINESS_GEOFAULT
 
 /**
  * @brief 简要说明
@@ -7,38 +7,38 @@
  * @date 2019-01-15
  */
 
+#include<area_business.h>
 #include <unordered_map>
 #include<vector>
-#include "module_singleton_base.h"
-#include "card.h"
-#include"area.h"
+#include<area.h>
+#include<point.h>
+
 #include"config_file.h"
 
 /**
  * @brief 当采煤机和掘进机有数据点过来的时候,判断当前点与地址断层坐标点的距离d。如d<设置的阈值,则告警,d>阈值则取消。
  */
-class module_geofault:public singleton_base<module_geofault>
+class area_business_geofault:public area_business
 {
-private:
-    friend class singleton_base<module_geofault>;
-    module_geofault()
+public:
+    int area_business_type()
     {
+        return 10;
     }
 
-public:
-    void on_enter(std::shared_ptr<card_location_base> card_ptr, int index);
-    void on_hover(std::shared_ptr<card_location_base> card_ptr, int index);
-    void on_leave(std::shared_ptr<card_location_base> card_ptr, int index);
+    void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr);
+    void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
+    void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
 
-    void init(config_file& config)
+    static void init(config_file& config)
     {
         _geofault_count_limit = std::stoi(config.get("service.geofault_count_limit","10"));
     }
 
-    void init_geofault_from_db();
+    static void init_geofault_from_db();
 
 private:
-    bool _is_near(std::shared_ptr<area>& area_ptr, double x, double y, double& out_dist);
+    static bool _is_near(std::shared_ptr<area>& area_ptr, double x, double y, double& out_dist);
 
     static std::vector<std::string> split(const std::string& str, char tag)
     {
@@ -84,9 +84,9 @@ private:
 
 private:
     //area_id: points
-    std::unordered_map<int, std::vector<point>> _area_geofault_map;
+    static std::unordered_map<int, std::vector<point>> _area_geofault_map;
 
-    int _geofault_count_limit;
+    static int _geofault_count_limit;
 };
 
-#endif // MODULE_GEOFAULT_H
+#endif // AREA_BUSINESS_GEOFAULT

+ 106 - 0
module_service/area_business_motionless_persion.cpp

@@ -0,0 +1,106 @@
+#include"area_business_motionless_persion.h"
+
+
+#include"common_tool.h"
+#include"log.h"
+#include"area.h"
+#include"event.h"
+#include"tool_time.h"
+#include"area_business.h"
+#include"card.h"
+
+
+struct motionless_data:business_data
+{
+    motionless_data()
+    {
+        m_acc_0count=0;
+//        m_acc_start_time=0;
+    }
+
+    ///;检测到多少次之后定位完全静止
+    std::atomic<int> m_acc_0count;
+//    ///检测到多久之后告警
+//    time_t m_acc_start_time;
+};
+
+void area_business_motionless_persion::on_enter(const std::shared_ptr<area_hover>&a,
+                                 const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
+{
+    auto ptr_temp = std::make_shared<motionless_data>();
+    ptr = ptr_temp;
+}
+
+void area_business_motionless_persion::on_hover(const std::shared_ptr<area_hover>&area_hover_ptr,
+                                         const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
+{
+    auto ptr_temp = static_cast<motionless_data*>(ptr.get());
+    if(0 == static_cast<int>(card_ptr->m_acc))
+    {
+        ptr_temp->m_acc_0count++;
+    }
+    else
+    {
+        ptr_temp->m_acc_0count=0;
+    }
+
+    if(ptr_temp->m_acc_0count >= _acc_0count_limit)
+    {
+        ptr_temp->m_acc_0count = _acc_0count_limit;
+    }
+
+    bool is_alarm = ptr_temp->m_acc_0count >= _acc_0count_limit;
+
+    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+    event_tool::instance()->handle_event(OT_CARD, ET_CARD_MOTIONLESS, id, 0, 0, is_alarm);
+}
+
+void area_business_motionless_persion::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)
+{
+    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+    event_tool::instance()->handle_event(OT_CARD, ET_CARD_MOTIONLESS, id, 0, 0, false);
+}
+
+//void module_motionless_persion::deal_alarm(std::shared_ptr<card_location_base>& card_ptr)
+//{
+//    auto area_hover_ptr = card_ptr->get_area_hover();
+//    if(!area_hover_ptr)
+//    {
+//        log_error("if(!area_hover_ptr)==true");
+//        return;
+//    }
+
+//    auto arr = area_hover_ptr->m_data;
+//    int index = 1;
+
+//    if(arr.size()<2 || !arr[index])
+//    {
+//        return;
+//    }
+
+//    auto ptr = static_cast<motionless_data*>(area_hover_ptr->m_data[index].get());
+
+//    if(ptr->m_acc_0count >= _acc_0count_limit)
+//    {
+//        ptr->m_acc_0count = _acc_0count_limit;
+//        if(0 == ptr->m_acc_start_time)
+//        {
+//            ptr->m_acc_start_time = tool_time::now_to_seconds();
+//        }
+//    }
+//    else
+//    {
+//        ptr->m_acc_start_time=0;
+//    }
+
+//    bool is_alarm = (0 != ptr->m_acc_start_time
+//            &&tool_time::elapse_seconds(ptr->m_acc_start_time)> _acc_seconds_limit);
+
+//    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+//    event_tool::instance()->handle_event(OT_CARD, ET_CARD_MOTIONLESS, id, 0, 0, is_alarm);
+//}
+
+
+
+

+ 62 - 0
module_service/area_business_motionless_persion.h

@@ -0,0 +1,62 @@
+#ifndef AREA_BUSINESS_MOTIONLESS_PERSION
+#define AREA_BUSINESS_MOTIONLESS_PERSION
+
+/**
+ * @brief 简要说明
+ * @author 戴月腾
+ * @date 2019-01-12
+ */
+
+//#include"module_singleton_base.h"
+//#include"module_i_thread.h"
+//#include"card.h"
+#include"area_business.h"
+#include"config_file.h"
+
+/**
+ * @brief 一、硬件输出的状态
+当完全静止时人卡会连续发送 30 次定位数据,在该定位数据中的加速度状态为 0;发送
+完这一系列的定位数据之后进入休眠状态,不再发送任何定位数据。
+ 当人卡从静止切换到运动状态会在毫秒级完成。然后 2 秒后把定位数据发上来,此时加
+速度状态为 1(运动状态)。
+二、处理逻辑
+当连续收到 X(X 可以配置,X 建议不小于 10)次静止状态定位数据之后才认为完全静止。
+经过 Y(Y 可以配置)秒之后开始告警,只要收到运动状态的定位数据就认为非静止立刻取消
+告警
+ */
+class area_business_motionless_persion : public area_business// : public i_thread, public singleton_base<module_motionless_persion>
+{
+//    void run()
+//    {
+//        auto cardlist = card_list::instance()->m_map;
+//        auto iter_m_map=cardlist.begin();
+//        for(;iter_m_map!=cardlist.end();++iter_m_map)
+//        {
+//            deal_alarm(iter_m_map->second);
+//        }
+//    }
+
+//    void deal_alarm(std::shared_ptr<card_location_base>& card_ptr);
+private:
+    static int _acc_0count_limit;
+
+public:
+    int area_business_type()
+    {
+        return 5;
+    }
+
+    static void init(config_file& config)
+    {
+ //       sleep_ms = std::stoi(config.get("service.motionless_thread_sleep_ms","5000"));
+        _acc_0count_limit = std::stoi(config.get("service.motionless_acc_0count_limit","40"));
+//        _acc_seconds_limit = std::stoi(config.get("service.motionless_acc_seconds_limit","120"));
+    }
+
+    void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr);
+    void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
+    void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
+
+};
+
+#endif // MODULE_MOTIONLESS_PERSION_H

+ 250 - 8
module_service/area_business_person_attendance.cpp

@@ -1,8 +1,28 @@
+#include "area_business_person_attendance.h"
 
-#include "area.h"
-#include "card_base.h"
+#include "db/db_tool.h"
+#include"db/db_api/CDBSingletonDefine.h"
+#include"log.h"
+#include"card.h"
+#include"area.h"
+#include"common_tool.h"
+#include"mine.h"
+#include"websocket/constdef.h"
+#include "websocket/wsClientMgr.h"
+#include"tool_time.h"
 
-#include "area_business_person_attendance.h"
+struct person_attendance_data:business_data
+{
+    person_attendance_data():m_is_attendance(false)
+      ,m_attendance_start_time(std::chrono::seconds(0))
+    {
+    }
+
+    ///考勤状态  0初始状态 1 没在考勤 2 考勤;参看ATTENDANCE_STATUS
+    bool m_is_attendance;
+    ///考勤开始时间
+    std::chrono::system_clock::time_point m_attendance_start_time;
+};
 
 area_business_person_attendance::area_business_person_attendance()
 {
@@ -11,22 +31,244 @@ area_business_person_attendance::area_business_person_attendance()
 
 //记录进入时间等信息,结束考勤,根据离开的时间和距离,判断是否记录一条新的考勤记录
 void area_business_person_attendance::on_enter(const std::shared_ptr<area_hover>&a,
-					const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&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)
+    {
+        //考勤开始
+        mine_tool_ptr->m_is_attendance=true;
+        mine_tool_ptr->m_attendance_start_time=std::chrono::system_clock::now();
+
+        //作为一条开始考勤记录保存到数据库
+        db_tool::save_attendance(card_ptr);
+
+//        log_info("人卡考勤开始:卡id=%d,卡type=%d,分站id=%d,分站reader_type_id=%d,stat_attendance=%d",
+//                 card_ptr->m_id, card_ptr->m_type,
+//                 site_ptr->m_id,site_ptr->m_reader_type_id,mine_tool_ptr->m_is_attendance);
+    }
 
+//    auto ptr_temp = std::make_shared<person_attendance_data>();
+//    ptr = ptr_temp;
+
+//    ptr_temp->m_is_attendance = true;
+//    ptr_temp->m_attendance_start_time = std::chrono::system_clock::now();
+
+//    //作为一条开始考勤记录保存到数据库
+//    db_tool::save_attendance(card_ptr, ptr_temp->m_is_attendance, ptr_temp->m_attendance_start_time);
 }
 
-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_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>&a,
-					const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+                                            const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
+{
+    if(!card_ptr->is_person())
+    {
+        return;
+    }
+
+    up_mine(card_ptr, false);
+
+//    if(nullptr == ptr)
+//    {
+//        log_error("结束考勤失败:nullptr == ptr");
+//        return;
+//    }
+
+//    auto ptr_temp = static_cast<person_attendance_data*>(ptr.get());
+
+//    if(ptr_temp->m_is_attendance)
+//    {
+//        ptr_temp->m_is_attendance = false;
+
+//        //作为一条开始考勤记录保存到数据库
+//        db_tool::save_attendance(card_ptr, ptr_temp->m_is_attendance, ptr_temp->m_attendance_start_time);
+//    }
+}
+
+///升井或收到web的删除卡命令  site_ptr==nullptr表示收到web的删除卡命令
+/// 保存考勤记录,发升井json,清理卡
+void area_business_person_attendance::up_mine(std::shared_ptr<card_location_base> card_ptr, bool is_web_delete)
+{
+    auto mine_tool_ptr = card_ptr->get_mine_tool();
+    if(!mine_tool_ptr->m_is_attendance)
+    {
+        return;
+    }
+
+    //考勤结束
+    mine_tool_ptr->m_is_attendance=false;
+
+    //作为一条结束考勤记录保存到数据库
+    db_tool::save_attendance(card_ptr);
+
+    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);
+    //module_meta_date_changed::clear_card(card_ptr);
+
+    auto rea_tool = card_ptr->get_area_tool();
+    rea_tool->on_leave(card_ptr);
+    card_ptr->clear();
+
+    //升井json发给web
+    if(datas.Size() > 0)
+    {
+        doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_UP_MINE, allocator);
+        //doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
+        doc.AddMember(JSON_ROOT_KEY_DATA, datas, allocator);
+
+        swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
+    }
+
+//    if(is_web_delete)
+//    {
+//        log_info("人卡考勤结束:卡id=%d,卡type=%d,分站id=%d,分站reader_type_id=%d,stat_attendance=%d",
+//                 card_ptr->m_id, card_ptr->m_type,
+//                 site_ptr->m_id,site_ptr->m_reader_type_id,mine_tool_ptr->m_is_attendance);
+//    }
+//    else
+//    {
+//        log_info("收到web的删除卡命令,人卡考勤结束:卡id=%d,卡type=%d, stat_attendance=%d",
+//                 card_ptr->m_id, card_ptr->m_type, mine_tool_ptr->m_is_attendance);
+//    }
+}
+
+/**
+ * @brief 手工升井函数
+ */
+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;
+    }
+
+    rapidjson::Document doc(rapidjson::kObjectType);
+    rapidjson::Value datas(rapidjson::kArrayType);
+    rapidjson::Document::AllocatorType& allocator=doc.GetAllocator();
+
+    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);
+
+            auto mine_tool_ptr = card_ptr->get_mine_tool();
+            if(mine_tool_ptr->m_is_attendance)
+            {
+                //考勤结束
+                mine_tool_ptr->m_is_attendance=false;
+
+                //作为一条结束考勤记录保存到数据库
+                db_tool::save_attendance(card_ptr);
+            }
+
+            //检查井下是否超员--是否需要取消
+            //CMineCardManager::instance()->OnPersonUp(card_ptr);
+
+            auto area_hover_ptr = card_ptr->get_area_hover();
+            if(area_hover_ptr && 0!=area_hover_ptr->id() && 0!=area_hover_ptr->mapid())
+            {
+                module_area::on_leave(card_ptr->m_id, area_hover_ptr, card_ptr->m_type);
+            }
+
+            _to_json_card_up_one(card_ptr, datas, allocator);
+            module_meta_date_changed::clear_card(card_ptr);
+        }
+        else
+        {
+            log_error("手工升井,在全局列表中找不到卡,卡id=%d,卡type=%d", id, type);
+        }
+    }
+
+    //升井json发给web
+    if(datas.Size() > 0)
+    {
+        doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_UP_MINE, allocator);
+        //doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
+        doc.AddMember(JSON_ROOT_KEY_DATA, datas, allocator);
 
+        swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
+    }
 }
 
+///升井json
+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);
+
+    //x,y坐标
+    data.PushBack(card_ptr->x, allocator);
+    data.PushBack(card_ptr->y, allocator); //CFunctions::round(card->y_offset_after(),2)
+
+    //入井时间戳
+    uint64_t t = tool_time::to_ms(mine_tool_ptr->m_attendance_start_time);	//转为ms
+    data.PushBack(t, allocator);
+
+    //进入区域时间戳
+    data.PushBack(0, allocator);
+
+    //接收时间戳
+    data.PushBack(0, allocator);
+    //工作时长
+    t = tool_time::elapse_ms(mine_tool_ptr->m_attendance_start_time);	//转为ms
+    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);
+}
 

+ 18 - 0
module_service/area_business_person_attendance.h

@@ -2,6 +2,10 @@
 #define _area_business_person_attendance_hpp_
 
 #include"area_business.h"
+#include<rapidjson/document.h>
+#include<rapidjson/prettywriter.h>
+#include<rapidjson/stringbuffer.h>
+#include<websocket/sio/sio_client.h>
 
 struct area_business_person_attendance:area_business
 {
@@ -19,6 +23,20 @@ struct area_business_person_attendance:area_business
 
     //记录离开考勤区域信息,结束考勤
     void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
+
+    ///升井或收到web的删除卡命令  site_ptr==nullptr表示收到web的删除卡命令
+    /// 保存考勤记录,发升井json,清理卡
+    static void up_mine(std::shared_ptr<card_location_base> card_ptr, bool is_web_delete);
+
+    /**
+     * @brief 手工升井函数
+     */
+    static void handle_up_mine(sio::message::ptr const& data);
+
+private:
+    ///升井json
+    static void _to_json_card_up_one(std::shared_ptr<card_location_base> card_ptr,
+                                       rapidjson::Value& out_datas, rapidjson::Document::AllocatorType& allocator);
 };
 
 

+ 145 - 6
module_service/area_business_speed_checker.cpp

@@ -1,5 +1,13 @@
 #include "area_business_speed_checker.h"
 
+#include"event.h"
+#include"common_tool.h"
+#include"db/db_api/CDBSingletonDefine.h"
+#include"log.h"
+
+#include"area.h"
+#include "card.h"
+
 struct over_speed_data:business_data
 {
     over_speed_data()
@@ -18,18 +26,149 @@ area_business_speed_checker::area_business_speed_checker()
 {
 }
 
-void area_business_speed_checker::on_enter(const std::shared_ptr<area_hover>&a,
-					const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
+void area_business_speed_checker::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)
 {
+    if(!card_ptr->is_vehicle())
+    {
+        return;
+    }
+
+    auto ptr_temp = std::make_shared<over_speed_data>();
+    ptr = ptr_temp;
+
+    double limit = area_hover_ptr->m_area->m_over_speed_vehicle;
+    if(area_hover_ptr->m_area->is_mine())
+    {
+        limit = _get_mine_limit_speed(card_ptr->get_vehicle_category_id());
+    }
+
+    if(limit < 0.01)
+    {
+        return;
+    }
+
+    ptr_temp ->m_limit_speed = limit;
+    if(limit < card_ptr->m_speed)
+    {
+        ptr_temp->m_over_speed_count++;
+    }
+}
+
+void area_business_speed_checker::on_hover(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_vehicle())
+    {
+        return;
+    }
+
+    auto ptr_temp = static_cast<over_speed_data*>(ptr.get());
+    double limit = ptr_temp ->m_limit_speed;
+    if(limit < 0.01)
+    {
+        return;
+    }
+
+    if(limit < card_ptr->m_speed)//超速
+    {
+        ptr_temp->m_over_speed_count++;
+    }
+    else//速度正常
+    {
+        ptr_temp->m_normal_speed_count++;
+    }
+
+    EVENT_TYPE ev_type = ET_CARD_AREA_OVER_SPEED;
+    if(area_hover_ptr->m_area->is_mine())
+    {
+        ev_type = ET_CARD_OVER_SPEED;
+    }
+
+    //确定告警
+    if(SPEED_COUNT_LIMIT <= ptr_temp->m_over_speed_count)
+    {
+        ptr_temp->m_over_speed_count=SPEED_COUNT_LIMIT;
+
+        auto ev_ptr_temp = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ev_type);
+        if(!ev_ptr_temp)//从没有告警状态转化为告警状态
+        {
+            ptr_temp->m_normal_speed_count=0;
+        }
+
+        uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+        event_tool::instance()->handle_event(OT_CARD, ev_type, id, limit, card_ptr->m_speed, true);
+    }
+
+    //确定正常
+    if(SPEED_COUNT_LIMIT <= ptr_temp->m_normal_speed_count)
+    {
+        ptr_temp->m_normal_speed_count=SPEED_COUNT_LIMIT;
+
+        auto ev_ptr_temp = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ev_type);
+        if(ev_ptr_temp && !ev_ptr_temp->is_end())
+        {
+            ptr_temp->m_over_speed_count=0;
+
+            uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+            event_tool::instance()->handle_event(OT_CARD, ev_type, id, limit, card_ptr->m_speed, false);
+        }
+    }
 }
 
-void area_business_speed_checker::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_speed_checker::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_vehicle())
+    {
+        return;
+    }
+
+    auto ptr_temp = static_cast<over_speed_data*>(ptr.get());
+    double limit = ptr_temp ->m_limit_speed;
+
+    EVENT_TYPE ev_type = ET_CARD_AREA_OVER_SPEED;
+    if(area_hover_ptr->m_area->is_mine())
+    {
+        ev_type = ET_CARD_OVER_SPEED;
+    }
+
+    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+    event_tool::instance()->handle_event(OT_CARD, ev_type, id, limit, card_ptr->m_speed, false);
 }
 
-void area_business_speed_checker::on_leave(const std::shared_ptr<area_hover>&a,
-					const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
+void area_business_speed_checker::init_vehicle_category_from_db()
 {
+    const char *sql = "SELECT vehicle_category_id, over_speed FROM dat_vehicle_category;";
+    std::string Error;
+    YADB::CDBResultSet DBRes;
+    sDBConnPool.Query(sql,DBRes,Error);
+    if(!Error.empty())
+        log_error("init_vehicle_category Error,%s",Error.c_str());
+    int64_t nCount = DBRes.GetRecordCount( Error );
+    if (nCount < 1)
+    {
+        log_error("错误,init_vehicle_category. The record count=%ld\n", nCount );
+        return;
+    }
+
+    log_info( "init_vehicle_category. The record count=%ld\n", nCount );
+
+    _vehicle_category_map.clear();
+    while ( DBRes.GetNextRecod(Error) )
+    {
+        int vehicle_category_id  = 0;
+        DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
+
+        double over_speed = 0;
+        DBRes.GetField( "over_speed",over_speed, Error );
+
+        _vehicle_category_map.insert({vehicle_category_id,over_speed});
+    }
+
+    for(const auto &p : _vehicle_category_map)
+        std_debug("dat_vehicle_category:category_id:%d--over_speed:%.2f",p.first,p.second);
 }
 
+
+

+ 21 - 2
module_service/area_business_speed_checker.h

@@ -1,13 +1,15 @@
 #ifndef AREA_BUSINESS_SPEED_CHECKER_H
 #define AREA_BUSINESS_SPEED_CHECKER_H
 
+#include<unordered_map>
 #include"area_business.h"
 
-struct area_business_speed_checker:area_business
+class area_business_speed_checker : public area_business
 {
+public:
     area_business_speed_checker();
 
-    int area_business_type()
+    virtual int area_business_type()
     {
         return 4;
     }
@@ -15,6 +17,23 @@ struct area_business_speed_checker:area_business
     void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr);
     void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
     void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
+
+    static void init_vehicle_category_from_db();
+
+private:
+    static double _get_mine_limit_speed(int category_id)
+    {
+        auto serch = _vehicle_category_map.find(category_id);
+        if(serch == _vehicle_category_map.end())
+        {
+            return 0;
+        }
+
+        return serch->second;
+    }
+
+private:
+    static std::unordered_map<int,double> _vehicle_category_map;
 };
 
 #endif // AREA_BUSINESS_SPEED_CHECKER_H

+ 0 - 175
module_service/module_area.h

@@ -1,175 +0,0 @@
-#ifndef MODULE_AREA_H
-#define MODULE_AREA_H
-
-/**
- * @brief 与区域相关的业务模块总接口
- * @author 戴月腾
- * @date 2018-08-25
- */
-
-#include"area.h"
-#include"module_const.h"
-#include"module_web.h"
-
-#include"module_attendance_vehicle.h"
-#include"module_area_over_count.h"
-#include"module_area_timeout.h"
-
-class module_area: public singleton_base<module_area>
-{
-private:
-    friend class singleton_base<module_area>;
-    module_area()
-    {
-    }
-
-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())
-        {
-            log_error("(0==c->id() || 0==c->mapid()), card_id=%d, 卡type=%d,areaid=%d,mapid=%d",
-                      card_id, type, c->id(), c->mapid());
-            return;
-        }
-
-        auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
-        if(!card_ptr)
-        {
-            log_error("卡不存在card_id=%d", card_id);
-            return;
-        }
-
-        c->m_enter_time = tool_time::now_to_seconds();
-
-        if(card_ptr->is_person())//统计人卡
-        {
-            c->m_area->m_person_count++;
-        }
-
-        if(card_ptr->is_vehicle())//统计车卡
-        {
-            c->m_area->m_vehicle_count++;
-            //车卡考勤
-            module_attendance_vehicle::instance()->on_enter(card_ptr, c);
-        }
-
-        //区域超员
-        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())
-        {
-            log_error("(0==c->id() || 0==c->mapid()), card_id=%d, 卡type=%d,areaid=%d,mapid=%d",
-                      card_id, type, c->id(), c->mapid());
-            return;
-        }
-
-        auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
-        if(!card_ptr)
-        {
-            log_error("卡不存在card_id=%d", card_id);
-            return;
-        }
-
-        //        if(card_ptr->is_person())//人卡
-        //        {
-
-        //        }
-
-        //        if(card_ptr->is_vehicle())//车卡
-        //        {
-
-        //        }
-
-        //区域超时
-        module_area_timeout::instance()->on_hover(card_ptr, c);
-    }
-
-    static void on_leave(uint32_t card_id, std::shared_ptr<area_hover>&c, int32_t type)
-    {
-        if(0==c->id() || 0==c->mapid())
-        {
-            log_error("(0==c->id() || 0==c->mapid()), card_id=%d, 卡type=%d,areaid=%d,mapid=%d",
-                      card_id, type, c->id(), c->mapid());
-            return;
-        }
-
-        auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
-        if(!card_ptr)
-        {
-            log_error("卡不存在card_id=%d", card_id);
-            return;
-        }
-
-        if(card_ptr->is_person())//统计人卡
-        {
-            c->m_area->m_person_count--;
-        }
-
-        if(card_ptr->is_vehicle())//统计车卡
-        {
-            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(),
-                tool_other::type_id_to_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());
-
-        db_tool::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(tool_time::now_to_ms());
-
-        sprintf(sql, "CALL %s(%s, %d, %d, %d, '%s','%s');", call.c_str(),
-                tool_other::type_id_to_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());
-
-        db_tool::PushAsync(sql);
-    }
-};
-
-#endif // MODULE_AREA_H

+ 0 - 70
module_service/module_area_entry_forbid.cpp

@@ -1,70 +0,0 @@
-#include"module_area_entry_forbid.h"
-
-#include<memory>
-
-#include "event.h"
-#include "area.h"
-#include"area_business.h"
-#include"log.h"
-#include"common_tool.h"
-
-struct forbid_data:business_data
-{
-    forbid_data()
-    {
-    }
-};
-
-void module_area_entry_forbid::on_enter(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-
-    area_hover_ptr->m_data[index] = std::make_shared<forbid_data>();
-
-    EVENT_TYPE ev_type = ET_CARD_AREA_FORBIDDEN_PERSON;
-    if(card_ptr->is_vehicle())
-    {
-        ev_type = ET_CARD_AREA_FORBIDDEN_VEHICLE;
-    }
-
-    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
-    event_tool::instance()->handle_event(OT_CARD, ev_type, id, 0, 0, true);
-}
-
-void module_area_entry_forbid::on_hover(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-
-}
-
-void module_area_entry_forbid::on_leave(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-
-    EVENT_TYPE ev_type = ET_CARD_AREA_FORBIDDEN_PERSON;
-    if(card_ptr->is_vehicle())
-    {
-        ev_type = ET_CARD_AREA_FORBIDDEN_VEHICLE;
-    }
-
-    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
-    event_tool::instance()->handle_event(OT_CARD, ev_type, id, 0, 0, false);
-
-    area_hover_ptr->m_data[index] = std::make_shared<forbid_data>();
-}
-
-
-
-
-
-
-

+ 0 - 31
module_service/module_area_entry_forbid.h

@@ -1,31 +0,0 @@
-#ifndef MODULE_AREA_ENTRY_FORBID_H
-#define MODULE_AREA_ENTRY_FORBID_H
-
-/**
- * @brief 简要说明
- * @author 戴月腾
- * @date 2019-01-10
- */
-
-
-#include "module_singleton_base.h"
-#include "card.h"
-
-
-
-class module_area_entry_forbid:public singleton_base<module_area_entry_forbid>
-{
-private:
-    friend class singleton_base<module_area_entry_forbid>;
-    module_area_entry_forbid()
-    {
-    }
-
-public:
-
-    void on_enter(std::shared_ptr<card_location_base> card_ptr, int index);
-    void on_hover(std::shared_ptr<card_location_base> card_ptr, int index);
-    void on_leave(std::shared_ptr<card_location_base> card_ptr, int index);
-};
-
-#endif // MODULE_AREA_ENTRY_FORBID_H

+ 0 - 139
module_service/module_area_over_count.h

@@ -1,139 +0,0 @@
-#ifndef MODULE_AREA_OVER_COUNT_H
-#define MODULE_AREA_OVER_COUNT_H
-/**
- * @brief 人员或车辆超员
- * @author 戴月腾
- * @date 2018-10-10
- */
-
-#include <string>
-#include <memory>
-#include <atomic>
-#include <mutex>
-#include <map>
-#include "module_const.h"
-
-
-class module_area_over_count:public singleton_base<module_area_over_count>
-{
-private:
-    friend class singleton_base<module_area_over_count>;
-    module_area_over_count()
-    {
-    }
-
-public:
-
-    void on_enter(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
-    {
-        auto area_ptr = c->m_area;
-
-        int limit = area_ptr->m_limit_person_count;
-        EVENT_TYPE ev_type = ET_AREA_OVER_COUNT_PERSON;
-        int cur_value = area_ptr->m_person_count;
-        if(card_ptr->is_vehicle())
-        {
-            limit = area_ptr->m_limit_vehicle_count;
-            ev_type = ET_AREA_OVER_COUNT_VEHICLE;
-            cur_value = area_ptr->m_vehicle_count;
-        }
-
-        //超员配置是否为0,0则不会进行告警
-        if(0 == limit)
-        {
-            return;
-        }
-
-        if(limit <= cur_value)//超员
-        {
-            std::lock_guard<std::mutex> lock(__lock);
-
-            auto ev_ptr = event_list::instance()->get_event_area(area_ptr->id(), ev_type);
-            if(ev_ptr)
-            {
-                event_list::copy_event(area_ptr, ev_ptr);
-
-                ev_ptr->m_limit_value=limit;
-                ev_ptr->m_cur_value=cur_value;
-
-                ev_ptr->m_status = ES_START;
-            }
-            else//从没有告警状态转化为告警状态
-            {
-                ev_ptr = event_list::create_event_area(area_ptr->id(), ev_type);
-
-                event_list::copy_event(area_ptr, ev_ptr);
-
-                ev_ptr->m_limit_value=limit;
-                ev_ptr->m_cur_value=cur_value;
-
-                //保存到数据库
-                event_list::save_event(ev_ptr);
-
-                event_list::instance()->add(ev_ptr->get_list_id(),ev_ptr);
-
-                log_info("区域超员开始:区域id=%d,区域门限=%d,当前卡数=%d, 卡类型=%d",
-                         area_ptr->id(), limit, cur_value, card_ptr->m_type);
-            }
-        }
-    }
-
-//    void on_hover(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
-//    {
-
-//    }
-
-    void on_leave(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
-    {
-        auto area_ptr = c->m_area;
-
-        int limit = area_ptr->m_limit_person_count;
-        EVENT_TYPE ev_type = ET_AREA_OVER_COUNT_PERSON;
-        int cur_value = area_ptr->m_person_count;
-        if(card_ptr->is_vehicle())
-        {
-            limit = area_ptr->m_limit_vehicle_count;
-            ev_type = ET_AREA_OVER_COUNT_VEHICLE;
-            cur_value = area_ptr->m_vehicle_count;
-        }
-
-        //超员配置是否为0,0则不会进行告警
-        if(0 == limit)
-        {
-            return;
-        }
-
-        if(limit > cur_value)//没有超员
-        {
-            //取消告警状态
-            auto ev_ptr = event_list::instance()->get_event_area(area_ptr->id(), ev_type);
-            if(ev_ptr && !ev_ptr->is_end())
-            {
-                std::lock_guard<std::mutex> lock(__lock);
-                if(ev_ptr->is_end())
-                {
-                    return;
-                }
-
-                event_list::copy_event(area_ptr, ev_ptr);
-
-                ev_ptr->m_limit_value=limit;
-                ev_ptr->m_cur_value=cur_value;
-
-                ev_ptr->m_status = ES_END;
-
-                //保存到数据库
-                event_list::save_event(ev_ptr);
-
-                log_info("区域超员结束:区域id=%d,区域门限=%d,当前卡数=%d, 卡类型=%d",
-                         area_ptr->id(), limit, cur_value, card_ptr->m_type);
-            }
-        }
-    }
-
-private:
-    std::mutex __lock;
-};
-
-
-#endif // MODULE_AREA_OVER_COUNT_H

+ 0 - 112
module_service/module_area_over_speed.cpp

@@ -1,112 +0,0 @@
-#include"module_area_over_speed.h"
-
-#include<memory>
-#include<string>
-
-#include"area_business.h"
-#include"event.h"
-#include"log.h"
-#include"common_tool.h"
-#include"area.h"
-
-
-struct over_speed_data:business_data
-{
-    over_speed_data()
-    {
-        m_over_speed_count=0;
-        m_normal_speed_count=0;
-    }
-
-    int m_over_speed_count;
-    int m_normal_speed_count;
-};
-
-void module_area_over_speed::on_enter(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-
-    area_hover_ptr->m_data[index] = std::make_shared<over_speed_data>();
-
-    double limit = area_hover_ptr->m_area->m_over_speed_vehicle;
-    if(limit < card_ptr->m_speed)
-    {
-        auto ptr = static_cast<over_speed_data*>(area_hover_ptr->m_data[index].get());
-        ptr->m_over_speed_count++;
-    }
-}
-
-void module_area_over_speed::on_hover(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-    auto ptr = static_cast<over_speed_data*>(area_hover_ptr->m_data[index].get());
-
-    double limit = area_hover_ptr->m_area->m_over_speed_vehicle;
-    if(limit < card_ptr->m_speed)//超速
-    {
-        ptr->m_over_speed_count++;
-    }
-    else//速度正常
-    {
-        ptr->m_normal_speed_count++;
-    }
-
-    //确定告警
-    if(SPEED_COUNT_LIMIT <= ptr->m_over_speed_count)
-    {
-        ptr->m_over_speed_count=SPEED_COUNT_LIMIT;
-
-        auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ET_CARD_AREA_OVER_SPEED);
-        if(!ev_ptr)//从没有告警状态转化为告警状态
-        {
-            ptr->m_normal_speed_count=0;
-        }
-
-        uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
-        event_tool::instance()->handle_event(OT_CARD, ET_CARD_AREA_OVER_SPEED, id, limit, card_ptr->m_speed, true);
-    }
-
-    //确定正常
-    if(SPEED_COUNT_LIMIT <= ptr->m_normal_speed_count)
-    {
-        ptr->m_normal_speed_count=SPEED_COUNT_LIMIT;
-
-        auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ET_CARD_AREA_OVER_SPEED);
-        if(ev_ptr && !ev_ptr->is_end())
-        {
-            ptr->m_over_speed_count=0;
-
-            uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
-            event_tool::instance()->handle_event(OT_CARD, ET_CARD_AREA_OVER_SPEED, id, limit, card_ptr->m_speed, false);
-        }
-    }
-}
-
-void module_area_over_speed::on_leave(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-
-    double limit = area_hover_ptr->m_area->m_over_speed_vehicle;
-
-    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
-    event_tool::instance()->handle_event(OT_CARD, ET_CARD_AREA_OVER_SPEED, id, limit, card_ptr->m_speed, false);
-
-    area_hover_ptr->m_data[index] = std::make_shared<over_speed_data>();
-}
-
-

+ 0 - 36
module_service/module_area_over_speed.h

@@ -1,36 +0,0 @@
-#ifndef MODULE_AREA_OVER_SPEED_H
-#define MODULE_AREA_OVER_SPEED_H
-
-/**
- * @brief 简要说明
- * @author 戴月腾
- * @date 2019-01-07
- */
-
-#include <mutex>
-#include <map>
-#include <chrono>
-#include <boost/thread.hpp>
-#include <boost/enable_shared_from_this.hpp>
-
-#include "module_singleton_base.h"
-#include "card.h"
-
-
-///区域超速
-class module_area_over_speed:public singleton_base<module_area_over_speed>
-{
-private:
-    friend class singleton_base<module_area_over_speed>;
-    module_area_over_speed()
-    {
-    }
-
-public:
-    void on_enter(std::shared_ptr<card_location_base> card_ptr, int index);
-    void on_hover(std::shared_ptr<card_location_base> card_ptr, int index);
-    void on_leave(std::shared_ptr<card_location_base> card_ptr, int index);
-};
-
-
-#endif // MODULE_AREA_OVER_SPEED_H

+ 0 - 119
module_service/module_area_timeout.h

@@ -1,119 +0,0 @@
-#ifndef MODULE_AREA_TIMEOUT_H
-#define MODULE_AREA_TIMEOUT_H
-/**
- * @brief 区域超时
- * @author 戴月腾
- * @date 2018-10-10
- */
-
-
-#include <mutex>
-#include <map>
-#include <chrono>
-#include <boost/thread.hpp>
-#include <boost/enable_shared_from_this.hpp>
-#include "point.h"
-#include "module_const.h"
-
-
-class module_area_timeout:public singleton_base<module_area_timeout>
-{
-private:
-    friend class singleton_base<module_area_timeout>;
-    module_area_timeout()
-    {
-    }
-
-public:
-    void on_enter(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
-    {
-//        EVENT_TYPE ev_type = card_ptr->is_person() ? ET_CARD_AREA_OVER_TIME_PERSON : ET_AREA_OVER_COUNT_VEHICLE;
-//        //中途服务器宕机处理
-//        if(auto ev_ptr = event_list::instance()->get(card_ptr->m_id, ev_type))
-//        {
-//            c->m_enter_time = std::chrono::system_clock::to_time_t(ev_ptr->m_cur_time);
-//        }
-//        else
-//        {
-//            std::time(&c->m_enter_time);
-//        }
-    }
-
-    void on_hover(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
-    {
-        auto area_ptr = c->m_area;
-
-        int limit = area_ptr->m_limit_person_second;
-        EVENT_TYPE ev_type = ET_CARD_AREA_OVER_TIME_PERSON;
-        if(card_ptr->is_vehicle())
-        {
-            limit = area_ptr->m_limit_vehicle_second;
-            ev_type = ET_CARD_AREA_OVER_TIME_VEHICLE;
-        }
-
-        int seconds = tool_time::elapse_seconds(c->m_enter_time);
-
-        if(seconds > limit)//发生告警
-        {
-            auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ev_type);
-            if(ev_ptr)
-            {
-                event_list::copy_event(card_ptr, ev_ptr);
-
-                ev_ptr->m_limit_value = limit;
-                ev_ptr->m_cur_value = seconds;
-            }
-            else//从没有告警状态转化为告警状态
-            {
-                ev_ptr = event_list::create_event_card(card_ptr->m_id, card_ptr->m_type, ev_type);
-
-                event_list::copy_event(card_ptr, ev_ptr);
-
-                ev_ptr->m_limit_value = limit;
-                ev_ptr->m_cur_value = seconds;
-
-                //保存到数据库
-                event_list::save_event(ev_ptr);
-
-                event_list::instance()->add(ev_ptr->get_list_id(),ev_ptr);
-
-                log_info("卡区域超时开始:卡id=%d,卡type=%d,区域id=%d,时间门限=%d,呆的时间长度=%d",
-                         card_ptr->m_id, card_ptr->m_type,
-                         area_ptr->id(), limit, seconds);
-            }
-        }
-    }
-
-    void on_leave(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
-    {
-        auto area_ptr = c->m_area;
-
-        int limit = area_ptr->m_limit_person_second;
-        EVENT_TYPE ev_type = ET_CARD_AREA_OVER_TIME_PERSON;
-        if(card_ptr->is_vehicle())
-        {
-            limit = area_ptr->m_limit_vehicle_second;
-            ev_type = ET_CARD_AREA_OVER_TIME_VEHICLE;
-        }
-
-        auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ev_type);
-        if(ev_ptr && !ev_ptr->is_end())//有超时告警就删除
-        {
-            event_list::copy_event(card_ptr, ev_ptr);
-
-            ev_ptr->m_limit_value = limit;
-            ev_ptr->m_cur_value = tool_time::elapse_seconds(c->m_enter_time);
-
-            ev_ptr->m_status = ES_END;
-
-            //保存到数据库
-            event_list::save_event(ev_ptr);
-
-            log_info("卡区域超时结束:卡id=%d,卡type=%d,区域id=%d,时间门限=%d",
-                     card_ptr->m_id, card_ptr->m_type,
-                     area_ptr->id(), limit);
-        }
-    }
-};
-
-#endif // MODULE_AREA_TIMEOUT_H

+ 0 - 242
module_service/module_attendance_person.cpp

@@ -1,242 +0,0 @@
-#include"module_attendance_person.h"
-
-#include <chrono>
-//#include <vector>
-
-#include "websocket/wsClientMgr.h"
-#include"mine.h"
-#include "module_meta_date_changed.h"
-
-#include "module_mine.h"
-#include "common_tool.h"
-#include "module_area.h"
-#include"log.h"
-#include "mine_module/MineCardManager.h"
-#include"db/db_tool.h"
-
-
-/**
- * @brief 进入分站覆盖区域处理,考勤
- * @param card_ptr
- * @param site_ptr
- */
-void module_attendance_person::enter_site(std::shared_ptr<card_location_base> card_ptr, std::shared_ptr<site> site_ptr)
-{
-    // 从井下切换到井上为考勤结束
-    // 从井下切换到井上为考勤结束
-    if(site_ptr->is_up_site())
-    {
-        up_mine(card_ptr, site_ptr);
-        //检查井下是否超员--是否需要取消
-        CMineCardManager::instance()->OnPersonUp(card_ptr);
-    }
-    else// 从井上切换到井下为考勤开始
-    {
-        auto mine_tool_ptr = card_ptr->get_mine_tool();
-        if(!mine_tool_ptr->is_attendance())
-        {
-            //考勤开始
-            mine_tool_ptr->m_stat_attendance=AS_ATTENDANCE;
-
-            mine_tool_ptr->m_attendance_start_time=std::chrono::system_clock::now();
-
-            //作为一条开始考勤记录保存到数据库
-            db_tool::save_attendance(card_ptr);
-
-            log_info("人卡考勤开始:卡id=%d,卡type=%d,分站id=%d,分站reader_type_id=%d,stat_attendance=%d",
-                     card_ptr->m_id, card_ptr->m_type,
-                     site_ptr->m_id,site_ptr->m_reader_type_id,mine_tool_ptr->m_stat_attendance);
-        }
-
-        //检查井下是否超员
-        CMineCardManager::instance()->OnPersonDown(card_ptr);
-    }
-}
-
-  /**
-   * @brief 离开现有分站处理,记录现有分站的进出时间和地点
-   * @param card_ptr
-   * @param site_ptr
-   */
-  void module_attendance_person::leave_site(std::shared_ptr<card_location_base> card_ptr, std::shared_ptr<site> site_ptr)
-  {
-
-  }
-
-///升井或收到web的删除卡命令  site_ptr==nullptr表示收到web的删除卡命令
-/// 保存考勤记录,发升井json,清理卡
-void module_attendance_person::up_mine(std::shared_ptr<card_location_base> card_ptr, std::shared_ptr<site> site_ptr)
-{
-    auto mine_tool_ptr = card_ptr->get_mine_tool();
-    if(!mine_tool_ptr->is_attendance())
-    {
-        return;
-    }
-
-    //考勤结束
-    mine_tool_ptr->m_stat_attendance=AS_NOT_ATTENDANCE;
-
-    //作为一条结束考勤记录保存到数据库
-    db_tool::save_attendance(card_ptr);
-
-    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);
-    module_meta_date_changed::clear_card(card_ptr);
-
-    //升井json发给web
-    if(datas.Size() > 0)
-    {
-        doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_UP_MINE, allocator);
-        //doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
-        doc.AddMember(JSON_ROOT_KEY_DATA, datas, allocator);
-
-        swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
-    }
-
-    if(site_ptr)
-    {
-        log_info("人卡考勤结束:卡id=%d,卡type=%d,分站id=%d,分站reader_type_id=%d,stat_attendance=%d",
-                 card_ptr->m_id, card_ptr->m_type,
-                 site_ptr->m_id,site_ptr->m_reader_type_id,mine_tool_ptr->m_stat_attendance);
-    }
-    else
-    {
-        log_info("收到web的删除卡命令,人卡考勤结束:卡id=%d,卡type=%d, stat_attendance=%d",
-                 card_ptr->m_id, card_ptr->m_type, mine_tool_ptr->m_stat_attendance);
-    }
-}
-
-/**
- * @brief 手工升井函数
- */
-void module_attendance_person::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;
-    }
-
-    rapidjson::Document doc(rapidjson::kObjectType);
-    rapidjson::Value datas(rapidjson::kArrayType);
-    rapidjson::Document::AllocatorType& allocator=doc.GetAllocator();
-
-    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);
-
-            auto mine_tool_ptr = card_ptr->get_mine_tool();
-            if(mine_tool_ptr->is_attendance())
-            {
-                //考勤结束
-                mine_tool_ptr->m_stat_attendance=AS_NOT_ATTENDANCE;
-
-                //作为一条结束考勤记录保存到数据库
-                db_tool::save_attendance(card_ptr);
-            }
-
-            //检查井下是否超员--是否需要取消
-            CMineCardManager::instance()->OnPersonUp(card_ptr);
-
-            auto area_hover_ptr = card_ptr->get_area_hover();
-            if(area_hover_ptr && 0!=area_hover_ptr->id() && 0!=area_hover_ptr->mapid())
-            {
-                module_area::on_leave(card_ptr->m_id, area_hover_ptr, card_ptr->m_type);
-            }
-
-            _to_json_card_up_one(card_ptr, datas, allocator);
-            module_meta_date_changed::clear_card(card_ptr);
-        }
-        else
-        {
-            log_error("手工升井,在全局列表中找不到卡,卡id=%d,卡type=%d", id, type);
-        }
-    }
-
-    //升井json发给web
-    if(datas.Size() > 0)
-    {
-        doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_UP_MINE, allocator);
-        //doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
-        doc.AddMember(JSON_ROOT_KEY_DATA, datas, allocator);
-
-        swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
-    }
-}
-
-///升井json
-void module_attendance_person::_to_json_card_up_one(std::shared_ptr<card_location_base> card_ptr,
-                                   rapidjson::Value& out_datas, rapidjson::Document::AllocatorType& allocator)
-{
-    auto site_area_ptr = card_ptr->get_site_area();
-    if(!card_ptr->m_display || !site_area_ptr || site_area_ptr->is_invalid())
-    {
-        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);
-
-    //x,y坐标
-    data.PushBack(card_ptr->x, allocator);
-    data.PushBack(card_ptr->y, allocator); //CFunctions::round(card->y_offset_after(),2)
-
-    //入井时间戳
-    uint64_t t = tool_time::to_ms(mine_tool_ptr->m_attendance_start_time);	//转为ms
-    data.PushBack(t, allocator);
-
-    //进入区域时间戳
-    data.PushBack(0, allocator);
-
-    //接收时间戳
-    data.PushBack(0, allocator);
-    //工作时长
-    t = tool_time::elapse_ms(mine_tool_ptr->m_attendance_start_time);	//转为ms
-    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);
-}
-
-
-
-

+ 0 - 59
module_service/module_attendance_person.h

@@ -1,59 +0,0 @@
-#ifndef MODULE_ATTENDANCE_PERSON_H
-#define MODULE_ATTENDANCE_PERSON_H
-
-/**
-  *@brief 人员考勤模块 2018-08-26 戴月腾修改
-  *主要是针对人卡进行考勤,人卡从井上切换到井下为考勤开始,人卡从井下切换到井上为考勤结束
-  *@author 陈欧美
-  *@date 2018-08-03
-*/
-
-#include<rapidjson/document.h>
-#include<rapidjson/prettywriter.h>
-#include<rapidjson/stringbuffer.h>
-#include "card.h"
-#include"module_singleton_base.h"
-#include "websocket/sio/sio_client.h"
-
-/**
- * @brief 主要是针对人卡进行考勤,人卡从井上切换到井下为考勤开始,人卡从井下切换到井上为考勤结束
- */
-class module_attendance_person:public singleton_base<module_attendance_person>
-{
-private:
-    friend class singleton_base<module_attendance_person>;
-    module_attendance_person()
-    {
-    }
-
-public:
-    /**
-     * @brief 进入分站覆盖区域处理,考勤
-     * @param card_ptr
-     * @param site_ptr
-     */
-    void enter_site(std::shared_ptr<card_location_base> card_ptr, std::shared_ptr<site> site_ptr);
-
-    /**
-     * @brief 离开现有分站处理,记录现有分站的进出时间和地点
-     * @param card_ptr
-     * @param site_ptr
-     */
-    void leave_site(std::shared_ptr<card_location_base> card_ptr, std::shared_ptr<site> site_ptr);
-
-    ///升井或收到web的删除卡命令  site_ptr==nullptr表示收到web的删除卡命令
-    /// 保存考勤记录,发升井json,清理卡
-    static void up_mine(std::shared_ptr<card_location_base> card_ptr, std::shared_ptr<site> site_ptr);
-
-    /**
-     * @brief 手工升井函数
-     */
-    void handle_up_mine(sio::message::ptr const& data);
-
-private:
-    ///升井json
-    static void _to_json_card_up_one(std::shared_ptr<card_location_base> card_ptr,
-                                       rapidjson::Value& out_datas, rapidjson::Document::AllocatorType& allocator);
-};
-
-#endif // MODULE_ATTENDANCE_PERSON_H

+ 0 - 165
module_service/module_attendance_vehicle.cpp

@@ -1,165 +0,0 @@
-#include "module_attendance_vehicle.h"
-
-#include<memory>
-#include<string>
-
-#include"area_business.h"
-#include"event.h"
-#include"log.h"
-#include"common_tool.h"
-#include"area.h"
-#include"db/db_api/CDBSingletonDefine.h"
-#include"db/db_tool.h"
-#include"mine.h"
-
-
-struct attendance_vehicle_data:business_data
-{
-    attendance_vehicle_data():m_is_attendance(false)
-      ,m_attendance_start_time(std::chrono::seconds(0))
-    {
-    }
-
-    ///考勤状态  0初始状态 1 没在考勤 2 考勤;参看ATTENDANCE_STATUS
-    bool m_is_attendance;
-    ///考勤开始时间
-    std::chrono::system_clock::time_point m_attendance_start_time;
-};
-
-void module_attendance_vehicle::on_enter(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-
-    area_hover_ptr->m_data[index] = std::make_shared<attendance_vehicle_data>();
-    auto ptr = static_cast<attendance_vehicle_data*>(area_hover_ptr->m_data[index].get());
-
-    ptr->m_is_attendance=true;
-    ptr->m_attendance_start_time=std::chrono::system_clock::now();
-
-    //作为一条开始考勤记录保存到数据库
-    db_tool::save_attendance(card_ptr, ptr->m_is_attendance, ptr->m_attendance_start_time);
-}
-
-void module_attendance_vehicle::on_hover(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-}
-
-
-void module_attendance_vehicle::on_leave(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-
-    area_hover_ptr->m_data[index] = std::make_shared<attendance_vehicle_data>();
-    auto ptr = static_cast<attendance_vehicle_data*>(area_hover_ptr->m_data[index].get());
-
-    if(ptr->m_is_attendance)
-    {
-        ptr->m_is_attendance=false;
-        //作为一条开始考勤记录保存到数据库
-        db_tool::save_attendance(card_ptr, ptr->m_is_attendance, ptr->m_attendance_start_time);
-    }
-}
-
-void module_attendance_vehicle::on_enter(std::shared_ptr<card_location_base> card_ptr, std::shared_ptr<area_hover>&c)
-{
-    auto area_ptr = c->m_area;
-
-    //从考勤状态转换为结束考勤
-    if(is_not_attendance_area(area_ptr->m_id, card_ptr->get_vehicle_type_id()))
-    {
-        save_attendance(card_ptr, area_ptr);
-    }
-    else//没在考勤状态转换为考勤状态
-    {
-        auto mine_tool_ptr = card_ptr->get_mine_tool();
-        if(!mine_tool_ptr->is_attendance())
-        {
-            //考勤开始
-            mine_tool_ptr->m_stat_attendance=AS_ATTENDANCE;
-            mine_tool_ptr->m_attendance_start_time=std::chrono::system_clock::now();
-
-            //作为一条开始考勤记录保存到数据库
-            db_tool::save_attendance(card_ptr);
-
-            log_info("车卡考勤开始:卡id=%d,卡type=%d,区域id=%d, stat_attendance=%d",
-                     card_ptr->m_id, card_ptr->m_type,
-                     area_ptr->m_id,mine_tool_ptr->m_stat_attendance);
-        }
-    }
-}
-
-void module_attendance_vehicle::init_attendance_area_from_db()
-{
-    const char *sql = "select a.area_id, a.att_rule_id,  vt.vehicle_type_id \
-            from dat_att_rule_area a, dat_att_rule_vehicle_type  vt, dat_att_rule r\
-            where a.att_rule_id=vt.att_rule_id and a.att_rule_id=r.att_rule_id;";
-    std::string Error;
-    YADB::CDBResultSet DBRes;
-    sDBConnPool.Query(sql,DBRes,Error);
-    if(!Error.empty())
-        log_error("初始化attendance_area Error,%s",Error.c_str());
-    uint64_t nCount = DBRes.GetRecordCount( Error );
-    if(int64_t(nCount) <= 0)
-    {
-        log_error("初始化attendance_area Error,%s",Error.c_str());
-    }
-
-    log_info( "init_attendance_area_from_db. The record count=%ld\n", nCount );
-
-    m_map.clear();
-    while ( DBRes.GetNextRecod(Error) )
-    {
-        int area_id  = 0;
-        DBRes.GetField( "area_id",area_id, Error );
-
-        int att_rule_id  = 0;
-        DBRes.GetField( "att_rule_id",att_rule_id, Error );
-
-        int vehicle_type_id  = 0;
-        DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
-
-        m_map.insert(std::make_pair(to_list_id(area_id, vehicle_type_id), att_rule_id));
-    }
-}
-
-///area_ptr==nullptr 表示接收到 web的删除卡命令
-void module_attendance_vehicle::save_attendance(std::shared_ptr<card_location_base>& card_ptr, std::shared_ptr<area> area_ptr)
-{
-    auto mine_tool_ptr = card_ptr->get_mine_tool();
-    if(!mine_tool_ptr->is_attendance())
-    {
-        return;
-    }
-
-    //考勤结束
-    mine_tool_ptr->m_stat_attendance=AS_NOT_ATTENDANCE;
-
-    //作为一条结束考勤记录保存到数据库
-    db_tool::save_attendance(card_ptr);
-
-    if(area_ptr)
-    {
-        log_info("车卡考勤结束:卡id=%d,卡type=%d,区域id=%d, stat_attendance=%d",
-                 card_ptr->m_id, card_ptr->m_type,
-                 area_ptr->m_id,mine_tool_ptr->m_stat_attendance);
-    }
-    else
-    {
-        log_info("收到web的删除卡命令,车卡考勤结束:卡id=%d,卡type=%d,stat_attendance=%d",
-                 card_ptr->m_id, card_ptr->m_type,mine_tool_ptr->m_stat_attendance);
-    }
-}
-
-
-
-

+ 0 - 55
module_service/module_attendance_vehicle.h

@@ -1,55 +0,0 @@
-#ifndef MODULE_ATTENDANCE_VEHICLE_H
-#define MODULE_ATTENDANCE_VEHICLE_H
-
-/**
-  *@brief 车辆考勤模块
-  *车辆进入某些特定区域,结束考勤;从特定区域进入其他区域,开始考勤
-  *@author 戴月腾
-  *@date 2018-08-07
-*/
-
-#include<unordered_map>
-#include "module_singleton_base.h"
-#include "card.h"
-#include"area.h"
-
-
-/**
- * @brief 车辆进入某些特定区域,结束考勤;从特定区域进入其他区域,开始考勤, 单例
- */
-class module_attendance_vehicle:public singleton_base<module_attendance_vehicle>
-{
-private:
-    friend class singleton_base<module_attendance_vehicle>;
-    module_attendance_vehicle()
-    {
-    }
-
-public:
-    void on_enter(std::shared_ptr<card_location_base> card_ptr, int index);
-    void on_hover(std::shared_ptr<card_location_base> card_ptr, int index);
-    void on_leave(std::shared_ptr<card_location_base> card_ptr, int index);
-
-    void on_enter(std::shared_ptr<card_location_base> card_ptr, std::shared_ptr<area_hover>&c);
-
-    void init_attendance_area_from_db();
-
-    ///area_ptr==nullptr 表示接收到 web的删除卡命令
-    static void save_attendance(std::shared_ptr<card_location_base>& card_ptr, std::shared_ptr<area> area_ptr);
-
-private:
-    bool is_not_attendance_area(int area_id, int vehicle_type_id)
-    {
-        return  m_map.end() != m_map.find(to_list_id(area_id, vehicle_type_id));
-    }
-
-    uint64_t to_list_id(int area_id, int vehicle_type_id)
-    {
-        return (static_cast<uint64_t>(area_id)<<32) | static_cast<uint64_t>(vehicle_type_id);
-    }
-
-    ///area_id<<32| vehicle_type_id; att_rule_id
-    std::unordered_map<uint64_t, int> m_map;
-};
-
-#endif // MODULE_ATTENDANCE_VEHICLE_H

+ 117 - 0
module_service/module_call.cpp

@@ -9,9 +9,51 @@
 
 #include <area.h>
 #include <site_area.h>
+#include"common_tool.h"
+#include"tool_time.h"
+#include"ant.h"
+#include"websocket/constdef.h"
+#include"websocket/wsClientMgr.h"
+
 #include"mine.h"
 
 
+uint64_t module_call::call_card::to_id64()
+{
+    return tool_other::type_id_to_u64(cardtype, cardid);
+}
+
+std::string module_call::call_card::to_id64_str()
+{
+    return tool_other::type_id_to_str(cardtype, cardid);
+}
+
+bool module_call::call_card::is_timeout()
+{
+    uint32_t seconds = tool_time::elapse_seconds(call_time);
+    return (seconds >= call_time_out*60);
+}
+
+bool module_call::call_user::is_timeout()
+{
+    uint32_t seconds = tool_time::elapse_seconds(call_time);
+    return (seconds >= call_time_out*60);
+}
+
+void module_call::to_node_element(rapidjson::Value& out_elemet,
+                                  const std::shared_ptr<call_card> card_ptr,
+                                  rapidjson::Document::AllocatorType& allocator)
+{
+    tool_json::push_back(out_elemet, card_ptr->user_name, allocator);
+    tool_json::push_back(out_elemet, card_ptr->to_id64_str(), allocator);
+
+    out_elemet.PushBack(card_ptr->stationid, allocator);
+    out_elemet.PushBack(card_ptr->call_time_interval, allocator);
+
+    out_elemet.PushBack(card_ptr->call_type_id, allocator);
+    out_elemet.PushBack(card_ptr->call_state, allocator);
+}
+
 void module_call::run()
 {
     std::vector<call_card_ptr> arr;
@@ -35,6 +77,81 @@ void module_call::run()
     }
 }
 
+///发呼叫的报文数据给分站
+void module_call::send_to_sites(call_site_map& site_map)
+{
+    auto iter_site = site_map.begin();
+
+    for(; iter_site != site_map.end(); ++iter_site)
+    {
+        if(iter_site->second->cards.size() > 254)
+        {
+            log_error("呼叫:分站下卡数量过多:分站id=%d, 卡数=%d",
+                      iter_site->first, iter_site->second->cards.size());
+            continue;
+        }
+
+        std::vector<char> arr;
+
+        //分站地址 4字节,支持大小分站呼叫协议;added by zhuyf 2018/06/04
+        //大小分站的全员呼叫,分站id要求4字节全为FF
+        uint32_t anchor_id = (iter_site->second->is_call_all()? 0xffffffff : static_cast<uint32_t>(iter_site->first));
+        memcpy_uint32(arr,anchor_id);
+
+        //卡数
+        arr.push_back(static_cast<char>(iter_site->second->cards.size()));
+        //呼叫类型
+        arr.push_back(static_cast<char>(iter_site->second->call_type_id));
+
+        if(!iter_site->second->is_call_all())
+        {
+            //循环添加卡信息
+            auto it_card = iter_site->second->cards.begin();
+            for(; it_card != iter_site->second->cards.end(); ++it_card)
+            {
+                //呼叫类型
+                arr.push_back(static_cast<char>(it_card->second->call_level_id));
+                //卡类型
+                arr.push_back(static_cast<char>(it_card->second->cardtype));
+                //卡ID长度
+                int id_len = 4;
+                arr.push_back(static_cast<char>(id_len));
+                //卡ID
+                memcpy_uint32(arr, it_card->second->cardid);
+            }
+        }
+
+        auto sit_ptr = sit_list::instance()->get(iter_site->first);
+        if(!sit_ptr || !sit_ptr->m_clt)
+        {
+            log_error("在全局分站列表中找不到分站 或者sit_ptr->m_clt==null:分站id=%d", iter_site->first);
+            continue;
+        }
+
+        //std::vector<char> arr2 = arr;
+        sit_ptr->m_clt->send(std::move(arr));
+
+        //print_test(std::move(arr2), iter_site->first);
+    }
+}
+
+void module_call::print_test(std::vector<char>&& arr, int siteid)
+{
+    std::string str("呼叫发送的数据帧,分站号=");
+    str.append(std::to_string(siteid));
+    str.append(":");
+
+    char a[4]={0};
+    for(std::vector<char>::size_type i=0; i<arr.size(); i++)
+    {
+        sprintf(a, "%02X ", static_cast<unsigned char>(arr[i]));
+
+        str.append(std::string(a));
+    }
+
+    log_info("%s", str.c_str());
+}
+
 void module_call::rev_from_card_resp(std::shared_ptr<card_location_base> card_ptr)
 {
     card_ptr->get_mine_tool()->m_status_call = CALL_SUCCESSED;

+ 13 - 104
module_service/module_call.h

@@ -15,9 +15,14 @@
 #include <boost/thread.hpp>
 #include <boost/enable_shared_from_this.hpp>
 #include <atomic>
+#include"rapidjson/document.h"
 #include "rapidjson/prettywriter.h"
 #include"module_singleton_base.h"
-#include"module_web.h"
+#include"card.h"
+#include"websocket/sio/sio_client.h"
+#include"module_i_thread.h"
+#include"config_file.h"
+
 
 /**
  * @brief 呼叫类型 全员 定员
@@ -102,21 +107,10 @@ private:
             return CCT_CALL_ALL == call_type_id;
         }
 
-        uint64_t to_id64()
-        {
-            return tool_other::type_id_to_u64(cardtype, cardid);
-        }
-
-        std::string to_id64_str()
-        {
-            return tool_other::type_id_to_str(cardtype, cardid);
-        }
+        uint64_t to_id64();
+        std::string to_id64_str();
 
-        bool is_timeout()
-        {
-            uint32_t seconds = tool_time::elapse_seconds(call_time);
-            return (seconds >= call_time_out*60);
-        }
+        bool is_timeout();
     };
     typedef std::shared_ptr<call_card>  call_card_ptr;
     typedef std::map<int64_t,call_card_ptr>  call_card_map;
@@ -141,11 +135,7 @@ private:
         ///呼叫卡列表
         call_card_map cards;
 
-        bool is_timeout()
-        {
-            uint32_t seconds = tool_time::elapse_seconds(call_time);
-            return (seconds >= call_time_out*60);
-        }
+        bool is_timeout();
 
         bool is_call_all()
         {
@@ -323,18 +313,7 @@ private:
     */
     static void to_node_element(rapidjson::Value& out_elemet,
                                 const std::shared_ptr<call_card> card_ptr,
-                                rapidjson::Document::AllocatorType& allocator)
-    {
-        tool_json::push_back(out_elemet, card_ptr->user_name, allocator);
-        tool_json::push_back(out_elemet, card_ptr->to_id64_str(), allocator);
-
-        out_elemet.PushBack(card_ptr->stationid, allocator);
-        out_elemet.PushBack(card_ptr->call_time_interval, allocator);
-
-        out_elemet.PushBack(card_ptr->call_type_id, allocator);
-        out_elemet.PushBack(card_ptr->call_state, allocator);
-    }
-
+                                rapidjson::Document::AllocatorType& allocator);
     static void to_node_array(rapidjson::Value& out_array,
                               const std::vector<std::shared_ptr<call_card>> cards,
                               rapidjson::Document::AllocatorType& allocator)
@@ -404,79 +383,9 @@ private:
     }
 
     ///发呼叫的报文数据给分站
-    void send_to_sites(call_site_map& site_map)
-    {
-        auto iter_site = site_map.begin();
-
-        for(; iter_site != site_map.end(); ++iter_site)
-        {
-            if(iter_site->second->cards.size() > 254)
-            {
-                log_error("呼叫:分站下卡数量过多:分站id=%d, 卡数=%d",
-                          iter_site->first, iter_site->second->cards.size());
-                continue;
-            }
+    void send_to_sites(call_site_map& site_map);
 
-            std::vector<char> arr;
-
-            //分站地址 4字节,支持大小分站呼叫协议;added by zhuyf 2018/06/04
-            //大小分站的全员呼叫,分站id要求4字节全为FF
-            uint32_t anchor_id = (iter_site->second->is_call_all()? 0xffffffff : static_cast<uint32_t>(iter_site->first));
-            memcpy_uint32(arr,anchor_id);
-
-            //卡数
-            arr.push_back(static_cast<char>(iter_site->second->cards.size()));
-            //呼叫类型
-            arr.push_back(static_cast<char>(iter_site->second->call_type_id));
-
-            if(!iter_site->second->is_call_all())
-            {
-                //循环添加卡信息
-                auto it_card = iter_site->second->cards.begin();
-                for(; it_card != iter_site->second->cards.end(); ++it_card)
-                {
-                    //呼叫类型
-                    arr.push_back(static_cast<char>(it_card->second->call_level_id));
-                    //卡类型
-                    arr.push_back(static_cast<char>(it_card->second->cardtype));
-                    //卡ID长度
-                    int id_len = 4;
-                    arr.push_back(static_cast<char>(id_len));
-                    //卡ID
-                    memcpy_uint32(arr, it_card->second->cardid);
-                }
-            }
-
-            auto sit_ptr = sit_list::instance()->get(iter_site->first);
-            if(!sit_ptr || !sit_ptr->m_clt)
-            {
-                log_error("在全局分站列表中找不到分站 或者sit_ptr->m_clt==null:分站id=%d", iter_site->first);
-                continue;
-            }
-
-            //std::vector<char> arr2 = arr;
-            sit_ptr->m_clt->send(std::move(arr));
-
-            //print_test(std::move(arr2), iter_site->first);
-        }
-    }
-
-    static void print_test(std::vector<char>&& arr, int siteid)
-    {
-        std::string str("呼叫发送的数据帧,分站号=");
-        str.append(std::to_string(siteid));
-        str.append(":");
-
-        char a[4]={0};
-        for(std::vector<char>::size_type i=0; i<arr.size(); i++)
-        {
-            sprintf(a, "%02X ", static_cast<unsigned char>(arr[i]));
-
-            str.append(std::string(a));
-        }
-
-        log_info("%s", str.c_str());
-    }
+    static void print_test(std::vector<char>&& arr, int siteid);
 
     void static memcpy_uint32(std::vector<char>& arr, uint32_t dwSrc)
     {

+ 4 - 14
module_service/module_call_help.cpp

@@ -4,6 +4,8 @@
 #include"common_tool.h"
 #include"websocket/constdef.h"
 #include"log.h"
+#include"db/db_tool.h"
+#include"tool_time.h"
 
 /**
  * @brief //1.如果已经有呼救告警
@@ -14,18 +16,8 @@
  */
 void module_call_help::rev_from_card_help(std::shared_ptr<card_location_base> card_ptr)
 {
-    auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ET_CARD_HELP);
-    if(!ev_ptr)
-    {
-        auto ev_ptr = event_list::create_event_card(card_ptr->m_id, card_ptr->m_type, ET_CARD_HELP);
-
-        event_list::copy_event(card_ptr, ev_ptr);
-
-        //保存到数据库
-        event_list::save_event(ev_ptr);
-
-        event_list::instance()->add(ev_ptr->get_list_id(), ev_ptr);
-    }
+    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+    event_tool::instance()->handle_event(OT_CARD, ET_CARD_HELP, id, 0, 0, true);
 }
 
 /**
@@ -54,8 +46,6 @@ void module_call_help::accept_web_deal_help(sio::message::ptr const& data)
         auto ev_ptr = event_list::instance()->get_event_card(id, type, ET_CARD_HELP);
         if(ev_ptr && ES_DEAL_HELP != ev_ptr->m_status)
         {
-            event_list::copy_event(card_ptr, ev_ptr);
-
             ev_ptr->m_status = ES_DEAL_HELP;
 
             event_list::save_event(ev_ptr);

+ 45 - 44
module_service/module_meta_date_changed.cpp

@@ -1,6 +1,6 @@
 #include "module_meta_date_changed.h"
-#include"module_attendance_person.h"
-#include"module_attendance_vehicle.h"
+#include"area_business_person_attendance.h"
+#include"area_business_car_attendance.h"
 
 #include"common_tool.h"
 #include "websocket/wsClientMgr.h"
@@ -8,6 +8,7 @@
 #include"event.h"
 
 #include"ant.h"
+#include"card.h"
 
 
 ///基础数据
@@ -100,29 +101,36 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
 ///速度,状态 呼救 呼叫 告警相关。即保留基础信息,其他的重置。
 void module_meta_date_changed::clear_card(std::shared_ptr<card_location_base> card_ptr)
 {
-    //删除
-    card_ptr->del_card_pos();
-    // 升井 删除所有报警信息
-    for(int i=0; i < CARD_EVENT_COUNT_MAX; i++ )
-    {
-        if (i == EVENT_TYPE::ET_CARD_LOW_POWER_SERIOUS)
-        {
-            continue;
-        }
+    auto rea_tool = card_ptr->get_area_tool();
+    rea_tool->on_leave(card_ptr);
+    card_ptr->clear();
 
-        auto ev_ptr = event_list::instance()->get_event_card(
-                card_ptr->m_id, card_ptr->m_type, static_cast<EVENT_TYPE>(i));
-        if(ev_ptr && !ev_ptr->is_end()) //
-        {
-            event_list::copy_event(card_ptr, ev_ptr);
+//    //删除
+//    //card_ptr->del_card_pos();
+//    // 升井 删除所有报警信息
+//    for(int i=0; i < CARD_EVENT_COUNT_MAX; i++ )
+//    {
+//        if (i == EVENT_TYPE::ET_CARD_LOW_POWER_SERIOUS)
+//        {
+//            continue;
+//        }
 
-            ev_ptr->m_status = ES_END;
+//        uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+//        event_tool::instance()->handle_event(OT_CARD, static_cast<EVENT_TYPE>(i), id, 0, 0, false);
+
+////        auto ev_ptr = event_list::instance()->get_event_card(
+////                card_ptr->m_id, card_ptr->m_type, static_cast<EVENT_TYPE>(i));
+////        if(ev_ptr && !ev_ptr->is_end()) //
+////        {
+////            event_list::copy_event(card_ptr, ev_ptr);
+
+////            ev_ptr->m_status = ES_END;
+
+////            event_list::save_event(ev_ptr);
+////        }
+//    }
 
-            event_list::save_event(ev_ptr);
-        }
-    }
 
-    card_ptr->clear();
 }
 
 
@@ -307,23 +315,24 @@ void module_meta_date_changed::remove_card(uint32_t id, int32_t type)
         return;
     }
 
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(area_hover_ptr && 0!=area_hover_ptr->id() && 0!=area_hover_ptr->mapid())
-    {
-        module_area::on_leave(card_ptr->m_id, area_hover_ptr, card_ptr->m_type);
-    }
+//    auto area_hover_ptr = card_ptr->get_area_hover();
+//    if(area_hover_ptr && 0!=area_hover_ptr->id() && 0!=area_hover_ptr->mapid())
+//    {
+//        module_area::on_leave(card_ptr->m_id, area_hover_ptr, card_ptr->m_type);
+//    }
 
-    if(card_ptr->is_person())
-    {
-        module_attendance_person::up_mine(card_ptr, nullptr);
-    }
-    else
-    {
-        module_attendance_vehicle::save_attendance(card_ptr, nullptr);
+//    if(card_ptr->is_person())
+//    {
+//        module_attendance_person::up_mine(card_ptr, nullptr);
+//    }
+//    else
+//    {
+//        module_attendance_vehicle::save_attendance(card_ptr, nullptr);
 
-        module_meta_date_changed::clear_card(card_ptr);
-    }
+//        module_meta_date_changed::clear_card(card_ptr);
+//    }
 
+    module_meta_date_changed::clear_card(card_ptr);
     // 避免状态重置
     card_list::instance()->remove(card_id);
     log_info("基础数据, 在全局列表中删除卡成功, id=%d, type=%d", id, type);
@@ -371,15 +380,7 @@ void module_meta_date_changed::delete_area_event(std::shared_ptr<area> area_ptr)
 {
     for(int i=0; i < CARD_EVENT_COUNT_MAX; i++ )
     {
-        auto ev_ptr = event_list::instance()->get_event_area(area_ptr->id(), static_cast<EVENT_TYPE>(i));
-        if(ev_ptr && !ev_ptr->is_end()) //
-        {
-            event_list::copy_event(area_ptr, ev_ptr);
-
-            ev_ptr->m_status = ES_END;
-
-            event_list::save_event(ev_ptr);
-        }
+        event_tool::instance()->handle_event(OT_AREA, static_cast<EVENT_TYPE>(i), area_ptr->id(), 0, 0, false);
     }
 }
 

+ 1 - 1
module_service/module_meta_date_changed.h

@@ -8,7 +8,7 @@
 
 #include"module_singleton_base.h"
 #include"websocket/sio/sio_client.h"
-#include"card.h"
+//#include"card.h"
 #include"area.h"
 
 

+ 11 - 11
module_service/module_mgr.cpp

@@ -4,11 +4,11 @@
 #include"module_web.h"
 #include"module_call_help.h"
 #include"module_call.h"
-#include"module_over_speed_vehicle.h"
+#include"area_business_speed_checker.h"
 #include"module_other_alarm.h"
-#include"module_attendance_vehicle.h"
-#include"module_motionless_persion.h"
-#include"module_geofault.h"
+#include"area_business_car_attendance.h"
+#include"area_business_motionless_persion.h"
+#include"area_business_geofault.h"
 #include"log.h"
 #include"common_tool.h"
 
@@ -20,8 +20,8 @@ void module_mgr::init(config_file& config, std::map<std::string, YA::MSG_HANDLE_
     module_web::instance()->init(config, MsgFuncList);
     module_call::instance()->init(config);
 
-    module_motionless_persion::instance()->init(config);
-    module_geofault::instance()->init(config);
+    area_business_motionless_persion::init(config);
+    area_business_geofault::init(config);
 }
 
 /**
@@ -29,13 +29,13 @@ void module_mgr::init(config_file& config, std::map<std::string, YA::MSG_HANDLE_
      */
 void module_mgr::start()
 {
-    module_geofault::instance()->init_geofault_from_db();
-    module_over_speed_vehicle::instance()->init_vehicle_category_from_db();
-    module_attendance_vehicle::instance()->init_attendance_area_from_db();
+    area_business_geofault::init_geofault_from_db();
+    area_business_speed_checker::init_vehicle_category_from_db();
+    //area_business_car_attendance::init_attendance_area_from_db();
 
     module_web::instance()->start();
     module_call::instance()->start();
-    module_motionless_persion::instance()->start();
+    //module_motionless_persion::instance()->start();
 }
 
 /**
@@ -45,7 +45,7 @@ void module_mgr::stop()
 {
     module_web::instance()->stop();
     module_call::instance()->stop();
-    module_motionless_persion::instance()->stop();
+    //module_motionless_persion::instance()->stop();
 }
 
 void module_mgr::do_status(STATUS_CARD st, uint32_t card_id, int32_t type)

+ 0 - 44
module_service/module_mine.h

@@ -1,44 +0,0 @@
-#ifndef MODULE_MINE_H
-#define MODULE_MINE_H
-/**
- * @brief 简要说明
- * @author 戴月腾
- * @date 2018-09-21
- */
-
-#include "module_const.h"
-#include "module_over_speed_vehicle.h"
-
-class module_mine: public singleton_base<module_mine>
-{
-private:
-    friend class singleton_base<module_mine>;
-    module_mine()
-    {
-    }
-
-public:
-    static void on_point(uint32_t card_id,int32_t type, int vehicle_category_id)
-    {
-        auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
-        if(!card_ptr)
-        {
-            log_error("卡不存在card_id=%d", card_id);
-            return;
-        }
-
-        if(card_ptr->is_person())//人卡
-        {
-            
-        }
-
-        if(card_ptr->is_vehicle())//车卡
-        {
-            //区域车卡超速
-            module_over_speed_vehicle::instance()->on_hover(card_ptr, vehicle_category_id);
-        }
-    }
-};
-
-
-#endif // MODULE_MINE_H

+ 0 - 113
module_service/module_motionless_persion.cpp

@@ -1,113 +0,0 @@
-#include"module_motionless_persion.h"
-
-
-#include"common_tool.h"
-#include"log.h"
-#include"area.h"
-#include"event.h"
-#include"tool_time.h"
-#include"area_business.h"
-
-
-struct motionless_data:business_data
-{
-    motionless_data()
-    {
-        m_acc_0count=0;
-        m_acc_start_time=0;
-    }
-
-    ///;检测到多少次之后定位完全静止
-    std::atomic<int> m_acc_0count;
-    ///检测到多久之后告警
-    time_t m_acc_start_time;
-};
-
-void module_motionless_persion::on_enter(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-
-    area_hover_ptr->m_data[index] = std::make_shared<motionless_data>();
-}
-
-void module_motionless_persion::on_hover(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-    auto ptr = static_cast<motionless_data*>(area_hover_ptr->m_data[index].get());
-    if(0 == static_cast<int>(card_ptr->m_acc))
-    {
-        ptr->m_acc_0count++;
-    }
-    else
-    {
-        ptr->m_acc_0count=0;
-    }
-}
-
-void module_motionless_persion::on_leave(std::shared_ptr<card_location_base> card_ptr, int index)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-
-    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
-    event_tool::instance()->handle_event(OT_CARD, ET_CARD_MOTIONLESS, id, 0, 0, false);
-
-    area_hover_ptr->m_data[index] = std::make_shared<motionless_data>();
-}
-
-void module_motionless_persion::deal_alarm(std::shared_ptr<card_location_base>& card_ptr)
-{
-    auto area_hover_ptr = card_ptr->get_area_hover();
-    if(!area_hover_ptr)
-    {
-        log_error("if(!area_hover_ptr)==true");
-        return;
-    }
-
-    auto arr = area_hover_ptr->m_data;
-    int index = 1;
-
-    if(arr.size()<2 || !arr[index])
-    {
-        return;
-    }
-
-    auto ptr = static_cast<motionless_data*>(area_hover_ptr->m_data[index].get());
-
-    if(ptr->m_acc_0count >= _acc_0count_limit)
-    {
-        ptr->m_acc_0count = _acc_0count_limit;
-        if(0 == ptr->m_acc_start_time)
-        {
-            ptr->m_acc_start_time = tool_time::now_to_seconds();
-        }
-    }
-    else
-    {
-        ptr->m_acc_start_time=0;
-    }
-
-    bool is_alarm = (0 != ptr->m_acc_start_time
-            &&tool_time::elapse_seconds(ptr->m_acc_start_time)> _acc_seconds_limit);
-
-    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
-    event_tool::instance()->handle_event(OT_CARD, ET_CARD_MOTIONLESS, id, 0, 0, is_alarm);
-}
-
-
-
-

+ 0 - 62
module_service/module_motionless_persion.h

@@ -1,62 +0,0 @@
-#ifndef MODULE_MOTIONLESS_PERSION_H
-#define MODULE_MOTIONLESS_PERSION_H
-
-/**
- * @brief 简要说明
- * @author 戴月腾
- * @date 2019-01-12
- */
-
-#include"module_singleton_base.h"
-#include"module_i_thread.h"
-#include"card.h"
-#include"config_file.h"
-
-/**
- * @brief 一、硬件输出的状态
-当完全静止时人卡会连续发送 30 次定位数据,在该定位数据中的加速度状态为 0;发送
-完这一系列的定位数据之后进入休眠状态,不再发送任何定位数据。
- 当人卡从静止切换到运动状态会在毫秒级完成。然后 2 秒后把定位数据发上来,此时加
-速度状态为 1(运动状态)。
-二、处理逻辑
-当连续收到 X(X 可以配置,X 建议不小于 10)次静止状态定位数据之后才认为完全静止。
-经过 Y(Y 可以配置)秒之后开始告警,只要收到运动状态的定位数据就认为非静止立刻取消
-告警
- */
-class module_motionless_persion : public i_thread, public singleton_base<module_motionless_persion>
-{
-private:
-    friend class singleton_base<module_motionless_persion>;
-    module_motionless_persion()
-    {
-    }
-
-    int _acc_0count_limit;
-    int _acc_seconds_limit;
-
-    void run()
-    {
-        auto cardlist = card_list::instance()->m_map;
-        auto iter_m_map=cardlist.begin();
-        for(;iter_m_map!=cardlist.end();++iter_m_map)
-        {
-            deal_alarm(iter_m_map->second);
-        }
-    }
-
-    void deal_alarm(std::shared_ptr<card_location_base>& card_ptr);
-
-public:
-    void init(config_file& config)
-    {
-        sleep_ms = std::stoi(config.get("service.motionless_thread_sleep_ms","5000"));
-        _acc_0count_limit = std::stoi(config.get("service.motionless_acc_0count_limit","20"));
-        _acc_seconds_limit = std::stoi(config.get("service.motionless_acc_seconds_limit","120"));
-    }
-
-    void on_enter(std::shared_ptr<card_location_base> card_ptr, int index);
-    void on_hover(std::shared_ptr<card_location_base> card_ptr, int index);
-    void on_leave(std::shared_ptr<card_location_base> card_ptr, int index);
-};
-
-#endif // MODULE_MOTIONLESS_PERSION_H

+ 0 - 116
module_service/module_over_speed_vehicle.cpp

@@ -1,116 +0,0 @@
-#include "module_over_speed_vehicle.h"
-
-#include "event.h"
-#include"log.h"
-#include"db/db_api/CDBSingletonDefine.h"
-#include"mine.h"
-
-
-void module_over_speed_vehicle::on_hover(std::shared_ptr<card_location_base> card_ptr, int vehicle_category_id)
-{
-    auto mine_tool_ptr = card_ptr->get_mine_tool();
-
-    if(is_over_speed(vehicle_category_id, card_ptr->m_speed))//超速
-    {
-        mine_tool_ptr->m_over_speed_count++;
-    }
-    else//速度正常
-    {
-        mine_tool_ptr->m_normal_speed_count++;
-    }
-
-    //确定超速
-    if(SPEED_COUNT_LIMIT <= mine_tool_ptr->m_over_speed_count)
-    {
-        mine_tool_ptr->m_over_speed_count=SPEED_COUNT_LIMIT;
-
-        auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ET_CARD_OVER_SPEED);
-        if(ev_ptr)
-        {
-            event_list::copy_event(card_ptr, ev_ptr);
-
-            ev_ptr->m_limit_value=limit_speed(vehicle_category_id);
-            ev_ptr->m_cur_value=card_ptr->m_speed;
-        }
-        else//从没有告警状态转化为告警状态
-        {
-            mine_tool_ptr->m_normal_speed_count=0;
-
-            auto ev_ptr = event_list::create_event_card(card_ptr->m_id, card_ptr->m_type, ET_CARD_OVER_SPEED);
-
-            event_list::copy_event(card_ptr, ev_ptr);
-
-            ev_ptr->m_limit_value = limit_speed(vehicle_category_id);
-            ev_ptr->m_cur_value = card_ptr->m_speed;
-
-            //保存到数据库
-            event_list::save_event(ev_ptr);
-
-            event_list::instance()->add(ev_ptr->get_list_id(),ev_ptr);
-
-            log_info("车卡矿井内超速开始:卡id=%d,卡type=%d,卡速=%f,卡category_id=%d,卡速门限=%f",
-                     card_ptr->m_id, card_ptr->m_type,card_ptr->m_speed,vehicle_category_id,
-                     limit_speed(vehicle_category_id));
-        }
-    }
-
-    //确定速度正常
-    if(SPEED_COUNT_LIMIT <= mine_tool_ptr->m_normal_speed_count)
-    {
-        mine_tool_ptr->m_normal_speed_count=SPEED_COUNT_LIMIT;
-
-        auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ET_CARD_OVER_SPEED);
-        if(ev_ptr && !ev_ptr->is_end())
-        {
-            mine_tool_ptr->m_over_speed_count=0;
-
-            event_list::copy_event(card_ptr, ev_ptr);
-
-            ev_ptr->m_limit_value = limit_speed(vehicle_category_id);
-            ev_ptr->m_cur_value = card_ptr->m_speed;
-
-            ev_ptr->m_status = ES_END;
-
-            //保存到数据库
-            event_list::save_event(ev_ptr);
-
-            log_info("车卡矿井内超速结束:卡id=%d,卡type=%d,卡速=%f,卡category_id=%d,卡速门限=%f",
-                     card_ptr->m_id, card_ptr->m_type,card_ptr->m_speed,vehicle_category_id,
-                     limit_speed(vehicle_category_id));
-        }
-    }
-}
-
-void module_over_speed_vehicle::init_vehicle_category_from_db()
-{
-    const char *sql = "SELECT vehicle_category_id, over_speed FROM dat_vehicle_category;";
-    std::string Error;
-    YADB::CDBResultSet DBRes;
-    sDBConnPool.Query(sql,DBRes,Error);
-    if(!Error.empty())
-        log_error("init_vehicle_category Error,%s",Error.c_str());
-    int64_t nCount = DBRes.GetRecordCount( Error );
-    if (nCount < 1)
-    {
-        log_error("错误,init_vehicle_category. The record count=%ld\n", nCount );
-        return;
-    }
-
-    log_info( "init_vehicle_category. The record count=%ld\n", nCount );
-
-    _vehicle_category_map.clear();
-    while ( DBRes.GetNextRecod(Error) )
-    {
-        int vehicle_category_id  = 0;
-        DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
-
-        double over_speed = 0;
-        DBRes.GetField( "over_speed",over_speed, Error );
-
-        _vehicle_category_map.insert({vehicle_category_id,over_speed});
-    }
-
-    for(const auto &p : _vehicle_category_map)
-        std_debug("dat_vehicle_category:category_id:%d--over_speed:%.2f",p.first,p.second);
-}
-

+ 0 - 56
module_service/module_over_speed_vehicle.h

@@ -1,56 +0,0 @@
-#ifndef MODULE_OVER_SPEED_VEHICLE_H
-#define MODULE_OVER_SPEED_VEHICLE_H
-/**
-  *@brief 车卡超速模块
-  * @author 戴月腾
-  * @date 2018-08-08
-*/
-
-#include <unordered_map>
-#include "module_singleton_base.h"
-#include "card.h"
-
-/**
- * @brief 区域超速类。当某张车卡速度超过某个区域的最大速度时,发出告警, 单例
- */
-class module_over_speed_vehicle:public singleton_base<module_over_speed_vehicle>
-{
-private:
-    friend class singleton_base<module_over_speed_vehicle>;
-    module_over_speed_vehicle()
-    {
-    }
-
-public:
-    void on_hover(std::shared_ptr<card_location_base> card_ptr, int vehicle_category_id);
-
-    void init_vehicle_category_from_db();
-
-private:
-    bool is_over_speed(int category_id, double speed)
-    {
-        auto serch = _vehicle_category_map.find(category_id);
-        if(serch == _vehicle_category_map.end())
-        {
-            return false;
-        }
-
-        return serch->second <= speed;
-    }
-
-    double limit_speed(int category_id) const
-    {
-        auto serch = _vehicle_category_map.find(category_id);
-        if(serch == _vehicle_category_map.end())
-        {
-            return 0;
-        }
-
-        return serch->second;
-    }
-
-private:
-    std::unordered_map<int,double> _vehicle_category_map;
-};
-
-#endif // MODULE_OVER_SPEED_VEHICLE_H

+ 0 - 67
module_service/module_site.cpp

@@ -1,67 +0,0 @@
-#include "module_site.h"
-
-#include<card.h>
-#include"module_attendance_person.h"
-#include"common_tool.h"
-#include"ant.h"
-#include"log.h"
-
-
-void module_site::enter_site(uint32_t card_id,int enter_site,int32_t type)
-{
-    auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
-    if(!card_ptr)
-    {
-        log_error("卡不存在card_id=%ld, type=%ld", card_id, type);
-        return;
-    }
-
-    auto site_ptr=sit_list::instance()->get(enter_site);
-    if(!site_ptr)
-    {
-        log_error("[enter site]%d,%d在分站列表中找不到分站,分站id=%d",card_id, type,enter_site);
-        return;
-    }
-
-    if(card_ptr->is_person())
-    {
-        module_attendance_person::instance()->enter_site(card_ptr, site_ptr);
-    }
-
-    if(card_ptr->is_vehicle())
-    {
-
-    }
-}
-
-/**
- * @brief 离开现有分站处理,记录现有分站的进出时间和地点
- * @param card_id
- * @param enter_site
- */
-void module_site::leave_site(uint32_t card_id,int enter_site, int32_t type)
-{
-    auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
-    if(!card_ptr)
-    {
-        log_error("卡不存在card_id=%ld, type=%ld", card_id, type);
-        return;
-    }
-
-    auto site_ptr=sit_list::instance()->get(enter_site);
-    if(!site_ptr)
-    {
-        log_error("[leave site]%d,%d在分站列表中找不到分站,分站id=%d",card_id,type, enter_site);
-        return;
-    }
-
-    if(card_ptr->is_person())
-    {
-
-    }
-
-    if(card_ptr->is_vehicle())
-    {
-
-    }
-}

+ 0 - 30
module_service/module_site.h

@@ -1,30 +0,0 @@
-#ifndef MODULE_SITE_H
-#define MODULE_SITE_H
-
-#include"module_singleton_base.h"
-
-class module_site : public singleton_base<module_site>
-{
-private:
-    friend class singleton_base<module_site>;
-    module_site()
-    {
-    }
-
-public:
-    /**
-     * @brief 进入分站覆盖区域处理,考勤
-     * @param card_id
-     * @param enter_site
-     */
-    static void enter_site(uint32_t card_id,int enter_site,int32_t type);
-
-    /**
-     * @brief 离开现有分站处理,记录现有分站的进出时间和地点
-     * @param card_id
-     * @param enter_site
-     */
-    static void leave_site(uint32_t card_id,int enter_site, int32_t type);
-};
-
-#endif // MODULE_SITE_H

+ 3 - 2
module_service/module_web.cpp

@@ -2,8 +2,9 @@
 
 #include"module_call_help.h"
 #include"module_call.h"
-#include"module_attendance_person.h"
+#include"area_business_person_attendance.h"
 #include"module_meta_date_changed.h"
+#include"common_tool.h"
 
 #include"log.h"
 
@@ -27,7 +28,7 @@ void module_web::accept( int ID, std::string const& name,
 
     if(JSON_CMD_VALUE_CLEAR_CARD == cmd)//手动升井
     {
-        module_attendance_person::instance()->handle_up_mine(data);
+        area_business_person_attendance::handle_up_mine(data);
     }
     else if (JSON_CMD_VALUE_REQUEST_ALL_DATA == cmd)//web登录请求所有信息
     {

+ 13 - 34
net-service.cpp

@@ -35,9 +35,10 @@ void net_service::on_timer()
 	sit_list::instance()->accept(vss);
 	mine_business::inst()->run_business();
 }
+
 void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t len)
 {
-	logn_bin(1,"",data,len);//输出二进制日志
+	logn_bin(1,clt->name().c_str(),data,len);//输出二进制日志
 
 	zistream is(data,len-2);
 	uint16_t cmd;
@@ -47,26 +48,16 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 		case CHAR_LOCATEDATA_TOF_EXTEND://tof-扩展
 			{
 				uint32_t site_id;
-				is>>site_id>>skip(12);
-				//message_siteinfo msgSiteInfo;
-				//msgSiteInfo.load(is,false);
-				//site_id = msgSiteInfo.m_site_id;
-				auto site_ptr = sit_list::instance()->get(static_cast<int32_t>(site_id));
-				if(!site_ptr)
-				{
-					log_error("在全局分站列表中找不到分站:分站id=%d", site_id);
-					break;
-				}
-				//分站数据到队列
-				//task* t_site=task::alloc<message_siteinfo>();
-				//message_siteinfo &msg = t_site->body<message_siteinfo>();
-				//msg = msgSiteInfo;
-				//t_site->m_cmd_code=cmd;
-				//t_site->m_hash_id=site_id;
-				//t_site->m_site_data = 1;
-				//m_loc_worker->request(t_site);
-				//设置连接到分站数据中
+				uint8_t  power;
+				is>>site_id>>skip(11)>>power;
+                auto site_ptr = sit_list::instance()->get(static_cast<int32_t>(site_id));
+                if(!site_ptr)
+                {
+                    log_error("在全局分站列表中找不到分站:分站id=%d", site_id);
+                    break;
+                }
                 site_ptr->set_client(clt);
+                site_ptr->on_power_status((power&1)==0);
 
 				struct timeval tv;
 				gettimeofday(&tv,NULL);
@@ -78,7 +69,7 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 					index++;
 					task*t=task::alloc<message_locinfo>();
 					message_locinfo&m=t->body<message_locinfo>();
-					m.load(is,cmd==0x863b);
+					m.load(is,false);
 					m.m_time_stamp=tstamp;
 					m.m_site_id=site_id;
 					//t_site->m_site_data = 0;
@@ -95,24 +86,12 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 			{
 				uint32_t site_id;
 				is>>site_id>>skip(12);
-				//分站数据
-				//message_siteinfo msgSiteInfo;
-				//msgSiteInfo.load(is,false);
-				//message_siteinfo &msg = t_site->body<message_siteinfo>();
-				//msg = msgSiteInfo;
-				//site_id = msgSiteInfo.m_site_id;
-				//task*t_site=task::alloc<message_locinfo>();
-				//t_site->m_cmd_code=cmd;
-				//t_site->m_hash_id=site_id;
-				//t_site->m_site_data = 1;
-				//m_loc_worker->request(t_site);
 				while(!is.eof())
 				{
 					task*t=task::alloc<message_locinfo>();
 					message_locinfo&m=t->body<message_locinfo>();
-					m.load(is,cmd==0x863b);
+					m.load(is,true);
 					m.m_site_id=site_id;
-					//t->m_site_data = 0;
 					t->m_cmd_code=cmd;
 					t->m_hash_id=m.m_card_id;
 					m_sync_worker->translate(m);

+ 1 - 0
net-service.h

@@ -20,3 +20,4 @@ struct net_service:service_callback
 
 #endif
 
+

+ 2 - 3
site_area.cpp

@@ -2,7 +2,6 @@
 #include "site_area.h"
 #include "card.h"
 #include "ant.h"
-#include "module_service/module_site.h"
 
 //每张卡包含这样一个对象,保存最后一个分站区域
 //1、记录卡进出分站的时间,地点
@@ -46,12 +45,12 @@ void site_area_hover::on_point(uint32_t card_id,int site_id,const point*pt,int32
 
 void site_area_hover::enter_site(uint32_t card_id,int enter_site,int32_t type)
 {
-    module_site::enter_site(card_id, enter_site, type);
+
 }
 
 void site_area_hover::leave_site(uint32_t card_id,int enter_site,int32_t type)
 {
-    module_site::leave_site(card_id, enter_site, type);
+
 }
 int site_area_hover::get_att_type() const 
 {