|
@@ -16,6 +16,12 @@
|
|
|
#include "card.h"
|
|
|
#include "area.h"
|
|
|
#include "event.h"
|
|
|
+#include <fstream>
|
|
|
+#include <unistd.h>
|
|
|
+#include <sys/stat.h>
|
|
|
+
|
|
|
+#include <boost/algorithm/string/split.hpp>
|
|
|
+#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
#include <rapidjson/writer.h>
|
|
|
#include <rapidjson/stringbuffer.h>
|
|
@@ -137,21 +143,39 @@ struct card_sensor_mgr
|
|
|
struct staffer_num_business
|
|
|
{
|
|
|
void record_staffer_num();
|
|
|
- void fetch_add(bool f)
|
|
|
+
|
|
|
+ void fetch_add(bool bDisplay,bool bAttendance = true)
|
|
|
{
|
|
|
- if(f)
|
|
|
+ if(bDisplay && bAttendance) {
|
|
|
m_staff_num++;
|
|
|
+ }
|
|
|
+ if (bDisplay){
|
|
|
+ m_staff_show_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_show_num() const { return m_staff_show_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;
|
|
|
+ m_staff_show_num = 0;
|
|
|
+ }
|
|
|
+ // 井下考勤并且要显示的人数
|
|
|
+ std::atomic<uint32_t> m_staff_num;
|
|
|
+ // 井下总人数
|
|
|
+ std::atomic<uint32_t> m_staff_num_real;
|
|
|
+ // 井下显示人数
|
|
|
+ std::atomic<uint32_t> m_staff_show_num;
|
|
|
+ // 通知web最后时间
|
|
|
std::time_t m_record_staffer_timeval;
|
|
|
};
|
|
|
|
|
@@ -255,14 +279,18 @@ mine_business* mine_business::inst()
|
|
|
}
|
|
|
void mine_business::run_business()
|
|
|
{
|
|
|
+ //公告牌显示井下人数
|
|
|
+ show_bulletin_board();
|
|
|
+
|
|
|
record_staffer_num();
|
|
|
handle_reverse_alarm();
|
|
|
handle_rear_end();
|
|
|
}
|
|
|
-void mine_business::fetch_add(bool f)
|
|
|
+void mine_business::fetch_add(bool bDisplay,bool bAttendance/* = true*/)
|
|
|
{
|
|
|
- m_staffer_num_ptr->fetch_add(f);
|
|
|
+ m_staffer_num_ptr->fetch_add(bDisplay,bAttendance);
|
|
|
}
|
|
|
+
|
|
|
void mine_business::record_staffer_num()
|
|
|
{
|
|
|
m_staffer_num_ptr->record_staffer_num();
|
|
@@ -297,6 +325,63 @@ void mine_business::clear_vehicle()
|
|
|
{
|
|
|
m_rear_ended_ptr->clear();
|
|
|
}
|
|
|
+
|
|
|
+void mine_business::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 += "/";
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//公告牌显示--当前井下人数: 100 人
|
|
|
+void mine_business::show_bulletin_board()
|
|
|
+{
|
|
|
+ std::time_t t = time(NULL);
|
|
|
+ if (m_lastshow_bulletin_time == 0)
|
|
|
+ {
|
|
|
+ m_lastshow_bulletin_time = t;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (t > m_lastshow_bulletin_time && t - m_lastshow_bulletin_time > CYaSetting::g_bulletin_board_time )
|
|
|
+ {
|
|
|
+ //把当前文件写到文件中
|
|
|
+ m_lastshow_bulletin_time = t;
|
|
|
+ uint32_t num = m_staffer_num_ptr->get_staff_show_num();
|
|
|
+ std::string path = CYaSetting::g_bulletin_board_path;
|
|
|
+ static bool g_bCreatePath = false;
|
|
|
+ if (!g_bCreatePath)
|
|
|
+ {
|
|
|
+ CreateDirectoryEx(path); //创建目录
|
|
|
+ g_bCreatePath = true;
|
|
|
+ }
|
|
|
+ path += "/" + CYaSetting::g_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());
|
|
|
+ }
|
|
|
+}
|
|
|
///////staffer_num_business
|
|
|
/**********************************
|
|
|
//每两分钟把人员数量入库。
|