浏览代码

before merge

zhuyf 4 年之前
父节点
当前提交
100a1b4e5e

+ 11 - 2
card_base.h

@@ -77,8 +77,14 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
 {
 	uint64_t m_timeval=0;
 	uint16_t m_display_old{0};			//1显示0不显示,往前端推送
-    void update_display(){m_display_old=m_display;}
-    bool eq_display(){return m_display_old==m_display;}
+    void update_display()
+    {
+        m_display_old = m_display;
+    }
+    bool eq_display()
+    {
+        return m_display_old == m_display;
+    }
     std::uint8_t m_event[CARD_EVENT_COUNT_MAX]{0};
     std::unique_ptr<select_tool> m_sel_tool;
     std::unique_ptr<smooth_tool> m_smo_tool;
@@ -103,6 +109,9 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
     boost::circular_buffer<point> m_cb_point;
     point m_last_point;
 
+    bool m_enable_anti_collision = false;
+    int m_call_level = 0;
+
     card_location_base()=default;
     card_location_base(const std::string&type,uint32_t id,uint16_t dis,int16_t t,int32_t,int32_t,uint32_t );
  

+ 59 - 4
card_car.cpp

@@ -12,6 +12,8 @@
 #include "tool_time.h"
 #include "mine_business.h"
 #include "loc_point.h"
+#include "module_service/module_call.h"
+#include "ya_setting.h"
 
 car::car(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,
 		int32_t categoryid, int type_id,int32_t level_id,uint32_t cid)
@@ -38,16 +40,69 @@ 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_timeval = m_time;
+    log_info("[anti_coll] m_id = %d, m_timeval = %lld", m_id, m_timeval);
 	handle_three_rates(pt);
     handle_traffic_light(pt);
+    if(m_enable_anti_collision){
+        handle_anti_coll(pt, site->m_id);
+    }
 	uint64_t id=tool_other::type_id_to_u64(m_type,m_id);
 	mine_business::inst()->make_arg(id,pt,m_time);
 }
 
 int car::get_vehicle_type_id()
 {
-	return  m_vehicle_type_id;
+	return m_vehicle_type_id;
+}
+
+void car::handle_anti_coll(const point& pt, const int& sid)
+{
+    log_info("[anti_coll] handle anti collision");   
+    // 车卡下发最紧急的呼叫类型
+    std::map<int, call_card> cards;
+    auto tmp_cards = card_list::instance()->m_map; 
+
+    for(auto k : CYaSetting::m_sys_setting.mp_anti_collision){
+        log_info("[anti_coll] key=%d, value=%.2f", k.first, k.second);
+        for(auto c : tmp_cards)
+        {
+            if(c.second->m_type == CT_VEHICLE){
+                continue;
+            }
+            bool s = false;
+            int d = (c.second->m_timeval >= m_timeval ? (c.second->m_timeval - m_timeval) : (m_timeval - c.second->m_timeval)) / 1000.0;
+            s = ((c.second->m_timeval >= m_timeval ? (c.second->m_timeval - m_timeval) : (m_timeval - c.second->m_timeval)) /1000.0 <= 30);
+            log_info("[anti_coll] distance=%.3f, thre_value=%.3f, time_diff=%d", pt.dist(*c.second), k.second, d);
+            if(pt.dist(*c.second) < k.second && s){
+                auto it = cards.find(c.second->m_id);
+                if(it != cards.end()){
+                    if(c.second->m_call_level < k.first + 3){
+                        c.second->m_call_level = k.first + 3;
+                    }
+                }else{
+                    log_info("[anti_coll] card_id=%d, ctype=%d, call_level=%d, call_type_id=%d, site_id=%d",c.second->m_id, c.second->m_type, k.first, CCT_CALL_APOINT, sid);
+                    cards.insert(std::make_pair(c.second->m_id, call_card(c.second->m_id, c.second->m_type, k.first, CCT_CALL_APOINT, sid)));
+                }
+            }
+        }
+    }
+    
+    if(cards.size() > 0){
+        // find the best emengency call
+        int call_level = 6;
+        for(auto c : cards){
+            if(c.second.call_level_id < call_level){
+                call_level = c.second.call_level_id;
+            }
+        }
+        cards.insert(std::make_pair(m_id, call_card(m_id, 2, call_level, CCT_CALL_APOINT, sid)));
+    }else{
+        log_info("[anti_coll] no card trigger anti collision rules.");
+        return;
+    } 
+
+    module_call::instance()->send_anti_collision(cards);
 }
 
 void car::handle_three_rates(const point &pt)
@@ -59,8 +114,8 @@ void car::handle_three_rates(const point &pt)
     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 = m_area_tool->get_mapid();
 	cp.vibration = m_acc;
 	put_three_rates(cp);

+ 1 - 5
card_car.h

@@ -3,7 +3,6 @@
 
 #include <string>
 #include <memory>
-
 #include "point.h"
 #include "card_base.h"
 #include "card_area.h"
