Browse Source

Merge branch 'master' of chensongchao/ya-serv into master

liheting 5 years ago
parent
commit
1aced25fff

+ 1 - 1
Makefile.am

@@ -22,7 +22,7 @@ SRC_MAIN= ant.cpp area.cpp base64.cpp bindmorecard.cpp mine_business.cpp card_ar
 		  landmark.cpp line_fit.cpp  message.cpp message_file.cpp mine.cpp \
 		  net-service.cpp point.cpp  special_area.cpp tdoa_sync.cpp visit.cpp \
 		  web-client.cpp worker.cpp event.cpp znet.cpp ya_setting.cpp area_business.cpp\
-		  forbid_staff_down_mine.cpp
+		  forbid_staff_down_mine.cpp bulletin_broad_show.cpp
 
 AM_SOURCES=$(SRC_MONKEYCAR) $(SRC_MODULE_SERVICE) $(SRC_MAIN) $(SRC_MAIN_EVENT)
 

+ 118 - 0
bulletin_broad_show.cpp

@@ -0,0 +1,118 @@
+//
+// Created by songchao.chen on 2019/6/26.
+//
+
+#include "bulletin_broad_show.h"
+#include "mine_business.h"
+#include <config_file.h>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string.hpp>
+#include <fstream>
+#include <unistd.h>
+#include <sys/stat.h>
+#include "log.h"
+#include <tool_time.h>
+
+bulletin_broad_show::bulletin_broad_show()
+{
+
+}
+bulletin_broad_show* bulletin_broad_show::inst()
+{
+    static bulletin_broad_show mb;
+    return &mb;
+}
+
+void bulletin_broad_show::OnInit(config_file * config)
+{
+    if (config == nullptr)
+    {
+        return;
+    }
+    //公告牌显示设置
+    m_bulletin_board_time = config->get("bulletinboard.showtime",1*60);
+    std::string tmpSz = config->get("bulletinboard.show_filepath","../log/bulletin");
+    set_bulletin_board_path(tmpSz);
+    m_bulletin_board_file_name = config->get("bulletinboard.show_filename","bulletin.txt");
+}
+
+void bulletin_broad_show::CreateDirectoryEx(const std::string & sPathName )
+{
+    std::vector<std::string> vecSegTag;
+    boost::split(vecSegTag, sPathName, boost::is_any_of("/"));
+    if (vecSegTag.size() == 1)  //数据发生错误
+    {
+        return;
+    }
+    std::string curPath = "";
+    for  (int i = 0 ; i < (int)vecSegTag.size() ; i++)
+    {
+        curPath += vecSegTag[i];
+        if(vecSegTag[i].length() > 1 && vecSegTag[i][0] != '.' )
+        {
+            int a = access(curPath.c_str(), F_OK);
+            if(a == -1)
+            {
+                mkdir(curPath.c_str(),0755);
+            }
+        }
+        curPath += "/";
+    }
+}
+
+void bulletin_broad_show::run_bulletin_board()
+{
+    uint32_t t = tool_time::now_to_seconds();
+    if (m_lastshow_bulletin_time == 0)
+    {
+        m_lastshow_bulletin_time = t;
+        return;
+    }
+    if (t > m_lastshow_bulletin_time && t - m_lastshow_bulletin_time > m_bulletin_board_time )
+    {
+        //把当前文件写到文件中
+        m_lastshow_bulletin_time = t;
+        uint32_t num = mine_business::inst()->get_mine_display_staff_num();
+        std::string path = m_bulletin_board_path;
+        static bool g_bCreatePath = false;
+        if (!g_bCreatePath)
+        {
+            CreateDirectoryEx(path); //创建目录
+            g_bCreatePath = true;
+        }
+        path += "/" + m_bulletin_board_file_name;
+        std::ofstream  f1(path.c_str());//打开文件用于写,若文件不存在就创建它
+        if(!f1.is_open()) {
+            return;//打开文件失败则结束运行
+        }
+        std::string szText = "井下当前总人数: " + std::to_string(num) + "人";
+        f1 << szText << std::endl;
+        f1.close(); //关闭文件
+        log_info("show_bulletin_board : %s" ,szText.c_str());
+    }
+}
+
+void bulletin_broad_show::set_bulletin_board_path(std::string & path)
+{
+    if (path.length() == 0)
+    {
+        return;
+    }
+    int count = 0;
+    for(int i = path.length() - 1 ; i > 0 ;i--)
+    {
+        if ( path[i] == '/')
+        {
+            count++;
+        }
+        else
+        {
+            break;
+        }
+    }
+    m_bulletin_board_path = path;
+    if (count > 0)
+    {
+        m_bulletin_board_path = path.substr(0,path.length() - count);
+    }
+}

