Browse Source

V0.6
1、打包成了docker镜像,基本可以跑起来了

Apple 1 tháng trước cách đây
mục cha
commit
72519bcf4c

+ 1 - 1
External

@@ -1 +1 @@
-Subproject commit 4dce7891c269f3967853f778a57726939eacd63a
+Subproject commit 21e6f4248c4bd9dd935b123e8295ec908da52677

+ 7 - 2
SQL/SecurePlay.sqlbook

@@ -101,7 +101,7 @@ ON "tRoomCamer"."RoomId" = "tRoomInfo"."PKID";
 INSERT INTO "tRoomCamer" ("RoomId","CamerId")
 VALUES (:roomID, :camerID);
 -- SQLBook: Code
--- Active: 1746948908373@@192.1.3.105@1433@EQM_BJ
+-- Active: 1725354130110@@192.1.3.105@1433@EQM_BJ
 #报警信息表
 SELECT *
 FROM "tAlarmInfo";
@@ -168,11 +168,16 @@ SET "FaceIdList" = '', "FaceNameList" = '', "ActionDes" = @actionDes, "CreateTim
 WHERE "PKID" = @pkid AND "OnWork" = @onWork;
 
 
-#结束人员计数的报警,通过频率ID和应用ID
+#结束人员计数的报警,通过频率ID和应用ID,结束时间等于2000-01-01 00:00:00的报警
 UPDATE "tAlarmInfo"
 SET "EndTime" = GetDate()
 WHERE "chnID" = @channelID AND "Appid" = @appID;
 
+#结束人员计数的报警,通过频率ID和应用ID,结束时间等于2000-01-01 00:00:00的报警
+UPDATE "tAlarmInfo"
+SET "EndTime" = GetDate()
+WHERE "chnID" = :channelID AND "Appid" = :appID AND "EndTime" = '2000-01-01 00:00:00';
+
 
 #根据开始时间删除一年前的信息
 DELETE FROM "tAlarmInfo"

+ 2 - 2
SecurePlayAuxServer/Application/FuncBase.cpp

@@ -56,7 +56,7 @@ void FuncBase::thread_task()
         {
             for(auto& act : cam.second)
             {
-                SPDLOG_LOGGER_DEBUG(m_logger, "房间ID: {}, 摄像机ID: {}, 算法ID: {}", room.RoomID, cam.first, act);
+                SPDLOG_LOGGER_INFO(m_logger, "房间ID: {}, 摄像机ID: {}, 算法ID: {}", room.RoomID, cam.first, act);
             }
         }
     }
@@ -260,7 +260,7 @@ bool FuncBase::isEventTimeVaild(const QDateTime& eventTime)
 {
     /* 判断时间差 */
     qint64 diff = m_nowTime.toSecsSinceEpoch() - eventTime.toSecsSinceEpoch();
-    if(diff > 600)
+    if(diff > GVariable.EventTimeValid)
     {
         return false;
     }

+ 1 - 1
SecurePlayAuxServer/Application/FuncIllegalInvasion.cpp

@@ -349,7 +349,7 @@ void FuncIllegalInvasion::task()
                 /* 没有报警,检查是否是报警结束了,是否符合写入数据库的条件 */
                 QDateTime currTime = QDateTime::currentDateTime();
                 int secs = currTime.toSecsSinceEpoch() - pIll->FirstTime.toSecsSinceEpoch();
-                if(secs >= GVariable.AppBadMan_Time)
+                if(secs >= GVariable.AppIllInvasion_Time)
                 {
                     if(!pIll->strImageInfo.empty())
                     {

+ 3 - 0
SecurePlayAuxServer/Application/FuncOnAndOffWork.cpp

@@ -560,6 +560,7 @@ void FuncOnAndOffWork::onWorkProcess(RoomOnWorkInfo* pRoomOnWorkInfo, std::pair<
             }
             alarmInfo.listBbox = getCameraNameList(roomInfo.second.mapCameraAction);    /* 直播间摄像机列表 */
             alarmInfo.ImageInfo = pRoomOnWorkInfo->strImagePath;
+            alarmInfo.StartTime = pRoomOnWorkInfo->StartTime;
             alarmInfo.EventTime = pRoomOnWorkInfo->StartTime;
             alarmInfo.ActionID = "";
             alarmInfo.Is_OnWork = true;
@@ -686,6 +687,7 @@ void FuncOnAndOffWork::offWorkProcess(RoomOnWorkInfo* pRoomOnWorkInfo, std::pair
             }
             alarmInfo.listBbox = getCameraNameList(roomInfo.second.mapCameraAction);    /* 直播间摄像机列表 */
             alarmInfo.ImageInfo = pRoomOnWorkInfo->strImagePath;
+            alarmInfo.StartTime = pRoomOnWorkInfo->StartTime;
             alarmInfo.EventTime = pRoomOnWorkInfo->StartTime;
             alarmInfo.ActionID = "";
             alarmInfo.Is_OnWork = false;
@@ -741,6 +743,7 @@ void FuncOnAndOffWork::offWorkProcess(RoomOnWorkInfo* pRoomOnWorkInfo, std::pair
                 }
                 alarmInfo.listBbox = getCameraNameList(roomInfo.second.mapCameraAction);    /* 直播间摄像机列表 */
                 alarmInfo.ImageInfo = pRoomOnWorkInfo->strImagePath;
+                alarmInfo.StartTime = pRoomOnWorkInfo->StartTime;
                 alarmInfo.EventTime = pRoomOnWorkInfo->listLeaveTime.front();
                 alarmInfo.ActionID = "";
                 alarmInfo.Is_OnWork = false;

+ 0 - 0
SecurePlayAuxServer/Application/FuncPersonOnWork.cpp → SecurePlayAuxServer/Application/FuncPersonOnWork.cpp__


+ 0 - 0
SecurePlayAuxServer/Application/FuncPersonOnWork.h → SecurePlayAuxServer/Application/FuncPersonOnWork.h__


+ 36 - 12
SecurePlayAuxServer/Application/FuncRegionalPerson.cpp

@@ -88,6 +88,9 @@ RoomPeopleInfo::RoomPeopleInfo()
     RoomName = "";
     MaxNum = 0;
     imagePath = "";
+    StartTime = GVariable.nullTime;
+    EventTime = GVariable.nullTime;
+    listBbox.clear();
 }
 
 RoomPeopleInfo::RoomPeopleInfo(const RoomPeopleInfo& other)
@@ -97,6 +100,9 @@ RoomPeopleInfo::RoomPeopleInfo(const RoomPeopleInfo& other)
     RoomName = other.RoomName;
     MaxNum = other.MaxNum;
     imagePath = other.imagePath;
+    StartTime = other.StartTime;
+    EventTime = other.EventTime;
+    listBbox = other.listBbox;
 }
 
 RoomPeopleInfo& RoomPeopleInfo::operator=(const RoomPeopleInfo& other) 
@@ -107,6 +113,9 @@ RoomPeopleInfo& RoomPeopleInfo::operator=(const RoomPeopleInfo& other)
         RoomName = other.RoomName;
         MaxNum = other.MaxNum;
         imagePath = other.imagePath;
+        StartTime = other.StartTime;
+        EventTime = other.EventTime;
+        listBbox = other.listBbox;
     }
     return *this;
 }