@@ -18,7 +17,6 @@ struct car:card_location_base,card_area
 {
 	int m_vehicle_category_id=0;
     int m_vehicle_type_id=0;
-
 public:
 
     car(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,
@@ -44,12 +42,10 @@ public:
 private:
 	void handle_three_rates(const point &pt);
     void handle_traffic_light(const point& pt);
+    void handle_anti_coll(const point& pt, const int& sid);
 	void on_timer();
 	void make_package();
 	loc_point getSmoothPoint();
 };
 
-
 #endif
-
-

+ 20 - 5
db/db_card.cpp

@@ -17,7 +17,7 @@ namespace db_card
 		std::string sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, cf.freq_value, \
 						   ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
 						   vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
-						   vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed \
+						   vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed, ve.enable_anti_collision \
 						   FROM dat_vehicle_extend ve \
 						   LEFT JOIN dat_vehicle v ON ve.vehicle_id = v.vehicle_id \
 						   LEFT JOIN dat_card c ON ve.card_id = c.card_id \
@@ -112,10 +112,25 @@ namespace db_card
 			uint64_t cardid = tool_other::type_id_to_u64(card_type_id,vsid);
             clb->m_freq = freq;
 
-            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});
-		}
+            int anti_collision = 0;
+            DBRes.GetField("enable_anti_collision", anti_collision, Error);
+            clb->m_enable_anti_collision = ((anti_collision == 1) ? true : false);
+	        
+            map.insert({cardid,clb});
+
+            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, anti_collision:%d",
+                    cardid,
+                    vsid,
+                    dept_id,
+                    need_display,
+                    card_id.c_str(),
+                    vehicle_category_id,
+                    vehicle_id,
+                    card_type_id,
+                    vehicle_type_id,
+                    anti_collision
+                    );
+        }
 
 		return map;
 	}

+ 1 - 1
module_service/area_business_person_attendance.cpp

@@ -12,7 +12,7 @@
 #include "websocket/wsClientMgr.h"
 #include "websocket/wsTimerThread.h"
 #include"tool_time.h"
-#include "module_meta_date_changed.h"
+#include "module_meta_data_changed.h"
 #include "his_location.h"
 //记录进入时间等信息,结束考勤,根据离开的时间和距离,判断是否记录一条新的考勤记录
 void area_business_person_attendance::on_enter(const std::shared_ptr<area_hover>&area_hover_ptr,

+ 19 - 3
module_service/module_call.cpp

@@ -15,17 +15,17 @@
 #include"websocket/wsClientMgr.h"
 #include "crc.h"
 #include"mine.h"
-uint64_t module_call::call_card::to_id64()
+uint64_t call_card::to_id64()
 {
     return tool_other::type_id_to_u64(cardtype, cardid);
 }
 
-std::string module_call::call_card::to_id64_str()
+std::string call_card::to_id64_str()
 {
     return tool_other::type_id_to_str(cardtype, cardid);
 }
 
-bool module_call::call_card::is_timeout()
+bool call_card::is_timeout()
 {
     uint32_t seconds = tool_time::elapse_seconds(call_time);
     return (seconds >= call_time_out*60);
@@ -754,3 +754,19 @@ void module_call::system_cancel_call_apoint(int card_id,int card_type)
 
     response_accept_cancel(result_user_ptr);
 }
+
+void module_call::send_anti_collision(const std::map<int, call_card>& cards)
+{
+    std::vector<call_card_ptr> vt_cards;
+    for(auto c : cards){
+        vt_cards.push_back(std::make_shared<call_card>(c.second));
+    }
+    log_info("[anti_coll] card's size = %d, vt_cards's size = %d", cards.size(), vt_cards.size());
+
+    call_site_map site_map;
+    get_site_map(vt_cards, site_map);
+    log_info("[anti_coll] site's size = %d", site_map.size());
+    if(!site_map.empty()){
+        send_to_sites(site_map);
+    }
+}

+ 51 - 38
module_service/module_call.h

@@ -56,6 +56,54 @@ enum CALL_STATE{
     CALL_END=100
 };
 
+/**
+ * @brief 呼叫卡的信息
+ */
+struct call_card
+{
+    /// 呼叫卡号 0为全员
+    uint32_t cardid;
+    int32_t cardtype;
+    /// 分站号  0为全员
+    int stationid;
+    ///呼叫类型 全员0, 定员1   CALL_CARD_TYPE
+    int call_type_id;
+    /// 呼叫类型:一般1,紧急2  CALL_CARD_LEVEL
+    int call_level_id;
+    /// 呼叫时长,单位分钟
+    uint32_t call_time_out;
+
+    int call_time_interval;
+    /// 呼叫开始时间
+    std::chrono::system_clock::time_point call_time;
+    /// 呼叫状态,正在呼叫、呼叫成功
+    int call_state;
+    ///呼叫人
+    std::string user_name;
+
+    bool is_display = true;
+
+    call_card()
+    {}
+
+    call_card(uint32_t id, int32_t type, int level_id, CALL_CARD_TYPE call_type, int sid): cardid(id), cardtype(type), stationid(sid), call_type_id(call_type), call_level_id(level_id)
+    {
+        user_name = "system";
+    }  
+
+    bool is_call_all()
+    {
+        return CCT_CALL_ALL == call_type_id;
+    }
+
+    uint64_t to_id64();
+    std::string to_id64_str();
+
+    bool is_timeout();
+};
+
+using call_card_ptr = std::shared_ptr<call_card>;
+
 /**
  * @brief 呼叫模块
  */
@@ -68,44 +116,6 @@ private:
     }
 
 private:
