Example #1
0
 private void ViewDetail(AlarmInfoModel item)
 {
     this.NavigationService.Navigate(new AlarmInfoPage()
     {
         ALARM_ID = item.ALARM_ID
     });
 }
        public AlarmInfoSerializer GetAlarmInfoById(String Id)
        {
            AlarmInfoModel      alarmInfo = this._alarmInfoDao.GetById(Id);
            AlarmInfoSerializer result    = new AlarmInfoSerializer(alarmInfo);

            return(result);
        }
Example #3
0
        ///// <summary>
        ///// 新增设备告警(含有位置信息,区域信息)
        ///// </summary>
        ///// <param name="eventType"></param>
        ///// <param name="device_code"></param>
        ///// <param name="alarm_location"></param>
        ///// <param name="area_id"></param>
        ///// <param name="alarm_level"></param>
        ///// <param name="report_time"></param>
        ///// <param name="content"></param>
        ///// <returns></returns>
        //public bool AddInformAlarm(int eventType, string device_code, string alarm_location, int area_id, int alarm_level, string content)
        //{
        //    try
        //    {
        //        ServInformAlarmModel model = new ServInformAlarmModel();
        //        model.alarm_level = alarm_level;
        //        model.alarm_location = alarm_location;
        //        model.area_id = area_id;
        //        model.content = content;
        //        model.device_code = device_code;
        //        model.event_type = eventType;
        //        model.report_time = DateTime.Now;
        //        model.status = (int)EnumClass.InformAlarmStatus.未处理;
        //        int res = servInformAlarmDal.AddEntity(model);
        //        if (res > 0)
        //        {
        //            return true;
        //        }
        //        else
        //        {
        //            return false;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //}

        /// <summary>
        /// 页面发送模拟报警至转发层
        /// </summary>
        /// <param name="alarmLevel"></param>
        /// <param name="deviceCode"></param>
        /// <param name="content"></param>
        /// <param name="eventCode"></param>
        /// <returns></returns>
        public bool AddDeviceAlarm(string alarmName, int alarmLevel, string deviceCode, string content, string eventCode)
        {
            try
            {
                sendAlarmPageDele = new SendAlarmPageDele(CSM.Utils.HttpHelper.PostJsonData);
                string              url         = System.Configuration.ConfigurationManager.AppSettings["InterfaceUrl"] + "/api/Interface/Forward";
                ServDeviceInfoDAL   deviceDal   = new ServDeviceInfoDAL();
                AlarmInfoModel      alarmModel  = new AlarmInfoModel();
                InterfaceData       data        = new InterfaceData();
                ServDeviceInfoModel deviceModel = deviceDal.GetDeviceByDeviceCode(deviceCode);
                alarmModel.alarm_cache_status = 0;
                alarmModel.alarm_event        = eventCode;
                alarmModel.alarm_level        = alarmLevel;
                alarmModel.alarm_location     = "";
                alarmModel.alarm_name         = alarmName;
                alarmModel.alarm_subsystem    = deviceModel.subsystem_id;
                alarmModel.alarm_text         = content;
                alarmModel.alarm_time         = DateTime.Now;
                alarmModel.alarm_type         = (int)EnumClass.AlarmType.设备报警;
                alarmModel.code = deviceCode;
                data.data       = alarmModel;
                data.dataType   = 1;
                data.subSysType = deviceModel.subsystem_id;
                data.mark       = "pageMoniter";
                string param = CSM.Utils.JsonHelper.ObjectToString(data);
                sendAlarmPageDele.BeginInvoke(url, param, Encoding.UTF8, null, null);
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public AlarmInfoSerializer(AlarmInfoModel alarmInfoModel)
 {
     this.id             = alarmInfoModel.Id;
     this.alarmInfo      = alarmInfoModel.AlarmInfo;
     this.deviceId       = alarmInfoModel.DeviceId;
     this.indexId        = alarmInfoModel.IndexId;
     this.indexName      = alarmInfoModel.IndexName;
     this.indexValue     = alarmInfoModel.IndexValue;
     this.thresholdValue = alarmInfoModel.ThresholdValue;
     this.timestamp      = alarmInfoModel.Timestamp
                           .ToString(Constant.getDateFormatString());
 }
 public AlarmInfoSerializer(AlarmInfoModel alarmInfoModel)
 {
     this.id             = alarmInfoModel.Id;
     this.alarmInfo      = alarmInfoModel.AlarmInfo;
     this.deviceId       = alarmInfoModel.DeviceId;
     this.indexId        = alarmInfoModel.IndexId;
     this.indexName      = alarmInfoModel.IndexName;
     this.indexValue     = alarmInfoModel.IndexValue;
     this.thresholdValue = alarmInfoModel.ThresholdValue;
     this.timestamp      = DateTime.Parse(alarmInfoModel.Timestamp.ToString())
                           .ToLocalTime().ToString(Constant.getDateFormatString());
     this.severity  = alarmInfoModel.Severity;
     this.processed = alarmInfoModel.Processed;
 }
Example #6
0
        /// <summary>
        /// 页面发送模拟报警至转发层
        /// </summary>
        /// <param name="alarmLevel"></param>
        /// <param name="deviceCode"></param>
        /// <param name="content"></param>
        /// <param name="eventCode"></param>
        /// <returns></returns>
        public RetMsgModel AddMapDeviceAlarm(string alarmName, int alarmLevel, string deviceCode, string content, string eventCode)
        {
            try
            {
                RetMsgModel retModel = new RetMsgModel();
                sendAlarmPageDele = new SendAlarmPageDele(CSM.Utils.HttpHelper.PostJsonData);
                string              url         = System.Configuration.ConfigurationManager.AppSettings["InterfaceUrl"] + "/api/Interface/Forward";
                ServDeviceInfoDAL   deviceDal   = new ServDeviceInfoDAL();
                AlarmInfoModel      alarmModel  = new AlarmInfoModel();
                InterfaceData       data        = new InterfaceData();
                ServDeviceInfoModel deviceModel = deviceDal.GetDeviceByDeviceCode(deviceCode);
                alarmModel.alarm_cache_status = 0;
                alarmModel.alarm_event        = eventCode;
                alarmModel.alarm_level        = alarmLevel;
                alarmModel.alarm_location     = "";
                alarmModel.alarm_name         = alarmName;
                alarmModel.alarm_subsystem    = deviceModel.subsystem_id;
                alarmModel.alarm_text         = content;
                alarmModel.alarm_time         = DateTime.Now;
                alarmModel.alarm_type         = (int)EnumClass.AlarmType.设备报警;
                alarmModel.code = deviceCode;
                data.data       = alarmModel;
                data.dataType   = 1;
                data.subSysType = deviceModel.subsystem_id;
                data.mark       = "pageMoniter";
                string param = CSM.Utils.JsonHelper.ObjectToString(data);
                //sendAlarmPageDele.BeginInvoke(url, param, Encoding.UTF8, null, null);
                string ret = Utils.HttpHelper.PostWebRequestBandError(url, param, "application/json;charset=utf-8", Encoding.UTF8);
                if (string.IsNullOrEmpty(ret))
                {
                    retModel.status  = 1;
                    retModel.message = "调用转发层返回值为空!";
                }
                else
                {
                    retModel = Utils.JsonHelper.StringToObject <RetMsgModel>(ret);
                }

                return(retModel);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
        public IPagedList <AlarmInfoModel> GetR_MCH_ALARM_DTL_T(string keyword, DateTime?alarmDateStart, DateTime?alarmDateEnd, int pageNo, int pageSize, int CraftDID)
        {
            DataTable tb = getR_MCH_ALARM_DTL_T();

            List <AlarmInfoModel> list = new List <AlarmInfoModel>();

            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    AlarmInfoModel info = new AlarmInfoModel();
                    info.ALARM_ID    = row[0].ToString();
                    info.MCH_CD      = row[1].ToString();
                    info.MCH_NM      = row[2].ToString();
                    info.MCH_ST      = row[3].ToString();
                    info.ALARM_TY    = row[4].ToString();
                    info.ALARM_INFO  = row[5].ToString();
                    info.ITEM_CD     = row[6].ToString();
                    info.MODEL_CD    = row[7].ToString();
                    info.SN_NO       = row[8].ToString();
                    info.ALARM_PART  = row[9].ToString();
                    info.ALARM_CRAFT = row[10].ToString();
                    info.OPER_CD     = row[11].ToString();

                    info.HAND_ST = row[12].ToString();
                    info.MO      = row[13].ToString();

                    info.CRT_ID = row[14].ToString();
                    if (row[4].ToString() != "")
                    {
                        info.CRT_DT = DateTime.Parse(row[15].ToString());
                    }


                    list.Add(info);
                }
            }
            IQueryable <AlarmInfoModel> superset = list.AsQueryable();

            return(new PagedList <AlarmInfoModel>(superset, pageNo, pageSize));
        }
Example #8
0
        /// <summary>
        /// 模型数据改变
        /// </summary>
        /// <param name="obj"></param>
        private void dataChanged(AlarmInfoModel AlarmInfoModel)
        {
            getPageData(pageRepuestParams.PageIndex, pageRepuestParams.PageSize);
            var tmpModel = AlarmInfoList.FirstOrDefault(a => a.Id == AlarmInfoModel.Id);

            this.AlarmInfo = AlarmInfoList.FirstOrDefault();
            ////新增、不存在的数据插入到第一行便于查看
            //if (Equals(tmpModel, null))
            //{
            //    this.AgvInfoList.Insert(0, AgvInfoModel);
            //    //this.AgvInfoList.Insert(0, AgvInfoModel);
            //    AgvInfoList.RemoveAt(this.AgvInfoList.Count - 1);
            //}
            //else
            //{
            //    //修改的更新后置于第一行,便于查看
            //    tmpModel = AgvInfoModel;
            //    AgvInfoList.Move(AgvInfoList.IndexOf(tmpModel), 0);
            //    tmpModel = AgvInfoModel;
            //}
        }
        public String InspectAlarmInfo()
        {
            List <DeviceDataModel> deviceData = _deviceDataDao.GetNotInspected();

            foreach (DeviceDataModel dd in deviceData)
            {
                if (Convert.ToInt32(dd.IndexValue) > 100)
                {
                    AlarmInfoModel alarmInfo = new AlarmInfoModel();
                    alarmInfo.AlarmInfo      = dd.Id;
                    alarmInfo.DeviceId       = dd.DeviceId;
                    alarmInfo.IndexId        = dd.IndexId;
                    alarmInfo.IndexName      = dd.IndexName;
                    alarmInfo.IndexValue     = dd.IndexValue;
                    alarmInfo.ThresholdValue = "100";
                    alarmInfo.Timestamp      = DateTime.Now;

                    _alarmInfoDao.Create(alarmInfo);
                }
            }
            return("success");
        }
        public AlarmInfoModel AlarmInfoGenerator(DeviceDataModel deviceData, ThresholdModel threshold)
        {
            AlarmInfoModel alarmInfo = new AlarmInfoModel
            {
                AlarmInfo      = threshold.Description,
                DeviceId       = deviceData.DeviceId,
                IndexId        = deviceData.IndexId,
                IndexName      = deviceData.IndexName,
                IndexValue     = deviceData.IndexValue,
                ThresholdValue = threshold.ThresholdValue,
                Timestamp      = DateTime.Now,
                Severity       = threshold.Severity,
                Processed      = "No"
            };

            if (threshold.Operator == "equal")
            {
                if (deviceData.IndexValue != threshold.ThresholdValue)
                {
                    return(alarmInfo);
                }
            }
            else if (threshold.Operator == "less")
            {
                if (deviceData.IndexValue > threshold.ThresholdValue)
                {
                    return(alarmInfo);
                }
            }
            else
            {
                if (deviceData.IndexValue < threshold.ThresholdValue)
                {
                    return(alarmInfo);
                }
            }
            return(null);
        }
        public void Run()
        {
            /*
             * this._logger.LogInformation("AlarmInfoJob Run ...");
             * List<DeviceModel> devices = this._deviceDao.Get("all");
             * //将所有设备置为在线状态
             * foreach (DeviceModel device in devices)
             * {
             *  this._deviceDao.SetDeviceOnlineStatus(device.HardwareDeviceId, "yes");
             * }
             * //获取设备数据中"IsScam"="false"的所有数据,并置为"true"
             * List<DeviceDataModel> dataNotInspected = _deviceDataDao.GetNotInspected();
             * Dictionary<String, List<DeviceDataModel>> sortedData = new Dictionary<string, List<DeviceDataModel>>();
             * Dictionary<String, List<String>> fieldMap = new Dictionary<string, List<string>>();
             * List<String> deviceIds = new List<string>();
             * //将deviceId相同的数据整合成sortedData,key存放deviceId,value存放相应的数据列表
             * //将deviceId相同的属性Id整合成fieldMap,key存放deviceId,value存放属性Id的列表
             * foreach (DeviceDataModel d in dataNotInspected)
             * {
             *  if (!sortedData.ContainsKey(d.DeviceId))
             *  {
             *      sortedData.Add(d.DeviceId, new List<DeviceDataModel>());
             *      sortedData[d.DeviceId].Add(d);
             *  }
             *  else
             *  {
             *      sortedData[d.DeviceId].Add(d);
             *  }
             *
             *  if (!fieldMap.ContainsKey(d.DeviceId))
             *  {
             *      fieldMap.Add(d.DeviceId, new List<string>());
             *      fieldMap[d.DeviceId].Add(d.IndexId);
             *  }
             *  else
             *  {
             *      fieldMap[d.DeviceId].Add(d.IndexId);
             *  }
             *
             *  deviceIds.Add(d.DeviceId);
             * }
             *
             * //Automatically add fields from device data
             * foreach (String did in fieldMap.Keys)
             * {
             *  List<FieldSerializer> affiliateFields = _fieldBus.GetAffiliateFields(did);
             *  List<String> affiliateFieldsId = new List<string>();
             *  foreach (var field in affiliateFields)
             *  {
             *      affiliateFieldsId.Add(field.fieldId);
             *  }
             *
             *  foreach (String fid in fieldMap[did])
             *  {
             *      if (!affiliateFieldsId.Contains(fid))
             *      {
             *          FieldSerializer tmpField = new FieldSerializer();
             *          tmpField.fieldName = fid;
             *          tmpField.fieldId = fid;
             *          DeviceModel tmpDevice = this._deviceDao.GetByDeviceId(did);
             *          tmpField.device = tmpDevice.DeviceName;
             *          this._fieldBus.CreateNewField(tmpField);
             *      }
             *  }
             * }
             *
             * deviceIds = deviceIds.Distinct().ToList();
             *
             * foreach (String did in deviceIds)
             * {
             *  this._deviceDao.UpdateLastConnectionTimeByDeviceId(did);
             * }
             *
             * foreach (DeviceModel d in devices)
             * {
             *  DeviceTypeModel tmpDeviceType = this._stateTypeDao.GetDeviceTypeByName(d.DeviceType);
             *  Double tmpOfflineTime = tmpDeviceType.OfflineTime;
             *  TimeSpan passTime = DateTime.Now - d.LastConnectionTime.ToLocalTime();
             *  if (passTime.TotalMinutes > tmpOfflineTime)
             *  {
             *      this._deviceDao.SetDeviceOnlineStatus(d.HardwareDeviceId, "no");
             *  }
             * }
             *
             * Dictionary<String, String> operatorName = new Dictionary<string, string>();
             * operatorName.Add("equal", "=");
             * operatorName.Add("greater", ">");
             * operatorName.Add("less", "<");
             * foreach (String did in deviceIds)
             * {
             *  List<ThresholdModel> thresholdDic = _thresholdDao.GetByDeviceId(did);
             *  foreach (DeviceDataModel data in sortedData[did])
             *  {
             *      var query = thresholdDic.AsQueryable()
             *          .Where(t => t.IndexId == data.IndexId)
             *          .ToList();
             *      foreach (var th in query)
             *      {
             *          String op = th.Operator;
             *          double threshold = th.ThresholdValue;
             *
             *          Boolean abnormal = false;
             *
             *          if (op == "equal")
             *          {
             *              if (data.IndexValue - threshold < 0.0001)
             *              {
             *                  abnormal = true;
             *              }
             *          }
             *          else if (op == "less")
             *          {
             *              if (data.IndexValue <= threshold)
             *              {
             *                  abnormal = true;
             *              }
             *          }
             *          else if (op == "greater")
             *          {
             *              if (data.IndexValue >= threshold)
             *              {
             *                  abnormal = true;
             *              }
             *          }
             *
             *          if (abnormal == true)
             *          {
             *              AlarmInfoModel alarmInfo = new AlarmInfoModel();
             *              alarmInfo.AlarmInfo = th.Description;
             *              alarmInfo.DeviceId = data.DeviceId;
             *              alarmInfo.IndexId = data.IndexId;
             *              alarmInfo.IndexName = data.IndexName;
             *              alarmInfo.IndexValue = data.IndexValue;
             *              alarmInfo.ThresholdValue = threshold;
             *              alarmInfo.Timestamp = DateTime.Now;
             *              alarmInfo.Severity = th.Severity;
             *              alarmInfo.Processed = "No";
             *
             *              _alarmInfoDao.Create(alarmInfo);
             *          }
             *      }
             *  }
             * }*/
            /* zxin-告警信息处理和离线判断方法的理解:
             * 告警信息处理:告警判断频率 1min
             * 1、从threshold表中获取所有告警规则
             * 2、按deviceId、MonitoringId获取前1min的数据,判断是否超过阈值,超过阈值的则向alarmInfo集合中插入告警信息
             * 设备离线判断:频率 1min
             * 1、从MySQL获取所有注册设备信息以及设备类型数据
             * 2、根据deviceId从MongoDB中获取最新一条数据,如果与当前时间差值大于超时告警时间则为离线状态(设备状态更新)
             */
            _logger.LogInformation("AlarmInfoJob Run...");
            _logger.LogInformation("告警判断...");
            /*告警判断*/
            //获取所有告警规则,插入告警信息到MongoDB
            List <ThresholdModel> alarmRules = this._thresholdDao.Get("all");

            foreach (var rule in alarmRules)
            {
                //获取具有告警规则的最新60秒的设备数据
                List <DeviceDataModel> deviceDatas = this._deviceDataDao.ListNewData(rule.DeviceId, 60, rule.IndexId);
                //var isAlarmInfo=deviceDatas.AsQueryable()
                //    .Where(dd=>dd.IndexValue>rule.ThresholdValue)
                foreach (var dd in deviceDatas)
                {
                    AlarmInfoModel alarmInfo = AlarmInfoGenerator(dd, rule);
                    if (alarmInfo != null)
                    {
                        _alarmInfoDao.Create(alarmInfo);
                    }
                }
            }


            _logger.LogInformation("设备离线判断...");
            /*设备离线判断*/
            List <DeviceModel>     devices               = this._deviceDao.Get("all");
            List <DeviceTypeModel> deviceTypes           = this._stateTypeDao.ListAllDeviceType();
            Dictionary <String, List <String> > fieldMap = new Dictionary <string, List <string> >();

            foreach (var device in devices)
            {
                //获取超时告警时间(分钟)
                double   offlinetime = deviceTypes.AsQueryable().Where(dt => dt.DeviceTypeName == device.DeviceType).FirstOrDefault().OfflineTime;
                DateTime date        = DateTime.UtcNow - TimeSpan.FromMinutes(offlinetime);
                //获取最新一条设备数据
                DeviceDataModel deviceData = this._deviceDataDao.GetByDeviceName(device.DeviceName, 1).FirstOrDefault();
                if (deviceData != null)
                {
                    if (deviceData.Timestamp >= date)
                    {
                        this._deviceDao.SetDeviceOnlineStatus(device.HardwareDeviceId, "yes");//设备在线
                    }
                    else
                    {
                        this._deviceDao.SetDeviceOnlineStatus(device.HardwareDeviceId, "no");
                    }
                }
                else
                {
                    this._deviceDao.SetDeviceOnlineStatus(device.HardwareDeviceId, "no");
                }

                /* 更新设备属性:
                 * 1、列出MySQL中现有属性
                 * 2、获取MongoDB中最新数据中的属性
                 * 3、比对并创建新属性
                 */
                List <string>          existedFieldIds = this._fieldDao.ListFieldIdsByDeviceId(device.HardwareDeviceId);
                List <DeviceDataModel> deviceDatas     = this._deviceDataDao.ListNewData(device.HardwareDeviceId, 60);
                foreach (var dd in deviceDatas)
                {
                    if (!existedFieldIds.Contains(dd.IndexId))
                    {
                        FieldModel field = new FieldModel
                        {
                            FieldId   = dd.IndexId,
                            FieldName = dd.IndexName,
                            Device    = dd.DeviceName
                        };
                        this._fieldDao.Create(field);
                    }
                }
                /*更新设备的总告警次数*/
                //获取设备当前总的告警次数
                //int totalInfo = _alarmInfoDao.GetDeviceAffiliateAlarmInfoNumber(device.HardwareDeviceId);
                //int totalInfo = 0;
                //更新MySQL中的设备的告警总次数
                //_deviceBus.UpdateTotalAlarmInfo(device.HardwareDeviceId, totalInfo);
            }
        }
Example #12
0
 public String Create(AlarmInfoModel alarmInfoModel)
 {
     _alarmInfo.InsertOne(alarmInfoModel);
     return("success");
 }
Example #13
0
        public void Run()
        {
            List <DeviceDataModel> dataNotInspected = _deviceDataDao.GetNotInspected();
            Dictionary <String, List <DeviceDataModel> > sortedData = new Dictionary <string, List <DeviceDataModel> >();
            List <String> deviceIds = new List <string>();

            foreach (DeviceDataModel d in dataNotInspected)
            {
                if (!sortedData.ContainsKey(d.DeviceId))
                {
                    sortedData.Add(d.DeviceId, new List <DeviceDataModel>());
                    sortedData[d.DeviceId].Add(d);
                }
                else
                {
                    sortedData[d.DeviceId].Add(d);
                }
                deviceIds.Add(d.DeviceId);
            }
            deviceIds = deviceIds.Distinct().ToList();
            Dictionary <String, String> operatorName = new Dictionary <string, string>();

            operatorName.Add("equal", "=");
            operatorName.Add("greater", ">");
            operatorName.Add("less", "<");
            foreach (String did in deviceIds)
            {
                List <ThresholdModel> thresholdDic = _thresholdDao.GetByDeviceId(did);
                foreach (DeviceDataModel data in sortedData[did])
                {
                    var query = thresholdDic.AsQueryable()
                                .Where(t => t.IndexId == data.IndexId)
                                .ToList();
                    foreach (var th in query)
                    {
                        String op        = th.Operator;
                        double threshold = th.ThresholdValue;
                        String svty      = this._severityDao.GetById(int.Parse(th.Severity)).SeverityName;

                        Boolean abnormal = false;

                        if (op == "equal")
                        {
                            if (double.Parse(data.IndexValue) - threshold < 0.0001)
                            {
                                abnormal = true;
                            }
                        }
                        else if (op == "less")
                        {
                            if (double.Parse(data.IndexValue) <= threshold)
                            {
                                abnormal = true;
                            }
                        }
                        else if (op == "greater")
                        {
                            if (double.Parse(data.IndexValue) >= threshold)
                            {
                                abnormal = true;
                            }
                        }

                        if (abnormal == true)
                        {
                            AlarmInfoModel alarmInfo = new AlarmInfoModel();
                            alarmInfo.AlarmInfo      = th.Description;
                            alarmInfo.DeviceId       = data.DeviceId;
                            alarmInfo.IndexId        = data.IndexId;
                            alarmInfo.IndexName      = data.IndexName;
                            alarmInfo.IndexValue     = data.IndexValue;
                            alarmInfo.ThresholdValue = operatorName[op] + threshold.ToString();
                            alarmInfo.Timestamp      = DateTime.Now;
                            alarmInfo.Severity       = svty;

                            _alarmInfoDao.Create(alarmInfo);
                        }
                    }
                }
            }
        }
Example #14
0
        public void Run()
        {
            List <DeviceDataModel> dataNotInspected = _deviceDataDao.GetNotInspected();
            Dictionary <String, List <DeviceDataModel> > sortedData = new Dictionary <string, List <DeviceDataModel> >();
            List <String> deviceIds = new List <string>();

            foreach (DeviceDataModel d in dataNotInspected)
            {
                if (!sortedData.ContainsKey(d.DeviceId))
                {
                    sortedData.Add(d.DeviceId, new List <DeviceDataModel>());
                    sortedData[d.DeviceId].Add(d);
                }
                else
                {
                    sortedData[d.DeviceId].Add(d);
                }
                deviceIds.Add(d.DeviceId);
            }
            //TODO: Uniquify
            deviceIds = deviceIds.Distinct().ToList();
            foreach (String did in deviceIds)
            {
                Dictionary <String, Tuple <String, int> > thresholdDic = _thresholdDao.GetByDeviceId(did);
                foreach (DeviceDataModel data in sortedData[did])
                {
                    String op        = thresholdDic[data.IndexId].Item1;
                    int    threshold = thresholdDic[data.IndexId].Item2;

                    Boolean abnormal = false;

                    if (op == "equal")
                    {
                        if (Int32.Parse(data.IndexValue) != threshold)
                        {
                            abnormal = true;
                        }
                    }
                    else if (op == "less")
                    {
                        if (Int32.Parse(data.IndexValue) <= threshold)
                        {
                            abnormal = true;
                        }
                    }
                    else if (op == "greater")
                    {
                        if (Int32.Parse(data.IndexValue) >= threshold)
                        {
                            abnormal = true;
                        }
                    }

                    if (abnormal == true)
                    {
                        AlarmInfoModel alarmInfo = new AlarmInfoModel();
                        alarmInfo.AlarmInfo      = data.Id;
                        alarmInfo.DeviceId       = data.DeviceId;
                        alarmInfo.IndexId        = data.IndexId;
                        alarmInfo.IndexName      = data.IndexName;
                        alarmInfo.IndexValue     = data.IndexValue;
                        alarmInfo.ThresholdValue = threshold.ToString();
                        alarmInfo.Timestamp      = DateTime.Now;

                        _alarmInfoDao.Create(alarmInfo);
                    }
                }
            }
        }
Example #15
0
        /// <summary>
        /// 处理报警数据
        /// </summary>
        /// <param name="message">报警数据</param>
        /// <param name="mark">驱动标识</param>
        /// <param name="dataType">数据类型</param>
        /// <param name="subsystem">子系统类型</param>
        /// <returns></returns>
        protected virtual bool HandleAlarmData(object message, string mark, int dataType, int subsystem)
        {
            try
            {
                AlarmInfoModel alarmInfo = JsonHelper.StringToObject <AlarmInfoModel>(message.ToString());
                if (alarmInfo != null)
                {
                    ServAlarmRecordModel alarmRecord    = new ServAlarmRecordModel();
                    ServAlarmRecordDAL   alarmRecordDal = new ServAlarmRecordDAL();
                    InterfaceData        data           = new InterfaceData();
                    alarmRecord.alarm_cache_status = alarmInfo.alarm_cache_status;
                    alarmRecord.alarm_code         = alarmInfo.code;

                    #region  旧版
                    //if (string.IsNullOrEmpty(alarmInfo.alarm_event) || alarmInfo.alarm_event == "")
                    //{
                    //    alarmRecord.alarm_event = -1;
                    //}
                    //else
                    //{
                    //    alarmRecord.alarm_event = GetBaseEventType(alarmInfo.alarm_event);
                    //}

                    #endregion

                    #region  新版
                    alarmRecord.alarm_event = alarmInfo.alarm_event;
                    #endregion
                    alarmRecord.alarm_level        = alarmInfo.alarm_level;
                    alarmRecord.alarm_location     = alarmInfo.alarm_location;
                    alarmRecord.alarm_name         = alarmInfo.alarm_name;
                    alarmRecord.alarm_subsystem    = alarmInfo.alarm_subsystem;
                    alarmRecord.alarm_text         = alarmInfo.alarm_text;
                    alarmRecord.alarm_time         = alarmInfo.alarm_time.ToLocalTime();
                    alarmRecord.alarm_type         = alarmInfo.alarm_type;
                    alarmRecord.confirm_alarm_text = "";
                    alarmRecord.confirm_alarm_time = alarmInfo.alarm_time.ToLocalTime();//确警时间为报警时间(表示未确警)
                    alarmRecord.confirm_person_id  = -1;
                    alarmRecord.confirm_result     = -1;
                    alarmRecord.confirm_state      = (int)EnumClass.ConfirmAlarmState.未确警;
                    int id = alarmRecordDal.AddEntity(alarmRecord);
                    if (id > 0)
                    {
                        alarmRecord.id = id;
                        // string paramData = JsonHelper.ObjectToString(alarmRecord);
                        data.data       = alarmRecord;
                        data.dataType   = dataType;
                        data.mark       = mark;
                        data.subSysType = subsystem;
                        string jsonStr = JsonHelper.ObjectToString(data);
                        HttpHelper.PostJsonData(SubSystemRouteBLL.GetToLogicAlarmRoute(), jsonStr, Encoding.UTF8);
                        return(true);
                    }
                    else
                    {
                        //log:报警数据插入数据库失败+message+mark+dataType+subsystem

                        Log4NetHelp.Info("插入报警数据失败!" + "内容:" + message.ToString() + "驱动标识:" + mark + "数据类型:" + dataType + "子系统类型:" + subsystem);
                        return(false);
                    }
                }
                else
                {
                    Log4NetHelp.Info("数据体格式不正确" + message.ToString());
                    return(false);
                }
            }
            catch (Exception ex)
            {
                //log:处理报警数据失败+message+mark+dataType+subsystem+ex.message
                string msgStr = JsonHelper.ObjectToString(message);
                Log4NetHelp.Error("处理报警数据失败!" + "内容:" + msgStr + "驱动标识:" + mark + "数据类型:" + dataType + "子系统类型:" + subsystem + "错误信息:" + ex.Message);
                return(false);
            }
        }