private IAggregateFluent <Person> CreateSubject() { var collection = CreateCollection <Person>(); var subject = new AggregateFluent <Person, Person>(collection, Enumerable.Empty <IPipelineStageDefinition>(), new AggregateOptions()); return(subject); }
private IAggregateFluent <Person, Person> CreateSubject() { var settings = new MongoCollectionSettings(); var collection = Substitute.For <IMongoCollection <Person> >(); collection.Settings.Returns(settings); var options = new AggregateOptions <Person>(); var subject = new AggregateFluent <Person, Person>(collection, new List <object>(), options); return(subject); }
private IAggregateFluent <Person> CreateSubject() { var settings = new MongoCollectionSettings(); var collection = Substitute.For <IMongoCollection <Person> >(); collection.DocumentSerializer.Returns(settings.SerializerRegistry.GetSerializer <Person>()); collection.Settings.Returns(settings); var subject = new AggregateFluent <Person, Person>(collection, Enumerable.Empty <IPipelineStageDefinition>(), new AggregateOptions()); return(subject); }
// private methods private IAggregateFluent<C> CreateSubject() { var settings = new MongoCollectionSettings(); _collection = Substitute.For<IMongoCollection<C>>(); _collection.DocumentSerializer.Returns(BsonSerializer.SerializerRegistry.GetSerializer<C>()); _collection.Settings.Returns(settings); var options = new AggregateOptions(); var subject = new AggregateFluent<C, C>(_collection, Enumerable.Empty<IPipelineStageDefinition>(), options); return subject; }
// private methods private IAggregateFluent <C> CreateSubject() { var settings = new MongoCollectionSettings(); _mockCollection = new Mock <IMongoCollection <C> >(); _mockCollection.SetupGet(c => c.DocumentSerializer).Returns(BsonSerializer.SerializerRegistry.GetSerializer <C>()); _mockCollection.SetupGet(c => c.Settings).Returns(settings); var options = new AggregateOptions(); var subject = new AggregateFluent <C, C>(_mockCollection.Object, Enumerable.Empty <IPipelineStageDefinition>(), options); return(subject); }
private IAggregateFluent <Person> CreateSubject( CancellationToken cancellationToken = default(CancellationToken), IAsyncCursor <Person> cursor = null) { var collection = CreateCollection <Person>(); var subject = new AggregateFluent <Person, Person>(collection, Enumerable.Empty <IPipelineStageDefinition>(), new AggregateOptions()); if (cursor != null) { subject.ToCursor(cancellationToken).Returns(cursor); subject.ToCursorAsync(cancellationToken).Returns(Task.FromResult(cursor)); } return(subject); }
// private methods private IAggregateFluent <C> CreateSubject(IClientSessionHandle session = null) { var mockDatabase = new Mock <IMongoDatabase>(); SetupDatabaseGetCollectionMethod <C>(mockDatabase); var settings = new MongoCollectionSettings(); _mockCollection = new Mock <IMongoCollection <C> >(); _mockCollection.SetupGet(c => c.Database).Returns(mockDatabase.Object); _mockCollection.SetupGet(c => c.DocumentSerializer).Returns(settings.SerializerRegistry.GetSerializer <C>()); _mockCollection.SetupGet(c => c.Settings).Returns(settings); var options = new AggregateOptions(); var subject = new AggregateFluent <C, C>(session, _mockCollection.Object, new EmptyPipelineDefinition <C>(), options); return(subject); }
public static IClientSessionHandle _session <TDocument, TResult>(this AggregateFluent <TDocument, TResult> obj) { var fieldInfo = typeof(AggregateFluent <TDocument, TResult>).GetField("_session", BindingFlags.NonPublic | BindingFlags.Instance); return((IClientSessionHandle)fieldInfo.GetValue(obj)); }
public static PipelineDefinition <TDocument, TResult> _pipeline <TDocument, TResult>(this AggregateFluent <TDocument, TResult> obj) { var fieldInfo = typeof(AggregateFluent <TDocument, TResult>).GetField("_pipeline", BindingFlags.NonPublic | BindingFlags.Instance); return((PipelineDefinition <TDocument, TResult>)fieldInfo.GetValue(obj)); }
public static AggregateOptions _options <TDocument, TResult>(this AggregateFluent <TDocument, TResult> obj) { var fieldInfo = typeof(AggregateFluent <TDocument, TResult>).GetField("_options", BindingFlags.NonPublic | BindingFlags.Instance); return((AggregateOptions)fieldInfo.GetValue(obj)); }
public static IMongoCollection <TDocument> _collection <TDocument, TResult>(this AggregateFluent <TDocument, TResult> obj) { var fieldInfo = typeof(AggregateFluent <TDocument, TResult>).GetField("_collection", BindingFlags.NonPublic | BindingFlags.Instance); return((IMongoCollection <TDocument>)fieldInfo.GetValue(obj)); }
protected IOrderedEnumerable <MembersRisingTendencyDetailDto> Group(int Type, string dateFormat, DateTime beginTime, DateTime endTime, int Period) { var builderFilter = Builders <BsonDocument> .Filter; var Bson = new List <BsonDocument>(); IAggregateFluent <BsonDocument> AggregateFluent; Dictionary <string, object> dateToStringKeyValuePairs = new Dictionary <string, object>(); dateToStringKeyValuePairs.Add("format", dateFormat); if (Type == 1) { dateToStringKeyValuePairs.Add("date", "$createdTime"); } else { dateToStringKeyValuePairs.Add("date", "$createTime"); } dateToStringKeyValuePairs.Add("timezone", "+08:00"); var Group = new BsonDocument { { "_id", new BsonDocument("$dateToString", new BsonDocument(dateToStringKeyValuePairs)) }, { "Value", new BsonDocument("$sum", 1) } }; var Group1 = new BsonDocument { { "_id", new BsonDocument { { "Day", new BsonDocument { { "$dateToString", new BsonDocument(dateToStringKeyValuePairs) } } }, { "UserId", "$uid" } } }, { "Value", new BsonDocument("$sum", 1) } }; var Group2 = new BsonDocument { { "_id", "$_id.Day" }, { "Value", new BsonDocument("$sum", 1) } }; var Group3 = new BsonDocument { { "_id", "" }, { "Value", new BsonDocument("$sum", 1) } }; var Group5 = new BsonDocument { { "_id", "$userId" }, { "Count", new BsonDocument("$sum", 1) } }; var Group6 = new BsonDocument { { "_id", 1 }, { "Count", new BsonDocument("$sum", 1) } }; var list = new List <MembersRisingTendencyDetailDto>(); switch (Type) { case 1: IQueryable <UmengApiData> umengApiDataQuery; Double activeUser; if (Period == 1) { for (int i = 0; i < 7; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddDays(i); var to = beginTime.AddDays(i).ToDayEnd(); umengApiDataQuery = _umengApiDataRepository.GetAll().Where(x => x.Date >= from && x.Date <= to); activeUser = umengApiDataQuery.Count() > 0 ? umengApiDataQuery.Average(x => x.UniqActiveUsers) : 0; data.Key = from.ToString("yyyy-MM-dd"); data.Value = activeUser; data.Year = to.Year; list.Add(data); } } else if (Period == 2) { for (int i = 0; i < 7; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddDays(i * 7); var to = beginTime.AddDays(6).AddDays(i * 7).ToDayEnd(); umengApiDataQuery = _umengApiDataRepository.GetAll().Where(x => x.Date >= from && x.Date <= to); activeUser = umengApiDataQuery.Count() > 0 ? umengApiDataQuery.Average(x => x.UniqActiveUsers) : 0; data.Key = string.Format(@"{0:D2}W{1}", from.AddDays(6).Month, from.AddDays(6).WeekDayInstanceOfMonth()); data.Value = activeUser; data.Year = to.Year; list.Add(data); } } else { for (int i = 0; i < 6; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddMonths(i); var to = (new DateTime(beginTime.Year, beginTime.Month, beginTime.TotalDaysInMonth())).ToDayEnd().AddMonths(i); umengApiDataQuery = _umengApiDataRepository.GetAll().Where(x => x.Date >= from && x.Date <= to); activeUser = umengApiDataQuery.Count() > 0 ? umengApiDataQuery.Average(x => x.UniqActiveUsers) : 0; data.Key = from.AddMonths(i).ToString("yyyy-MM"); data.Value = activeUser; data.Year = to.Year; list.Add(data); } } break; case 2: if (Period == 2) { for (int i = 1; i < 7; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddDays(i * 7); var to = beginTime.AddDays(6).AddDays(i * 7).ToDayEnd(); AggregateFluent = GetAggregateFluent(Type, "createTime", from, to); data.Key = string.Format(@"{0:D2}W{1}", from.AddDays(6).Month, from.AddDays(6).WeekDayInstanceOfMonth()); var result = AggregateFluent.Group(Group3).FirstOrDefault(); data.Value = result == null ? 0 : result.GetValue("Value").ToDouble(); data.Year = to.Year; list.Add(data); } } else { AggregateFluent = GetAggregateFluent(Type, "createTime", beginTime, endTime); Bson = AggregateFluent.Group(Group).ToList(); } break; case 3: if (Period == 1) { for (int i = 0; i < 7; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddDays(i); var to = beginTime.AddDays(i).ToDayEnd(); var NewRechargeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("refundStatus", "3"), builderFilter.Ne("payWay", "6"), builderFilter.Ne("payWay", "10"), builderFilter.Lt("operateTime", from))); var NewRechargeUsersBsonDate = NewRechargeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var NewRechargeUsers = NewRechargeUsersBsonDate == null ? 0 : NewRechargeUsersBsonDate.GetValue("Count"); var TotalRechargeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("refundStatus", "3"), builderFilter.Ne("payWay", "6"), builderFilter.Ne("payWay", "10"), builderFilter.Lte("operateTime", to))); var TotalRechargeUsersBsonDate = TotalRechargeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var TotalRechargeUsers = TotalRechargeUsersBsonDate == null ? 0 : TotalRechargeUsersBsonDate.GetValue("Count"); data.Key = from.ToString("yyyy-MM-dd"); data.Value = TotalRechargeUsers.ToInt32() - NewRechargeUsers.ToInt32(); data.Year = to.Year; list.Add(data); } } else if (Period == 2) { for (int i = 0; i < 7; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddDays(i * 7); var to = beginTime.AddDays(6).AddDays(i * 7).ToDayEnd(); var NewRechargeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("refundStatus", "3"), builderFilter.Ne("payWay", "6"), builderFilter.Ne("payWay", "10"), builderFilter.Lt("operateTime", from))); var NewRechargeUsersBsonDate = NewRechargeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var NewRechargeUsers = NewRechargeUsersBsonDate == null ? 0 : NewRechargeUsersBsonDate.GetValue("Count"); var TotalRechargeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("refundStatus", "3"), builderFilter.Ne("payWay", "6"), builderFilter.Ne("payWay", "10"), builderFilter.Lte("operateTime", to))); var TotalRechargeUsersBsonDate = TotalRechargeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var TotalRechargeUsers = TotalRechargeUsersBsonDate == null ? 0 : TotalRechargeUsersBsonDate.GetValue("Count"); data.Key = string.Format(@"{0:D2}W{1}", from.AddDays(6).Month, from.AddDays(6).WeekDayInstanceOfMonth()); data.Value = TotalRechargeUsers.ToInt32() - NewRechargeUsers.ToInt32(); data.Year = to.Year; list.Add(data); } } else { for (int i = 0; i < 6; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddMonths(i); var to = (new DateTime(beginTime.Year, beginTime.Month, beginTime.TotalDaysInMonth())).ToDayEnd().AddMonths(i); var NewRechargeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("refundStatus", "3"), builderFilter.Ne("payWay", "6"), builderFilter.Ne("payWay", "10"), builderFilter.Lt("operateTime", from))); var NewRechargeUsersBsonDate = NewRechargeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var NewRechargeUsers = NewRechargeUsersBsonDate == null ? 0 : NewRechargeUsersBsonDate.GetValue("Count"); var TotalRechargeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("refundStatus", "3"), builderFilter.Ne("payWay", "6"), builderFilter.Ne("payWay", "10"), builderFilter.Lte("operateTime", to))); var TotalRechargeUsersBsonDate = TotalRechargeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var TotalRechargeUsers = TotalRechargeUsersBsonDate == null ? 0 : TotalRechargeUsersBsonDate.GetValue("Count"); data.Key = from.ToString("yyyy-MM"); data.Value = TotalRechargeUsers.ToInt32() - NewRechargeUsers.ToInt32(); data.Year = to.Year; list.Add(data); } } break; case 4: if (Period == 1) { for (int i = 0; i < 7; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddDays(i); var to = beginTime.AddDays(i).ToDayEnd(); var NewConsumeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("type", "8"), builderFilter.Lt("operateTime", from))); var NewConsumeUsersBsonDate = NewConsumeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var NewConsumeUsers = NewConsumeUsersBsonDate == null ? 0 : NewConsumeUsersBsonDate.GetValue("Count"); var TotalConsumeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("type", "8"), builderFilter.Lte("operateTime", to))); var TotalConsumeUsersBsonDate = TotalConsumeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var TotalConsumeUsers = TotalConsumeUsersBsonDate == null ? 0 : TotalConsumeUsersBsonDate.GetValue("Count"); data.Key = from.ToString("yyyy-MM-dd"); data.Value = TotalConsumeUsers.ToInt32() - NewConsumeUsers.ToInt32(); data.Year = to.Year; list.Add(data); } } else if (Period == 2) { for (int i = 0; i < 7; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddDays(i * 7); var to = beginTime.AddDays(6).AddDays(i * 7).ToDayEnd(); var NewConsumeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("type", "8"), builderFilter.Lt("operateTime", from))); var NewConsumeUsersBsonDate = NewConsumeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var NewConsumeUsers = NewConsumeUsersBsonDate == null ? 0 : NewConsumeUsersBsonDate.GetValue("Count"); var TotalConsumeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("type", "8"), builderFilter.Lte("operateTime", to))); var TotalConsumeUsersBsonDate = TotalConsumeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var TotalConsumeUsers = TotalConsumeUsersBsonDate == null ? 0 : TotalConsumeUsersBsonDate.GetValue("Count"); data.Key = string.Format(@"{0:D2}W{1}", from.AddDays(6).Month, from.AddDays(6).WeekDayInstanceOfMonth()); data.Value = TotalConsumeUsers.ToInt32() - NewConsumeUsers.ToInt32(); data.Year = to.Year; list.Add(data); } } else { for (int i = 0; i < 6; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddMonths(i); var to = (new DateTime(beginTime.Year, beginTime.Month, beginTime.TotalDaysInMonth())).ToDayEnd().AddMonths(i); var NewConsumeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("type", "8"), builderFilter.Lt("operateTime", from))); var NewConsumeUsersBsonDate = NewConsumeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var NewConsumeUsers = NewConsumeUsersBsonDate == null ? 0 : NewConsumeUsersBsonDate.GetValue("Count"); var TotalConsumeUsersAggregateFluent = _mongoDBRepository.Database.GetCollection <BsonDocument>("tshare_spending_detail").Aggregate() .Match(builderFilter.And(builderFilter.Eq("type", "8"), builderFilter.Lte("operateTime", to))); var TotalConsumeUsersBsonDate = TotalConsumeUsersAggregateFluent.Group(Group5).Group(Group6).FirstOrDefault(); var TotalConsumeUsers = TotalConsumeUsersBsonDate == null ? 0 : TotalConsumeUsersBsonDate.GetValue("Count"); data.Key = from.ToString("yyyy-MM"); data.Value = TotalConsumeUsers.ToInt32() - NewConsumeUsers.ToInt32(); data.Year = to.Year; list.Add(data); } } break; case 5: IQueryable <UmengApiData> umengApiDataQuery2; Double NewDownloads; if (Period == 1) { for (int i = 0; i < 7; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddDays(i); var to = beginTime.AddDays(i).ToDayEnd(); umengApiDataQuery2 = _umengApiDataRepository.GetAll().Where(x => x.Date >= from && x.Date <= to); NewDownloads = umengApiDataQuery2.Count() > 0 ? umengApiDataQuery2.Sum(x => x.TotalInstallUser) : 0; data.Key = from.ToString("yyyy-MM-dd"); data.Value = NewDownloads; data.Year = to.Year; list.Add(data); } } else if (Period == 2) { for (int i = 0; i < 7; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddDays(i * 7); var to = beginTime.AddDays(6).AddDays(i * 7).ToDayEnd(); umengApiDataQuery2 = _umengApiDataRepository.GetAll().Where(x => x.Date >= from && x.Date <= to); NewDownloads = umengApiDataQuery2.Count() > 0 ? umengApiDataQuery2.Sum(x => x.TotalInstallUser) : 0; data.Key = string.Format(@"{0:D2}W{1}", from.AddDays(6).Month, from.AddDays(6).WeekDayInstanceOfMonth()); data.Value = NewDownloads; data.Year = to.Year; list.Add(data); } } else { for (int i = 0; i < 6; i++) { var data = new MembersRisingTendencyDetailDto(); var from = beginTime.AddMonths(i); var to = (new DateTime(beginTime.Year, beginTime.Month, beginTime.TotalDaysInMonth())).ToDayEnd().AddMonths(i); umengApiDataQuery2 = _umengApiDataRepository.GetAll().Where(x => x.Date >= from && x.Date <= to); NewDownloads = umengApiDataQuery2.Count() > 0 ? umengApiDataQuery2.Sum(x => x.TotalInstallUser) : 0; data.Key = from.ToString("yyyy-MM"); data.Value = NewDownloads; data.Year = to.Year; list.Add(data); } } break; } Bson.ForEach(x => { var data = new MembersRisingTendencyDetailDto(); data.Key = x.GetValue("_id").ToString(); data.Value = x.GetValue("Value").ToDouble(); data.Year = endTime.Year; list.Add(data); }); return(list.OrderBy(x => x.Year).ThenBy(x => x.Key)); }
protected IOrderedEnumerable <RechargeTendencyDetailDto> Group(int Type, string dateFormat, DateTime beginTime, DateTime endTime, bool IsWeek) { var builderFilter = Builders <BsonDocument> .Filter; var Bson = new List <BsonDocument>(); Dictionary <string, object> dateToStringKeyValuePairs = new Dictionary <string, object>(); dateToStringKeyValuePairs.Add("format", dateFormat); dateToStringKeyValuePairs.Add("date", "$operateTime"); dateToStringKeyValuePairs.Add("timezone", "+08:00"); var Group = new BsonDocument { { "_id", new BsonDocument("$dateToString", new BsonDocument(dateToStringKeyValuePairs)) }, { "Value", new BsonDocument("$sum", 1) } }; var Group1 = new BsonDocument { { "_id", new BsonDocument { { "Day", new BsonDocument { { "$dateToString", new BsonDocument(dateToStringKeyValuePairs) } } }, { "UserId", "$userId" } } }, { "Value", new BsonDocument("$sum", 1) } }; var Group2 = new BsonDocument { { "_id", "$_id.Day" }, { "Value", new BsonDocument("$sum", 1) } }; var RechargeGroup = new BsonDocument { { "_id", new BsonDocument("$dateToString", new BsonDocument(dateToStringKeyValuePairs)) }, { "Value", new BsonDocument("$sum", "$rechargeMoney") } }; var PresenterGroup = new BsonDocument { { "_id", new BsonDocument("$dateToString", new BsonDocument(dateToStringKeyValuePairs)) }, { "Value", new BsonDocument("$sum", "$givenMoney") } }; var WeekGroup1 = new BsonDocument { { "_id", "$userId" }, { "Value", new BsonDocument("$sum", 1) } }; var WeekGroup2 = new BsonDocument { { "_id", "" }, { "Value", new BsonDocument("$sum", 1) } }; var WeekGroup3 = new BsonDocument { { "_id", "" }, { "Value", new BsonDocument("$sum", "$rechargeMoney") } }; var WeekGroup4 = new BsonDocument { { "_id", "" }, { "Value", new BsonDocument("$sum", "$givenMoney") } }; IAggregateFluent <BsonDocument> AggregateFluent; var list = new List <RechargeTendencyDetailDto>(); if (Type == 1) { if (IsWeek) { for (int i = 0; i < 7; i++) { var data = new RechargeTendencyDetailDto(); var from = beginTime; var to = beginTime.AddDays(6); AggregateFluent = GetAggregateFluent(Type, "operateTime", from.AddDays(i * 7), to.AddDays(i * 7)); data.Key = string.Format(@"{0:D2}W{1}", from.AddDays(i * 7).AddDays(6).Month, from.AddDays(i * 7).AddDays(6).WeekDayInstanceOfMonth()); var result = AggregateFluent.Group(WeekGroup1).Group(WeekGroup2).FirstOrDefault(); data.Value = result == null? 0:result.GetValue("Value").ToDouble(); data.Year = to.AddDays(i * 7).Year; list.Add(data); } } else { AggregateFluent = GetAggregateFluent(Type, "operateTime", beginTime, endTime); Bson = AggregateFluent.Group(Group1).Group(Group2).ToList(); } } if (Type == 2) { if (IsWeek) { for (int i = 0; i < 7; i++) { var data = new RechargeTendencyDetailDto(); var from = beginTime; var to = beginTime.AddDays(6); AggregateFluent = GetAggregateFluent(Type, "operateTime", from.AddDays(i * 7), to.AddDays(i * 7)); data.Key = string.Format(@"{0:D2}W{1}", from.AddDays(i * 7).AddDays(6).Month, from.AddDays(i * 7).AddDays(6).WeekDayInstanceOfMonth()); var result = AggregateFluent.Group(WeekGroup2).FirstOrDefault(); data.Value = result == null ? 0 : result.GetValue("Value").ToDouble(); data.Year = to.AddDays(i * 7).Year; list.Add(data); } } else { AggregateFluent = GetAggregateFluent(Type, "operateTime", beginTime, endTime); Bson = AggregateFluent.Group(Group).ToList(); } } if (Type == 3) { if (IsWeek) { for (int i = 0; i < 7; i++) { var data = new RechargeTendencyDetailDto(); var from = beginTime; var to = beginTime.AddDays(6); AggregateFluent = GetAggregateFluent(Type, "operateTime", from.AddDays(i * 7), to.AddDays(i * 7)); data.Key = string.Format(@"{0:D2}W{1}", from.AddDays(i * 7).AddDays(6).Month, from.AddDays(i * 7).AddDays(6).WeekDayInstanceOfMonth()); var result = AggregateFluent.Group(WeekGroup3).FirstOrDefault(); data.Value = result == null ? 0 : result.GetValue("Value").ToDouble(); data.Year = to.AddDays(i * 7).Year; list.Add(data); } } else { AggregateFluent = GetAggregateFluent(Type, "operateTime", beginTime, endTime); Bson = AggregateFluent.Group(RechargeGroup).ToList(); } } if (Type == 4) { if (IsWeek) { for (int i = 0; i < 7; i++) { var data = new RechargeTendencyDetailDto(); var from = beginTime; var to = beginTime.AddDays(6); AggregateFluent = GetAggregateFluent(Type, "operateTime", from.AddDays(i * 7), to.AddDays(i * 7)); data.Key = string.Format(@"{0:D2}W{1}", from.AddDays(i * 7).AddDays(6).Month, from.AddDays(i * 7).AddDays(6).WeekDayInstanceOfMonth()); var result = AggregateFluent.Group(WeekGroup4).FirstOrDefault(); data.Value = result == null ? 0 : result.GetValue("Value").ToDouble(); data.Year = to.AddDays(i * 7).Year; list.Add(data); } } else { AggregateFluent = GetAggregateFluent(Type, "operateTime", beginTime, endTime); Bson = AggregateFluent.Group(PresenterGroup).ToList(); } } Bson.ForEach(x => { var data = new RechargeTendencyDetailDto(); data.Key = x.GetValue("_id").ToString(); data.Value = x.GetValue("Value").ToDouble(); data.Year = endTime.Year; list.Add(data); }); return(list.OrderBy(x => x.Year).ThenBy(x => x.Key)); }