-    /**
-     * @brief 呼叫卡的信息
-     */
-    struct call_card
-    {
-        /// 呼叫卡号 0为全员
-        uint32_t cardid;
-        int32_t cardtype;
-        /// 分站号  0为全员
-        int stationid;
-        ///呼叫类型 全员0, 定员1   CALL_CARD_TYPE
-        int call_type_id;
-        /// 呼叫类型:一般1,紧急2  CALL_CARD_LEVEL
-        int call_level_id;
-        /// 呼叫时长,单位分钟
-        uint32_t call_time_out;
-
-        int call_time_interval;
-        /// 呼叫开始时间
-        std::chrono::system_clock::time_point call_time;
-        /// 呼叫状态,正在呼叫、呼叫成功
-        int call_state;
-        ///呼叫人
-        std::string user_name;
-
-        bool is_display = true;
-
-        bool is_call_all()
-        {
-            return CCT_CALL_ALL == call_type_id;
-        }
-
-        uint64_t to_id64();
-        std::string to_id64_str();
-
-        bool is_timeout();
-    };
-    typedef std::shared_ptr<call_card>  call_card_ptr;
     typedef std::map<int64_t,call_card_ptr>  call_card_map;
 
     /**
@@ -184,6 +194,9 @@ public:
      * @brief 系统自动发送呼叫给指定的卡
      */
     void system_cancel_call_apoint(int card_id,int card_type);
+
+    void send_anti_collision(const std::map<int, call_card>& cards);
+
     /**int card_id,int card_type
      * @brief
      */

+ 536 - 0
module_service/module_meta_data_changed.cpp

