Jelajahi Sumber

解决卡加载历史时,时间加载不正确的问题 && 增加日志,打印人卡超时的信息 && 告警初始化卡的告警标志位置位

lixioayao 6 tahun lalu
induk
melakukan
66ea644281
14 mengubah file dengan 85 tambahan dan 34 penghapusan
  1. 3 2
      area.cpp
  2. 7 1
      area.h
  3. 0 1
      card_car.cpp
  4. 5 0
      card_message_handle.cpp
  5. 34 3
      card_person.cpp
  6. 5 3
      card_person.h
  7. 9 0
      event.cpp
  8. 0 12
      mine.cpp
  9. 0 4
      mine.h
  10. 10 2
      module_service/module_mgr.cpp
  11. 1 1
      net-service.cpp
  12. 1 1
      net-service.h
  13. 6 0
      tool_time.h
  14. 4 4
      znet.cpp

+ 3 - 2
area.cpp

@@ -658,8 +658,9 @@ void area_tool::on_point(const std::shared_ptr<card_location_base>& c,const poin
              }
          }
          char sql[1024] = {0};
-         snprintf(sql, 1024, "REPLACE INTO rt_location (card_id, site_id, x, y, z, state, area_info) VALUES (%s, %d, %lf, %lf, %lf, 0, '%s');",
-             tool_other::type_id_to_str(c->m_type, c->m_id).c_str(), m_site->id(), pt.x, pt.y, pt.z, strAreaInfo.c_str());
+         std::string _time=tool_time::to_str_ex(c->time_());
+         snprintf(sql, 1024, "REPLACE INTO rt_location (card_id, site_id,cur_time, x, y, z, state, area_info) VALUES (%s, %d,'%s',%lf, %lf, %lf, 0, '%s');",
+             tool_other::type_id_to_str(c->m_type, c->m_id).c_str(), m_site->id(),_time.c_str(), pt.x, pt.y, pt.z, strAreaInfo.c_str());
          db_tool::PushAsync(sql);
     }
 }

+ 7 - 1
area.h

@@ -228,7 +228,13 @@ public:
     {
         m_area_info.clear();
     }
-
+    const int get_site_id() const
+    {
+        int sid=-1;
+        if(m_site)
+            sid=m_site->m_id;
+        return sid;
+    }
     void set_site(const std::shared_ptr<site>& s)
     {
 		if(s == nullptr || m_site == s)

+ 0 - 1
card_car.cpp

@@ -37,7 +37,6 @@ void car::do_business(const std::shared_ptr<site>&site,const point &pt,double ac
 	m_acc=acc;
 	m_area_tool->on_point(shared_from_this(),pt);
 	m_timeval=m_time;
-	m_mine_tool->on_point(m_id, m_type, m_vehicle_category_id);
 	handle_three_rates(pt);
 	uint64_t id=tool_other::type_id_to_u64(m_type,m_id);
 	mine_business::inst()->make_arg(id,pt,m_time);

+ 5 - 0
card_message_handle.cpp

@@ -119,6 +119,11 @@ struct one_ct_message_handle
 
 		std::vector<point> rc=std::move(m_loc_tool.calc_location(v));
 		log_info("calc_location:%d size:%d",m_card->m_id,rc.size());
+#if 1
+        if(v[0].m_sit->m_id==367)
+            for(const auto &_p:rc)
+		        log_info("calc_location:%d (%.2f,%.2f)",m_card->m_id,_p.x,_p.y);
+#endif
 
 		if(!rc.empty()) m_card->on_location(std::move(rc),v);
 

+ 34 - 3
card_person.cpp

@@ -1,4 +1,3 @@
-
 #include <string>
 #include <thread>
 #include "card_person.h"
@@ -16,13 +15,16 @@
 #include"common_tool.h"
 #include"db/db_tool.h"
 #include "forbid_staff_down_mine.h"
+#include <config_file.h>
 
+extern config_file config;
+int person::m_limit_detained_time=config.get("service.detained_time",10);
 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,int worketype_id)
 	:card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
 	,m_workLine(wl)
+	,m_worktype_id(worketype_id)
 	,m_stafferName(sname)
 	,m_deptName(dname)
-	,m_worktype_id(worketype_id)
 {
 	m_message_handle.reset(new card_message_handle(this));
 	m_his_location_card.reset(new location_staff(m_id,m_type,cid));
@@ -128,7 +130,7 @@ void person::on_timer()
 	cp.work_time = m_mine_tool->get_work_time();
 	cp.is_on_duty= m_mine_tool->is_on_duty();
 	upt_card_pos(cp,pt);
-	log_info("on_timer here ...%d,%lld,%.2f,%.2f,%d,%d--",m_id,_time,pt.x,pt.y,cp.map_id,cp.area_info.size());
+	log_info("on_timer here ...%d,%lld,%.2f,%.2f,%d,%d--%d",m_id,_time,pt.x,pt.y,cp.map_id,cp.area_info.size(),person::m_limit_detained_time);
     int sid=0;
     if(auto st=m_area_tool->m_site)sid=st->m_area_id;
 	m_his_location_card->push(_time,pt,sid,cp.map_id);
@@ -146,8 +148,37 @@ void person::on_timer()
 		m_upmine_flag=0;
 		m_area_tool->on_leave(shared_from_this());
 	}
+    print_card_detained();
 }