@@ -182,6 +191,9 @@ void FuncRegionalPersonCount::task()
         SPDLOG_LOGGER_ERROR(m_logger, "{} 初始化数据接口失败", m_baseLog);
         return;
     }
+    /* 先结束之前未结束的报警 */
+    autoEndAlarm();
+    
     while (m_bRunning)
     {
         std::this_thread::sleep_for(std::chrono::milliseconds(GVariable.ThreadSleepMS()));
@@ -252,7 +264,7 @@ void FuncRegionalPersonCount::task()
             peopleInfo.RoomType = RoomInfo.RoomType;
             peopleInfo.RoomName = RoomInfo.strRoomName;
             /* 获取该房间内最大人数 */
-            getRoomMaxNum(RoomInfo.RoomID, peopleInfo.MaxNum, peopleInfo.imagePath);
+            getRoomMaxNum(RoomInfo.RoomID, peopleInfo);
 
             m_mapRoomPeople.insert(std::make_pair(RoomInfo.RoomID, peopleInfo));
         }
@@ -285,6 +297,9 @@ void FuncRegionalPersonCount::task()
         liveDicMaxNumInfo.MaxNum = liveDicMaxNum;
         liveDicMaxNumInfo.imagePath = strImagePath;
         liveDicMaxNumInfo.RoomName = "直播间+导播间";
+        liveDicMaxNumInfo.StartTime = m_nowTime;
+        liveDicMaxNumInfo.EventTime = m_nowTime;
+        /* 处理直播间+导播间人数最大值 */
         handleRoomMaxNum(liveDicMaxNumInfo);
         handleRoomMinNum(liveDicMaxNumInfo);
     }
@@ -403,7 +418,7 @@ void FuncRegionalPersonCount::autoEndAlarm()
     /* 判断报警是否已经结束,没有结束就结束报警 */
     if(m_mapAlarmBuffer.empty())
     {
-        SPDLOG_LOGGER_DEBUG(m_logger, "{} 报警已经结束", m_baseLog);
+        SPDLOG_LOGGER_INFO(m_logger, "{} 报警已经结束", m_baseLog);
         return;
     }
     /* 结束该频率人员计数的所有报警 */
@@ -419,23 +434,29 @@ void FuncRegionalPersonCount::autoEndAlarm()
 
 
 /* 取出一个房间内的最大人数 */
