Example #1
0
        public ActionResult DeviceFault(int userId, int dId, string pageNo)
        {
            //int totalRecord = 0;
            //int yyyy = DateTime.Now.Year;
            int intValue = 0;
            int.TryParse(pageNo, out intValue);
            Pager page = new Pager() { PageSize = ComConst.PageSize, PageIndex = intValue };
            Hashtable table = new Hashtable();
            table.Add("page", page);
            Fault fault = new Fault() { confirmed = "0", device = new Device() { id = dId }, sendTime = DateTime.Now };
            table.Add("fault", fault);
            ViewData["page"] = page;
            IList<Fault> faultsList = faultService.GetDeviceLogsPage(table);
            /*
            totalRecord += (table["page"] as Pager).RecordCount;

            int startIndex = (intValue - 1) * page.PageSize;//当前页码的开始索引
            IList<Fault> faults = new List<Fault>();

            if (totalRecord > startIndex)
            {
                foreach (Fault item in faultsList)
                {
                    if (faults.Count < page.PageSize)
                        faults.Add(item);
                    else
                        break;
                }
            }

            while (yyyy-- > DateTime.Now.Year - 5)
            {
                //改成开始时间
                page.PageIndex = Math.Abs(startIndex + page.PageSize - totalRecord) / page.PageSize;
                fault.sendTime = fault.sendTime.AddYears(-1);
                faultsList = faultService.GetDeviceLogsPage(table);
                int skip = 0;
                if (Math.Abs(totalRecord - startIndex) < page.PageSize)
                    skip = totalRecord - startIndex;

                totalRecord += (table["page"] as Pager).RecordCount;
                if (totalRecord > startIndex)
                {
                    foreach (Fault item in faultsList)
                    {
                        if (faults.Count < page.PageSize && skip++ >= 0)
                            faults.Add(item);
                    }
                }

            }

            page.RecordCount = totalRecord;//返回查询的所有年数的所有记录
            page.PageIndex = intValue; */
            ViewData["user"] = UserService.GetInstance().Get(userId);

            return View("devicefault", faultsList);
        }
        public void Run()
        {
            try
            {
                InitData();
                Hashtable table = new Hashtable();
                string inforank = ErrorType.ERROR_TYPE_INFORMATRION + "," + ErrorType.ERROR_TYPE_FAULT + "," + ErrorType.ERROR_TYPE_ERROR + "," + ErrorType.ERROR_TYPE_WARN;
                DateTime endTime = DateTime.Now.AddDays(1);//结束时间
                DateTime startTime = DateTime.Now.AddDays(-1);//开始时间
                Pager page = new Pager() { PageIndex = 1, PageSize = 50 };

                Fault fault = new Fault() { sendTime = startTime, confirmed = "1,0", inforank = inforank };
                table.Add("page", page);
                table.Add("fault", fault);
                table.Add("endTime", endTime);
                table.Add("fromview", true);
                if (allPlants != null && allPlants.Count > 0)

                    foreach (Plant plant in allPlants)
                    {
                        if (plant.plantUnits == null || plant.plantUnits.Count == 0 || plant.hasFaultDevice == false)
                            continue;
                        string collectorString = string.Empty;

                        foreach (PlantUnit unit in plant.plantUnits)
                        {
                            if (unit.collector == null)
                                continue;
                            collectorString += string.Format("{0},", unit.collector.id);//电站下所有采集器
                        }
                        if (collectorString.Length > 1)
                            collectorString = collectorString.Substring(0, collectorString.Length - 1);
                        if (string.IsNullOrEmpty(collectorString)) continue;
                        fault.collectorString = collectorString;
                        IList<Fault> plantFaults = null;
                        try
                        {
                            plantFaults = faultService.GetPlantLoglist(table);//查询时间是倒序排列
                            if (plantFaults.Count == 0)
                            {
                                ConsoleColor color = Console.ForegroundColor;
                                Console.ForegroundColor = ConsoleColor.Blue;
                                Console.WriteLine(string.Format("there was no fault msg in the plant of {0}", plant.name));
                                Console.ForegroundColor = color;

                            }
                        }
                        catch
                        {
                            throw;
                        }
                        if (plantFaults != null && plantFaults.Count > 0)
                            if (plantFaults[0].sendTime > plant.waringLastSendTime)
                            {
                                User user = UserService.GetInstance().Get((int)plant.userID);
                                if (user != null)
                                {
                                    string lang = "en-us";
                                    if (user.Language != null)
                                        lang = user.Language.codename;
                                    SendWarningHtml(lang, plant.id, plant.name, user.email, user.id);
                                    //更新最后发送时间
                                    plantService.UpdataWarningLastSendTime(plant.id, DateTime.Now);
                                    plant.waringLastSendTime = DateTime.Now;
                                    ConsoleColor color = Console.ForegroundColor;
                                    Console.ForegroundColor = ConsoleColor.Blue;
                                    Console.WriteLine(string.Format("warning device list of plant {0} sent success", plant.name));
                                    Console.ForegroundColor = color;
                                }
                            }
                    }
            }
            catch (Exception e )
            {
                Console.WriteLine(e.Message);
            }
        }
