private void UpdateConfig() { lock (BasePublic.lockerConfig) { if (BasePublic.lstTagsAll == null || BasePublic.lstTagsAll.Count == 0) { BasePublic.lstTagsAll = BLLFactory <B_BS_TagDefine> .Instance.Find(" TagGroupID <> '-1' and IsUse='1' and IsVirtual<1 "); } mtTable = new MTTable(); foreach (var item in BasePublic.lstTagsAll) { var model = new MTKeyValue(); model.Key = item.ID; model.Count = 0; model.StartTime = DateTime.Now; model.AlarmCount = 0; model.NoDataCount = 0; model.Tag = item; mtTable.Add(model); } mtTableNQ = new MTTable(); foreach (var item in BasePublic.lstTagsAllNQ) { var model = new MTKeyValue(); model.Key = item.ID; model.Count = 0; model.StartTime = DateTime.Now; model.AlarmCount = 0; model.NoDataCount = 0; model.Tag = item; mtTableNQ.Add(model); } Console.WriteLine(string.Format("Socket位号配置更新成功...")); } }
/// <summary> /// 将实时数据进行处理 /// </summary> /// <param name="lst"></param> /// <returns></returns> private DataTable GetSendTable(List <M_BS_Realdata_Spt> lst, string type = "0") { var dt = BaseFunction.CreateTable("TagID,TagValue,TagName,TagStatus,RealValue,RealTime"); DataRow dr = null; double value = 0; var status = 0; var str = ""; foreach (var item in lst) { M_BS_TagDefine model_Tag = null; MTKeyValue mtRow = null; if (type == "0") { model_Tag = (from li in BasePublic.lstTagsAll where li.ID == item.TagID select li).FirstOrDefault(); //查找该位号的缓存数据 mtRow = (from li in mtTable where li.Key == item.TagID select li).FirstOrDefault(); } else { model_Tag = (from li in BasePublic.lstTagsAllNQ where li.ID == item.TagID select li).FirstOrDefault(); //查找该位号的缓存数据 mtRow = (from li in mtTableNQ where li.Key == item.TagID select li).FirstOrDefault(); } if (mtRow == null || model_Tag == null) { continue; } if (mtRow.Count == 0) { mtRow.StartTime = DateTime.Now; } mtRow.Count += 1; mtRow.NoDataCount = 0; if (mtRow.Count >= BasePublic.OneDataCount) { mtRow.Value = BasePublic.OneDataCount; mtRow.Count = 0; //mtRow.AlarmCount = 0; } dr = dt.NewRow(); dr["RealTime"] = DateTime.Now.ToString(BasePublic.strTimeFormat); dr["RealValue"] = item.RealValue; dr["TagID"] = item.TagID; dr["TagName"] = model_Tag.TagName; str = ""; status = 0; var IsAlarm = false; if (model_Tag.IsAlarm) { var model_PreTags = (from li in BasePublic.lstTagsAll where li.ID == model_Tag.PreTags select li).FirstOrDefault(); if (model_PreTags == null || model_PreTags.PreTags.Trim().Length == 0) { IsAlarm = true; } else { var model_PreValue = (from li in lst where li.TagID == model_PreTags.ID select li).FirstOrDefault(); if (model_PreValue.RealValue > 0) { IsAlarm = true; } } if (IsAlarm) { if (item.RealValue > model_Tag.TagHH) { status = 1; str = string.Format("参数值({1})过高,正常值{2}({3}至{4})", model_Tag.TagName, item.RealValue, model_Tag.TagVal, model_Tag.TagLL, model_Tag.TagHH); } if (item.RealValue < model_Tag.TagLL) { status = 1; str = string.Format("参数值({1})过低,正常值{2}({3}至{4})", model_Tag.TagName, item.RealValue, model_Tag.TagVal, model_Tag.TagLL, model_Tag.TagHH); } mtRow.AlarmCount += 1; mtRow.Status = status; mtRow.Msg = str; if (mtRow.AlarmCount >= 10) { try { } catch (Exception e) { var msg = string.Format("{0} {1} {2}", DateTime.Now.ToString(BasePublic.strTimeFormat), "转化实时数据出错", e.Message); Console.WriteLine(string.Format(msg)); BasePublic.ExceptionDeal(BaseEnum.Socket, msg); continue; } } } } dr["TagStatus"] = status; dr["TagValue"] = str; dt.Rows.Add(dr); } return(dt); }
/// <summary> /// 验证数据是否报警,并操作 /// </summary> /// <param name="lstAll"></param> /// <param name="dtStore"></param> /// <param name="mtTemp"></param> /// <param name="dtAlarm"></param> public void VerfyAlarm(List <M_BS_TagDefine> lstAll, DataTable dtStore, MTTable mtTemp, ref DataTable dtAlarm) { var rs = false; M_BS_TagDefine modelTag = null; MTKeyValue tempInfo = null; foreach (DataRow item in dtStore.Rows) { modelTag = (from li in lstAll where li.ID == item["TagID"].ToString() select li).FirstOrDefault(); tempInfo = (from li in mtTemp where li.Key == item["TagID"].ToString() select li).FirstOrDefault(); if (tempInfo == null || modelTag == null) { continue; } if (tempInfo.Count == 0) { tempInfo.StartTime = DateTime.Now; tempInfo.AlarmCount = 0; } if (tempInfo.Count >= BasePublic.OneDataCount) { tempInfo.StartTime = DateTime.Now; tempInfo.Count = 0; tempInfo.AlarmCount = 0; } tempInfo.Count += 1; var IsAlarm = false; var status = 0; if (modelTag.IsAlarm) { //该位号的前置位号 var modelPreTags = (from li in BasePublic.lstTagsAll where li.ID == modelTag.PreTags select li).FirstOrDefault(); if (modelPreTags == null || string.IsNullOrEmpty(modelPreTags.PreTags)) { } else { //查找前置位号的值 var modelPreValue = dtStore.Select(string.Format("TagID='{0}'", modelPreTags.ID)).FirstOrDefault(); //(from li in lst where li.TagID == model_PreTags.ID select li).FirstOrDefault(); if (modelPreValue != null && decimal.Parse(modelPreValue["RealValue"].ToString()) > 0) { IsAlarm = true; } } if (IsAlarm) { var isDo = (decimal.Parse(item["RealValue"].ToString()) > modelTag.TagHH) || (decimal.Parse(item["RealValue"].ToString()) < modelTag.TagLL); if (isDo) { tempInfo.AlarmCount += 1; //tempInfo.Status = status; } else { tempInfo.AlarmCount = 0; //tempInfo.Status = 0; } if (tempInfo.AlarmCount >= BasePublic.LimitAlarmCount) { if ( !(modelTag.AlarmTime <= DateTime.Parse(item["RealTime"].ToString()).AddSeconds(-BasePublic.AlarmPeriod))) { continue; } var modelEquipTag = (from li in lstEquipTags where li.TagCode == modelTag.ID select li).FirstOrDefault(); if (modelEquipTag == null) { continue; } var drAlarm = dtAlarm.NewRow(); drAlarm["ID"] = Guid.NewGuid(); drAlarm["EquCode"] = modelEquipTag.EquCode; drAlarm["EquName"] = modelEquipTag.EquipName; drAlarm["TagCode"] = modelEquipTag.TagCode; drAlarm["TagName"] = modelEquipTag.TagName; drAlarm["TagEU"] = modelTag.TagEU; drAlarm["TagLL"] = modelTag.TagLL; drAlarm["TagL"] = modelTag.TagL; drAlarm["TagH"] = modelTag.TagH; drAlarm["TagHH"] = modelTag.TagHH; drAlarm["RealValue"] = item["RealValue"]; drAlarm["RealState"] = 1; drAlarm["RealTime"] = item["RealTime"]; drAlarm["IsDealed"] = 1; dtAlarm.Rows.Add(drAlarm); tempInfo.AlarmCount = 0; tempInfo.Status = 0; } } } } InsertToServer(dtAlarm, "T_EP_EquipWarning"); }