-bool FuncRegionalPersonCount::getRoomMaxNum(int roomID, int& maxNum, std::string& strImagePath)
+bool FuncRegionalPersonCount::getRoomMaxNum(int roomID, RoomPeopleInfo& roomInfo)
 {
-    strImagePath.clear();
+    roomInfo.imagePath.clear();
     for(auto it : m_listSrcAlarm.listAlarmInfo)
     {
         if(it->RoomID == roomID)
         {
             /* 取出最大人数 */
             int num = it->listBbox.size();
-            if(num > maxNum)
+            if(num > roomInfo.MaxNum)
             {
-                maxNum = num;
-                strImagePath = it->ImageInfo;
+                roomInfo.MaxNum = num;
+                roomInfo.imagePath = it->ImageInfo;
+                roomInfo.StartTime = it->StartTime;
+                roomInfo.EventTime = it->EventTime;
+                roomInfo.listBbox = it->listBbox;
             }
-            if(strImagePath.empty())
+            if(roomInfo.imagePath.empty())
             {
-                strImagePath = it->ImageInfo;
+                roomInfo.imagePath = it->ImageInfo;
+                roomInfo.StartTime = it->StartTime;
+                roomInfo.EventTime = it->EventTime;
+                roomInfo.listBbox = it->listBbox;
             }
         }
     }
@@ -538,8 +559,9 @@ void FuncRegionalPersonCount::handleRoomMaxNum(const RoomPeopleInfo& peopleInfo)
             alarmInfo.DeviceID = roomInfo.mapCameraAction.begin()->first;
             alarmInfo.ImageInfo = peopleInfo.imagePath;
             alarmInfo.ActionID = roomInfo.mapCameraAction.begin()->second.front();
-            alarmInfo.StartTime = m_nowTime;
-            alarmInfo.EventTime = m_nowTime;
+            alarmInfo.StartTime = peopleInfo.StartTime;
+            alarmInfo.EventTime = peopleInfo.EventTime;
+            alarmInfo.listBbox = peopleInfo.listBbox;
             alarmInfo.Is_Alarm = true;
             alarmInfo.ActionDes = fmt::format("{}人数为{},已超过最大人数{}限制", 
                                                 roomName, peopleInfo.MaxNum, maxNum);
@@ -700,7 +722,9 @@ void FuncRegionalPersonCount::handleRoomMinNum(const RoomPeopleInfo& peopleInfo)
                     alarmInfo.DeviceID = roomInfo.mapCameraAction.begin()->first;
                     alarmInfo.ImageInfo = peopleInfo.imagePath;
                     alarmInfo.ActionID = roomInfo.mapCameraAction.begin()->second.front();
-                    alarmInfo.EventTime = m_nowTime;
+                    alarmInfo.StartTime = peopleInfo.StartTime;
+                    alarmInfo.EventTime = peopleInfo.EventTime;
+                    alarmInfo.listBbox = peopleInfo.listBbox;
                     alarmInfo.Is_Alarm = true;
                     alarmInfo.ActionDes = fmt::format("{}人数为{},已低于最小人数{}限制", 
                                                         roomName, peopleInfo.MaxNum, minNum);

+ 5 - 1
SecurePlayAuxServer/Application/FuncRegionalPerson.h

@@ -57,6 +57,10 @@ struct RoomPeopleInfo
     int MaxNum;                 /* 最大人数 */
     std::string imagePath;      /* 图片路径 */
 
+    QDateTime StartTime;        /* 这一轮检测的检测开始时间 */
+    QDateTime EventTime;        /* 报警时间 */
+    std::list<std::string> listBbox;       /* Bbox列表,图片中的报警位置 */
+
     RoomPeopleInfo();
     RoomPeopleInfo(const RoomPeopleInfo& other);
     RoomPeopleInfo& operator=(const RoomPeopleInfo& other);
@@ -113,7 +117,7 @@ private:
     /* 自动结束报警 */
     void autoEndAlarm();
     /* 取出一个房间内的最大人数 */
-    bool getRoomMaxNum(int roomID, int& maxNum, std::string& strImagePath);
+    bool getRoomMaxNum(int roomID, RoomPeopleInfo& roomInfo);
 
     /* 处理房间内的人数最大值 */
     void handleRoomMaxNum(const RoomPeopleInfo& peopleInfo);

+ 55 - 31
SecurePlayAuxServer/GlobalInfo/GlobalConfig.cpp

@@ -3,6 +3,7 @@
 #include <QCoreApplication>
 
 #include "spdlog/spdlog.h"
+#include "LHLogInit.h"
 
 #include "GlobalVariable.h"
 
@@ -119,6 +120,16 @@ void GlobalConfig::initService()
     }
     printAppConfig();
 
+    /* 设置日志输出级别 */
+    if(GVariable.m_logDetail == 0)
+    {
+        changeLogLevel(ELogLevel::Log_Info);
+    }
+    else if(GVariable.m_logDetail == 1)
+    {
+        changeLogLevel(ELogLevel::Log_Debug);
+    }
+
     SPDLOG_INFO("========================================================");
 }
 
@@ -154,6 +165,11 @@ bool GlobalConfig::readBaseConfig(const QString& strConfigFile)
     m_superBrainAppSecret = settings.value("AppSecret", "").toString().toStdString();
     settings.endGroup();
 
+    /* 读取Docker相关的配置 */
+    settings.beginGroup("Docker");
+    m_listenPort = settings.value("TcpListenPort", 0).toInt();
+    settings.endGroup();
+
     return true;
 }
 
