/// <summary> /// 获取所有前代对象 /// </summary> /// <param name="node"></param> /// <param name="predicate"></param> /// <returns></returns> public static IEnumerable <Meter> Ancestors(this Meter node, Expression <Func <Meter, bool> > predicate) { return(node.Ancestors().Where(predicate.Compile())); }
public static MeterData ToViewData(this Meter node, CategoryDictionary suffix = CategoryDictionary.None) { if (node == null) { return(null); } var model = new MeterData() { Id = node.Id, ParentId = node.ParentId, TreeId = node.TreeId, Rank = node.Rank, Parent = (suffix & CategoryDictionary.Parent) == CategoryDictionary.Parent && node.ParentId.HasValue ? node.Parent.ToViewData() : null, HasChildren = node.Children.Count, BuildingId = node.BuildingId, RelayElecState = node.RelayElecState, PaulElecState = node.PaulElecState, Building = (suffix & CategoryDictionary.Building) == CategoryDictionary.Building ? node.Building.ToViewData() : null, EnergyCategoryId = node.EnergyCategoryId, EnergyCategory = (suffix & CategoryDictionary.EnergyCategory) == CategoryDictionary.EnergyCategory ? (DictionaryCache.Get()[node.EnergyCategoryId].ToViewData()) : null, BrandId = node.BrandId, BrandName = node.Brand == null ? null : node.Brand.Name, Brand = (suffix & CategoryDictionary.Brand) == CategoryDictionary.Brand ? node.Brand.ToViewData() : null, CoordinateMapId = node.CoordinateMapId, Coordinate2dId = node.Coordinate2dId, IsControlByHand = node.IsControlByHand, Coordinate3dId = node.Coordinate3dId, Code = node.Code, GbCode = node.GbCode, Name = node.Name, AliasName = node.AliasName, Initial = node.Initial, Type = node.Type, TypeDict = (suffix & CategoryDictionary.Dictionary) == CategoryDictionary.Dictionary || (suffix & CategoryDictionary.MeterType) == CategoryDictionary.MeterType ? DictionaryCache.Get()[node.Type].ToViewData() : null, Access = node.Access, Sequence = node.Sequence, Address = node.Address, MacAddress = node.MacAddress, Enable = node.Enable, StatusNote = node.StatusNote, GetInterval = node.GetInterval, BranchName = node.BranchName, BranchEnable = node.BranchEnable, Rate = node.Rate, Description = node.Description, IsTurnOn = node.IsTurnOn, SetupMode = node.SetupMode, PortNumber = node.PortNumber, Rs485Address = node.Rs485Address, ActivePrecise = node.ActivePrecise, ReactivePrecise = node.ReactivePrecise, BasicCurrent = node.BasicCurrent, ComProtocol = node.ComProtocol, SpeedRate = node.SpeedRate, IsHarmonic = node.IsHarmonic, Precision = node.Precision, PtRate = node.PtRate, RangeRatio = node.RangeRatio, Caliber = node.Caliber, Hydraulic = node.Hydraulic, Flow = node.Flow, //SetupPosition = node.SetupPosition, SupplyRegion = node.SupplyRegion, Manufactor = node.Manufactor, SetupDate = node.SetupDate, InitialValue = node.InitialValue, PortDescription = node.PortDescription, EffectiveBasePrice = node.EffectiveBasePrice, EffectiveModel = node.EffectiveModel, Status = node.MeterStatus.Where(s => s.Enabled).ToList().OrderByDescending(o => o.MeterMessageType.FirstValue).ThenByDescending(o => o.MeterMessageType.SecondValue).Select(s => s.ToViewData()).ToList(), Organization = ((suffix & CategoryDictionary.Organization) == CategoryDictionary.Organization) && node.Building != null && node.Building.Organization != null?node.Building.Organization.ToViewData() : null, }; if ((suffix & CategoryDictionary.Momentary) == CategoryDictionary.Momentary) { model.MomentaryValues = node.MomentaryValues.Select(x => x.ToViewData()).ToList(); } if ((suffix & CategoryDictionary.Children) == CategoryDictionary.Children) { model.Children = node.Children.Select(x => x.ToViewData(suffix & CategoryDictionary.Momentary)).ToList(); } if ((suffix & CategoryDictionary.Descendant) == CategoryDictionary.Descendant) { model.Descendants = node.Descendants(false).Select(x => x.ToViewData()).ToList(); } if ((suffix & CategoryDictionary.Ancestor) == CategoryDictionary.Ancestor) { model.Ancestors = node.Ancestors().Select(x => x.ToViewData()).ToList(); } EmpContext ctx = null; if ((suffix & CategoryDictionary.Gateway) == CategoryDictionary.Gateway) { if (ctx == null) { ctx = new EmpContext(); } var m = ctx.Meters.FirstOrDefault(x => x.Type == 50101 && x.Access == node.Access); model.Gateway = m == null ? null : m.ToViewData(suffix & CategoryDictionary.Momentary); } if ((suffix & CategoryDictionary.Sibling) == CategoryDictionary.Sibling) { if (ctx == null) { ctx = new EmpContext(); } model.Siblings = ctx.Meters.Where(x => x.ParentId == node.ParentId && x.Access == node.Access).ToList().Select(x => x.ToViewData(CategoryDictionary.Children | CategoryDictionary.Momentary)).ToList(); } if ((suffix & CategoryDictionary.ExtensionField) == CategoryDictionary.ExtensionField) { if (ctx == null) { ctx = new EmpContext(); } model.ExtensionFields = ctx.ExtensionFields.Where(x => x.Table == "Meter" && x.JoinId == node.Id).ToViewList(); } return(model); }