@@ -0,0 +1,536 @@
+#include "module_meta_data_changed.h"
+#include"area_business_person_attendance.h"
+#include"area_business_car_attendance.h"
+
+#include"common_tool.h"
+#include "websocket/wsClientMgr.h"
+#include"db/db_api/CDBSingletonDefine.h"
+#include"event.h"
+
+#include"ant.h"
+#include"card.h"
+#include"area.h"
+#include "forbid_staff_down_mine.h"
+#include "landmark.h"
+#include <three_rates.h>
+#include"area_business_geofault.h"
+#include <boost/format.hpp>
+#include <boost/tokenizer.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string.hpp>
+#include <card_path.h>
+#include "ya_setting.h"
+///基础数据
+void module_meta_data_changed::accept(sio::message::ptr const& data)
+{
+    std::string name="";
+    if(!tool_map::try_get_value(name, JSON_KEY_NAME, data))
+    {
+        log_error("web发来的数据: 基础数据找不到name字段");
+        return;
+    }
+
+    std::string szParam = "0";
+    tool_map::try_get_value(szParam,JSON_KEY_ID,data);
+
+   // int id=-1;
+   // tool_map::try_get_value(id,JSON_KEY_ID,data);
+
+    std::string op_type="";
+    tool_map::try_get_value(op_type, JSON_KEY_OP_TYPE, data);
+
+    log_info("web发来数据:cmd=meta_data_changed.name:%s Param:%s OpType:%s",name.c_str(),szParam.c_str(),op_type.c_str());
+    if(!szParam.empty() && !op_type.empty())
+    {
+        EDIT_TYPE_ID edit_type_id;
+        if(!try_get_edit_type_id(op_type, edit_type_id))
+        {
+            log_error("web发来的数据: 基础数据op_type字段错误:op_type=%s", op_type.c_str());
+            return;
+        }
+
+        if(JSON_KEY_NAME_VEHICLE == name || JSON_KEY_NAME_VEHICLE_EXTEND == name)
+        {
+            deal_call_edit_vehicle_or_staff(szParam, edit_type_id);
+        }
+        else if(JSON_KEY_NAME_STAFF == name || JSON_KEY_NAME_STAFF_EXTEND == name)
+        {
+            deal_call_edit_vehicle_or_staff(szParam, edit_type_id);
+        }
+        else if(JSON_KEY_NAME_CARD == name)
+        {
+            deal_call_edit_card(szParam, edit_type_id);
+        }
+        else if(JSON_KEY_NAME_AREA == name)
+        {
+            deal_call_edit_area(szParam, edit_type_id);
+        }
+        else if(JSON_KEY_NAME_READER == name)
+        {
+            deal_call_edit_reader(szParam, edit_type_id);
+        }
+        else if (JSON_KEY_NAME_ANTENNA == name)
+        {
+            int id = std::stoi(szParam);
+            deal_call_edit_antenna(id,edit_type_id);
+        }
+        else if(JSON_KEY_NAME_PATH == name)
+        {
+            int id = std::stoi(szParam);
+            deal_call_edit_path(id, edit_type_id);
+        }
+        else if(JSON_KEY_NAME_MAP == name || JSON_KEY_NAME_MAP_GIS == name)
+        {
+            int id = std::stoi(szParam);
+            deal_call_edit_map(id, edit_type_id);
+        }
+        else if (JSON_KEY_NAME_LIGHT == name)
+        {
+            int id = std::stoi(szParam);
+            deal_call_edit_light(id,edit_type_id);///待实现
+        }
+        else if (JSON_KEY_NAME_LIGHTS_GROUP== name)
+        {
+            int id = std::stoi(szParam);
+            deal_call_edit_lights_group(id,edit_type_id);///待实现
+        }
+        else if (JSON_KEY_NAME_FORBID_PERSON_DOWN_MINE == name)
+        {
+            deal_call_edit_forbid_person_down_mine(szParam,edit_type_id);
+        }
+        else if (JSON_KEY_NAME_PERSONS_DYNAMIC_THRE == name)
+        {
+            int id = std::stoi(szParam);
+            deal_call_edit_persons_dynamic_thre(id,edit_type_id);
+        }
+		else if (JSON_KEY_NAME_GEO_FAULT == name)//地址断层更新
+		{
+			area_business_geofault::init_geofault_from_db();
+		}
+		else if (JSON_KEY_NAME_LANDMARK == name)//地标信息更新
+		{
+			deal_call_edit_landmark(szParam, edit_type_id);
+		}
+		else if (JSON_KEY_NAME_COALFACE==name|| JSON_KEY_NAME_COALFACE_VEHICLE == name || 
+			JSON_KEY_NAME_DRIVING_FACE == name || JSON_KEY_NAME_DRIVINGFACE_VEHICLE == name
+			|| JSON_KEY_NAME_DRIVINGFACE_REF_POINT == name
+			|| JSON_KEY_NAME_DRIVINGFACE_WARNING_POINT == name)
+		{			
+			three_rates::get_instance()->update_db_data(name, szParam, edit_type_id);
+		}else if(JSON_KEY_NAME_ANTI_COLLISION == name){
+            deal_edit_anti_collision(szParam, edit_type_id);
+        }
+        else
+        {
+            log_error("web发来的数据: 基础数据name字段错误:name=%s", name.c_str());
+        }
+    }
+    else
+    {
+        if(JSON_KEY_NAME_SETTING == name)
+        {
+            //阈值限制接口
+            init_setting(); ///待实现
+        }
+        else
+        {
+            log_error("web发来的数据: 基础数据name字段错误:name=%s", name.c_str());
+        }
+    }
+}
+
+///3.清除卡相关信息,区域相关,分站相关,考勤相关,清除定时器,
+///速度,状态 呼救 呼叫 告警相关。即保留基础信息,其他的重置。
+void module_meta_data_changed::clear_card(const std::shared_ptr<card_location_base>& card_ptr)
+{
+    card_ptr->get_area_tool()->on_leave(card_ptr);
+}
+/*
+ * 修改车及卡的数据
+ * id64 = ;员工ID或者车ID;卡ID=101;0010000001198  分号间隔
+ */
+void module_meta_data_changed::deal_call_edit_vehicle_or_staff(const std::string & id64, EDIT_TYPE_ID edit_type_id)
+{
+    std::vector<std::string> vecSegTag;
+    boost::split(vecSegTag, id64, boost::is_any_of(";"));
+    if (vecSegTag.size() == 1)  //数据发生错误
+    {
+        log_errno("Web Send Data Error!(%s)", id64.c_str());
+        return;
+    }
+    std::string lsz_card_id = vecSegTag[1];
+    int cid = std::stoi(vecSegTag[0].c_str());
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        if (ET_UPDATE == edit_type_id)
+        {
+            auto c = card_list::instance()->get_card_by_cid(cid);
+            if (nullptr != c && tool_other::type_id_to_str(c->m_type,c->m_id) != lsz_card_id)
+            {
+                //如果修改了卡号,则删除原来的卡的数据
+                remove_card(c);
+            }
+        }
+        int c_type = tool_other::id64_to_type(lsz_card_id);
+        if (tool_other::is_vehicle(c_type))
+        {
+            card_list::instance()->init_vehicle(lsz_card_id);
+        }
+        else if (tool_other::is_person(c_type))
+        {
+            card_list::instance()->init_staffer(lsz_card_id);
+        }
+    }
+    else
+    {
+        if(!lsz_card_id.empty())
+            remove_card(tool_other::id64_to_id(lsz_card_id), tool_other::id64_to_type(lsz_card_id));
+    }
+}
+
+void module_meta_data_changed::deal_call_edit_card(std::string & id64, EDIT_TYPE_ID edit_type_id)
+{
+    std::string card_id64_str = tool_other::to13str(id64);
+    int type = tool_other::id64_to_type(card_id64_str);
+    if(tool_other::is_person(type) || tool_other::is_vehicle(type))
+    {
+        auto c = card_list::instance()->get(tool_other::card_id_to_u64(card_id64_str));
+        if (nullptr == c) {
+            log_info("web edit card:%s Not bind staff or vehicle. editType:%d", card_id64_str.c_str(), edit_type_id);
+            return ;
+        }
+        std::string lsz = std::to_string(c->m_cid) + ";" + card_id64_str;
+        deal_call_edit_vehicle_or_staff(lsz,edit_type_id);
+    }
+    else
+    {
+        log_error("基础数据 删除卡type不对:type=%d", type);
+    }
+}
+
+void module_meta_data_changed::deal_call_edit_area(const std::string& id,EDIT_TYPE_ID edit_type_id)
+{
+    int cid = std::stoi(id);
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id){
+        area_list::instance()->init_from_db(cid);
+    }else if(ET_DELETE == edit_type_id)
+    {
+        if(auto area_ptr = area_list::instance()->get(cid)){
+            log_info("区域删除:areaid=%d", cid);
+            area_ptr->clear();
+            area_list::instance()->remove(cid);
+        }
+    }
+}
+
+void module_meta_data_changed::deal_call_edit_reader(const std::string &ids, EDIT_TYPE_ID edit_type_id)
+{
+    //新增发送的都是单个分站名称,所以
+    if(ET_INSERT == edit_type_id){
+        sit_list::instance()->load_from_db(ids);
+    }
+    else if(ET_UPDATE == edit_type_id){
+        sit_list::instance()->init_site(ids);
+    }else if(ET_DELETE == edit_type_id){
+        int id =std::stoi(ids);
+        if(auto sit_ptr=sit_list::instance()->get(id)){
+            log_info("分站删除:sid=%d", id);
+            sit_ptr->clear_event();
+            sit_list::instance()->remove(id);
+            card_path::init();
+        }
+    }
+}
+
+void module_meta_data_changed::deal_call_edit_antenna(int id,EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        sit_list::instance()->read_sit_list(id);
+    }
+    //else if(ET_DELETE == edit_type_id)
+    //{
+        //delete_antenna(id);
+   // }
+}
+
+void module_meta_data_changed::deal_call_edit_path(int id, EDIT_TYPE_ID edit_type_id)
+{
+   // if(ET_INSERT == edit_type_id)
+   // {
+   //     log_error("path不支持增加操作");
+   //     std_debug("path不支持增加操作");
+   // }
+   // else if(ET_UPDATE == edit_type_id)
+   // {
+   // }
+    if(sit_list::instance()->get(id))
+        sit_list::instance()->read_ant_path(id);
+}
+
+void module_meta_data_changed::deal_call_edit_map(int id, EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        if(!is_cur_map(id))
+        {
+            log_info("修改的不是当前使用的地图,要修改地图id=%d,当前使用地图id=%d", id, cur_map_id());
+            return;
+        }
+
+       update_map_info(id);
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+        if(is_cur_map(id))
+        {
+            log_error("删除了当前使用的地图");
+            return;
+        }
+    }
+}
+
+void module_meta_data_changed::deal_call_edit_light(int id, EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+    }
+}
+
+void module_meta_data_changed::deal_call_edit_lights_group(int id, EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+    }
+}
+
+// 禁止指定人员下井 id = (rt_person_forbid_down_mine)数据库中自增长ID
+void module_meta_data_changed::deal_call_edit_forbid_person_down_mine(const std::string & lszId,EDIT_TYPE_ID edit_type_id)
+{
+    std::vector<std::string> vecSegTag;
+    boost::split(vecSegTag, lszId, boost::is_any_of(";"));
+    if (vecSegTag.size() == 1)  //数据发生错误
+    {
+        log_errno("Web Send Data Error!(%s)", lszId.c_str());
+        return;
+    }
+    int db_id = std::stoi(vecSegTag[0].c_str());
+    int staff_id = std::stoi(vecSegTag[1].c_str());
+
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        forbid_staff_down_mine::instance()->init_forbid_staff(db_id,edit_type_id);
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+        forbid_staff_down_mine::instance()->del_forbid_data(db_id,staff_id);
+    }
+}
+
+// 设置区域中时间段人员超员阈值等数据
+void module_meta_data_changed::deal_call_edit_persons_dynamic_thre(int area_id,EDIT_TYPE_ID edit_type_id)
+{
+    area_list::instance()->init_area_persons_dynamic_thre_from_db(area_id);
+}
+
+// 修改地标信息
+void module_meta_data_changed::deal_call_edit_landmark(const std::string & landmarkid, EDIT_TYPE_ID edit_type_id)
+{
+	int id = atoi(landmarkid.c_str());
+
+	if (ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+	{
+		Landmark_list::instance()->init_landmarkInfo(id);
+	}
+	else if (ET_DELETE == edit_type_id)
+	{
+		Landmark_list::instance()->remove(id);
+	}
+}
+
+void module_meta_data_changed::init_setting()
+{
+    CYaSetting::Init_sys_setting();
+}
+
+void module_meta_data_changed::remove_card(uint32_t id, int32_t type) {
+    uint64_t card_id = tool_other::type_id_to_u64(type, id);
+    auto card_ptr = card_list::instance()->get(card_id);
+    if (!card_ptr) {
+        log_error("基础数据, 在全局列表中删除卡,全局列表中已经不存在此卡, id=%d, type=%d", id, type);
+        return;
+    }
+    remove_card(card_ptr);
+}
+
+void module_meta_data_changed::remove_card(std::shared_ptr<card_location_base> card_ptr)
+{
+    if (!card_ptr)
+    {
+        return;
+    }
+    log_info("基础数据, 在全局列表中删除卡成功, type=%d, id=%d",card_ptr->m_type, card_ptr->m_id);
+    //    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);
+
+    //        module_meta_data_changed::clear_card(card_ptr);
+    //    }
+    module_meta_data_changed::clear_card(card_ptr);
+    // 避免状态重置
+    uint64_t card_id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+    card_list::instance()->remove(card_id);
+}
+
+bool module_meta_data_changed::try_get_edit_type_id(const std::string& op_type, EDIT_TYPE_ID& out_edit_type_id)
+{
+    if(JSON_KEY_OP_TYPE_UPDATE == op_type)
+    {
+        out_edit_type_id = ET_UPDATE;
+    }
+    else if(JSON_KEY_OP_TYPE_DELETE == op_type)
+    {
+        out_edit_type_id = ET_DELETE;
+    }
+    else if(JSON_KEY_OP_TYPE_INSERT == op_type)
+    {
+        out_edit_type_id = ET_INSERT;
+    }
+    else
+    {
+        return false;
+    }
+
+    return true;
+}
+
+///删除区域所有报警信息
+//void module_meta_data_changed::delete_area_event(std::shared_ptr<area> area_ptr)
+//{
+//    for(int i=0; i < CARD_EVENT_COUNT_MAX; i++ )
+//    {
+//        event_tool::instance()->handle_event(OT_AREA, static_cast<EVENT_TYPE>(i), area_ptr->id(), 0, 0, false);
+//    }
+//}
+
+//void module_meta_data_changed::delete_antenna(int id)
+//{
+//    int sitid=-8;
+//    auto map = sit_list::instance()->m_map;
+//    for(auto&it:map)
+//    {
+//        auto sit_ptr = it.second;
+//        if(sit_ptr->m_ant[0].m_id == id)
+//        {
+//            sitid=sit_ptr->m_id;
+//            sit_ptr->delete_antenna(0);
+//            break;
+//        }
+//        if(sit_ptr->m_ant[1].m_id == id)
+//        {
+//            sitid=sit_ptr->m_id;
+//            sit_ptr->delete_antenna(1);
+//            break;
+//        }
+//    }
+//
+//    if(sitid==-8)
+//    {
+//        std_debug("天线已经删除了,在分站列表中找不到该天线:天线id=%d", id);
+//        log_info("天线已经删除了,在分站列表中找不到该天线:天线id=%d", id);
+//    }
+//    else
+//    {
+//        std_debug("删除天线成功:天线id=%d,分站id=%d", id, sitid);
+//        log_info("删除天线成功:天线id=%d,分站id=%d", id, sitid);
+//    }
+//}
+//
+bool module_meta_data_changed::is_cur_map(int id)
+{
+    return cur_map_id()==id;
+}
+
+int module_meta_data_changed::cur_map_id()
+{
+    auto tmp = area_list::instance()->m_map;
+    for(auto&it:tmp)
+    {
+        if(0!=it.second->m_mapid)
+        {
+            return it.second->m_mapid;
+        }
+    }
+
+    return -1;
+}
+
+void module_meta_data_changed::update_map_info(int id)
+{
+    std::string sql = "SELECT scale FROM dat_map WHERE map_id=";
+
+    sql.append(std::to_string(id));
+    sql.append(";");
+
+    std_debug("修改地图 sql=%s", sql.c_str());
+    log_info("修改地图 sql=%s", sql.c_str());
+
+    std::string Error;
+    YADB::CDBResultSet DBRes;
+    sDBConnPool.Query(sql.c_str(),DBRes,Error);
+    int nCount = DBRes.GetRecordCount( Error );
+    if (nCount < 1)
+    {
+        log_error("修改地图失败,数据库中找不到: map_id=%d", id);
+        return ;
+    }
+    double scale  = 0;
+    if (DBRes.GetNextRecod(Error))
+    {
+        DBRes.GetField("scale", scale, Error);
+    }
+    if (scale < 1e-4)
+    {
+        log_error("修改地图,数据库地图比例尺错误: map_id=%d,scale=%.2f", id,scale);
+        return;
+    }
+    auto area = area_list::instance()->m_map;
+    for(auto& it : area)
+    {
+        it.second->m_scale = scale;
+    }
+
+    auto site = sit_list::instance()->m_map;
+    for(auto& it : site)
+    {
+        it.second->m_scale = scale;
+    }
+}
+
+void module_meta_data_changed::deal_edit_anti_collision(const std::string& value, EDIT_TYPE_ID& edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        CYaSetting::m_sys_setting.init_anti_coll_value(value);
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+        CYaSetting::m_sys_setting.del_anti_coll_value();
+    }
+}

