2021-11-22 15:09:19 +08:00
|
|
|
|
using System;
|
2021-11-29 08:38:33 +08:00
|
|
|
|
using System.Collections.Generic;
|
2021-11-22 15:09:19 +08:00
|
|
|
|
using ShardingCore.Core.EntityMetadatas;
|
|
|
|
|
using ShardingCore.Sharding.PaginationConfigurations;
|
2021-11-26 14:55:59 +08:00
|
|
|
|
using ShardingCore.Test.Domain.Entities;
|
|
|
|
|
using ShardingCore.Test.Shardings.PaginationConfigs;
|
2021-11-22 15:09:19 +08:00
|
|
|
|
using ShardingCore.VirtualRoutes.Days;
|
|
|
|
|
|
2021-11-26 14:55:59 +08:00
|
|
|
|
namespace ShardingCore.Test.Shardings
|
2021-11-22 15:09:19 +08:00
|
|
|
|
{
|
|
|
|
|
public class LogDayVirtualTableRoute:AbstractSimpleShardingDayKeyDateTimeVirtualTableRoute<LogDay>
|
|
|
|
|
{
|
2022-06-01 09:50:43 +08:00
|
|
|
|
//public override bool? EnableRouteParseCompileCache => true;
|
2021-11-22 15:09:19 +08:00
|
|
|
|
protected override bool EnableHintRoute => true;
|
|
|
|
|
|
|
|
|
|
public override DateTime GetBeginTime()
|
|
|
|
|
{
|
|
|
|
|
return new DateTime(2021, 1, 1);
|
|
|
|
|
}
|
2021-11-26 14:55:59 +08:00
|
|
|
|
|
2021-11-22 15:09:19 +08:00
|
|
|
|
|
|
|
|
|
public override void Configure(EntityMetadataTableBuilder<LogDay> builder)
|
|
|
|
|
{
|
|
|
|
|
builder.ShardingProperty(o => o.LogTime);
|
|
|
|
|
builder.TableSeparator(string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IPaginationConfiguration<LogDay> CreatePaginationConfiguration()
|
|
|
|
|
{
|
|
|
|
|
return new LogDayPaginationConfiguration();
|
|
|
|
|
}
|
2021-11-24 08:12:03 +08:00
|
|
|
|
|
|
|
|
|
public override bool AutoCreateTableByTime()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-11-29 08:38:33 +08:00
|
|
|
|
|
2022-07-02 21:43:19 +08:00
|
|
|
|
protected override List<string> CalcTailsOnStart()
|
2021-11-29 08:38:33 +08:00
|
|
|
|
{
|
|
|
|
|
var beginTime = GetBeginTime().Date;
|
|
|
|
|
|
|
|
|
|
var tails = new List<string>();
|
|
|
|
|
//提前创建表
|
|
|
|
|
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;
|
|
|
|
|
}
|
2021-11-22 15:09:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|