Browse Source

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

researchman 5 years ago
parent
commit
986beac1a2

+ 1 - 1
ant.cpp

@@ -592,7 +592,7 @@ void sit_list::read_sit_list(int id)
         DBRes.GetField( "idx",idx, Error );
 
         int antid = idx-1;
-        if(antid >= 2)
+        if(antid >= 2 || antid < 0)
           continue;
 
         double x= 0;

+ 6 - 11
ant.h

@@ -175,22 +175,17 @@ struct site:point,std::enable_shared_from_this<site>
     point get_dstp(const point pt) const
     {
         point tmp;
-        for(const auto & p : m_ant[0].m_path)
-        {
-            for(int i=0;i<2;i++)
-            {
-                if(!p[i].empty())
-                {
-                    if(p[i].contain(pt,0.01))
-                    {
-                        //if(i==0)
-                        // return *this;
-                        //else
+        for(const auto & p : m_ant[0].m_path){
+            for(int i=0;i<2;i++){
+                if(!p[i].empty()){
+                    if(p[i].contain(pt,0.01)){
                         tmp = p[i][0];
                     }
                 }
             }
         }
+        if(tmp.empty())
+            log_info("(%f,%f) can't find the point at [%d]",pt.x,pt.y,m_id);
         return tmp;
     }
 

+ 9 - 10
card.cpp

@@ -367,8 +367,8 @@ void card_list::load_his_card_postion_staff()
 void card_list::on_message(zloop<task*> *loop, message_locinfo&loc,bool is_history)
 {
 	uint64_t cardid = tool_other::type_id_to_u64(loc.m_card_type,loc.m_card_id);
-	const auto c=card_list::instance()->get(cardid);
-	if(c==nullptr)
+	const auto &c=card_list::instance()->get(cardid);
+	if(!c)
 	{
 		log_warn("数据库中未定义该卡的信息,card_id=%d, card_type=%d,cardid:%lld",loc.m_card_id,loc.m_card_type,cardid);
 		return;
@@ -380,21 +380,20 @@ void card_list::on_message(zloop<task*> *loop, message_locinfo&loc,bool is_histo
 			loc.m_acc,loc.m_rssi,loc.m_batty_status,loc.m_time_stamp);
     if(loc.m_card_type != CT_PERSON && CYaSetting::m_sys_setting.test_rav(loc.m_card_type,loc.m_card_id))
         loc.set_rav(0);
-
+    
 	c->on_message(loop,loc,is_history);
+
+	if(tool_other::is_driving(loc.m_card_type,c->get_vehicle_type_id()))
+        mine_business::inst()->make_reverse_condition(loc.m_card_type,loc.m_card_id,loc.m_ant_id,loc.m_card_ct,loc.m_tof,loc.m_site_id);
 }
 
 //获取卡数据  //标识id 人staff_id 车 vehicle_id
-std::shared_ptr<card_location_base> card_list::get_card_by_cid(int cid)
+const std::shared_ptr<card_location_base> card_list::get_card_by_cid(int cid)
 {
-    auto t_map = m_map;
-    for(std::pair<int,std::shared_ptr<card_location_base>> me:t_map)
-    {
+    auto t_map = card_list::instance()->m_map;
+    for(const std::pair<int,std::shared_ptr<card_location_base>> &me:t_map)
         if ((int)me.second->m_cid == cid)
-        {
             return me.second;
-        }
-    }
     return nullptr;
 }
 

+ 1 - 1
card.h

@@ -24,7 +24,7 @@ struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_ba
     void load_his_card_postion_from_db();
 
     //获取卡数据  //标识id 人staff_id 车 vehicle_id
-    std::shared_ptr<card_location_base> get_card_by_cid(int cid);
+    const std::shared_ptr<card_location_base> get_card_by_cid(int cid);
     ~card_list(){}
 };
 #endif

+ 0 - 5
card_person.cpp

@@ -143,11 +143,6 @@ void person::handle_three_rates(const point & pt)
 
 void person::on_timer()
 {
-    if(!m_1sto2s){
-        m_1sto2s=true;
-        return ;
-    }
-    m_1sto2s=false;
     if(!m_mine_tool->m_is_attendance)
 	{
 		if(m_upmine_flag.load())

+ 0 - 1
card_person.h

@@ -13,7 +13,6 @@ struct person:card_location_base, card_area
     static int m_limit_detained_time;
     static int m_auto_up_mine_time;
     static int m_person_cards_flag;
-    bool       m_1sto2s{true};
     std::weak_ptr<monkey_person> m_monkeyPerson;
     std::string m_stafferName,m_deptName;
     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);

+ 5 - 1
common.h

@@ -61,7 +61,11 @@ enum CARD_TYPE
     ///    5  掘进机
     CT_HEADING_MACHINE=5
 };
-
+enum VEHICLE_TYPE
+{
+    VT_COAL_CUTTER=25,
+    VT_HEADING_MACHINE=26
+};
 enum AREA_TYPE
 {
 	AREA_TYPE_UPMINE =0,

+ 6 - 10
common_tool.h

@@ -95,21 +95,17 @@ class tool_other
             return type_id_to_u64(card_id_to_type(cardid),card_id_to_id(cardid));
         }
 
-        ///采煤机
-        static bool is_coal(int32_t type)
+        static bool is_coal(int32_t type,int32_t vtype)
         {
-            return CT_COAL_CUTTER == type;
+            return CT_COAL_CUTTER == type || vtype==VT_COAL_CUTTER;
         }
-
-        /// 掘进机
-        static bool is_driving(int32_t type)
+        static bool is_driving(int32_t type,int32_t vtype)
         {
-            return CT_HEADING_MACHINE == type;
+            return CT_HEADING_MACHINE == type || vtype==VT_HEADING_MACHINE;
         }
-
-        static bool is_coal_or_driving(int32_t type)
+        static bool is_coal_or_driving(int32_t type,int32_t vtype)
         {
-            return CT_COAL_CUTTER == type || CT_HEADING_MACHINE == type;
+            return is_coal(type,vtype) || is_driving(type,vtype);
         }
 };
 

+ 3 - 3
db/db_card.cpp

@@ -99,7 +99,7 @@ namespace db_card
 			std::string strategy;
 			if(card_type_id ==CT_VEHICLE)
 				strategy = config.get("car.strategy","CS_1");
-			else if(card_type_id ==CT_COAL_CUTTER)
+			else if(vehicle_type_id==VT_COAL_CUTTER)
 				strategy = config.get("coalface.strategy","WS_1");
             else
 				strategy = config.get("person.strategy","PS_1");
@@ -107,8 +107,8 @@ namespace db_card
 			auto clb = card_location_base::make_car(strategy,vsid,need_display,card_type_id,
 					dept_id,vehicle_category_id, vehicle_type_id,vehicle_level_id,vehicle_id);
 			uint64_t cardid = tool_other::type_id_to_u64(card_type_id,vsid);
-			log_info("cardId:%llu,id:%d dept_id:%d,need_display:%d-cardid:%s,categoryid:%d,vchile_id:%d,type:%d",
-					cardid,vsid,dept_id,need_display,card_id.c_str(),vehicle_category_id,vehicle_id,card_type_id);
+			log_info("cardId:%llu,id:%d dept_id:%d,need_display:%d-cardid:%s,categoryid:%d,vchile_id:%d,type:%d,vehicle_type_id:%d",
+					cardid,vsid,dept_id,need_display,card_id.c_str(),vehicle_category_id,vehicle_id,card_type_id,vehicle_type_id);
 			map.insert({cardid,clb});
 		}
 

+ 31 - 9
event.cpp

@@ -97,7 +97,8 @@ void Event::handle_alarm_event(EVENT_TYPE et,uint64_t id,double limit_value,doub
         {
             //已经存在告警
             event_ptr->m_cur_value = cur_value;
-            event_ptr->m_is_sent=false;
+            if(et!=ET_READER_ERROR)
+                event_ptr->m_is_sent=false;
         }
         else
         {
@@ -250,10 +251,16 @@ void event_list::save_event(const std::shared_ptr<ya_event> &ev_ptr)
     db_tool::PushAsync(sql);
 }
 
-void event_list::load_his_data_from_db()
+void event_list::load_his_data_from_db(bool init /*=true*/)
 {
+    static std::time_t s_last_time=0;
+    if(!init){
+        std::time_t t=time(0);
+        if(t-s_last_time<15)return;
+        s_last_time=t;
+    }
     std::unordered_map<uint64_t, std::shared_ptr<ya_event>> map;
-    const char *sql = "SELECT event_id, id,stat,event_type_id,obj_type_id,obj_id,dis_type,map_id,area_id,\
+    std::string sql("SELECT event_id, id,stat,event_type_id,obj_type_id,obj_id,dis_type,map_id,area_id,\
             limit_value,cur_value,x,y, cur_time FROM his_event_data \
             WHERE event_id IN (SELECT MAX(event_id) FROM his_event_data \
                                WHERE cur_time > (CASE obj_type_id \
@@ -266,10 +273,12 @@ void event_list::load_his_data_from_db()
                                AND cur_time < NOW()\
                                GROUP BY event_type_id, obj_id,dis_type) \
             AND  event_id NOT IN ( SELECT event_id FROM his_event_data WHERE  stat=100)\
-            AND event_type_id NOT IN (21,22,31,36);";
+            AND event_type_id NOT IN (21,22,31,36);");
+    if(!init)
+        sql="SELECT event_id, id,stat,event_type_id,obj_type_id,obj_id,dis_type,map_id,area_id,limit_value,cur_value,x,y, cur_time FROM his_event_data WHERE cur_time > date_sub(NOW(),interval 20 second) and source=1 order by stat;";
     std::string Error;
     YADB::CDBResultSet DBRes;
-    sDBConnPool.Query(sql,DBRes,Error);
+    sDBConnPool.Query(sql.c_str(),DBRes,Error);
     if(!Error.empty())
         log_error("初始化事件列表 Error,%s",Error.c_str());
     uint64_t nCount = DBRes.GetRecordCount( Error );
@@ -321,8 +330,20 @@ void event_list::load_his_data_from_db()
             int stat  = 0;
             DBRes.GetField( "stat",stat, Error );
 
+            std::shared_ptr<ya_event> ev=nullptr;
+            bool flag=false;
+            if(!init){
+                ev=event_list::instance()->get(id);
+                if(!ev){
+                    ev = std::make_shared<ya_event>(event_id);
+                }else{
+                    flag=true;
+                    if(stat==100)ev->m_is_sent=false;
+                }
+            }else{
+                ev = std::make_shared<ya_event>(event_id);
+            }
 
-            std::shared_ptr<ya_event> ev = std::make_shared<ya_event>(event_id);
             ev->m_status = static_cast<EVENT_STATUS>(stat);
             ev->m_ev_type = static_cast<EVENT_TYPE>(event_type_id);
 
@@ -357,8 +378,8 @@ void event_list::load_his_data_from_db()
             if(ev->m_ev_type==ET_READER_POWER_BY_BATTERY)
                 if(auto r=sit_list::instance()->get(std::stoi(obj_id)))
                     r->m_power_ac_down=true;
-            
-            map.insert(std::make_pair(id, ev));
+            if(!flag) 
+                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"
                      , ev->m_ev_id,ev->m_id,ev->m_status,ev->m_ev_type,ev->m_obj_type,ev->m_obj_id.c_str(),ev->m_dis_type
                      ,ev->m_map_id,ev->m_area_id,ev->m_limit_value,ev->m_cur_value
@@ -399,7 +420,8 @@ void event_list::_ev_to_node(std::shared_ptr<ya_event> ev_ptr,
 {
     rapidjson::Value ev(rapidjson::kObjectType);
 
-    ev.AddMember(JSON_KEY_EVENT_EVENT_ID,ev_ptr->m_ev_id, allocator);
+    //ev.AddMember(JSON_KEY_EVENT_EVENT_ID,ev_ptr->m_id, allocator);
+    tool_json::add_member(ev, JSON_KEY_EVENT_EVENT_ID, std::to_string(ev_ptr->m_id), allocator);
     ev.AddMember(JSON_KEY_EVENT_STATUS,ev_ptr->m_status, allocator);
 
     ev.AddMember(JSON_KEY_EVENT_TYPE_ID,ev_ptr->m_ev_type, allocator);

+ 1 - 2
event.h

@@ -117,7 +117,7 @@ public:
 
     static void save_event(const std::shared_ptr<ya_event> &event_ptr);
 
-    void load_his_data_from_db();
+    void load_his_data_from_db(bool init=true);
 
     ~event_list(){}
 
@@ -133,6 +133,5 @@ private:
     static void _ev_to_node(std::shared_ptr<ya_event> ev_ptr,
                             rapidjson::Document::AllocatorType& allocator,
                             rapidjson::Value& out_data);
-
 };
 #endif

+ 7 - 3
message.cpp

@@ -2,6 +2,8 @@
 #include "zstream.h"
 #include "message.h"
 #include "log.h"
+#include "common_tool.h"
+#include "card.h"
 
 void message_locinfo::zero_this()
 {
@@ -68,7 +70,8 @@ void message_locinfo::load(zistream&is,bool tdoa)
 
 	//加速度
 	is>>b;
-	if(m_card_type == 1 || m_card_type==4 || m_card_type==5)
+    const auto &c=card_list::instance()->get(tool_other::type_id_to_u64(m_card_type,m_card_id));
+	if(m_card_type == 1 ||(c && tool_other::is_coal_or_driving(m_card_type,c->get_vehicle_type_id())))
 		m_acc=b;
 	else
 		m_acc=((b&0x80)?-1.:1.)*(b&0x7f)*0.01;
@@ -106,7 +109,7 @@ std::vector<task*> message_locinfo::load_opt(zistream&is)
 	m.zero_this();
 
 	uint8_t  b;
-	uint16_t card_id;
+    uint16_t card_id;
 	//卡类型、卡号、CT、电池状态
 	is>>b>>card_id>>m.m_card_ct;
 	m.m_card_type=b&0xF;
@@ -125,7 +128,8 @@ std::vector<task*> message_locinfo::load_opt(zistream&is)
 
     //加速度
 	is>>b;
-	if(m.m_card_type==1 || m.m_card_type==4 || m.m_card_type==5)
+    auto c=card_list::instance()->get(tool_other::type_id_to_u64(m.m_card_type,m.m_card_id));
+	if(m.m_card_type == 1 ||(c && tool_other::is_coal_or_driving(m.m_card_type,c->get_vehicle_type_id())))
 		m.m_acc=b;
 	else
 		m.m_acc=((b&0x80)?-1.:1.)*(b&0x7f)*0.01;

+ 3 - 3
module_service/area_business_geofault.cpp

@@ -40,7 +40,7 @@ void area_business_geofault::on_load_his(const std::shared_ptr<area_hover>&area_
 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)
 {
-    if(!tool_other::is_coal_or_driving(card_ptr->m_type))
+    if(!tool_other::is_coal_or_driving(card_ptr->m_type,card_ptr->get_vehicle_type_id()))
     {
         return;
     }
@@ -65,7 +65,7 @@ void area_business_geofault::on_enter(const std::shared_ptr<area_hover>&area_hov
 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)
 {
-    if(!tool_other::is_coal_or_driving(card_ptr->m_type))
+    if(!tool_other::is_coal_or_driving(card_ptr->m_type,card_ptr->get_vehicle_type_id()))
     {
         return;
     }
@@ -120,7 +120,7 @@ void area_business_geofault::on_hover(const std::shared_ptr<area_hover>&area_hov
 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)
 {
-    if(!tool_other::is_coal_or_driving(card_ptr->m_type))
+    if(!tool_other::is_coal_or_driving(card_ptr->m_type,card_ptr->get_vehicle_type_id()))
     {
         return;
     }

+ 1 - 1
module_service/module_meta_date_changed.cpp

@@ -89,7 +89,7 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
             int id = std::stoi(szParam);
             deal_call_edit_light(id,edit_type_id);///待实现
         }
-        else if ("lights_group" == name)
+        else if ("lights_group"== name)
         {
             int id = std::stoi(szParam);
             deal_call_edit_lights_group(id,edit_type_id);///待实现

+ 5 - 8
module_service/module_web.cpp

@@ -99,7 +99,7 @@ void module_web::response_login()
 void module_web::run()
 {
     std::vector<std::shared_ptr<ya_event>> arr;
-    _get_all_events(arr);
+    _get_all_events(arr,true);
 
     if(!arr.empty())//发送给web端
     {
@@ -117,12 +117,14 @@ void module_web::run()
     }
 }
 
-void module_web::_get_all_events(std::vector<std::shared_ptr<ya_event>>& arr)
+void module_web::_get_all_events(std::vector<std::shared_ptr<ya_event>>& arr,bool f)
 {
     auto _map = event_list::instance()->m_map;
     auto it_map = _map.begin();
     for(;it_map!=_map.end();++it_map)
     {
+        if(f && it_map->second->m_is_sent)continue;
+        else it_map->second->m_is_sent=true;
         arr.push_back(it_map->second);
     }
 }
@@ -131,18 +133,13 @@ void module_web::_get_all_events(std::vector<std::shared_ptr<ya_event>>& arr)
 void module_web::_delete_end(std::vector<std::shared_ptr<ya_event>>& arr)
 {
     std::vector<uint64_t> todelete;
+
     auto arr_iter = arr.begin();
     for(;arr_iter!=arr.end();++arr_iter)
-    {
         if((*arr_iter)->is_end())//删除掉已经处理的
-        {
             todelete.push_back((*arr_iter)->get_list_id());
-        }
-    }
 
     if(!todelete.empty())
-    {
         event_list::instance()->remove(todelete);
-    }
 }
 

+ 1 - 1
module_service/module_web.h

@@ -63,7 +63,7 @@ private:
     void run();
 
     ///获取所有的告警事件
-    void _get_all_events(std::vector<std::shared_ptr<ya_event>>& arr);
+    void _get_all_events(std::vector<std::shared_ptr<ya_event>>& arr,bool f=false);
 
     ///在全局列表中删除已经处理或结束了的告警
     void _delete_end(std::vector<std::shared_ptr<ya_event>>& arr);

+ 1 - 5
net-service.cpp

@@ -65,7 +65,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 					site_tm.tm_year+=2000-1900;
 					site_tm.tm_mon-=1;
 
-					auto site_ptr = sit_list::instance()->get(static_cast<int32_t>(site_id));
+					const auto &site_ptr = sit_list::instance()->get(static_cast<int32_t>(site_id));
 					if(!site_ptr)
 					{
 						logn_error(1,"在全局分站列表中找不到分站:%s,%d", clt->name().c_str(), site_id);
@@ -117,8 +117,6 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 
 						t->m_cmd_code=cmd;
 						t->m_hash_id=m.m_card_id;
-						if(m.m_card_type==5)
-						    mine_business::inst()->make_reverse_condition(m.m_card_type,m.m_card_id,m.m_ant_id,m.m_card_ct,m.m_tof,m.m_site_id);
 						m_loc_worker->request(t);
 					}
 				}
@@ -197,8 +195,6 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 
 							tk->m_hash_id=m.m_card_id;
 							tk->m_cmd_code=cmd;
-							if(m.m_card_type==5)
-								mine_business::inst()->make_reverse_condition(m.m_card_type,m.m_card_id,m.m_ant_id,m.m_card_ct,m.m_tof,m.m_site_id);
 
 							m_loc_worker->request(tk);
 						}

+ 3 - 1
websocket/jsonBuilder.cpp

@@ -411,6 +411,8 @@ namespace YA
 
 	std::string jsonBuilder::BuildCardPos( const std::map<uint64_t, _CARD_POS_>& CardPosList )
 	{
+        static bool p2s=false;
+        p2s=p2s?false:true;
 		rapidjson::StringBuffer sb;
 		rapidjson::Writer<rapidjson::StringBuffer> writer( sb );
 		rapidjson::Document doc;
@@ -438,7 +440,7 @@ namespace YA
 			//{
 			//	continue;
 			//}
-
+            if(p2s && mit_card->second.Type == 1)continue;
 			rapidjson::Value DetailItem;
 			if ( !__BuildDetail( mit_card->second, Allocator, DetailItem ) )
 			{

+ 3 - 2
worker.cpp

@@ -18,6 +18,7 @@
 #include "clock.h"
 #include "mine_business.h"
 #include "bulletin_broad_show.h"
+#include "event.h"
 
 loop_thread::loop_thread ()
 {
@@ -98,8 +99,7 @@ struct timer_worker_thread: loop_thread
 
 		int v = card_list::instance()->version();
 		card_list_visit clv;
-		if(v != version)
-		{
+		if(v != version){
 			version=v;
 			clv._flag=true;
 			mine_business::inst()->clear_vehicle();
@@ -107,6 +107,7 @@ struct timer_worker_thread: loop_thread
 		card_list::instance()->accept(clv);
 		bulletin_broad_show::inst()->run_bulletin_board();
 		mine_business::inst()->run_business();
+        event_list::instance()->load_his_data_from_db(false);
 
 		log_info("timer_worker_thread use time:%ldus", clock.count_us());
 	}

+ 1 - 1
znet.cpp

@@ -404,8 +404,8 @@ struct sock_client:fd_io,client_ex
 	{
 		m_recv_timer.stop();
 		fd_io::stop();
-		m_ic.on_close(shared_from_this());
 		logn_info(1,"socket %s closed.",m_name.c_str());
+		m_ic.on_close(shared_from_this());
 	}
 
 	size_t calc_length(uint8_t*b)const