+ 93 - 0
module_service/module_meta_data_changed.h

@@ -0,0 +1,93 @@
+#ifndef MODULE_META_DATE_CHANGED_H
+#define MODULE_META_DATE_CHANGED_H
+#include"module_singleton_base.h"
+#include"websocket/sio/sio_client.h"
+
+struct card_location_base;
+struct area;
+
+
+enum EDIT_TYPE_ID
+{
+    ET_INSERT = 0, // 新增
+    ET_UPDATE,	   // 修改
+    ET_DELETE      // 删除
+};
+
+class module_meta_data_changed:public singleton_base<module_meta_data_changed>
+{
+private:
+    friend class singleton_base<module_meta_data_changed>;
+    module_meta_data_changed()
+    {
+    }
+
+    ///已经实现的:'card', 'staff', 'vehicle', 'vehicle_extend', 'staff_extend', 'area', 'reader',
+    /// map antenna  path
+    ///提供了接口未实现的: setting  light  lights_group
+    ///下面的是暂时不要处理的
+    ///'drivingface', 'drivingface_render', 'dat_drivingface_warning_point',
+    ///'rules', 'drivingface_vehicle', 'dat_handup_vehicle', 'lights_binding'
+public:
+    ///基础数据
+    void accept(sio::message::ptr const& data);
+
+    ///3.清除卡相关信息,区域相关,分站相关,考勤相关,清除定时器,
+    ///速度,状态 呼救 呼叫 告警相关。即保留基础信息,其他的重置。
+    static void clear_card(const std::shared_ptr<card_location_base> &card_ptr);
+
+private:
+    /*
+     * 修改车及卡的数据
+     * id64 = ;员工ID或者车ID;卡ID=101;0010000001198  分号间隔
+     */
+    void deal_call_edit_vehicle_or_staff(const std::string & id64, EDIT_TYPE_ID edit_type_id);
+
+    ///id64格式为10000006666
+    void deal_call_edit_card(std::string & id64, EDIT_TYPE_ID edit_type_id);
+
+    void deal_call_edit_reader(const std::string & areaids, EDIT_TYPE_ID edit_type_id);
+
+    ///待实现
+    void deal_call_edit_path(int id, EDIT_TYPE_ID edit_type_id);
+
+    void deal_call_edit_antenna(int id,EDIT_TYPE_ID edit_type_id);
+
+    void deal_call_edit_area(const std::string & id, EDIT_TYPE_ID edit_type_id);
+
+    void deal_call_edit_map(int id, EDIT_TYPE_ID edit_type_id);
+
+    ///待实现
+    void deal_call_edit_light(int id,EDIT_TYPE_ID edit_type_id);
+
+    ///待实现
+    void deal_call_edit_lights_group(int id,EDIT_TYPE_ID edit_type_id);
+
+    // 禁止指定人员下井
+    void deal_call_edit_forbid_person_down_mine(const std::string & lszId,EDIT_TYPE_ID edit_type_id);
+	//地标
+	void deal_call_edit_landmark(const std::string & landmarkid, EDIT_TYPE_ID edit_type_id);
+
+    // 设置区域中时间段人员超员阈值等数据
+    void deal_call_edit_persons_dynamic_thre(int area_id,EDIT_TYPE_ID edit_type_id);
+
+    ///待实现
+    void init_setting();
+
+    void remove_card(uint32_t id, int32_t type);
+    void remove_card(std::shared_ptr<card_location_base> card_ptr);
+
+    bool try_get_edit_type_id(const std::string& op_type, EDIT_TYPE_ID& out_edit_type_id);
+
+    //void delete_antenna(int id);
+
+    bool is_cur_map(int id);
+
+    int cur_map_id();
+
+    void update_map_info(int id);
+
+    void deal_edit_anti_collision(const std::string& value, EDIT_TYPE_ID& edit_type_id);
+};
+
+#endif // MODULE_META_DATE_CHANGED_H