+ 39 - 0
bulletin_broad_show.h

@@ -0,0 +1,39 @@
+//
+// Created by songchao.chen on 2019/6/26.
+// 公告牌显示
+//
+
+#ifndef WORKSPACE_BULLETIN_BROAD_SHOW_H
+#define WORKSPACE_BULLETIN_BROAD_SHOW_H
+
+#include <string>
+
+struct config_file;
+struct bulletin_broad_show
+{
+private:
+    bulletin_broad_show();
+public:
+    bulletin_broad_show(const bulletin_broad_show&)=delete;
+    bulletin_broad_show & operator=(const bulletin_broad_show&)=delete;
+    static bulletin_broad_show *inst();
+
+    void OnInit(config_file * config);
+    //公告牌显示
+    void run_bulletin_board();
+private:
+    void CreateDirectoryEx(const std::string & sPathName );
+    void set_bulletin_board_path(std::string & path);
+
+    //公告牌显示--当前井下人数: 100 人
+    uint32_t m_lastshow_bulletin_time = 0;
+    //公告牌显示-时间间隔
+    uint32_t m_bulletin_board_time = 0 ;
+    // 公告牌显示内容文件的目录
+    std::string m_bulletin_board_path = "";
+    // 公告牌显示内容文件名
+    std::string m_bulletin_board_file_name = "";
+};
+
+
+#endif //WORKSPACE_BULLETIN_BROAD_SHOW_H

+ 4 - 2
card_person.cpp

@@ -240,8 +240,10 @@ point person::getSmoothPoint(uint64_t& t)
 }
 void person::get_card(bool f)
 {
-    if(!m_mine_tool->m_is_attendance)
-		return;
+	if (!m_mine_tool->m_is_attendance)
+	{
+		return ;
+	}
 	mine_business::inst()->fetch_add(m_display);
 }
 

+ 1 - 1
forbid_staff_down_mine.cpp

@@ -16,7 +16,7 @@ void forbid_staff_down_mine::init_forbid_staff(int id /* = -1*/,int etype)
     int nCount = DBRes.GetRecordCount( Error );
     if (nCount < 1)
     {
-        log_error("增加或修改失败,数据库中找不到: sql=%s", sql.c_str());
+        log_info("增加或修改失败,数据库中没有记录: sql=%s", sql.c_str());
         return ;
     }
     while ( DBRes.GetNextRecod(Error) )

+ 5 - 1
main.cpp

@@ -18,10 +18,10 @@
 #include <config_file.h>
 #include "three_rates.h"
 #include "mine_business.h"
-#include "main_test.h"
 #include "ya_setting.h"
 #include "websocket/web_connect.h"
 #include "forbid_staff_down_mine.h"
+#include "bulletin_broad_show.h"
 
 config_file config;
 void handlereader(uint32_t readerid,bool duration,uint32_t t)
@@ -72,6 +72,8 @@ struct Init_Setting
             log_warn("连接webServer[%s] 失败!",url.c_str());
         }
 		CYaSetting::Init_sys_setting();
+        bulletin_broad_show::inst()->OnInit(&config);
+
         sit_list::instance()->load_from_db();
         card_list::instance()->init_card_from_db();
         area_list::instance()->init_from_db();
