Beispiel #1
0
        protected override Expression <Func <string, bool> > GetRouteToFilter(DateTime shardingKey, ShardingOperatorEnum shardingOperator)
        {
            var t = TimeFormatToTail(shardingKey);

            switch (shardingOperator)
            {
            case ShardingOperatorEnum.GreaterThan:
            case ShardingOperatorEnum.GreaterThanOrEqual:
                return(tail => String.Compare(tail, t, StringComparison.Ordinal) >= 0);

            case ShardingOperatorEnum.LessThan:
            {
                var currentMonth = ShardingCoreHelper.GetCurrentMonthFirstDay(shardingKey);
                //处于临界值 o=>o.time < [2021-01-01 00:00:00] 尾巴20210101不应该被返回
                if (currentMonth == shardingKey)
                {
                    return(tail => String.Compare(tail, t, StringComparison.Ordinal) < 0);
                }
                return(tail => String.Compare(tail, t, StringComparison.Ordinal) <= 0);
            }

            case ShardingOperatorEnum.LessThanOrEqual:
                return(tail => String.Compare(tail, t, StringComparison.Ordinal) <= 0);

            case ShardingOperatorEnum.Equal: return(tail => tail == t);

            default:
            {
#if DEBUG
                Console.WriteLine($"shardingOperator is not equal scan all table tail");
#endif
                return(tail => true);
            }
            }
        }
        protected override string TimeFormatToTail(DateTime time)
        {
            var currentMonday = ShardingCoreHelper.GetCurrentMonday(time);
            var currentSunday = ShardingCoreHelper.GetCurrentSunday(time);

            return($"{currentMonday:yyyyMM}{currentMonday:dd}_{currentSunday:dd}");
        }
Beispiel #3
0
        public override List <string> GetAllTails()
        {
            var beginTime = ShardingCoreHelper.GetCurrentMonthFirstDay(GetBeginTime());

            var tails = new List <string>();
            //提前创建表
            var nowTimeStamp = ShardingCoreHelper.GetNextMonthFirstDay(beginTime);

            if (beginTime > nowTimeStamp)
            {
                throw new ArgumentException("起始时间不正确无法生成正确的表名");
            }
            var currentTimeStamp = beginTime;

            while (currentTimeStamp <= nowTimeStamp)
            {
                var tail = ShardingKeyToTail(currentTimeStamp);
                tails.Add(tail);
                currentTimeStamp = ShardingCoreHelper.GetNextMonthFirstDay(currentTimeStamp);
            }
            return(tails);
        }
Beispiel #4
0
        public override List <string> GetAllTails()
        {
            var beginTime = GetBeginTime();

            var tails = new List <string>();
            //提前创建表
            var nowTimeStamp = beginTime.AddYears(1).Date;

            if (beginTime > nowTimeStamp)
            {
                throw new ArgumentException("起始时间不正确无法生成正确的表名");
            }
            var currentTimeStamp = beginTime;

            while (currentTimeStamp <= nowTimeStamp)
            {
                var currentTimeStampLong = ShardingCoreHelper.ConvertDateTimeToLong(currentTimeStamp);
                var tail = ShardingKeyToTail(currentTimeStampLong);
                tails.Add(tail);
                currentTimeStamp = currentTimeStamp.AddYears(1);
            }
            return(tails);
        }
        /// <summary>
        /// 如何将shardingkey转成对应的tail
        /// </summary>
        /// <param name="shardingKey"></param>
        /// <returns></returns>
        public override string ShardingKeyToTail(object shardingKey)
        {
            var shardingKeyStr = ConvertToShardingKey(shardingKey);

            return(Math.Abs(ShardingCoreHelper.GetStringHashCode(shardingKeyStr) % Mod).ToString());
        }
Beispiel #6
0
        protected override string TimeFormatToTail(long time)
        {
            var datetime = ShardingCoreHelper.ConvertLongToDateTime(time);

            return($"{datetime:yyyy}");
        }