@@ -166,11 +182,13 @@ void GlobalConfig::printBaseConfig()
     SPDLOG_INFO("--------------------------------------------------------");
     SPDLOG_INFO("Redis IP:              {}", m_redisIP);
     SPDLOG_DEBUG("Redis Port:           {}", m_redisPort);
-    SPDLOG_DEBUG("Redis Password:       {}", m_redisPWD);
+    SPDLOG_TRACE("Redis Password:       {}", m_redisPWD);
     SPDLOG_INFO("--------------------------------------------------------");
     SPDLOG_INFO("SuperBrain URL:        {}", m_superBrainUrl);
-    SPDLOG_DEBUG("SuperBrain AppKey:    {}", m_superBrainAppKey);
-    SPDLOG_DEBUG("SuperBrain AppSecret: {}", m_superBrainAppSecret);
+    SPDLOG_TRACE("SuperBrain AppKey:    {}", m_superBrainAppKey);
+    SPDLOG_TRACE("SuperBrain AppSecret: {}", m_superBrainAppSecret);
+    SPDLOG_INFO("--------------------------------------------------------");
+    SPDLOG_INFO("TCP Listen Port:       {}", m_listenPort);
 }
 
 
@@ -204,11 +222,11 @@ bool GlobalConfig::readAlgorithmConfig(const QString& strConfigFile)
 /* 打印算法配置文件 */
 void GlobalConfig::printAlgorithmConfig()
 {
-    SPDLOG_DEBUG("========================================================");
-    SPDLOG_DEBUG("人脸识别算法ID:       {}", GVariable.ActFaceIdentify());
-    SPDLOG_DEBUG("人员计数算法ID:       {}", GVariable.ActPersonCount());
-    SPDLOG_DEBUG("玩手机算法ID:         {}", GVariable.ActPlayPhone());
-    SPDLOG_DEBUG("违禁品算法ID:         {}", GVariable.ActContraband());
+    SPDLOG_INFO("========================================================");
+    SPDLOG_INFO("人脸识别算法ID:       {}", GVariable.ActFaceIdentify());
+    SPDLOG_INFO("人员计数算法ID:       {}", GVariable.ActPersonCount());
+    SPDLOG_INFO("玩手机算法ID:         {}", GVariable.ActPlayPhone());
+    SPDLOG_INFO("违禁品算法ID:         {}", GVariable.ActContraband());
 }
 
 
@@ -225,21 +243,25 @@ bool GlobalConfig::readAppConfig(const QString& strConfigFile)
     settings.setIniCodec("UTF-8");
 
     settings.beginGroup("System");
+    GVariable.m_threadSleepMS = settings.value("FuncThreadSleep", 1000).toInt();        /* 任务线程休眠时间,单位是ms */
+    GVariable.CheckAppSet = settings.value("CkeckAppSetTime", 300).toInt();             /* 服务端多久检测一次配置 */
+    GVariable.m_logDetail = settings.value("LogDetail", 0).toInt();                     /* 详细日志级别,打印Debug日志,0表示不打印,1表示打印 */
 
-    GVariable.AppUpdateOnWorkTimeInterval_Time = settings.value("WorkOnInfoSecond", 600).toInt();   /* 更新在岗信息的时间间隔 */
-    GVariable.AppPeopleOnWork_Time = settings.value("APPPEPOLEONWORK", 300).toInt();                /* 离岗时间 */
-    GVariable.AppContraband_Time = settings.value("APPBADTHING", 50).toInt();                       /* 违禁物品出现的时间 */
-    GVariable.AppBadMan_Time = settings.value("APPBADMAN", 50).toInt();                             /* 非法入侵 */
-    GVariable.AppTired_Time = settings.value("APPTIRED", 50).toInt();                               /* 疲劳检测时间 */
-    GVariable.AppPeopleCount_LessTime = settings.value("APPPEPOLECONT", 50).toInt();                /* 人员聚集时间 */
-    GVariable.AppPlayPhone = settings.value("APPPLAYPHONE", 50).toInt();                            /* 玩手机识别 */
-    GVariable.AppMouse = settings.value("APPMOUSE", 50).toInt();                                    /* 手势识别 */
-    GVariable.AppMask = settings.value("APPMASK", 5).toInt();                                       /* 戴口罩识别 */
+    settings.endGroup();
 
-    GVariable.CheckSet = settings.value("CHECKSET", 300).toInt();                       /* 服务端多久检测一次配置 */
-    GVariable.EventTimeValid = settings.value("EventTimeValid", 300).toInt();           /* 事件时间有效期 */
+    settings.beginGroup("AppConfig");
 