+ 2 - 2
module_service/module_web.cpp

@@ -3,7 +3,7 @@
 #include"module_call_help.h"
 #include"module_call.h"
 #include"area_business_person_attendance.h"
-#include"module_meta_date_changed.h"
+#include"module_meta_data_changed.h"
 #include"common_tool.h"
 #include"event.h"
 
@@ -49,7 +49,7 @@ void module_web::accept( int ID, std::string const& name,
 
         if(JSON_CMD_VALUE_META_DATA_CHANGED == cmd)///基础数据
         {
-            module_meta_date_changed::instance()->accept(data_value);
+            module_meta_data_changed::instance()->accept(data_value);
         }
         else if(JSON_CMD_VALUE_DEAL_HELP == cmd) // 处理呼救信息
         {

+ 3 - 0
websocket/constdef.h

@@ -60,10 +60,12 @@
 #define JSON_KEY_NAME_STAFF "staff"
 #define JSON_KEY_NAME_STAFF_EXTEND "staff_extend"
 #define JSON_KEY_NAME_VEHICLE "vehicle"
+#define JSON_KEY_NAME_ANTENNA "antenna"
 
 #define JSON_KEY_NAME_VEHICLE_EXTEND "vehicle_extend"
 #define JSON_KEY_NAME_SECTION "section"
 #define JSON_KEY_NAME_LIGHT   "light"
+#define JSON_KEY_NAME_LIGHTS_GROUP "lights_group"
 #define JSON_KEY_NAME_CHAMBER "chamber"
 #define JSON_KEY_NAME_SHIFT "shift"
 #define JSON_KEY_NAME_PATROL_TASK "patrol_task"
@@ -135,6 +137,7 @@
 #define JSON_KEY_LANDMARK_ID "landmark_id"
 #define JSON_KEY_DIRECTORY_ID "landmark_direction_id"
 #define JSON_KEY_LANDMARK_DIS "landmark_distance"
+#define JSON_KEY_NAME_ANTI_COLLISION "anti_collision"
 
 // id, name, type, map_id
 #define JSON_KEY_AREA_ID "area_id" // "������"

+ 17 - 3
ya_setting.cpp

@@ -49,9 +49,23 @@ bool CYaSetting::Init_sys_setting()
 			D_GetValue(m_sys_setting.rear_end_t,"rear_end_time",1,"")
 			D_GetValue(m_sys_setting.geofault_warn_dis,"geofault_warn",1,"")
 #undef D_GetValue
-		}
-		log_info("init_setting:rear_end_d:%f,t:%ld,person:%u,v:%u,tp:%u,tv:%u,s:%f",m_sys_setting.rear_end_d,m_sys_setting.rear_end_t,
-					m_sys_setting.over_count_person,m_sys_setting.over_count_vehicle,m_sys_setting.over_time_person,m_sys_setting.over_time_vehicle,m_sys_setting.over_speed);
+
+            if(strVal == "anti_collision"){
+                val = "";
+                DBRes.GetField("value", val, Error);
+                log_info("init_setting: anti_collision:%s", val.c_str());
+                m_sys_setting.init_anti_coll_value(val);
+            }
+        }
+        log_info("init_setting:rear_end_d:%f, rear_end_t:%ld, over_count_person:%u, over_count_vehicle:%u, over_time_person:%u, over_time_vehicle:%u, over_speed:%f",
+                    m_sys_setting.rear_end_d,
+                    m_sys_setting.rear_end_t,
+					m_sys_setting.over_count_person,
+                    m_sys_setting.over_count_vehicle,
+                    m_sys_setting.over_time_person,
+                    m_sys_setting.over_time_vehicle,
+                    m_sys_setting.over_speed
+                    );
 	}
 
     return true;