Example #3
0
 /// <summary>
 /// 取得告警列表
 /// </summary>
 /// <returns></returns>
 public void GetFaultList()
 {
     if (this.listTcpbug != null && listTcpbug.Count > 0)
     {
         Fault fault = null;
         int colllectorID = GetCollectorId();
         foreach (Bug bug in listTcpbug)
         {
             fault = new Fault();
             fault.address = bug.deviceAddress.ToString();
             fault.errorCode = bug.faultType;
             fault.errorTypeCode = ErrorItem.getErrorTypefromMemcached(bug.faultType);
             fault.data1 = bug.data1;
             fault.data2 = bug.data2;
             fault.sendTime = bug.faultTime;
             fault.collectorID = colllectorID;
             fault.confirm = false;
             int deviceID = this.GetDeviceId(colllectorID, bug.deviceAddress);
             fault.device = new Device() { id = deviceID };
             faultList.Add(fault);
         }
     }
 }
Example #4
0
 /// <summary>
 /// 取得告警列表
 /// </summary>
 /// <returns></returns>
 public void GetFaultList()
 {
     if (this.listTcpbug != null && listTcpbug.Count > 0)
     {
         Fault fault = null;
         int colllectorID = GetCollectorId();
         foreach (Bug bug in listTcpbug)
         {
             fault = new Fault();
             fault.address = bug.deviceAddress.ToString();
             fault.errorCode = bug.faultType;
             ErrorItem errorItem = ErrorItem.getErrotItemByCode(bug.faultType);
             fault.errorTypeCode = errorItem == null?ErrorType.ERROR_TYPE_FAULT:errorItem.errorType;
             fault.sendTime = bug.faultTime;
             fault.collectorID = colllectorID;
             fault.confirm = false;
             int deviceID = this.GetDeviceId(colllectorID, bug.deviceAddress);
             fault.device = new Device() { id = deviceID };
             faultList.Add(fault);
         }
     }
 }
Example #5
0
        public ActionResult Logs()
        {
            string pageIndexStr = Request.QueryString["page"];
            int pageindex = 0;
            int.TryParse(pageIndexStr, out pageindex);
            string pidStr = Request.QueryString["pid"];
            int pid = 0;
            int.TryParse(pidStr, out pid);
            #region 将查询时间设为23点59分59秒
            DateTime startTime = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            DateTime endTime = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString());
            #endregion

            #region 获取电站所有采集器ID字符串
            string collectorString = string.Empty;
            {
                Plant curPlant = PlantService.GetInstance().GetPlantInfoById(pid);
                foreach (PlantUnit unit in curPlant.plantUnits)
                {
                    collectorString += string.Format("{0},", unit.collector.id);
                }
            }
            if (collectorString.Length > 1)
                collectorString = collectorString.Substring(0, collectorString.Length - 1);
            #endregion

            //错误项目字符串
            string inforank = ErrorType.ERROR_TYPE_INFORMATRION + "," + ErrorType.ERROR_TYPE_FAULT + "," + ErrorType.ERROR_TYPE_ERROR + "," + ErrorType.ERROR_TYPE_WARN;

            Hashtable table = new Hashtable();
            Pager page = new Pager() { PageIndex = pageindex, PageSize = 10 };
            Fault fault = new Fault() { sendTime = startTime, confirmed = "0", inforank = inforank, collectorString = collectorString };
            table.Add("page", page);
            table.Add("fault", fault);
            table.Add("endTime", endTime);
            ViewData["page"] = table["page"];
            IList<Fault> logs = null;
            try
            {
                logs = logService.GetPlantLoglist(table);
            }
            catch
            {
                logs = new List<Fault>();
            }
            return View(logs);
        }
Example #6
0
 public IList<Fault> Getlist(Fault fault)
 {
     return _faultDao.Getlist(fault);
 }
