FuncBase.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef FUNCBASE_H
  2. #define FUNCBASE_H
  3. #include <memory>
  4. #include "GlobalVariable.h"
  5. #include "GlobalFuncThread.h"
  6. #include "spdlog/spdlog.h"
  7. class FromRedis;
  8. class FromWebAPI;
  9. struct FuncThreadInfo;
  10. /**
  11. * @brief 功能基础类,包含读取Redis数据和写入EQM数据库的功能
  12. *
  13. */
  14. class FuncBase
  15. {
  16. public:
  17. FuncBase();
  18. ~FuncBase();
  19. /* 任务线程 */
  20. void thread_task();
  21. /* 设置功能信息 */
  22. void setFuncThreadInfo(FuncThreadInfo* pFuncAct);
  23. void setFuncThreadInfo(FuncThreadInfo& FuncAct);
  24. /* 获取该实例的功能 */
  25. AppFunction getApp();
  26. /* 获取线程运行状态 */
  27. bool getThreadRunning() const;
  28. protected:
  29. /* 真正执行任务的地方 */
  30. virtual void task() = 0;
  31. /* 初始化数据接口 */
  32. bool initDataInterface();
  33. /* 判断是否在检测时间内,不检测日期,只检测时间 */
  34. bool isInDetectTime(const QDateTime& start, const QDateTime& end);
  35. /* 更新检测时间范围,一定时间更新一次,不是每次都更新 */
  36. inline bool updateDetectTime(DetectPeriodInfo& periodInfo);
  37. /* 判断是否在检测时间内,重载版,会自动打印日志 */
  38. bool isInDetectTime(const DetectPeriodInfo& periodInfo);
  39. protected:
  40. std::shared_ptr<spdlog::logger> m_logger = nullptr;
  41. /* 读取Redis的实例 */
  42. std::shared_ptr<FromRedis> m_fromRedis = nullptr;
  43. /* 写入EQM数据库的实例 */
  44. std::shared_ptr<FromWebAPI> m_fromWebAPI = nullptr;
  45. /* 线程信息 */
  46. FuncThreadInfo m_funcThreadInfo;
  47. std::atomic_bool m_bRunning = false; /* 线程运行状态 */
  48. std::string m_baseLog; /* 带有频道功能信息的基础字符串 */
  49. DetectPeriodInfo m_periodInfo; /* 检测时间段 */
  50. QDateTime m_nowTime; /* 当前时间 */
  51. };
  52. #endif // FUNCBASE_H