| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 | 
							- #pragma once
 
- #include <map>
 
- #include <thread>
 
- #include <string>
 
- #include <list>
 
- #include "AlarmDefine.h"
 
- #include <rapidjson/stringbuffer.h>
 
- #include <mutex>
 
- class CResistAlarm
 
- {
 
- 	CResistAlarm();
 
- 	~CResistAlarm();
 
- 	friend class CResistAlarmMng;
 
- public:
 
- };
 
- typedef struct tagBaseInfo
 
- {
 
- 	uint8_t no = 255;    //0, 1, 2 //通道号
 
- 	eZL_ALARMTYPE  type = (eZL_ALARMTYPE)0x00;  //报警类型
 
- 	bool  enable = false; //报警开关
 
- 	time_t tmLastCheckTime = 0;
 
- }BASE_INFO;
 
- typedef struct tagMax_Over_Limit : public tagBaseInfo
 
- {
 
- 	short alarm_high_limit = SHORT_MAX; //锁闭力  定向反
 
- 	short warn_high_limit = SHORT_MAX;	//锁闭力  反向定
 
- 	//short d_alarm_high_limit;
 
- 	//short d_warn_high_limit;
 
- 	short f_alarm_high_limit = SHORT_MAX;  //保持力  反向定
 
- 	short f_warn_high_limit = SHORT_MAX;  //保持力	反向定
 
- }MAX_OVER_LIMIT_INFO;
 
- typedef struct tagFriction_Over_Limit : public tagBaseInfo
 
- {
 
- 	int up_alarm_low_limit = INT_MAX; //上超低限报警值(暂定名称) 整数
 
- 	int up_warn_low_limit = INT_MAX;   //上超低限预警值 整数
 
- 	int dw_alarm_high_limit = INT_MIN;	//下超高限报警值 整数
 
- 	int dw_warn_high_limit = INT_MIN;	//下超高限预警值 整数
 
- }FRICTION_OVER_LIMIT_INFO;
 
- typedef struct tagSuobi_Over_Limit : public tagBaseInfo
 
- {
 
- 	int alarm_low_limit = INT_MIN;  //最小告警值
 
- 	int warn_low_limit = INT_MIN;	//最小预警值
 
- 	int alarm_high_limit = INT_MAX;		//最大告警值
 
- 	int warn_high_limit = INT_MAX;		//最大预警值
 
- }SUOBI_OVER_LIMIT_INFO;
 
- typedef struct tagConvertResist_Over_Limit : public tagBaseInfo
 
- {
 
- 	int dw_alarm_low_limit = INT_MIN;	//伸出告警值
 
- 	int dw_warn_low_limit = INT_MIN;	//伸出预警值
 
- 	int up_alarm_high_limit = INT_MAX;  //缩进告警值
 
- 	int up_warn_high_limit = INT_MAX;  //缩进预警值
 
- }CONVERT_RESIST_OVER_LIMIT;
 
- typedef struct tagAlarmInfo
 
- {
 
- 	uint32_t id;   //报警唯一ID
 
- 	string mo; //监控对象
 
- 	string mp; //监控点
 
- 	uint8_t no; //通道
 
- 	eZL_ALARMTYPE type;//报警类型
 
- 	uint8_t level;      //0 预警  1 报警
 
- 	SYSTEMTIME time;   //报警时间
 
- 	string desc;	//报警描述
 
- 	string suggest; //建议
 
- 	short val = 0;
 
- 	uint8_t  ack_result = 0;     //是否受理
 
- 	string ack_name;		//受理人
 
- 	CTime ack_time;		//受理时间
 
- 	string event_id;  //事件ID
 
- 	string rel_id;    //第一次报警id
 
- }ALARM_INFO;
 
- //获取报警名称
 
- inline string GetAlarmName(eZL_ALARMTYPE id)
 
- {
 
- 	switch (id)
 
- 	{
 
- 	case eZL_ALARMTYPE::MAX_OVER_LIMIT:
 
- 		return "最大值超限";
 
- 	case eZL_ALARMTYPE::FRICTION_OVER_LIMIT:
 
- 		return "摩擦力超限";
 
- 	case eZL_ALARMTYPE::EQUIP_OFFLINE:
 
- 		return "设备离线";
 
- 	case eZL_ALARMTYPE::SENSOR_ABNORMAL:
 
- 		return "传感器异常";
 
- 	case eZL_ALARMTYPE::CONVERT_LIMIT:
 
- 		return "转换阻力超限";
 
- 	case eZL_ALARMTYPE::SUOBI_LOCK_LIMIT:
 
- 		return "锁闭力超限";
 
- 	default:
 
- 		return "未知";
 
- 	}
 
- }
 
- typedef struct eCalcMoveInfo
 
- {
 
- 	string imei;
 
- 	uint8_t idx;
 
- 	string mo;
 
- 	string mp;
 
- 	eCalcMoveInfo(string a, uint8_t b, string c, string d)
 
- 	{
 
- 		imei = a;
 
- 		idx = b;
 
- 		mo = c;
 
- 		mp = d;
 
- 	}
 
- }CALC_MOVE_INFO;
 
- class CResistAlarmMng
 
- {
 
- 	 CResistAlarmMng();
 
- 	 ~CResistAlarmMng();
 
- 	 friend class CLWSServer;
 
- 	 friend class CMGDataHandler;
 
- 	 friend class CLNHandle;
 
- public:
 
- 	static CResistAlarmMng* Instance() { return &obj; }
 
- 	BOOL Start();
 
- 	void Stop();
 
- 	//BASE_INFO* Find(string momp, uint8_t no, uint8_t type);
 
- 	BASE_INFO* Find(string mo, string mp, uint8_t no, eZL_ALARMTYPE type);
 
- 	bool Insert(string mo, string mp, uint8_t no, uint8_t type, BASE_INFO* info);
 
- 	//bool Insert(const string& momp, uint8_t no, uint8_t type, BASE_INFO* info);
 
- 	//bool ConfirmAlarm(string mo, string mp, uint8_t no, uint8_t type, const SYSTEMTIME& st);
 
- 	//受理报警
 
- 	bool AckAlarm(int alarm_id, string& name, CTime& time);
 
- 	//处理报警
 
- 	bool HandleAlarm(int alarm_id);
 
- 	//外部调用产生报警
 
- 	void GeneralAlarm(string mo, string mp, uint8_t no, eZL_ALARMTYPE type, uint8_t level, SYSTEMTIME& tAlarm);
 
- 	//外部调用恢复报警
 
- 	void RecoverAlarm(const string mo, const string mp, const uint8_t no, const eZL_ALARMTYPE type, const uint8_t level, const SYSTEMTIME& tAlarm);
 
- 	static bool AlarmInfo2Pack(const ALARM_INFO* pAlarmInfo, rapidjson::StringBuffer& strBuf, bool bGb2312 = false);
 
- 	eZL_MP_STAT GetAlarmStat(string& mo, string& mp, SYSTEMTIME& stAlarm);
 
- 	inline void InsertCalcMoveInfo(string imei, uint8_t idx, string mo, string mp)
 
- 	{
 
- 		m_lstCalcMoveInfo.emplace_back(imei, idx, mo, mp);
 
- 	}
 
- private:
 
- 	static CResistAlarmMng obj; 
 
- 	static void InsertToDBByMove(string mo, string mp, time_t show_time, time_t start_time, time_t end_time, int curr_val, int show_val, uint8_t idx, uint8_t posi, string mark);
 
- 	//报警规则检测线程
 
- 	static void ThreadProcAlarmSet(DWORD_PTR);
 
- 	//设备报警检测线程
 
- 	static void ThreadProcDevice(DWORD_PTR);
 
- 	BOOL LoadAlarmSet();
 
- 	BOOL LoadAlarmID();
 
- 	BOOL LoadUnAck();
 
- 	//报警ID
 
- 	int m_nAlarmID = 0;
 
- 	time_t m_lastDetectTime = 0;
 
- 	bool m_bWork = false;
 
- 	//报警规则检测线程
 
- 	std::thread *m_pThreadAlarmSet = nullptr;
 
- 	//设备报警检测线程
 
- 	std::thread* m_pThreadDevice = nullptr;
 
- 	//计算阻力值和锁闭力值
 
- 	std::list<CALC_MOVE_INFO> m_lstCalcMoveInfo;  
 
- 	//报警参数 mo.mp
 
- 	std::map<std::string, BASE_INFO*> m_alarm_set;
 
- 	//未确认报警
 
- 	std::mutex m_mtxAlarm;
 
- 	std::list<ALARM_INFO*> m_lstUnConfirmAlarm;
 
- };
 
 
  |