Exemplo n.º 1
0
        public static List <DateTime> GetRuleDate(RSScheduleRule rule, DateTime beginDate, DateTime endDate)
        {
            beginDate = beginDate.Date;
            endDate   = endDate.Date;
            var result = new List <DateTime>();
            var days   = (endDate - beginDate).Days;

            if (days < 0)
            {
                return(result);
            }
            for (int i = 0; i < days; i++)
            {
                var thisDate = beginDate.AddDays(i);
                if (rule.ExceptDate?.Split(',').Any(a => a == thisDate.ToString("yyyyMMdd")) ?? false)
                {
                    continue;
                }
                if (rule.InDate?.Split(',').Any(a => a == thisDate.ToString("yyyyMMdd")) ?? false)
                {
                    result.Add(thisDate);
                    continue;
                }
                if (rule.DayType == EScheduleDayType.Month &&
                    (rule.DayList?.Split(',').Any(a => a == thisDate.Day.ToString()) ?? false))
                {
                    result.Add(thisDate);
                    continue;
                }
                if (rule.DayType == EScheduleDayType.Week &&
                    (rule.DayList?.Split(',').Any(a => a == GetDayOfWeekInt(thisDate.DayOfWeek).ToString()) ?? false))
                {
                    result.Add(thisDate);
                    continue;
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public static List <RSScheduleOfDay> GenerateScheduleByRule(RSScheduleRule rule, DateTime beginDate, DateTime endDate)
        {
            var result = new List <RSScheduleOfDay>();
            var dates  = GetRuleDate(rule, beginDate, endDate);

            foreach (var date in dates)
            {
                result.Add(new RSScheduleOfDay
                {
                    Id           = IdGenerator.Generate <string>(),
                    CreateTime   = DateTime.Now,
                    IsDeleted    = false,
                    RemainNum    = rule.MaxNum,
                    RemainNums   = GetRemainNumsByMaxNum(rule.MaxNum),
                    ScheduleDate = date,
                    ScheduleName = rule.ScheduleName,
                    UpdateTime   = DateTime.Now,
                    RuleId       = rule.Id,
                    ExtraInfo    = rule.ExtraInfo
                });
            }
            return(result);
        }