Browse Source

his_location中last_time 升井没有赋值更新

chensongchao 5 years ago
parent
commit
fada8bb7d8
6 changed files with 13 additions and 53 deletions
  1. 2 2
      card_base.cpp
  2. 1 1
      card_base.h
  3. 3 0
      card_person.cpp
  4. 6 45
      his_location.cpp
  5. 1 3
      his_location.h
  6. 0 2
      module_service/area_business_person_attendance.cpp

+ 2 - 2
card_base.cpp

@@ -77,11 +77,11 @@ void card_location_base::do_status(int st)
 
     module_mgr::do_status((STATUS_CARD)st, m_id, m_type);
 }
-void card_location_base::make_his_location(uint64_t t,const point & pt)
+void card_location_base::make_his_location(uint64_t t,const point & pt,bool bclose /*= false*/)
 {
      int sid=0,mapid=0;
 	if(auto site_ptr=get_area_tool()->m_site){sid=site_ptr->m_area_id;mapid=site_ptr->m_map_id;}
-    m_his_location_card->push(t,pt,sid,mapid);
+    m_his_location_card->push(t,pt,sid,mapid,bclose);
 }
 
 void card_location_base::on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm )

+ 1 - 1
card_base.h

@@ -102,7 +102,7 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
 	virtual void get_card(bool f)=0;
 	virtual void site_hover(int sid){}
 
-    void make_his_location(uint64_t t,const point & pt);
+    void make_his_location(uint64_t t,const point & pt,bool bclose = false);
     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 );
     void do_status(int st);

+ 3 - 0
card_person.cpp

@@ -46,6 +46,8 @@ void person::clear()
 {
 	//m_area_tool.reset(new area_tool);
 	//m_mine_tool.reset(new mine_tool);
+    make_his_location(m_time,point(x,y,0),true);
+
     m_mine_tool->clear();
     m_area_tool->clear();
     //清除部分信息
@@ -67,6 +69,7 @@ void person::clear()
     	m.cmd=CMD_CLEAR;m.cardid=m_type<<32|m_id;
     	cardMgr::instance()->tryPut(m);
     }
+
 }
 
 void person::set_area_info(int mapid,double scale,int areaid,uint64_t t,int type)

+ 6 - 45
his_location.cpp

@@ -144,7 +144,7 @@ bool location_card::is_map_changed(int new_mapid)
     }
     return flag;
 }
-void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid)
+void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid,bool bclose/* = false*/)
 {
     log_info("his_location:card[%d] area[%d] Point(%.2f,%.2f)--->(%.2f,%.2f)",m_cardid,areaid,m_p.x,m_p.y,p.x,p.y);
 
@@ -155,6 +155,11 @@ void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32
         m_d.emplace(p,timestamp);
         return ;
     }
+    if (bclose) //卡移除后直接更新his_location
+    {
+        update(p,timestamp,true);
+        return;
+    }
 
     if(!is_valid())
     {
@@ -239,50 +244,6 @@ void location_card::update(const point &p,uint64_t timestamp,int flag/*=0*/,int
     sDBConnPool.PushAsync(nsql);
 }
 
-//查询之前未处理数据last_time is null
-bool location_card::up_mine (const point & p1,int areaid,uint64_t timestamp)
-{
-    if (timestamp < m_timestamp || m_timestamp == 0)
-    {
-        return false;
-    }
-    char nsql[512] = {0};
-    double t = (m_timestamp  - m_timestamp) / 1000;
-    if (t < 0.001) t = 1.0;
-    double speed = 0.0;
-    int dist = p1.dist(m_p);
-    if(dist > 10)    //当前点距离原来的点有点远
-    {
-        speed = dist / t;
-        if (std::isnan(speed) || std::isinf(speed)) {
-            speed = 0.0;
-        }
-
-        const char *sql = "update his_location set last_time='%s',speed=%.3f,direction=%f,location_flag=%d where obj_id=%d and begin_time='%s' and last_time is null;";
-        snprintf(nsql, 512, sql, tool_time::to_str(timestamp / 1000).c_str(), speed, m_arg, 1, m_objid,tool_time::to_str(m_timestamp/1000).c_str());
-        log_info("up_mine: his_location[%d]:%s[%lu,%lu]",m_cardid,nsql,timestamp,m_timestamp);
-        sDBConnPool.PushAsync(nsql);
-
-        memset(nsql,0, sizeof(nsql));
-        const char * insert_sql = "replace into his_location (obj_id,card_type_id,ident,begin_time,last_time,map_id,area_id,begin_pt,direction)"
-                           "values(%d,%d,%d,'%s',%d,%d,'%.2f,%.2f',%f);";
-        snprintf(nsql,512,insert_sql,m_objid,m_type,m_cardid,tool_time::to_str(timestamp/1000).c_str(),tool_time::to_str(timestamp/1000 + 1).c_str(),m_mapid
-                ,m_areaid,p1.x,p1.y,m_arg);
-        log_info("up_mine: his_location[%d,%lu]:%s",m_cardid,m_timestamp,nsql);
-        sDBConnPool.PushAsync(nsql);
-    }
-    else
-    {
-        const char *sql = "update his_location set last_time='%s',speed=%.3f,direction=%f,location_flag=%d where obj_id=%d and begin_time='%s' and last_time is null;";
-        snprintf(nsql, 512, sql, tool_time::to_str(timestamp / 1000).c_str(), 0.0, m_arg, 1, m_objid,tool_time::to_str(m_timestamp/1000).c_str());
-
-        log_info("up_mine: his_location[%d]:%s[%lu,%lu]",m_cardid,nsql,timestamp,m_timestamp);
-        sDBConnPool.PushAsync(nsql);
-    }
-
-    return true;
-}
-
 std::vector<point> location_card::find_path(const point &p1,const point &p2)
 {
     std::vector<point> rc=card_path::inst().find_path(point(p1.x,-p1.y),point(p2.x,-p2.y));

+ 1 - 3
his_location.h

@@ -54,7 +54,7 @@ struct location_card
     // 地图变化
 	bool is_map_changed(int new_mapid);
     // 计算当前点是否需要记录到DB中
-	void push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid);
+	void push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid,bool bclose = false);
 
 	void insert();
 
@@ -66,7 +66,5 @@ struct location_card
 	bool  handle_message(const point &p,uint64_t timestamp);
     // 处理获取到点的集合,在路径上
     bool handle_path(std::vector<point> &rc,uint64_t timestamp,bool flag);
-    //查询之前未处理数据last_time is null
-    bool up_mine(const point & p1,int areaid,uint64_t timestamp);
 };
 #endif

+ 0 - 2
module_service/area_business_person_attendance.cpp

@@ -60,8 +60,6 @@ void area_business_person_attendance::on_leave(const std::shared_ptr<area_hover>
     }
     //作为一条结束考勤记录保存到数据库
     db_tool::save_attendance(card_ptr, area_hover_ptr);
-	//升井 更新his_location中的数据
-    card_ptr->m_his_location_card->up_mine(point(card_ptr->x,card_ptr->y,0),card_ptr->get_area(),tool_time::now_to_ms());
 
 	YA::_CARD_POS_ cp;
 	cp.Type=card_ptr->m_type;