/// <summary> /// 获取跨库查询所需的表达式 /// </summary> /// <returns></returns> protected override DisPageEntity <HeartbeatEntity> GetDisPageEntity(HeartbeatEntityParams paramz) { DisPageEntity <HeartbeatEntity> disPageEntity = new DisPageEntity <HeartbeatEntity>(); disPageEntity.InCondition = (entities) => { List <long?> keys = entities.Select(a => a.Id).ToList(); return(a => keys.Contains(a.Id)); }; HeartbeatEntityOrderBy orderBy = paramz.orderByAsc; if (orderBy != null) { disPageEntity.OrderType = true; if (orderBy.Id) { disPageEntity.OrderCol = a => a.Id; disPageEntity.OrderColLazy = a => a.Id; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.Id) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.Id) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.Id) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.Id) >= 0; return(disPageEntity); } if (orderBy.LastHeartbeatTime) { disPageEntity.OrderCol = a => a.LastHeartbeatTime; disPageEntity.OrderColLazy = a => a.LastHeartbeatTime; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id, LastHeartbeatTime = a.LastHeartbeatTime }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.LastHeartbeatTime) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.LastHeartbeatTime) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.LastHeartbeatTime) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.LastHeartbeatTime) >= 0; return(disPageEntity); } if (orderBy.RobotMac) { disPageEntity.OrderCol = a => a.RobotMac; disPageEntity.OrderColLazy = a => a.RobotMac; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id, RobotMac = a.RobotMac }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.RobotMac) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.RobotMac) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.RobotMac) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.RobotMac) >= 0; return(disPageEntity); } if (orderBy.Remark) { disPageEntity.OrderCol = a => a.Remark; disPageEntity.OrderColLazy = a => a.Remark; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id, Remark = a.Remark }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.Remark) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.Remark) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.Remark) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.Remark) >= 0; return(disPageEntity); } if (orderBy.ExtendField) { disPageEntity.OrderCol = a => a.ExtendField; disPageEntity.OrderColLazy = a => a.ExtendField; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id, ExtendField = a.ExtendField }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.ExtendField) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.ExtendField) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.ExtendField) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.ExtendField) >= 0; return(disPageEntity); } if (orderBy.MonitorServer) { disPageEntity.OrderCol = a => a.MonitorServer; disPageEntity.OrderColLazy = a => a.MonitorServer; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id, MonitorServer = a.MonitorServer }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.MonitorServer) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.MonitorServer) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.MonitorServer) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.MonitorServer) >= 0; return(disPageEntity); } } disPageEntity.OrderType = false; orderBy = paramz.orderByDesc; if (orderBy != null) { if (orderBy.Id) { disPageEntity.OrderCol = a => a.Id; disPageEntity.OrderColLazy = a => a.Id; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.Id) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.Id) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.Id) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.Id) >= 0; return(disPageEntity); } else if (orderBy.LastHeartbeatTime) { disPageEntity.OrderCol = a => a.LastHeartbeatTime; disPageEntity.OrderColLazy = a => a.LastHeartbeatTime; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id, LastHeartbeatTime = a.LastHeartbeatTime }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.LastHeartbeatTime) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.LastHeartbeatTime) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.LastHeartbeatTime) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.LastHeartbeatTime) >= 0; return(disPageEntity); } else if (orderBy.RobotMac) { disPageEntity.OrderCol = a => a.RobotMac; disPageEntity.OrderColLazy = a => a.RobotMac; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id, RobotMac = a.RobotMac }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.RobotMac) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.RobotMac) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.RobotMac) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.RobotMac) >= 0; return(disPageEntity); } else if (orderBy.Remark) { disPageEntity.OrderCol = a => a.Remark; disPageEntity.OrderColLazy = a => a.Remark; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id, Remark = a.Remark }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.Remark) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.Remark) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.Remark) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.Remark) >= 0; return(disPageEntity); } else if (orderBy.ExtendField) { disPageEntity.OrderCol = a => a.ExtendField; disPageEntity.OrderColLazy = a => a.ExtendField; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id, ExtendField = a.ExtendField }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.ExtendField) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.ExtendField) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.ExtendField) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.ExtendField) >= 0; return(disPageEntity); } else if (orderBy.MonitorServer) { disPageEntity.OrderCol = a => a.MonitorServer; disPageEntity.OrderColLazy = a => a.MonitorServer; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id, MonitorServer = a.MonitorServer }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.MonitorServer) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.MonitorServer) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.MonitorServer) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.MonitorServer) >= 0; return(disPageEntity); } else { disPageEntity.OrderCol = a => a.Id; disPageEntity.OrderColLazy = a => a.Id; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.Id) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.Id) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.Id) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.Id) >= 0; return(disPageEntity); } } else { disPageEntity.OrderCol = a => a.Id; disPageEntity.OrderColLazy = a => a.Id; disPageEntity.OrderColAndKeyLazy = a => new HeartbeatEntity { Id = a.Id }; disPageEntity.GreatThan = (val) => a => val.CompareTo(a.Id) < 0; disPageEntity.GreatEqThan = (val) => a => val.CompareTo(a.Id) <= 0; disPageEntity.LessThan = (val) => a => val.CompareTo(a.Id) > 0; disPageEntity.LessEqThan = (val) => a => val.CompareTo(a.Id) >= 0; return(disPageEntity); } }
/// <summary> /// 升序、降序排序的查询参数设置,当对应字段的升序设置为true时才会对 /// 该字段降序。 /// </summary> /// <param name="query">待设置降序参数的query对象</param> /// <param name="orderBy">装载降序参数的实体类</param> /// <returns>返回设置好降序参数的query对象</returns> IQueryable <HeartbeatEntity> OrderBy(IQueryable <HeartbeatEntity> query, HeartbeatEntityParams eqArgs) { HeartbeatEntityOrderBy orderBy = eqArgs.orderByAsc; if (orderBy != null) { if (orderBy.Id) { return(query = query.OrderBy(a => a.Id)); } else if (orderBy.LastHeartbeatTime) { return(query = query.OrderBy(a => a.LastHeartbeatTime)); } else if (orderBy.RobotMac) { return(query = query.OrderBy(a => a.RobotMac)); } else if (orderBy.Remark) { return(query = query.OrderBy(a => a.Remark)); } else if (orderBy.ExtendField) { return(query = query.OrderBy(a => a.ExtendField)); } else if (orderBy.MonitorServer) { return(query = query.OrderBy(a => a.MonitorServer)); } } orderBy = eqArgs.orderByDesc; if (orderBy != null) { if (orderBy.Id) { return(query = query.OrderByDescending(a => a.Id)); } else if (orderBy.LastHeartbeatTime) { return(query = query.OrderByDescending(a => a.LastHeartbeatTime)); } else if (orderBy.RobotMac) { return(query = query.OrderByDescending(a => a.RobotMac)); } else if (orderBy.Remark) { return(query = query.OrderByDescending(a => a.Remark)); } else if (orderBy.ExtendField) { return(query = query.OrderByDescending(a => a.ExtendField)); } else if (orderBy.MonitorServer) { return(query = query.OrderByDescending(a => a.MonitorServer)); } else { return(query = query.OrderByDescending(a => a.Id)); } } else { return(query = query.OrderByDescending(a => a.Id)); } }