-    GVariable.m_threadSleepMS = settings.value("FuncThreadSleep", 1000).toInt();        /* 任务线程休眠时间,单位是ms */
+    GVariable.AppUpdateOnWorkTimeInterval_Time = settings.value("UpdateWorkOnInfoSecond", 600).toInt();  /* 更新在岗信息的时间间隔 */
+    GVariable.AppLeaveOnWork_Time = settings.value("AppleLeaveWorkTime", 300).toInt();              /* 离岗报警时间 */
+    GVariable.AppContraband_Time = settings.value("AppContrabandTime", 50).toInt();                 /* 违禁物品出现的时间 */
+    GVariable.AppIllInvasion_Time = settings.value("AppIllegalInvasion", 50).toInt();               /* 非法入侵 */
+    GVariable.AppTired_Time = settings.value("AppTired", 50).toInt();                               /* 疲劳检测时间 */
+    GVariable.AppPeopleCount_LessTime = settings.value("AppPeopleCount", 50).toInt();               /* 人员聚集时间 */
+    GVariable.AppPlayPhone = settings.value("AppPlayPhone", 50).toInt();                            /* 玩手机识别 */
+    GVariable.AppMouse = settings.value("AppMouse", 50).toInt();                                    /* 手势识别 */
+    GVariable.AppMask = settings.value("AppNoMask", 5).toInt();                                     /* 戴口罩识别 */
+
+    GVariable.EventTimeValid = settings.value("EventTimeValid", 300).toInt();                       /* 检测事件时间有效期 */
 
     settings.endGroup();
 
@@ -251,18 +273,20 @@ bool GlobalConfig::readAppConfig(const QString& strConfigFile)
 void GlobalConfig::printAppConfig()
 {
     SPDLOG_INFO("========================================================");
-    SPDLOG_INFO("APPPEPOLEONWORK:   {}", GVariable.AppPeopleOnWork_Time);
-    SPDLOG_INFO("APPBADTHING:       {}", GVariable.AppContraband_Time);
-    SPDLOG_INFO("APPBADMAN:         {}", GVariable.AppBadMan_Time);
-    SPDLOG_INFO("APPTIRED:          {}", GVariable.AppTired_Time);
-    SPDLOG_INFO("APPPEOPLECONT:     {}", GVariable.AppPeopleCount_LessTime);
-    SPDLOG_INFO("APPPLAYPHONE:      {}", GVariable.AppPlayPhone);
-    SPDLOG_INFO("APPMOUSE:          {}", GVariable.AppMouse);
-    SPDLOG_INFO("APPMASK:           {}", GVariable.AppMask);
-    SPDLOG_INFO("CHECKSET:          {}", GVariable.CheckSet);
-    SPDLOG_INFO("EventTimeValid:    {}", GVariable.EventTimeValid);
+    SPDLOG_INFO("AppUpdateOnWorkTimeInterval:   {}", GVariable.AppUpdateOnWorkTimeInterval_Time);
+    SPDLOG_INFO("AppleLeaveWorkTime:            {}", GVariable.AppLeaveOnWork_Time);
+    SPDLOG_INFO("AppContrabandTime:             {}", GVariable.AppContraband_Time);
+    SPDLOG_INFO("AppIllegalInvasion:            {}", GVariable.AppIllInvasion_Time);
+    SPDLOG_INFO("AppTired:                      {}", GVariable.AppTired_Time);
+    SPDLOG_INFO("AppPeopleCount:                {}", GVariable.AppPeopleCount_LessTime);
+    SPDLOG_INFO("AppPlayPhone:                  {}", GVariable.AppPlayPhone);
+    SPDLOG_INFO("AppMouse:                      {}", GVariable.AppMouse);
+    SPDLOG_INFO("AppNoMask:                     {}", GVariable.AppMask);
+    SPDLOG_INFO("EventTimeValid:                {}", GVariable.EventTimeValid);
     SPDLOG_INFO("---------------------------------------------------------");
-    SPDLOG_INFO("FuncThreadSleep:   {}", GVariable.ThreadSleepMS());
+    SPDLOG_INFO("CkeckAppSetTime:               {}", GVariable.CheckAppSet);
+    SPDLOG_INFO("FuncThreadSleep:               {}", GVariable.ThreadSleepMS());
+    SPDLOG_INFO("LogDetail:                     {}", GVariable.m_logDetail);
 }
 
 /* 添加通道信息 */

+ 11 - 6
SecurePlayAuxServer/GlobalInfo/GlobalConfig.h

@@ -30,20 +30,20 @@ public:
     }
 
     int AppUpdateOnWorkTimeInterval_Time;   /* 更新在岗信息的时间间隔 */
-    int AppPeopleOnWork_Time;               /* 离岗时间 */
+    int AppLeaveOnWork_Time;                /* 离岗报警时间 */
     int AppContraband_Time;                 /* 违禁物品出现的时间 */
-    int AppBadMan_Time;                     /* 非法入侵超时时间 */
+    int AppIllInvasion_Time;                /* 非法入侵超时时间 */
     int AppTired_Time;                      /* 疲劳检测时间 */
     int AppPeopleCount_LessTime;            /* 区域人员统计少于多长时间会取消报警 */
     int AppPlayPhone;                       /* 玩手机识别 */
     int AppMouse;                           /* 老鼠识别 */
     int AppMask;                            /* 戴口罩识别 */
 
-    int CheckSet;                           /* 服务端多久检测一次配置 */
+    int CheckAppSet;                        /* 服务端多久检测一次配置 */
     int EventTimeValid;                     /* 事件时间有效期 */
 
     
