public IHttpActionResult GetAllDeviceInfos() { //过滤的设备名 过滤备注schDeviceId schStatusFlag var queryParam = new DeviceQueryParam() { PageSize = 10, PageIndex = 1, Total = 0 }; var pageData = DeviceParameterInfoService.ApiGetDeviceParameter().ToList(); return(Json(pageData)); }
/// <summary> /// 查询设备信息 /// </summary> /// <param name="deviceQueryParam"></param> /// <returns>分页设备数据</returns> public IQueryable <Device> LoagDevicePageData(DeviceQueryParam deviceQueryParam) { var deviceParameterInfo = DbSession.DeviceParameterInfoDal.GetEntities(t => true); var deviceInfo = DbSession.DeviceInfoDal.GetEntities(d => d.IsDeleted == false); //查询每台机器的最新一条数据(分组查询) var query = from t1 in deviceParameterInfo from t2 in deviceParameterInfo.GroupBy(m => m.DeviceInfoId).Select(p => new { newestTime = p.Max(q => q.SubTime), deviceInfoId = p.Key }) join t3 in deviceInfo on t1.DeviceInfoId equals t3.Id where t1.DeviceInfoId == t2.deviceInfoId && t1.SubTime == t2.newestTime select new Device { Id = t3.Id, DeviceId = t3.DeviceId, StatusFlag = t1.StatusFlag, }; //按设备ID查找 if (!string.IsNullOrEmpty(deviceQueryParam.SchDeviceId)) { query = query.Where(u => u.DeviceId.Contains(deviceQueryParam.SchDeviceId)).AsQueryable(); } //按设备状态筛选 if (!string.IsNullOrEmpty(deviceQueryParam.SchStatusFlag)) { query = query.Where(u => u.StatusFlag.Contains(deviceQueryParam.SchStatusFlag)).AsQueryable(); } deviceQueryParam.Total = query.Count(); return(query.OrderBy(d => d.DeviceId) .Skip(deviceQueryParam.PageSize * (deviceQueryParam.PageIndex - 1)) .Take(deviceQueryParam.PageSize).AsQueryable()); }
/// <summary> /// 获取所有设备信息 /// </summary> /// <returns></returns> public ActionResult GetAllDeviceInfos(string limit, string page, string schDeviceId, string schStatusFlag) { int pageSize = int.Parse(limit ?? "10"); int pageIndex = int.Parse(page ?? "1"); //过滤的设备名 过滤备注schDeviceId schStatusFlag var queryParam = new DeviceQueryParam() { PageSize = pageSize, PageIndex = pageIndex, SchDeviceId = schDeviceId, SchStatusFlag = schStatusFlag, Total = 0 }; var pageData = DeviceInfoService.LoagDevicePageData(queryParam).ToList(); var data = new { code = 0, msg = "", count = queryParam.Total, data = pageData.ToList() }; if (!string.IsNullOrEmpty(schDeviceId) || !string.IsNullOrEmpty(schStatusFlag)) { //写操作日志 OperationLogService.Add("查找设备", "设备管理", LoginInfo, schDeviceId, schStatusFlag); } return(Json(data, JsonRequestBehavior.AllowGet)); }