@@ -182,6 +184,7 @@ int main(int argc ,char * argv[])
     log_init("../etc/log.ini");
     if(config.open("../etc/config.ini"))
         return -1;
+
     Init_Setting is;
     is.init();
 
@@ -194,6 +197,7 @@ int main(int argc ,char * argv[])
 
     log_info("service_handle::instance(&mh)->run(%d)",port);
     std_info("service_handle::instance(&mh)->run(%d)",port);
+
     service_handle::instance(&mh)->run(port);
     
     sDBConnPool.Close();

+ 0 - 86
main_test.h

@@ -1,86 +0,0 @@
-#pragma once 
-
-#include "db_api/CDBSingletonDefine.h"
-#include"module_service/module_mgr.h"
-
-void test_find_path(const point&p1,const point&p2)
-{
-	printf("\nfind-path:  from=(%.3lf,%.3lf),to=(%.3lf,%.3lf)\n",p1.x,p1.y,p2.x,p2.y);
-	std::vector<point> rc=card_path::inst().find_path(p1,p2);
-	for(uint32_t i=0;i<rc.size();i++)
-		printf("x=%.3lf,y=%.3lf\n",rc[i].x,rc[i].y);
-}
-
-struct test_Sa{
-    static void test_savedata2db(void * p)
-    {
-        while(true)
-        {
-            std::string sql = "CALL add_att_staff(0010000002323, 2323, '2018-12-14 14:00:14', '2018-12-14 14:00:14', 0, 0, 0.000);";
-            sDBConnPool.PushAsync(sql.c_str());
-            //boost::this_thread::sleep( boost::posix_time::microseconds( 10000 ) );
-            usleep(1000*1000);
-        }
-    }
-
-    static void test_query(void *p)
-    {
-        std::string sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
-                            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 \
-                            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 \
-                            LEFT JOIN dat_dept d ON ve.dept_id = d.dept_id \
-                            LEFT JOIN dat_group g ON ve.group_id = g.group_id \
-                            LEFT JOIN dat_vehicle_type vt ON v.vehicle_type_id = vt.vehicle_type_id \
-                            LEFT JOIN dat_vehicle_category vc ON vc.vehicle_category_id = vt.vehicle_category_id \
-                            WHERE c.state_id = 0";
-
-        std::string Error;
-        YADB::CDBResultSet DBRes;
-        while(true)
-        {
-            if (!sDBConnPool.Query(sql.c_str(),DBRes,Error))
-            {
-                printf(" Error = %s \n",Error.c_str());
-            }
-            usleep(10);
-        }
-    }
-
-    static void Test_JsonDataSend(void * p)
-    {
-        std::string text = "";
-        FILE * pfile = fopen("message_error.json","r");
-        if ( NULL != pfile)
-        {
-            
-            char p[10240] = {0};
-            while(!feof(pfile))
-            {
-                memset(p,0,sizeof(p));
-                fread(p,1,sizeof(p) - 1,pfile);
-                text += std::string(p);
-            }
-            fclose(pfile); 
-        }
-        int count = 0;
-        while(true)
-        {
-            swsClientMgr.send(JSON_CMD_VALUE_PUSH,text);
-            usleep(1000*1000*2);
-            printf("WSClient Send DataLen=%d count=%d \n",(int)text.length(),count++);
-        }
-    }
-};
-
-
-void test_createthread()
-{
-    for (int i = 1 ; i < 1 ; i++)
-    {
-        new  std::thread( std::bind( &test_Sa::Test_JsonDataSend, &i ) );
-    }
-}

+ 25 - 8
mine_business.cpp

