Browse Source

解决获取当天凌晨时间错误导致车辆出勤车辆数量显示错误得bug。同时修复当天出勤车辆,采集重启导致,没有计入出勤数量得bug

lixioayao 6 years ago
parent
commit
6b2a2bee46
4 changed files with 24 additions and 12 deletions
  1. 3 3
      card.cpp
  2. 5 1
      card_car.cpp
  3. 7 3
      mine.cpp
  4. 9 5
      tool_time.h

+ 3 - 3
card.cpp

@@ -183,11 +183,11 @@ void card_list::load_his_card_postion_vehicle()
             
             card_ptr->m_time = tool_time::to_time(cur_time)*1000;
             card_ptr->set(x,y,z);
-
+            //考勤结束也要初始化该变量,用于统计今天出勤过得车卡数量
+            auto mine_tool_ptr = card_ptr->get_mine_tool();
+            mine_tool_ptr->m_attendance_start_time = tool_time::to_time_ex(start_time);
             if(end_time.empty())
             {
-                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_is_attendance = true;
                 log_info("vehicle加载考勤,考勤开始时间: %s, 卡id=%s", start_time.c_str(), card_id.c_str());
             }

+ 5 - 1
card_car.cpp

@@ -89,7 +89,11 @@ void car::make_package()
 	cp.biz_stat=biz_stat;
 	cp.down_time = m_mine_tool->get_down_time();
 	cp.work_time = m_mine_tool->get_work_time();
-	cp.is_on_duty=m_mine_tool->is_on_duty();
+    uint32_t on_duty=0;
+   // if(m_mine_tool->m_is_attendance)
+    on_duty=m_mine_tool->is_on_duty();
+	cp.is_on_duty=on_duty;
+    //log_info("%s,down_time:%f,today:%lu,duty:%u",tool_other::type_id_to_str(m_type,m_id).c_str(),cp.down_time,tool_time::morning_of_today_ms(),on_duty);
 	upt_card_pos(cp,pt);
     int sid=0;
     if(auto st=m_area_tool->m_site)sid=st->m_area_id;

+ 7 - 3
mine.cpp

@@ -1,17 +1,21 @@
 #include "mine.h"
 #include "common_tool.h"
 #include"tool_time.h"
-
+#include "log.h"
 uint64_t mine_tool::get_down_time()
 {
 	return tool_time::to_ms(m_attendance_start_time);
 }
 uint64_t mine_tool::get_work_time()
 {
-	return tool_time::elapse_ms(m_attendance_start_time)	;
+	return tool_time::elapse_ms(m_attendance_start_time);
 }
 int32_t mine_tool::is_on_duty()
 {
-	return get_down_time()>tool_time::morning_of_today_ms();
+    uint64_t dt=get_down_time();
+    uint64_t mt=tool_time::morning_of_today_ms();
+//    log_info("down_time_now :%s,%lu - %lu = %d",cid.c_str(),dt,mt,dt>mt?1:0);
+//	return get_down_time()>tool_time::morning_of_today_ms()?1:0;
+    return dt>mt?1:0;
 }
 

+ 9 - 5
tool_time.h

@@ -54,11 +54,15 @@ public:
     }
 	static uint64_t morning_of_today_ms()
 	{
-		std::time_t now = time(0);
-		struct tm * loc_t = localtime(&now);
-		loc_t->tm_hour=0;loc_t->tm_min=0;loc_t->tm_sec=0;
-		now = mktime(loc_t);
-		return now*1000;
+        time_t now = time(0);
+
+        return ((now+8*3600)/86400*86400-8*3600)*1000;
+
+		//time_t now = time(0);
+		//struct tm * loc_t = localtime(&now);
+		//loc_t->tm_hour=0;loc_t->tm_min=0;loc_t->tm_sec=0;
+		//time_t x = mktime(loc_t);
+		//return x*1000;
 	}
     //"%Y-%m-%d %H:%M:%S"
     static time_t to_time(const std::string&str)