Ejemplo n.º 1
0
        /// <summary>
        /// /获取报警信息
        /// </summary>
        /// <returns></returns>
        public IQueryable <dynamic> GetWarningInfo(WarningQueryParam warningQueryParam)
        {
            var firstTime = Convert.ToDateTime(warningQueryParam.FirstTime);
            var lastTime  = Convert.ToDateTime(warningQueryParam.LastTime);
            //获取报警信息表实体
            var warningInfo = DbSession.WarningInfoDal.GetEntities(w => w.IsDeleted == false);

            var query = from t1 in warningInfo
                        from t2 in warningInfo.GroupBy(w => w.DeviceId).Select(p => new
            {
                newestSubTime    = p.Max(q => q.SubTime),
                warningStartTime = p.Min(q => q.SubTime),
                deviceId         = p.Key
            })
                        where t1.DeviceId == t2.deviceId && t1.SubTime == t2.newestSubTime
                        select new
            {
                t1.DeviceId,
                t1.WarningMessage,
                t2.warningStartTime,
                day    = EntityFunctions.DiffDays(t2.warningStartTime, t2.newestSubTime),
                hour   = EntityFunctions.DiffHours(t2.warningStartTime, t2.newestSubTime),
                minute = EntityFunctions.DiffMinutes(t2.warningStartTime, t2.newestSubTime),
            };

            //按设备ID编号筛选
            if (!string.IsNullOrEmpty(warningQueryParam.SchDeviceId))
            {
                query = query.Where(w => w.DeviceId.Contains(warningQueryParam.SchDeviceId)).AsQueryable();
            }
            //按报警信息筛选
            if (!string.IsNullOrEmpty(warningQueryParam.SchMessage))
            {
                query = query.Where(w => w.WarningMessage.Contains(warningQueryParam.SchMessage)).AsQueryable();
            }
            //按报警时间查询
            if (!string.IsNullOrEmpty(warningQueryParam.FirstTime) && !string.IsNullOrEmpty(warningQueryParam.LastTime))
            {
                query = query.Where(w => (w.warningStartTime > firstTime && w.warningStartTime < lastTime)).AsQueryable();
            }
            //总条数
            warningQueryParam.Total = query.Count();
            return(query);
        }
Ejemplo n.º 2
0
        // GET: Warning
        /// <summary>
        /// 获取设备报警信息
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <param name="firsTime"></param>
        /// <param name="lastTime"></param>
        /// <param name="schMessage"></param>
        /// <param name="schDeviceId"></param>
        /// <returns></returns>
        public ActionResult GetWarningInfo(string limit, string page, string firsTime, string lastTime, string schMessage, string schDeviceId)
        {
            int pageSize  = int.Parse(limit ?? "10");
            int pageIndex = int.Parse(page ?? "1");

            //过滤条件
            var warningQueryParam = new WarningQueryParam()
            {
                PageSize    = pageSize,
                PageIndex   = pageIndex,
                FirstTime   = firsTime,
                LastTime    = lastTime,
                SchMessage  = schMessage,
                SchDeviceId = schDeviceId,
                Total       = 0,
            };
            var pageData = WarningInfoService.GetWarningInfo(warningQueryParam);
            var data     = new { code = 0, msg = "", count = warningQueryParam.Total, data = pageData.ToList() };

            return(Json(data, JsonRequestBehavior.AllowGet));
        }