@@ -137,21 +137,32 @@ struct card_sensor_mgr
 struct staffer_num_business
 {
 	void record_staffer_num();
-	void fetch_add(bool f)
+
+	void fetch_add(bool bDisplay)
     {
-        if(f)
+        if(bDisplay) {
             m_staff_num++;
+        }
 		m_staff_num_real++;
-        
     }
 	staffer_num_business()
 	{
         reset();
 		m_record_staffer_timeval = 0;
 	}
-	private:
-	void reset(){m_staff_num=0;m_staff_num_real=0;}
-	std::atomic<uint32_t> m_staff_num,m_staff_num_real;
+    uint32_t get_staff_num() const { return m_staff_num;}
+    uint32_t get_staff_real_num() const { return m_staff_num_real;}
+
+private:
+	void reset(){
+	    m_staff_num=0;
+	    m_staff_num_real=0;
+	}
+	// 井下考勤并且要显示的人数
+	std::atomic<uint32_t> m_staff_num;
+	// 井下总人数
+    std::atomic<uint32_t> m_staff_num_real;
+    // 通知web最后时间
 	std::time_t m_record_staffer_timeval;
 };
 
@@ -259,10 +270,11 @@ void mine_business::run_business()
     handle_reverse_alarm();
     handle_rear_end();
 }
-void mine_business::fetch_add(bool f)
+void mine_business::fetch_add(bool bDisplay)
 {
-    m_staffer_num_ptr->fetch_add(f);
+    m_staffer_num_ptr->fetch_add(bDisplay);
 }
+
 void mine_business::record_staffer_num()
 {
     m_staffer_num_ptr->record_staffer_num();
@@ -297,6 +309,11 @@ void mine_business::clear_vehicle()
 {
     m_rear_ended_ptr->clear();
 }
+
+uint32_t mine_business::get_mine_display_staff_num()
+{
+    return m_staffer_num_ptr->get_staff_num();
+}
 ///////staffer_num_business
 /**********************************
 //每两分钟把人员数量入库。

+ 5 - 3
mine_business.h

@@ -14,15 +14,17 @@ struct mine_business
 	mine_business & operator=(const mine_business&)=delete;
 	static mine_business *inst();
 	void run_business();
-//人员数量曲线功
+	//人员数量曲线功
 	void fetch_add(bool);
-//天线反向功能
+	//天线反向功能
 	void load();
 	void make_reverse_condition(uint64_t type,uint32_t id,int32_t antid,uint32_t ct,uint64_t tof,uint32_t sid);
-//车辆防追尾告警
+	//车辆防追尾告警
 	void put(const std::shared_ptr<card_location_base>&);
 	void make_arg(uint64_t cid,const point &p,uint64_t t);
 	void clear_vehicle();
+
+	uint32_t get_mine_display_staff_num();
 private:
 	mine_business();
 	void handle_reverse_alarm();

+ 1 - 1
module_service/module_meta_date_changed.cpp

@@ -76,7 +76,7 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
             int id = std::stoi(szParam);
             deal_call_edit_path(id, edit_type_id);
         }
-        else if(JSON_KEY_NAME_MAP == name)
+        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);

+ 1 - 0
websocket/constdef.h

@@ -51,6 +51,7 @@
 #define JSON_KEY_OP_TYPE_DELETE "DELETE"
 
 #define JSON_KEY_NAME "name"
+#define JSON_KEY_NAME_MAP_GIS "map_gis"
 #define JSON_KEY_NAME_MAP "map"
 #define JSON_KEY_NAME_AREA "area"
 #define JSON_KEY_NAME_PATH "reader_path_tof_n"

+ 2 - 0
worker.cpp

@@ -17,6 +17,7 @@
 #include "area.h"
 #include "clock.h"
 #include "mine_business.h"
+#include "bulletin_broad_show.h"
 
 loop_thread::loop_thread ()
 {
@@ -104,6 +105,7 @@ struct timer_worker_thread: loop_thread
 			mine_business::inst()->clear_vehicle();
 		}
 		card_list::instance()->accept(clv);
+		bulletin_broad_show::inst()->run_bulletin_board();
 		mine_business::inst()->run_business();
 
 		log_info("timer_worker_thread use time:%ldus", clock.count_us());