using System; using System.Collections.Generic; using ShardingCore.Core.EntityMetadatas; using ShardingCore.Sharding.PaginationConfigurations; using ShardingCore.Test3x.Domain.Entities; using ShardingCore.Test3x.Shardings.PaginationConfigs; using ShardingCore.VirtualRoutes.Days; namespace ShardingCore.Test3x.Shardings { public class LogDayVirtualTableRoute:AbstractSimpleShardingDayKeyDateTimeVirtualTableRoute { protected override bool EnableHintRoute => true; //public override bool? EnableRouteParseCompileCache => true; public override DateTime GetBeginTime() { return new DateTime(2021, 1, 1); } public override void Configure(EntityMetadataTableBuilder builder) { builder.ShardingProperty(o => o.LogTime); builder.TableSeparator(string.Empty); } public override IPaginationConfiguration CreatePaginationConfiguration() { return new LogDayPaginationConfiguration(); } public override bool AutoCreateTableByTime() { return true; } protected override List CalcTailsOnStart() { var beginTime = GetBeginTime().Date; var tails = new List(); //提前创建表 var nowTimeStamp = new DateTime(2021,11,20).Date; if (beginTime > nowTimeStamp) throw new ArgumentException("begin time error"); var currentTimeStamp = beginTime; while (currentTimeStamp <= nowTimeStamp) { var tail = ShardingKeyToTail(currentTimeStamp); tails.Add(tail); currentTimeStamp = currentTimeStamp.AddDays(1); } return tails; } } }