private void Run() { while (WaitHandle.WaitAny(m_WaitHandles) == 0) { if (m_alarmLogQueue.Count == 0) { m_queueThreadSemaphore.Reset(); } //出列,处理 AlarmLog alarmLog = null; bool dequeueOk = m_alarmLogQueue.TryDequeue(out alarmLog); if (dequeueOk) { //报警联动 using (var db = new AllInOneContext.AllInOneContext()) { try { var setting = GetAlarmSetting(db, alarmLog); if (setting != null) { int code = 0; if (Int32.TryParse(setting.AlarmSource.Organization.OrganizationCode, out code)) { setting.AlarmSource.IPDeviceCode = code; } Plan plan = null; DeviceAlarmStatus status = null; //本地广播报警消息 MQPulish.PublishMessage("AlarmLog", alarmLog); if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100001"))) //执行预案,状态未确认 { if (ScheduleUtility.IsValidSchedule(setting.Schedule, DateTime.Now)) //符合当前排班的情况 { ////本地广播报警消息 //MQPulish.PublishMessage("AlarmLog", alarmLog); plan = db.Plan.Include(t => t.Actions).ThenInclude(t => t.PlanActions).ThenInclude(t => t.Action).FirstOrDefault(t => t.PlanId.Equals(setting.BeforePlanId)); } } else if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100002"))) //执行应急预案 { //预案确认 plan = db.Plan.Include(t => t.Actions).ThenInclude(t => t.PlanActions).ThenInclude(t => t.Action).FirstOrDefault(t => t.PlanId.Equals(setting.EmergencyPlanId)); //哨位报警,确认需推送报警确认/取消到哨位中心服务 status = GetDeviceAlarmStatus(db, setting, true); } else if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100003"))) //报警取消,停止联动动作 { //哨位报警,取消需推送报警确认/取消到哨位中心服务 status = GetDeviceAlarmStatus(db, setting, false); StopPlan(setting); } else if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100004"))) //停止联动动作,已关闭 { status = GetDeviceAlarmStatus(db, setting, false); StopPlan(setting); } //找到满足条件的预案,发送到任务服务,启动预案 if (plan != null) { plan.PlanTrigger = new PlanTriggerSource() { AlarmSource = setting.AlarmSource, AlarmType = setting.AlarmType, BeforePlanId = setting.BeforePlanId, EmergencyPlanId = setting.EmergencyPlanId, AlarmLogId = alarmLog.AlarmLogId }; StartPlan(plan); } if (status != null) { SendAlarmStatusToASCS(status, setting.AlarmSource.OrganizationId); } } else { _logger.LogInformation("未配置报警,没有任务联动响应!!!!"); } } catch (Exception ex) { _logger.LogError("报警处理异常,Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } } } }