示例#1
0
        /// <summary>
        /// 得到年得所以分片
        /// </summary>
        /// <returns></returns>
        protected virtual IList <ShardingInfo> GetAllYearShardings()
        {
            var maxTableIndex = GetMaxTableIndex();
            var shardings     = new List <ShardingInfo>();
            var maxDate       = DateTime.Parse(maxTableIndex.Insert(4, "-").Insert(7, "-").Insert(10, " "));
            var curDate       = DateTime.Parse(TableIndex.Insert(4, "-").Insert(7, "-").Insert(10, " "));
            var i             = 1;

            while (curDate < maxDate)
            {
                var sharding = new ShardingInfo
                {
                    GetDataBase   = GetQueryDataBaseIndex(i),
                    SetDataBase   = GetSaveDataBaseIndex(i),
                    IsWrite       = IsWrite,
                    MaxTableIndex = MaxTableIndex,
                    TableStep     = TableStep,
                    TableStepType = TableStepType
                };
                sharding.TableIndex = curDate.ToString("yyyy");
                curDate             = curDate.AddYears(TableStep);
                shardings.Add(sharding);
                i++;
            }
            return(shardings);
        }
示例#2
0
        /// <summary>
        /// 得到最大步长
        /// </summary>
        /// <returns></returns>
        public virtual int GetTableMaxStep()
        {
            var maxTableIndex = GetMaxTableIndex();

            switch (TableStepType)
            {
            case TableStepType.Value:
                return(int.Parse(maxTableIndex));

            case TableStepType.Hour:
            {
                var maxDate = DateTime.Parse(maxTableIndex.Insert(4, "-").Insert(7, "-").Insert(10, " "));
                var curDate = DateTime.Parse(TableIndex.Insert(4, "-").Insert(7, "-").Insert(10, " "));
                return((int)(maxDate - curDate).TotalHours + 1);
            }

            case TableStepType.Day:
            {
                var maxDate = DateTime.Parse(maxTableIndex.Insert(4, "-").Insert(7, "-"));
                var curDate = DateTime.Parse(TableIndex.Insert(4, "-").Insert(7, "-"));
                return((int)(maxDate - curDate).TotalDays);
            }

            case TableStepType.Month:
            {
                var maxDate = DateTime.Parse(maxTableIndex.Insert(4, "-"));
                var curDate = DateTime.Parse(TableIndex.Insert(4, "-"));
                var step    = (maxDate.Year - curDate.Year) * 12 + (maxDate.Month - curDate.Month);
                return(step + 1);
            }

            case TableStepType.Year:
            {
                var maxDate = DateTime.Parse(maxTableIndex.Insert(4, "-"));
                var curDate = DateTime.Parse(TableIndex.Insert(4, "-"));
                return(maxDate.Year - curDate.Year + 1);
            }
            }
            return(-1);
        }