+//***********************************************
+//整点打印入井超过设定时长(默认10h)
+//进入盲区超过2h的卡
+void person::print_card_detained()
+{
+    static point p(4677,-193.7);
+    static double limit_dist=45.0;
+    int h=tool_time::get_hour();
+    uint64_t _now=tool_time::now_to_ms();
+    uint64_t work_time=m_mine_tool->get_work_time();
+    uint64_t lost_time=_now>m_time?_now-m_time:m_time-_now;
+    if(m_thour != h && (work_time > static_cast<uint64_t>(person::m_limit_detained_time*60*60*1000)) && lost_time>2*60*60*1000)
+    {
+        m_thour=h;
+        auto start = m_mine_tool->m_attendance_start_time;
+        std::string enter_time=tool_time::to_str(start);
+        uint32_t min=work_time/1000/60;
+        uint32_t lmin=lost_time/1000/60;
+        double dist=p.dist(*this);
+        std::string last_time=tool_time::to_str_ex(m_time);
+        std::string alarm_time{"No Alarm."};
+        auto event_power=event_list::instance()->get_event_card(m_id,m_type,ET_CARD_LOW_POWER_SERIOUS);
+        if(event_power)
+            alarm_time=tool_time::to_str(event_power->m_cur_time);
 
+        log_warn("[card_detained]卡号:%03d%010d,分站:%d,入井时间点:%s,入井时长:%d小时%d分钟,(%.2f,%.2f)是否在处在井底范围内:%s,最后接收时间点:%s,进入盲区时长:%d小时%d分钟,是否低电量告警:%s,低电量开始时间点:%s",
+                    m_type,m_id,m_area_tool->get_site_id(),enter_time.c_str(),min/60,min%60,x,y,dist<limit_dist?"True":"False",last_time.c_str(),lmin/60,lmin%60,event_power?"Ture":"False",alarm_time.c_str());
+    }
+}
 point person::getSmoothPoint(uint64_t& t)
 {
 	point pt;

+ 5 - 3
card_person.h

@@ -6,11 +6,13 @@
 
 struct person:card_location_base, card_area
 {
-    std::weak_ptr<monkey_person> m_monkeyPerson;
     int m_workLine=0;	
+	int m_worktype_id=0;
+    int m_thour{-1};
     time_t m_iris_recognition_timeval = 0;
+    static int m_limit_detained_time;
+    std::weak_ptr<monkey_person> m_monkeyPerson;
     std::string m_stafferName,m_deptName;
-	int m_worktype_id=0;
     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,int workrype_id);
     ~person();
 
@@ -21,6 +23,7 @@ struct person:card_location_base, card_area
     void on_timer();
     void IKSDK_DB(int);
     point getSmoothPoint(uint64_t& t);
+    void print_card_detained();
 
     virtual void site_hover(int sid);
 	virtual void get_card(bool f);
@@ -36,7 +39,6 @@ struct person:card_location_base, card_area
         return m_workLine;
     }
 };
-
 #endif
 
 

+ 9 - 0
event.cpp