-    const int CheckDeviceTime = 20;         /* 从超脑平台检测设备的时间间隔,单位是秒 */
+    const int CheckDeviceTime = 60;         /* 从超脑平台检测设备的时间间隔,单位是秒 */
 
     
 
@@ -82,11 +82,13 @@ public:
     // std::string getFullActionID(const std::string& actionID);
 
     /* 设置一个空时间,设置这个时间,在数据库里都是空 */
-    const QDateTime nullTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
+    const std::string nullTimeStr = "2000-01-01 00:00:00";
+    const QDateTime nullTime = QDateTime::fromString(nullTimeStr.c_str(), "yyyy-MM-dd hh:mm:ss");
 
 private:
 
     int m_threadSleepMS = 1000;             /* 线程休眠时间,单位是ms */
+    int m_logDetail = 0;                    /* 详细日志级别,打印Debug日志,0表示不打印,1表示打印 */
 
     /* 算法ID,通过这个识别从超脑平台获取到的算法,这个算法ID是全的,带有后缀的 */
     /* 人脸识别算法ID */
@@ -174,7 +176,8 @@ public:
     std::string superBrainAppKey() { return m_superBrainAppKey; }
     std::string superBrainAppSecret() { return m_superBrainAppSecret; }
 
-    
+    /* 获取TCP监听端口 */
+    int listenPort() { return m_listenPort; }
 
 public:
     /* 添加通道信息 */
@@ -211,6 +214,8 @@ private:
     std::string m_superBrainUrl;                          /* 超脑的URL */
     std::string m_superBrainAppKey;                       /* 超脑的AppKey */
     std::string m_superBrainAppSecret;                    /* 超脑的AppSecret */
+
+    int m_listenPort;                                   /* TCP监听端口 */
  };
 
 

+ 7 - 6
SecurePlayAuxServer/GlobalInfo/GlobalVariable.cpp

@@ -1,6 +1,7 @@
 #include "GlobalVariable.h"
 
 #include "spdlog/spdlog.h"
+#include "GlobalConfig.h"
 
 // #include "FuncBase.h"
 
@@ -142,9 +143,9 @@ AlarmInfo::AlarmInfo()
     ChannelID = 0;
     State = 0;
     OnWork = 0;
-    StartTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
-    EndTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
-    EventTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
+    StartTime = GVariable.nullTime;
+    EventTime = GVariable.nullTime;
+    EndTime = QDateTime();
     // PicUrl = "";
     ImageInfo = "";
     // AppID = "";
@@ -229,9 +230,9 @@ void AlarmInfo::reInit()
     ChannelID = 0;
     State = 0;
     OnWork = 0;
-    StartTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
-    EndTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
-    EventTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
+    StartTime = GVariable.nullTime;
+    EventTime = GVariable.nullTime;
+    EndTime = QDateTime();
     // PicUrl = "";
     ImageInfo = "";
     // AppID = "";

+ 3 - 3
SecurePlayAuxServer/GlobalInfo/UniversalFunc.cpp

@@ -271,14 +271,14 @@ QDateTime strToDateTime(const std::string& strTime)
 {
     /* 将字符串转换成QDateTime,带有小数点 */
     QDateTime eventTime = QDateTime::fromString(QString::fromStdString(strTime), "yyyy-MM-dd hh:mm:ss.zzz");
-    if(eventTime.isNull())
+    if(eventTime.isNull() || !eventTime.isValid())
     {
         /* 尝试不带小数点的格式 */
         eventTime = QDateTime::fromString(QString::fromStdString(strTime), "yyyy-MM-dd hh:mm:ss");
-        if(eventTime.isNull())
+        if(eventTime.isNull() || !eventTime.isValid())
         {
             SPDLOG_WARN("时间格式错误:{}", strTime);
-            return QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
+            return GVariable.nullTime;
         }
     }
     return eventTime;

+ 31 - 1
SecurePlayAuxServer/SPAServer.cpp

@@ -14,6 +14,7 @@
 #include "GlobalFuncThread.h"
 
 #include <QCoreApplication>
+#include <QTcpSocket>
 
 
 SPAServer::SPAServer()
@@ -42,6 +43,14 @@ SPAServer::~SPAServer()
 /* 启动服务 */
 void SPAServer::startServer()
 {
+    /* 获取TCP监听的端口,创建TCP连接 */
+    short Port = GConfig.listenPort();
+
+    /* 连接信号和槽 */
+    m_tcpServer.listen(QHostAddress::Any, Port);
+    connect(&m_tcpServer, SIGNAL(newConnection()), this, SLOT(do_newConnection()));
+
+
     /* 设置全局运行标志位 */
     GThreadInfo.setRunning(true);
     /* 添加获取基础信息的线程 */
@@ -59,6 +68,24 @@ void SPAServer::startServer()
     
 }
 
+/* 接收到新的TCP连接 */
+void SPAServer::do_newConnection()
+{
+    // SPDLOG_LOGGER_INFO(m_logger, "接收到一个新的TCP连接");
+    QTcpSocket* pTcpSocket = m_tcpServer.nextPendingConnection();
+    if(pTcpSocket == nullptr)
+    {
+        SPDLOG_LOGGER_ERROR(m_logger, "TCP Socket is nullptr");
+        return;
+    }
+    // SPDLOG_LOGGER_INFO(m_logger, "接收到一个TCP连接,IP:{}, Port:{}", pTcpSocket->peerAddress().toString().toStdString(), pTcpSocket->peerPort());
+    // connect(pTcpSocket, SIGNAL(readyRead()), this, SLOT(do_recvTCPData()));
+    /* 删掉连接 */
+    pTcpSocket->close();
+    pTcpSocket->deleteLater();
+}
+
+
 
 /**
  * @brief 从基础平台获取算法信息和设备信息的线程函数
@@ -465,6 +492,7 @@ void SPAServer::compareDeviceAlgorithmInfo(const std::vector<DeviceInfo>& vecNew
             就会创建新的ActionInfo,那么RunState的状态是INIT,需要开启新的线程
             如果刷新完成后,算法对应的摄像机列表为空,那么对应的线程就会停止运行,将RunState设置为STOP,本线程的下一轮
             循环就会删除这个ActionInfo
+        4、在这里定期删除一年前的报警数据
 
  */
 void SPAServer::threadDistribution()
@@ -551,6 +579,8 @@ void SPAServer::threadDistribution()
                 }
                 CPPTP.add_task(&FuncBase::thread_task, pFunc);
                 m_listFuncBase.push_back(pFunc);
