/// <summary> /// 报警,应急联动 /// </summary> /// <param name="args"></param> private void DataAnalysisService_AnalysisReulstHandlerEvent(AnalysisChangedEventArgs args) { try { JC_LargedataAnalysisConfigInfo analysisConfigInfo = args.AnalysisConfig; string analysisModelId = analysisConfigInfo.Id; List <JC_AlarmNotificationPersonnelConfigInfo> responseAlarmConfigList; JC_EmergencyLinkageConfigInfo responseEmergencyLinkageConfig; List <JC_RegionOutageConfigInfo> responseRegionOutageConfigList; //多系统融合应急联动 SysEmergencyLinkageInfo responsesysEmergencyLinkInfo; //分析模板传感器分级报警配置 Jc_AnalysistemplatealarmlevelInfo analysistemplatealarmlevelInfo; try { responseAlarmConfigList = AlarmConfigCache.Instance.Query(q => q.AnalysisModelId == analysisModelId); responseEmergencyLinkageConfig = EmergencyLinkageConfigCache.Instance.Query(q => q.AnalysisModelId == analysisModelId).FirstOrDefault(); responseRegionOutageConfigList = RegionOutageConfigCache.Instance.Query(q => q.AnalysisModelId == analysisModelId); // //responsesysEmergencyLinkInfos = SysEmergencyLinkageCache.Instance.Query(o => o.MasterModelId == analysisModelId && o.Type == 2).FirstOrDefault(); responsesysEmergencyLinkInfo = sysEmergencyLinkageService.GetAllSysEmergencyLinkageList().Data.FirstOrDefault(o => o.MasterModelId == analysisModelId && o.Type == 2); AnalysistemplatealarmlevelGetByAnalysistemplateIdRequest cacherequest = new AnalysistemplatealarmlevelGetByAnalysistemplateIdRequest(); cacherequest.AnalysistemplateId = analysisModelId; analysistemplatealarmlevelInfo = analysistemplatealarmlevelService.GetAnalysistemplatealarmlevelByAnalysistemplateId(cacherequest).Data; } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("获取输出配置信息出错:{0}", ex.StackTrace)); return; } #region 报警配置 //存在报警配置 if (responseAlarmConfigList != null && responseAlarmConfigList.Count > 0) { try { //报警 BasicResponse <JC_AlarmHandleInfo> alarmHandleResponse = alarmHandleService.GetUnclosedAlarmByAnalysisModelId(new AlarmHandleGetByAnalysisModelIdRequest() { AnalysisModelId = analysisModelId }); if (analysisConfigInfo.AnalysisResult == 2) { if (alarmHandleResponse.Data == null) { //报警消息格式: 测点号+安装位置+分析模型名称+输出结果 StringBuilder alarmMessage = new StringBuilder(); var analysisSuccessfulPointList = ObjectConverter.CopyList <AnalysisSuccessfulPointInfo, AnalysisSuccessfulPointInfo>(analysisConfigInfo.AnalysisSuccessfulPointList); foreach (var item in analysisSuccessfulPointList) { alarmMessage.Append(string.Format("{0} {1} {2} {3}", item.Point, item.Wz, analysisConfigInfo.Name, analysisConfigInfo.TrueDescription)).Append(Environment.NewLine); } alarmHandleService.AddJC_AlarmHandle(new AlarmHandleAddRequest() { JC_AlarmHandleInfo = new JC_AlarmHandleInfo() { Id = IdHelper.CreateLongId().ToString(), AnalysisModelId = analysisModelId, AnalysisResult = alarmMessage.ToString(), StartTime = DateTime.Now, AlarmType = responseAlarmConfigList[0].AlarmType, AlarmColor = responseAlarmConfigList[0].AlarmColor, EndTime = new DateTime(1900, 1, 1, 0, 0, 0) } }); } } else { //不成立或未知更新报警结束时间 if (alarmHandleResponse.Data != null) { alarmHandleResponse.Data.EndTime = DateTime.Now; alarmHandleService.UpdateJC_AlarmHandle(new AlarmHandleUpdateRequest() { JC_AlarmHandleInfo = alarmHandleResponse.Data }); } } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("添加或更新报警信息出错:{0}", ex.StackTrace)); } } #endregion #region 应急联动 //应急联动 if (analysisConfigInfo.AnalysisResult == 2 && responseEmergencyLinkageConfig != null) { analysisConfigInfo.IsEmergencyLinkage = true; analysisConfigInfo.EmergencyLinkageConfig = responseEmergencyLinkageConfig.Coordinate; } else { //不成立或未知解除应急联动 analysisConfigInfo.IsEmergencyLinkage = false; analysisConfigInfo.EmergencyLinkageConfig = string.Empty; } try { largeDataAnalysisCacheClientService.UpdateLargeDataAnalysisConfigCahce(new LargeDataAnalysisConfigCacheUpdateRequest() { //LargeDataAnalysisConfigInfo = ObjectConverter.DeepCopy<JC_LargedataAnalysisConfigInfo>(analysisConfigInfo) LargeDataAnalysisConfigInfo = analysisConfigInfo }); } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("更新应急联动配置信息到缓存出错:{0}", ex.StackTrace)); } #endregion #region 区域断电 //存在区域断电配置 if (responseRegionOutageConfigList != null && responseRegionOutageConfigList.Count > 0) { //分析成立时 if (analysisConfigInfo.AnalysisResult == 2) { //要控制的列表 List <Jc_JcsdkzInfo> controlList = new List <Jc_JcsdkzInfo>(); //要解控的列表 List <Jc_JcsdkzInfo> removeControlList = new List <Jc_JcsdkzInfo>(); foreach (var item in responseRegionOutageConfigList) { BasicResponse <List <Jc_JcsdkzInfo> > analysisBKResponse; try { BasicResponse <bool> controlPointLegalResponse = pointDefineService.ControlPointLegal(new Sys.Safety.Request.PointDefine.PointDefineGetByPointIDRequest() { PointID = item.PointId }); if (!controlPointLegalResponse.Data) { //风电闭锁控制口或者甲烷风电闭锁控制口,数据分析这边不处理.如果风电闭锁和甲烷风电闭锁后定义并且当前控制口已被控制则解除控制。 analysisBKResponse = manualCrossControlService.GetManualCrossControlByTypeZkPointBkPoint(new ManualCrossControlGetByTypeZkPointBkPointRequest() { ZkPoint = analysisModelId, BkPoint = item.Point, Type = (short)Enums.ControlType.LargeDataAnalyticsAreaPowerOff }); if (analysisBKResponse.Data != null && analysisBKResponse.Data.Count > 0) { try { manualCrossControlService.DeleteManualCrossControls(new ManualCrossControlsRequest() { ManualCrossControlInfos = analysisBKResponse.Data }); } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("解除控制出错:{0}", ex.StackTrace)); } } continue; } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("风电闭锁控制口或者甲烷风电闭锁控制口,数据分析这边不处理:{0}", ex.StackTrace)); } try { //查询测点为item.Point的被控列表 analysisBKResponse = manualCrossControlService.GetManualCrossControlByBkPoint(new ManualCrossControlGetByBkPointRequest() { BkPoint = item.Point }); } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("查询测点为item.Point的被控列表出错:{0}", ex.StackTrace)); continue; } //控制 if (item.ControlStatus == 1) { //删除此处判断,添加了模型成立后,再添加区域断电,不会控制 20180919 ////如果上一次也是分析成立,则不再添加控制,为了避免一边添加控制一边解除控制这种情况。 //if (analysisConfigInfo.PrevAnalysisResult == analysisConfigInfo.AnalysisResult) // continue; if (analysisBKResponse.Data != null && analysisBKResponse.Data.Count > 0) { //被控测点 item.Point 已经存在控制,不能再控. continue; } else { //向 jc_jcsdkz 插入数据 if (!controlList.Exists(p => p.ZkPoint == item.AnalysisModelId && p.Bkpoint == item.Point)) { controlList.Add(new Jc_JcsdkzInfo() { ID = IdHelper.CreateLongId().ToString(), ZkPoint = item.AnalysisModelId, Type = (short)Enums.ControlType.LargeDataAnalyticsAreaPowerOff, Upflag = "0", Bkpoint = item.Point }); } } } //解除控制 if (item.ControlStatus == 0) { //表 jc_jcsdkz 存在被控测点为当前解控测点的记录. if (analysisBKResponse.Data != null && analysisBKResponse.Data.Count > 0) { //如果表 jc_jcsdkz 存在和当前解控模型和当前解控测点有关的控制则解除. Jc_JcsdkzInfo JkInfo = analysisBKResponse.Data.FirstOrDefault(q => q.ZkPoint == item.RemoveModelId && q.Bkpoint == item.Point && q.Type == (short)Enums.ControlType.LargeDataAnalyticsAreaPowerOff); if (JkInfo != null) { removeControlList.Add(new Jc_JcsdkzInfo() { ID = JkInfo.ID, ZkPoint = JkInfo.ZkPoint, Bkpoint = JkInfo.Bkpoint, Type = JkInfo.Type, Upflag = JkInfo.Upflag }); } } } } if (controlList.Count > 0) { try { manualCrossControlService.AddManualCrossControls(new ManualCrossControlsRequest() { ManualCrossControlInfos = controlList }); } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("添加控制出错:{0}", ex.StackTrace)); } } if (removeControlList.Count > 0) { try { manualCrossControlService.DeleteManualCrossControls(new ManualCrossControlsRequest() { ManualCrossControlInfos = removeControlList }); } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("解除控制出错:{0}", ex.StackTrace)); } } } else { BasicResponse <List <Jc_JcsdkzInfo> > analysisZKResponse = null; try { //查询主控为analysisModelId的列表 analysisZKResponse = manualCrossControlService.GetManualCrossControlByTypeZkPoint(new ManualCrossControlGetByTypeZkPointRequest() { ZkPoint = analysisModelId, Type = (short)Enums.ControlType.LargeDataAnalyticsAreaPowerOff }); } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("查询主控为{0}的列表出错:{1}", analysisModelId, ex.StackTrace)); } if (analysisZKResponse != null && analysisZKResponse.Data != null && analysisZKResponse.Data.Count > 0) { //不成立或未知时,首先看表达式测点是否还存在。 如果不存在, 分析模型控制的测点全部解除控制. foreach (var modelPoint in analysisConfigInfo.AnalysisModelPointRecordInfoList) { Jc_DefInfo definedPoint = null; try { definedPoint = PointCache.Instance.Query(q => q.PointID == modelPoint.PointId, false).FirstOrDefault(); } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("获取测点缓存信息出错, 错误消息:{0}", ex.StackTrace)); } if (PointCache.Instance.Count > 0 && definedPoint == null /*测点不存在*/) { try { manualCrossControlService.DeleteManualCrossControls(new ManualCrossControlsRequest() { ManualCrossControlInfos = analysisZKResponse.Data }); } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("解除控制出错:{0}", ex.StackTrace)); } return; } } //不成立或未知时解除分析成立时所加的控制 List <Jc_JcsdkzInfo> removeControlList = new List <Jc_JcsdkzInfo>(); foreach (var item in responseRegionOutageConfigList) { try { BasicResponse <bool> controlPointLegalResponse = pointDefineService.ControlPointLegal(new Sys.Safety.Request.PointDefine.PointDefineGetByPointIDRequest() { PointID = item.PointId }); if (!controlPointLegalResponse.Data) { //风电闭锁控制口或者甲烷风电闭锁控制口,数据分析这边不处理.如果风电闭锁和甲烷风电闭锁后定义并且当前控制口已被控制则解除控制。 BasicResponse <List <Jc_JcsdkzInfo> > analysisBKResponse = manualCrossControlService.GetManualCrossControlByTypeZkPointBkPoint(new ManualCrossControlGetByTypeZkPointBkPointRequest() { ZkPoint = analysisModelId, BkPoint = item.Point, Type = (short)Enums.ControlType.LargeDataAnalyticsAreaPowerOff }); if (analysisBKResponse.Data != null && analysisBKResponse.Data.Count > 0) { try { manualCrossControlService.DeleteManualCrossControls(new ManualCrossControlsRequest() { ManualCrossControlInfos = analysisBKResponse.Data }); } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("解除控制出错:{0}", ex.StackTrace)); } } continue; } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("风电闭锁控制口或者甲烷风电闭锁控制口,数据分析这边不处理:{0}", ex.StackTrace)); } //是否配置当分析不成立时解除分析成立时所加的控制. 1-解除控制 if (item.ControlStatus == 1 && item.IsRemoveControl == 1) { Jc_JcsdkzInfo JkInfo = analysisZKResponse.Data.FirstOrDefault(q => q.ZkPoint == item.AnalysisModelId && q.Bkpoint == item.Point && q.Type == (short)Enums.ControlType.LargeDataAnalyticsAreaPowerOff); if (JkInfo != null) { removeControlList.Add(new Jc_JcsdkzInfo() { ID = JkInfo.ID, ZkPoint = JkInfo.ZkPoint, Bkpoint = JkInfo.Bkpoint, Type = JkInfo.Type, Upflag = JkInfo.Upflag }); } } } if (removeControlList.Count > 0) { try { manualCrossControlService.DeleteManualCrossControls(new ManualCrossControlsRequest() { ManualCrossControlInfos = removeControlList }); } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("解除控制出错:{0}", ex.StackTrace)); } } } } } else { try { //没有区域断电配置. BasicResponse <List <Jc_JcsdkzInfo> > analysisZKResponse = manualCrossControlService.GetManualCrossControlByTypeZkPoint(new ManualCrossControlGetByTypeZkPointRequest() { ZkPoint = analysisModelId, Type = (short)Enums.ControlType.LargeDataAnalyticsAreaPowerOff }); if (analysisZKResponse != null && analysisZKResponse.Data != null && analysisZKResponse.Data.Count > 0) { manualCrossControlService.DeleteManualCrossControls(new ManualCrossControlsRequest() { ManualCrossControlInfos = analysisZKResponse.Data }); } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(string.Format("没有区域断电配置时删除控制出错:{0}", ex.StackTrace)); } } #endregion #region 多系统融合应急联动 if (responsesysEmergencyLinkInfo != null && !string.IsNullOrEmpty(responsesysEmergencyLinkInfo.Id)) { SysEmergencyLinkHandle(analysisConfigInfo, responsesysEmergencyLinkInfo); } #endregion #region 感器分级报警 if (analysistemplatealarmlevelInfo != null) { AnalysistemplateAlarmLevelHandle(analysisConfigInfo, analysistemplatealarmlevelInfo); } //如果报警配置等级不存在,则更新模型关联传感器报警等级为0 else { ManualCrossControlGetByTypeZkPointRequest mcrequest = new ManualCrossControlGetByTypeZkPointRequest(); mcrequest.Type = 12; mcrequest.ZkPoint = analysisConfigInfo.Id; var kzinfo = manualCrossControlService.GetManualCrossControlByTypeZkPoint(mcrequest).Data; if (kzinfo.Count > 0) { kzinfo.ForEach(kz => kz.Upflag = "0"); ManualCrossControlsRequest updaterequest = new ManualCrossControlsRequest(); updaterequest.ManualCrossControlInfos = kzinfo; manualCrossControlService.UpdateManualCrossControls(updaterequest); } } #endregion //更新上一次的分析结果 Dictionary <string, object> upddateitems = new Dictionary <string, object>(); upddateitems.Add("PrevAnalysisResult", analysisConfigInfo.AnalysisResult); if (analysisConfigInfo.AnalysisTime != null) { upddateitems.Add("PrevAnalysisTime", analysisConfigInfo.AnalysisTime.Value); } AnalysisModelCache.Instance.UpdateProperties(analysisConfigInfo.Id, upddateitems); } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex.ToString()); } }
public BasicResponse <List <Jc_JcsdkzInfo> > GetManualCrossControlByBkPoint(Sys.Safety.Request.ManualCrossControl.ManualCrossControlGetByBkPointRequest ManualCrossControlRequest) { return(_ManualCrossControlService.GetManualCrossControlByBkPoint(ManualCrossControlRequest)); }