Example #7
0
        /// <summary>
        /// hashtable 索引
        /// user.用户对象 可空
        /// plants.电站对象集合 可空
        /// startTime.开始时间
        /// endTime.结束时间
        /// items.查询项目  告警  错误  信息 。。。逗号分隔
        /// state.状态 已确认  未确认 逗号分隔
        /// page.分页对象 page 类型
        /// 注意  0 1 只能一项为空 两项都不为空时以电站对象为准
        /// 返回数据取 hashtable["source"]
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public void GetAllLogs(Hashtable table)
        {
            if (table["user"] == null && table["plants"] == null)
                return;

            //IList<Fault> faults = new List<Fault>();

            Hashtable htable = new Hashtable();

            #region  查询项目
            string inforank = table["items"] as string;

            inforank = inforank.EndsWith(",") ? inforank.Substring(0, inforank.Length - 1) : inforank;
            if (inforank.IndexOf("-1") > -1)
            {
                inforank = ErrorType.ERROR_TYPE_INFORMATRION + "," + ErrorType.ERROR_TYPE_FAULT + "," + ErrorType.ERROR_TYPE_ERROR + "," + ErrorType.ERROR_TYPE_WARN;
            }

            #endregion

            #region 采集器Ids
            string collectorString = string.Empty;//采集器id组合

            //电站信息参数
            if (table["plants"] != null)
            {
                collectorString = string.Empty;
                IList<Plant> plants = table["plants"] as IList<Plant>;
                foreach (Plant plant in plants)
                {
                    foreach (PlantUnit unit in plant.allFactUnits)
                    {
                        collectorString += string.Format("{0},", unit.collector.id);
                    }
                }
            }
            else
            {
                User user = table["user"] as User;
                foreach (Plant plant in user.displayPlants)
                {
                    foreach (PlantUnit unit in plant.allFactUnits)
                    {
                        collectorString += string.Format("{0},", unit.collector.id);
                    }
                }
            }

            collectorString = collectorString.EndsWith(",") ? collectorString.Substring(0, collectorString.Length - 1) : collectorString;
            #endregion

            #region 开始时间

            DateTime startTime = DateTime.Parse(table["startTime"].ToString());

            #endregion

            #region 结束时间
            DateTime endTime = DateTime.Parse(table["endTime"].ToString()).AddDays(1);

            #endregion

            #region 状态
            string stateStr = table["state"] as string;
            stateStr = stateStr.Equals("-1") ? "1,0" : stateStr;
            #endregion

            #region 分页对象

            Pager page = table["page"] as Pager;
            int startIndex = page.PageSize * (page.PageIndex - 1);
            int pageIndex = page.PageIndex;

            #endregion

            Fault fault = new Fault() { sendTime = startTime, confirmed = stateStr, inforank = inforank, collectorString = collectorString };
            htable.Add("page", page);
            htable.Add("fault", fault);
            htable.Add("endTime", endTime);
            htable["fromview"] = table["fromview"];
            IList<Fault> faultsList = GetPlantLoglist(htable);

            /*
            int totalRecord = 0;
            //跨年
            if (endTime.Year > startTime.Year)
            {
                int yyyy = endTime.Year;
                while (yyyy-- > startTime.Year)
                {
                    //改成开始时间
                    fault.sendTime = new DateTime(yyyy + 1, 1, 1, 0, 0, 0);

                    //htable["endTime"] = new DateTime(yyyy - 1, 12, 31);
                    IList<Fault> faultsList = GetPlantLoglist(htable);
                    int skip = 0;
                    if (Math.Abs(totalRecord - startIndex) < page.PageSize)
                        skip = totalRecord - startIndex;

                    totalRecord += (htable["page"] as Pager).RecordCount;
                    if (totalRecord > startIndex)
                    {
                        foreach (Fault item in faultsList)
                        {
                            if (faults.Count < page.PageSize && skip++ >= 0)
                                faults.Add(item);
                            else
                                break;
                        }
                    }
                    page.PageIndex = Math.Abs(startIndex + page.PageSize - totalRecord) / page.PageSize;
                    //fault.sendTime = new DateTime(yyyy, 01, 01);
                    htable["endTime"] = new DateTime(yyyy, 12, 31, 23, 59, 59);

                }
                //htable["endTime"] = endTime;
                fault.sendTime = new DateTime(yyyy + 1, 01, 01, 0, 0, 0);
                if (fault.sendTime < startTime)
                    fault.sendTime = startTime;
                IList<Fault> lastfaultsList = GetPlantLoglist(htable);
                int lastskip = 0;
                if (Math.Abs(totalRecord - startIndex) < page.PageSize)
                    lastskip = totalRecord - startIndex;
                totalRecord += (htable["page"] as Pager).RecordCount;
                if (totalRecord > startIndex)
                {
                    foreach (Fault item in lastfaultsList)
                    {
                        if (faults.Count < page.PageSize && lastskip++ >= 0)
                            faults.Add(item);
                        if (faults.Count > page.PageSize)
                            break;
                    }

                    if (faults.Count < page.PageSize)//如果不够获取下一页的数据
                    {
                        page.PageIndex = page.PageIndex + 1;
                        IList<Fault> nextPageList = GetPlantLoglist(htable);
                        foreach (Fault fau in nextPageList)
                            if (faults.Count < page.PageSize)
                                faults.Add(fau);
                            else
                                break;

                    }
                }
            }
            else
            {
                IList<Fault> faultsList = GetPlantLoglist(htable);
                totalRecord = (htable["page"] as Pager).RecordCount;
                faults = faultsList;
            }
            page.RecordCount = totalRecord;//返回查询的所有年数的所有记录
            page.PageIndex = pageIndex;*/
            faultsList = faultsList.OrderByDescending(m => m.sendTime).ToList<Fault>();
            table.Add("source", faultsList);
        }