+                /* 睡眠50ms,让这个线程初始化完成 */
+                std::this_thread::sleep_for(std::chrono::milliseconds(50));
             }
         }
         
@@ -560,7 +590,7 @@ void SPAServer::threadDistribution()
         pFromWebAPI->deleteOverOneYearAlarm();
 
         /* 休眠n秒,默认应该是300秒 */
-        std::this_thread::sleep_for(std::chrono::seconds(GVariable.CheckSet));
+        std::this_thread::sleep_for(std::chrono::seconds(GVariable.CheckAppSet));
         // std::this_thread::sleep_for(std::chrono::seconds(3));
     }
 

+ 9 - 2
SecurePlayAuxServer/SPAServer.h

@@ -1,6 +1,8 @@
 #ifndef SPASERVER_H
 #define SPASERVER_H
 
+#include <QTcpServer>
+
 #include "FromSuperBrain.h"
 #include "FromRedis.h"
 #include "FromWebAPI.h"
@@ -8,14 +10,14 @@
 class FuncBase;
 class FuncThreadInfo;
 
-
 /**
  * 安播辅助提示系统服务类
  *      写入EQM数据库的报警逻辑
  * 
  */
-class SPAServer
+class SPAServer : public QObject
 {
+    Q_OBJECT
 public:
     SPAServer();
     ~SPAServer();
@@ -23,6 +25,10 @@ public:
     /* 启动服务 */
     void startServer();
 
+private slots:
+    /* 接收到新的TCP连接 */
+    void do_newConnection();
+
 private:
     /*--------------------------------------------------------------------------------
      * 从基础平台获取算法信息和设备信息功能线程和所需要的函数,这里更新维护EQM数据库的tAction、
@@ -58,6 +64,7 @@ private:
 
     std::atomic_bool m_threadRunning = true;                        /* 线程正在运行 */
 
+    QTcpServer m_tcpServer;     /* TCP Server,主要是为了k8s监测服务是否还活着 */
     FromSuperBrain m_fromSuperBrain;
     FromWebAPI m_fromWebAPIUseSB;                       /* 用于SuperBrain的WebAPI */
 

+ 32 - 4
SecurePlayAuxServer/common/LHLog/LHLogInit.cpp

@@ -38,12 +38,19 @@ void initLog(QString ModuleName, CLHQLogApi& lhQLog)
         auto sink_custom = std::make_shared<spdlog::sinks::LHLog_file_sink_mt>(&lhQLog, QString(libName.c_str()), ModuleName);
         /* 给默认记录器用的sink */
         auto sink_default = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
- 
+
         /* 修改输出格式 */
+#if  defined (C_DEBUG)
         sink_consolse->set_pattern("%^[%Y-%m-%d %H:%M:%S:%e] [%l] [%n] [%s %#] %v%$");
         // sink_file->set_pattern("[%Y-%m-%d %H:%M:%S] [%^%n%$] [%^%l%$] %s %#: %v");
         sink_custom->set_pattern("%v");
         sink_default->set_pattern("%^[%Y-%m-%d %H:%M:%S:%e] [%l] [%s %#] %v%$");
+#elif defined(C_RELEASE)
+        sink_consolse->set_pattern("%^[%Y-%m-%d %H:%M:%S:%e] [%l] [%n] %v%$");
+        // sink_file->set_pattern("[%Y-%m-%d %H:%M:%S] [%^%n%$] [%^%l%$] %s %#: %v");
+        sink_custom->set_pattern("%v");
+        sink_default->set_pattern("%^[%Y-%m-%d %H:%M:%S:%e] [%l] %v%$");
+#endif
 
         /* 日志输出方向,终端和文件 */
         std::vector<spdlog::sink_ptr> sinks;
@@ -92,8 +99,8 @@ void initLog(QString ModuleName, CLHQLogApi& lhQLog)
 #elif defined(C_RELEASE)
         spdlog::set_level(spdlog::level::info);             /* 只输出info以上的输出 */
         spdlog::flush_on(spdlog::level::info);              /* 设置刷新等级 */
-        sink_consolse->set_level(spdlog::level::off);       /* 控制台不输出 */
-        sink_default->set_level(spdlog::level::off);        /* 默认sink也不输出 */
+        // sink_consolse->set_level(spdlog::level::off);       /* 控制台不输出 */
+        // sink_default->set_level(spdlog::level::off);        /* 默认sink也不输出 */
 #endif
 
 //    SPDLOG_LOGGER_DEBUG(logger_main,"******* 有行号且debug也能输出 *******");
@@ -101,4 +108,25 @@ void initLog(QString ModuleName, CLHQLogApi& lhQLog)
     catch (const spdlog::spdlog_ex& ex) {
         qDebug() << "Log initialization failed: " << ex.what() ;
     }
-}
+}
+
+
+/* 修改日志输出等级,输入1表示 */
+void changeLogLevel(ELogLevel level)
+{
+    if(ELogLevel::Log_Debug == level)
+    {
+        spdlog::set_level(spdlog::level::debug);
+        spdlog::flush_on(spdlog::level::debug);
+    }
+    else if(ELogLevel::Log_Info == level)
+    {
+        spdlog::set_level(spdlog::level::info);
+        spdlog::flush_on(spdlog::level::info);
+        /* 获取写入文件的sink,release模式下不写入文件 */
+        auto logger = spdlog::get("main");
+        auto sinks = logger->sinks();
+        sinks[1]->set_level(spdlog::level::info);
+    }
+}
+

+ 8 - 0
SecurePlayAuxServer/common/LHLog/LHLogInit.h

@@ -4,8 +4,16 @@
 class QString;
 class CLHQLogApi;
 
+enum class ELogLevel
+{
+    Log_Info = 0,
+    Log_Debug = 1
+};
+
 void initLog(QString ModuleName, CLHQLogApi& lhQLog);
 
+/* 修改日志输出等级,输入1表示 */
+void changeLogLevel(ELogLevel level);
 
 
 #endif /* LHLOGINIT_H */

+ 12 - 11
SecurePlayAuxServer/communication/FromWebAPI.cpp

@@ -6,6 +6,7 @@
 #include "FuncOnAndOffWork.h"
 #include "FuncRegionalPerson.h"
 #include "UniversalFunc.h"
+#include "GlobalConfig.h"
 
 
 FromWebAPI::FromWebAPI()
@@ -1326,15 +1327,15 @@ bool FromWebAPI::insertAlarmInfo(const AlarmInfo& alarmInfo, int& PKID)
         json0["opName"] = "SPSS_InsertToAlarm";
         nJson json1;
         json1["alarmID"] = alarmInfo.AlarmID;
-        json1["startTime"] = alarmInfo.StartTime.toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString();
-        json1["createTime"] = alarmInfo.EventTime.toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString();
-        // std::string strEndTime = "";
-        // /* 这里判断一下结束时间是否需要设置,如果不需要,则设置成小于2020年即可,写入数据库就是空 */
-        // if(alarmInfo.EndTime > QDateTime::fromString("2020-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss"))
-        // {
-        //     strEndTime = alarmInfo.EndTime.toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString();
-        // }
-        json1["endTime"] = alarmInfo.EndTime.toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString();
+        json1["startTime"] = alarmInfo.StartTime.toString("yyyy-MM-dd hh:mm:ss").toStdString();
+        json1["createTime"] = alarmInfo.EventTime.toString("yyyy-MM-dd hh:mm:ss").toStdString();
+        /* 这里判断一下结束时间是否需要设置,如果不需要,则设置成小于2000年即可 */
+        if(alarmInfo.EndTime.isValid())
+        {
+            json1["endTime"] = alarmInfo.EndTime.toString("yyyy-MM-dd hh:mm:ss").toStdString();
+        }else {
+            json1["endTime"] = GVariable.nullTimeStr;
+        }
         json1["bbox"] = strBbox;
         json1["picUrl"] = alarmInfo.ImageInfo;
         json1["appID"] = getAppFunctionID(alarmInfo.appFunction);
@@ -1575,8 +1576,8 @@ bool FromWebAPI::getMaxAlarmPKID(const int ChannelID, const AppFunction AppID, i
     nJson json0;
     json0["opName"] = "SPSS_GetChnAlarmMaxPKID";
     nJson json1;
-    json1["ChannelID"] = ChannelID;
-    json1["AppID"] = static_cast<int>(AppID);
+    json1["channelID "] = ChannelID;
+    json1["appId"] = getAppFunctionID(AppID);
     json0["paramList"] = json1;
 
     QString strCmd = QString::fromStdString(json0.dump());

+ 0 - 2
存在的问题

@@ -1,3 +1 @@
-1、摄像机信息表存在重复的问题
-2、自动删除一年前的数据还未添加
 3、打包成Docker镜像