using JiShe.CollectBus.Common.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace JiShe.CollectBus.ShardingStrategy
{
///
/// 按天分表策略
///
///
public class DayShardingStrategy : IShardingStrategy
{
///
/// 获取指定时间对应的集合名
///
///
///
public string GetCollectionName(DateTime dateTime)
{
var baseName = typeof(TEntity).Name;
return $"{baseName}_{dateTime.GetDataTableShardingStrategy()}";
}
///
/// 获取当前时间对应的集合名
///
///
public string GetCurrentCollectionName()
{
var baseName = typeof(TEntity).Name;
return $"{baseName}_{DateTime.Now.GetDataTableShardingStrategy()}";
}
///
/// 用于查询时确定目标集合
///
///
///
///
public IEnumerable GetQueryCollectionNames(DateTime? startTime, DateTime? endTime)
{
var months = new List();
var current = startTime ?? DateTime.MinValue;
var end = endTime ?? DateTime.MaxValue;
var baseName = typeof(TEntity).Name;
while (current <= end)
{
months.Add($"{baseName}_{current.GetDataTableShardingStrategy()}");
current = current.AddMonths(1);
}
return months.Distinct();
}
}
}