private void DataProc() { List <Jc_DefInfo> pointDefineItems = null; SettingInfo settingInfo = null; string settingTime = ""; //上次加载倍率报警配置时间 List <JC_MultiplesettingInfo> multiplesettingInfotems = null; JC_MultiplesettingInfo multiplesettingInfotem = null; List <RatioAlarmConditions> ratioAlarmConditionItems = null; RatioAlarmConditions ratioAlarmConditionItem = null; double sszValue = 0; double basicValue = 0; int alarmType = 0; JC_MbInfo ratioAlarm = null; DateTime getBasicValueDate = DateTime.Now.AddDays(-1); //上次获取周平均值的时间 List <JC_MbInfo> alarm_AddItems = new List <JC_MbInfo>(); List <JC_MbInfo> alarm_DelItems = new List <JC_MbInfo>(); List <JC_MbInfo> alarm_UpdateItems = new List <JC_MbInfo>(); DateTime lastProcData = DateTime.Now; //最后一次处理数据的日期 DateTime nowTime = DateTime.Now; //本次处理时间 for (; ;) { try { nowTime = DateTime.Now; if (isStop) { break; } //获取定义信息 pointDefineItems = CacheDataHelper.GetKJPointDefineItems(); //判断是否重载倍率报警定义 settingInfo = CacheDataHelper.GetSettingByKeyStr("MultipleSettingUpdateTime"); if (settingInfo != null) { if (settingTime != settingInfo.StrValue) { //重新加载倍率报警定义信息 multiplesettingInfotems = GetAllMultiplesettingInfo(); settingTime = settingInfo.StrValue; } } else { Thread.Sleep(timeSpan * 1000); continue; } //筛选模拟量 pointDefineItems = pointDefineItems.Where(a => (a.DevPropertyID == (int)DeviceProperty.Analog) && (multiplesettingInfotems.FirstOrDefault(b => b.Devid == a.Devid) != null)).ToList(); if (pointDefineItems.Count == 0) { Thread.Sleep(timeSpan * 1000); continue; } //重载周平均值 if (getBasicValueDate.Date != nowTime.Date) { ReloadBasicValues(pointDefineItems); getBasicValueDate = nowTime; } if (pointDefineItems == null) { Thread.Sleep(timeSpan * 1000); continue; } if (pointDefineItems.Count == 0) { Thread.Sleep(timeSpan * 1000); continue; } alarm_AddItems = new List <JC_MbInfo>(); alarm_DelItems = new List <JC_MbInfo>(); alarm_UpdateItems = new List <JC_MbInfo>(); if (lastProcData.Date != nowTime.Date) { //结束报警重新生成 CrossDay(pointDefineItems, multiplesettingInfotems, new DateTime(lastProcData.Year, lastProcData.Month, lastProcData.Day, 23, 59, 59), new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 0, 0, 0)); lastProcData = nowTime; } foreach (Jc_DefInfo def in pointDefineItems) { if (isStop) { break; } if (double.TryParse(def.Ssz, out sszValue)) { multiplesettingInfotem = multiplesettingInfotems.FirstOrDefault(a => a.Devid == def.Devid); if (multiplesettingInfotem == null) { continue; } //未定义该设备类型的倍率报警 ratioAlarmConditionItems = GetRatioAlarmConditionsFromStr(multiplesettingInfotem); //解析倍率报警配置 if (ratioAlarmConditionItems == null) { continue; } //提取倍率报警定义出错,不继续计算 basicValue = GetBasicValueByDef(def); //获取周平均值 if (basicValue == 0) { continue; } //没有基础值,不计算 //计算报警等级 alarmType = JudgeAlarmType(sszValue, ratioAlarmConditionItems, basicValue); if (alarmType != 0) { ratioAlarmConditionItem = ratioAlarmConditionItems[alarmType - 1]; //获取当前报警的倍率信息配置 } ratioAlarm = GetAlarmInfo(def.Point); #region ----报警处理---- if (ratioAlarm == null) { if (alarmType > 0) { //之前没有报警 现在有报警(新增报警) ratioAlarm = new JC_MbInfo(); ratioAlarm.Id = IdHelper.CreateLongId().ToString(); ratioAlarm.Point = def.Point; ratioAlarm.PointID = def.PointID; ratioAlarm.Fzh = def.Fzh.ToString(); ratioAlarm.Kh = def.Kh.ToString(); ratioAlarm.Dzh = def.Dzh.ToString(); ratioAlarm.Devid = def.Devid; ratioAlarm.Wzid = def.Wzid; ratioAlarm.Type = alarmType.ToString(); ratioAlarm.Bstj = "[" + ratioAlarmConditionItem.minValue + "," + ratioAlarmConditionItem.maxValue + "," + ratioAlarmConditionItem.ratioValue + "]"; ratioAlarm.Bsz = ratioAlarmConditionItem.ratioValue; ratioAlarm.Stime = nowTime; ratioAlarm.Ssz = Convert.ToDouble(def.Ssz); ratioAlarm.Pjz = basicValue; ratioAlarm.Zdz = sszValue; ratioAlarm.Zdzs = nowTime; alarm_AddItems.Add(ratioAlarm); } } else { if (alarmType == 0) { //之前有报警 现在没有报警(结束报警) ratioAlarm.Etime = nowTime; alarm_DelItems.Add(ratioAlarm); } else { if (alarmType.ToString() != ratioAlarm.Type) { //之前有报警 报警切换(结束旧报警,生成新报警) ratioAlarm.Etime = nowTime; alarm_DelItems.Add(ratioAlarm); //生成新报警 ratioAlarm = new JC_MbInfo(); ratioAlarm.Id = IdHelper.CreateLongId().ToString(); ratioAlarm.Point = def.Point; ratioAlarm.PointID = def.PointID; ratioAlarm.Fzh = def.Fzh.ToString(); ratioAlarm.Kh = def.Kh.ToString(); ratioAlarm.Dzh = def.Dzh.ToString(); ratioAlarm.Devid = def.Devid; ratioAlarm.Wzid = def.Wzid; ratioAlarm.Type = alarmType.ToString(); ratioAlarm.Bstj = "[" + ratioAlarmConditionItem.minValue + "," + ratioAlarmConditionItem.maxValue + "," + ratioAlarmConditionItem.ratioValue + "]"; ratioAlarm.Bsz = ratioAlarmConditionItem.ratioValue; ratioAlarm.Stime = nowTime; ratioAlarm.Ssz = Convert.ToDouble(def.Ssz); ratioAlarm.Pjz = basicValue; ratioAlarm.Zdz = sszValue; ratioAlarm.Zdzs = nowTime; alarm_AddItems.Add(ratioAlarm); } else { //报警状态持续,更新报警期间最大值 if (sszValue > ratioAlarm.Zdz) { ratioAlarm.Zdz = sszValue; ratioAlarm.Zdzs = nowTime; //更新报警 alarm_UpdateItems.Add(ratioAlarm); } } } } #endregion } } if (alarm_DelItems.Count > 0) { EndAlarmItems(alarm_DelItems); } if (alarm_AddItems.Count > 0) { StartAlarms(alarm_AddItems); } if (alarm_UpdateItems.Count > 0) { UpdateAlarm(alarm_UpdateItems); } } catch (Exception ex) { LogHelper.Error("RatioAlarmProcHandle DataProc Error" + ex.Message); } Thread.Sleep(timeSpan * 1000); } }
/// <summary> /// 跨天和五分钟处理方法 /// </summary> private void CrossDayAndFiveMinite() { DateTime fiveMiniteProcMinite = DateTime.Now; DateTime nowTime = DateTime.Now; List <Jc_DefInfo> pointDefineItems; List <Jc_DevInfo> pointDevItems; Jc_DevInfo pointDevItem; IDriver driverObj = null; int totalcount = 0; bool doFiveMinData = false; //是否要处理五分钟数据 2017.9.15 by for (; ;) { try { doFiveMinData = false; if (isStop) { LogHelper.Info("停止数据处理模块【跨天和五分钟处理方法处理完成】!"); break; } if (DateTime.Now.Day != nowTime.Day) { //2017.12.18 by 异常处理跨天(手动修改电脑时间) CrossDay(new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59), new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0)); } nowTime = DateTime.Now; //if (nowTime.Hour == 0 && nowTime.Minute == 0) //{ // doFiveMinData = false; //刚跨天00:00:00 满足写记录条件,但不应该写记录 //} //else if (nowTime.Hour == 23 && nowTime.Minute == 59 && nowTime.Second > 40 && nowTime.Minute != fiveMiniteProcMinite.Minute) //2017.9.15 by //{ // doFiveMinData = true; //} //else if ((nowTime.Minute % 5 == 0) && (nowTime.Minute != fiveMiniteProcMinite.Minute)) { doFiveMinData = true; } //if ((nowTime.Minute % 5 == 0) && (nowTime.Minute != fiveMiniteProcMinite.Minute)) if (doFiveMinData) { fiveMiniteProcMinite = nowTime; #region ----五分钟数据处理---- pointDefineItems = CacheDataHelper.GetKJPointDefineItems(); pointDefineItems = pointDefineItems.Where(a => a.DevPropertyID == (int)DeviceProperty.Substation).ToList(); pointDevItems = CacheDataHelper.GetAllDevItems(); foreach (Jc_DefInfo station in pointDefineItems) { pointDevItem = pointDevItems.FirstOrDefault(a => a.Devid == station.Devid); if (pointDevItem != null) { if (GlobleStaticVariable.driverHandle.DriverItems.ContainsKey(pointDevItem.Sysid)) { driverObj = GlobleStaticVariable.driverHandle.DriverItems[pointDevItem.Sysid].DLLObj; DriverTransferInterface.Drv_FiveMinPro(driverObj, station.Fzh, nowTime); } } } #endregion } if (nowTime.Hour == 23 && nowTime.Minute == 59 && nowTime.Second > 50) { isCrossDay = true; #region ----跨天处理---- //判断数据处理线程数据是否处理完成,处理完成才继续进行跨天处理 20170703 while (DataProcHandle.Instance.GetArriveDataCount() > 0) { Thread.Sleep(200); } //处理时已跨天 输出日志 20170703 if (DateTime.Now.Day != nowTime.Day) { Basic.Framework.Logging.LogHelper.Error("处理跨天数据时,时间已到第二天!"); } //DateTime nowTime = time; //nowTime = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59); //DateTime tomorrowTime = nowTime.AddDays(1); //tomorrowTime = new DateTime(tomorrowTime.Year, tomorrowTime.Month, tomorrowTime.Day, 0, 0, 0); CrossDay(new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59), new DateTime(nowTime.AddDays(1).Year, nowTime.AddDays(1).Month, nowTime.AddDays(1).Day, 0, 0, 0)); //2017.12.18 by 增加手动修改电脑日期处理时增加 while (true) { Thread.Sleep(200); if (DateTime.Now.Hour != 23) { CreatDayTable(DateTime.Now); break; } } #endregion isCrossDay = false; nowTime = DateTime.Now; //正常跨天处理完成,将时间赋值到第二天 } totalcount++; if (totalcount >= 20)//每4秒记算一次馈电信息 { totalcount = 0; CheckAlarmFeeding(); } } catch (Exception ex) { LogHelper.Error("CrossDayAndFiveMinite Error:" + ex.Message); } Thread.Sleep(200); } }