| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 | 
							- #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
 
- {
 
- 	char momp[20] = { 0 };
 
- 	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
 
- {
 
- 	int alarm_high_limit = INT_MAX; //锁闭力  定向反
 
- 	int warn_high_limit = INT_MAX;	//锁闭力  反向定
 
- 	//short d_alarm_high_limit;
 
- 	//short d_warn_high_limit;
 
- 	int f_alarm_high_limit = INT_MAX;  //保持力  反向定
 
- 	int f_warn_high_limit = INT_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 tagRetension_Force_Drop : public  tagBaseInfo
 
- {
 
- 	int dw_alarm_low_drop = INT_MIN;    //最低预警值
 
- 	int alarm_low_percent = INT_MIN;    //下降百分比报警值
 
- 	int alarm_high_percent = INT_MIN;    //上升百分比报警值
 
- 	time_t tLastCalc = 0;				//上一次计算时间(不参与配置)   //是不是可以用 tmLastCheckTime
 
- 	tagRetension_Force_Drop()
 
- 	{
 
- 		type = eZL_ALARMTYPE::RETENSION_FORCE;
 
- 		enable = false;
 
- 	}
 
- }RETENSION_FORCE_DROP;
 
- //有string 不能拷贝
 
- 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; //建议
 
- 	int val = 0;
 
- 	uint8_t  ack_result = 0;     //是否受理
 
- 	string ack_name;		//受理人
 
- 	CTime ack_time;		//受理时间
 
- 	string event_id;  //事件ID
 
- 	string rel_id;    //第一次报警id
 
- 	eDaoChaPosi posi = eDaoChaPosi::DCP_UNKNOWN;   //方向
 
- 	eLowHigh loworhigh = eLowHigh::LH_UNKNOWN;
 
- 	int refer_val = 0;   //报警参数值
 
- 	SYSTEMTIME recoveryTime = { 0 };
 
- 	uint32_t  zzjno = 0;
 
- 	uint8_t  sunroof = 0; //是否天窗
 
- }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 "锁闭力超限";
 
- 	case eZL_ALARMTYPE::RETENSION_FORCE:
 
- 		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;
 
- BOOL ConmpareValue(std::map<time_t, int>::const_iterator i, std::map<time_t, int>::const_iterator j, int refer_value, int& hight_num, int& low_num);
 
- class CResistAlarmMng
 
- {
 
- 	 CResistAlarmMng();
 
- 	 ~CResistAlarmMng();
 
- 	 friend class CLWSServer;
 
- 	 friend class CMGDataHandler;
 
- 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);
 
- 	}
 
- 	//序列化
 
- 	uint32_t  GeneralAlarmSet(uint8_t** pack, int* len);
 
- 	uint32_t  GeneralUnAck(uint8_t** pack, int* len);
 
- 	static uint32_t  GeneralNewAlarmData(ALARM_INFO *pAlarmInfo, uint8_t** pack, int* len);
 
- 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, uint8_t type, string mark);
 
- 	static void JudgeAlarm(CResistAlarmMng* pService, SUOBI_OVER_LIMIT_INFO* pSuobiOverInfo,
 
- 		time_t show_time, int show_val, eSuoBiPosi posi, string mo, string mp, uint32_t zzjno);
 
- 	static void JudgeAlarm(CResistAlarmMng* pService, CONVERT_RESIST_OVER_LIMIT* pConvertResistOverLimitInfo,
 
- 		time_t show_time, int show_val, eDaoChaPosi posi, eUpOrDownInfo eUpOrDown, string mo, string mp, uint32_t zzjno);
 
- 	//不调用
 
- 	static void JudgeAlarm2(CResistAlarmMng* pService, RETENSION_FORCE_DROP* pRetensionForceDropInfo,
 
- 		time_t show_time, int show_val, eSuoBiPosi posi, string mo, string mp, uint32_t zzjno);
 
- 	//不调用
 
- 	static void JudgeAlarm3(CResistAlarmMng* pService, RETENSION_FORCE_DROP* pRetensionForceDropInfo,
 
- 		time_t show_time, int show_val, eSuoBiPosi posi, string mo, string mp, uint32_t zzjno);
 
- 	//判断报警,且保存数据
 
- 	static void JudgeAlarm(CResistAlarmMng* pService, RETENSION_FORCE_DROP* pConstRetensionForceWaveInfo,
 
- 		time_t show_time, int show_val, eSuoBiPosi posi, string mo, string mp, void* pMoMpInfo);
 
- 	//摩檫力报警判断
 
- 	static void JudgeAlarm(CResistAlarmMng* pService, FRICTION_OVER_LIMIT_INFO* pAlarmSet,
 
- 		time_t show_time, int show_val, eDaoChaPosi posi, eUpOrDownInfo eUpOrDown, void* pMoMpInfo);
 
- 	//报警规则检测线程
 
- 	static void ThreadProcAlarmSet(DWORD_PTR);	
 
- 	//设备报警检测线程	
 
- 	static void ThreadProcDevice(DWORD_PTR);
 
- 	//扳动线程检测线程
 
- 	static void ThreadProcMove(DWORD_PTR);
 
- 	//搬动线程外部数据线程
 
- 	static void ThreadProcMoveFromDB(DWORD_PTR);
 
- 	BOOL LoadAlarmSet();
 
- 	BOOL LoadAlarmID();
 
- 	BOOL LoadUnAck();
 
- 	//报警ID
 
- 	int m_nAlarmID = 0;
 
- 	time_t m_lastDetectTime = 0;
 
- 	time_t m_lastDetectMove = 0;
 
- 	time_t m_lastDetectDrop = 0;
 
- 	bool m_bWork = false;
 
- 	//报警规则检测线程
 
- 	std::thread *m_pThreadAlarmSet = nullptr;
 
- 	//设备报警检测线程
 
- 	std::thread* m_pThreadDevice = nullptr;
 
- 	//扳动线程检测
 
- 	std::thread* m_pThreadMove = 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;  //未受理报警和未恢复集合
 
- };
 
 
  |