+ 25 - 3
ya_setting.h

@@ -3,6 +3,8 @@
 
 #include <time.h>
 #include <map>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/classification.hpp>
 #include "common_tool.h"
 #include "service_position.h"
 
@@ -26,6 +28,8 @@ struct  SSys_setting // system_limit_setting
 	time_t rear_end_t;
 	double geofault_warn_dis;
     std::string rav_disable;
+    std::map<int, float> mp_anti_collision;
+
     SSys_setting()
     {
         init();
@@ -34,9 +38,9 @@ struct  SSys_setting // system_limit_setting
     {
         bool f = false;
         std::string cardid=tool_other::type_id_to_str(type,id);
-       if(rav_disable.find(cardid) != std::string::npos) 
-         f=true;
-       return f;
+        if(rav_disable.find(cardid) != std::string::npos) 
+            f=true;
+        return f;
     }
     void init()
     {
@@ -54,6 +58,24 @@ struct  SSys_setting // system_limit_setting
         rear_end_t = 0;
         geofault_warn_dis=50; 
     }
+
+    void init_anti_coll_value(const std::string& ctx)
+    {
+        std::string c = ctx;
+        std::vector<std::string> vt;
+        boost::split(vt, c, boost::is_any_of(","));
+
+        for(size_t i = 0;i < vt.size(); ++i)
+        {
+            mp_anti_collision.insert(std::make_pair(i, atof(vt[i].c_str())));
+        }
+    }
+
+    bool del_anti_coll_value()
+    {
+        mp_anti_collision.clear();
+        return mp_anti_collision.empty();
+    }
 };
 
 class CYaSetting