@@ -334,6 +334,15 @@ void event_list::load_his_data_from_db()
             ev->x = x;
             ev->y = y;
             ev->m_id = id;
+            //这里当是卡告警的时候,对m_event数据进行赋值
+            //方便清理
+            //备注防追尾告警和一人多卡告警可能不适用,后续整理
+            if(ev->m_obj_type==OT_CARD)
+            {
+                uint64_t c_id= tool_other::card_id_to_u64(ev->m_obj_id);
+                if(auto c=card_list::instance()->get(c_id))
+                    c->set_event_flag(ev->m_ev_type);
+            }  
             
             map.insert(std::make_pair(id, ev));
             log_info("event_list %lld,%lld,%d,%d,%d,%s,%d,%d,%d,%.2f,%.2f,%.2f,%.2f,%s"

+ 0 - 12
mine.cpp

@@ -2,18 +2,6 @@
 #include "common_tool.h"
 #include"tool_time.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);
-}
-
-//检查井下超时
-void mine_tool::on_check_overtime(uint32_t card_id, int32_t type)
-{
-    //CMineCardManager::instance()->OnPersonInMineOverTime(card_id,type);
-
-}
-
 uint64_t mine_tool::get_down_time()
 {
 	return tool_time::to_ms(m_attendance_start_time);

+ 0 - 4
mine.h

@@ -47,10 +47,6 @@ struct mine_tool
     //井下超时时间
     std::chrono::system_clock::time_point m_overtime;
 
-    void on_point(uint32_t card_id, int32_t type, int vehicle_category_id);
-
-    //检查井下超时
-    void on_check_overtime(uint32_t card_id, int32_t type);
 	uint64_t get_down_time();
 	uint64_t get_work_time();
 	int32_t is_on_duty();

+ 10 - 2
module_service/module_mgr.cpp

@@ -67,11 +67,19 @@ void module_mgr::do_status(STATUS_CARD st, uint32_t card_id, int32_t type)
     }
     if(STATUS_POWER_LOWER_SERIOUS == st)
     {
-        module_other_alarm::power_lower_serious(card_ptr);
+        if(!card_ptr->get_event_flag(ET_CARD_LOW_POWER_SERIOUS))
+        {
+            card_ptr->set_event_flag(ET_CARD_LOW_POWER_SERIOUS);
+            module_other_alarm::power_lower_serious(card_ptr);
+        }
     }
     if(STATUS_POWER_NOMARL == st)
     {
-        module_other_alarm::power_nomarl(card_ptr);
+        if(card_ptr->get_event_flag(ET_CARD_LOW_POWER_SERIOUS))
+        {
+            card_ptr->set_event_flag(ET_CARD_LOW_POWER_SERIOUS,0);
+            module_other_alarm::power_nomarl(card_ptr);
+        }
     }
 }
 

+ 1 - 1
net-service.cpp

@@ -88,7 +88,7 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 
 					site_ptr->set_client(clt);
 					site_ptr->on_power_status((power&1)==0);
-                    clt->set_site_id(site_id);
+                    //clt->set_site_id(site_id);
 
 					struct timeval tv;
 					gettimeofday(&tv,NULL);

+ 1 - 1
net-service.h

@@ -16,7 +16,7 @@ struct net_service:service_callback
 	~net_service();
 	void on_message(std::shared_ptr<client> clt,const char*data,size_t len);
 	void on_timer();
-    void on_connect(std::shared_ptr<clinet> clt);
+    void on_connect(std::shared_ptr<client> clt);
 };
 
 #endif

+ 6 - 0
tool_time.h

@@ -125,6 +125,12 @@ public:
 
         return std::string(_time);
     }
+    static int get_hour()
+    {
+        time_t tt = time(0);
+        struct tm *local_time=localtime(&tt);
+        return local_time->tm_hour;
+    }
 };
 
 #endif

+ 4 - 4
znet.cpp

@@ -335,10 +335,10 @@ struct sock_client:fd_io,client_ex
 	{
 		return m_fd;
 	}
-    void set_site_id(int sid)
-    {
-        m_site_id=id;
-    }
+    //void set_site_id(int sid)
+    //{
+     //   m_site_id=id;
+    //}
 	void grow_buf(int len)
 	{
 		if(m_size-m_clen>=len)