feat(api, dal, nextRun): переделал вызов рассчета NextRun на INextRunService

This commit is contained in:
Mikhail Trubnikov
2026-01-22 11:46:05 +10:00
parent b34be5ccbe
commit 91082915bc
9 changed files with 280 additions and 277 deletions

View File

@@ -68,7 +68,7 @@ namespace PARR.DAL.TransformServices
return GetNextDate(esppSchedule, referenceDate);
}
public DateTimeOffset GetNextDate(EsppScheduleDto esppSchedule, DateTimeOffset referenceDate)
private DateTimeOffset GetNextDate(EsppScheduleDto esppSchedule, DateTimeOffset referenceDate)
{
var nextRun = referenceDate;
@@ -111,62 +111,62 @@ namespace PARR.DAL.TransformServices
}
private List<DateTimeOffset> GetNextSchedule(EsppScheduleDto esppSchedule, DateTimeOffset referenceDate)
{
// расписание на оставшееся на сегодня время. его так мало...
referenceDate = referenceDate.UtcDateTime;
var schedules = new List<DateTimeOffset>();
var curTime = referenceDate;
//private List<DateTimeOffset> GetNextSchedule(EsppScheduleDto esppSchedule, DateTimeOffset referenceDate)
//{
// // расписание на оставшееся на сегодня время. его так мало...
// referenceDate = referenceDate.UtcDateTime;
// var schedules = new List<DateTimeOffset>();
// var curTime = referenceDate;
//Если ещё не произошло то добавляем расписание, возможно это новое AiW и он ещё ниразу не запускался.
//lastRun это будущее
if (referenceDate >= DateTimeOffset.UtcNow && referenceDate <= DateTimeOffset.UtcNow.EndOfDay())
schedules.Add(referenceDate);
// //Если ещё не произошло то добавляем расписание, возможно это новое AiW и он ещё ниразу не запускался.
// //lastRun это будущее
// if (referenceDate >= DateTimeOffset.UtcNow && referenceDate <= DateTimeOffset.UtcNow.EndOfDay())
// schedules.Add(referenceDate);
while (curTime < DateTimeOffset.UtcNow.EndOfDay())
{
switch (esppSchedule.TypeSchedule.Id)
{
case (int)EsppSchTypeScheduleEnum.Regularly:
curTime = GetNextDateRegularly(esppSchedule.Values, curTime);
break;
case (int)EsppSchTypeScheduleEnum.Weekly:
curTime = GetNextDateWeekly(esppSchedule.Values, curTime);
break;
case (int)EsppSchTypeScheduleEnum.Monthly:
curTime = GetNextDateMonthly(esppSchedule.Values, curTime);
break;
case (int)EsppSchTypeScheduleEnum.Monthly2:
curTime = GetNextDateMonthly2(esppSchedule.Values, curTime);
break;
case (int)EsppSchTypeScheduleEnum.Annually:
curTime = GetNextDateAnnually(esppSchedule.Values, curTime);
break;
case (int)EsppSchTypeScheduleEnum.Annually2:
curTime = GetNextDateAnnually2(esppSchedule.Values, curTime);
break;
}
// while (curTime < DateTimeOffset.UtcNow.EndOfDay())
// {
// switch (esppSchedule.TypeSchedule.Id)
// {
// case (int)EsppSchTypeScheduleEnum.Regularly:
// curTime = GetNextDateRegularly(esppSchedule.Values, curTime);
// break;
// case (int)EsppSchTypeScheduleEnum.Weekly:
// curTime = GetNextDateWeekly(esppSchedule.Values, curTime);
// break;
// case (int)EsppSchTypeScheduleEnum.Monthly:
// curTime = GetNextDateMonthly(esppSchedule.Values, curTime);
// break;
// case (int)EsppSchTypeScheduleEnum.Monthly2:
// curTime = GetNextDateMonthly2(esppSchedule.Values, curTime);
// break;
// case (int)EsppSchTypeScheduleEnum.Annually:
// curTime = GetNextDateAnnually(esppSchedule.Values, curTime);
// break;
// case (int)EsppSchTypeScheduleEnum.Annually2:
// curTime = GetNextDateAnnually2(esppSchedule.Values, curTime);
// break;
// }
schedules.Add(curTime);
}
schedules.RemoveAll(s => s > DateTimeOffset.UtcNow.EndOfDay());
// schedules.Add(curTime);
// }
// schedules.RemoveAll(s => s > DateTimeOffset.UtcNow.EndOfDay());
return schedules.OrderBy(t => t).ToList();
}
// return schedules.OrderBy(t => t).ToList();
//}
public async Task<List<DateTimeOffset>> GetNextScheduleAsync(Guid jobGroupId, DateTimeOffset referenceDate)
{
//TODO: тут не проверен переход через выходные дни!!! Переход не используется, так как тут не рассчитываем NextRun.
//В общем проверить, когда будем тестировать агента, что с датами все ок
var esppSchedule = await GetEsppScheduleAsync(jobGroupId);
var nextSchedule = GetNextSchedule(esppSchedule, referenceDate);
//public async Task<List<DateTimeOffset>> GetNextScheduleAsync(Guid jobGroupId, DateTimeOffset referenceDate)
//{
// //TODO: тут не проверен переход через выходные дни!!! Переход не используется, так как тут не рассчитываем NextRun.
// //В общем проверить, когда будем тестировать агента, что с датами все ок
// var esppSchedule = await GetEsppScheduleAsync(jobGroupId);
// var nextSchedule = GetNextSchedule(esppSchedule, referenceDate);
return nextSchedule;
}
// return nextSchedule;
//}
private async Task<EsppScheduleDto> GetEsppScheduleAsync(Guid jobGroupId)
@@ -429,68 +429,68 @@ namespace PARR.DAL.TransformServices
}
public DateTimeOffset GetNextDateForDistributionRun(DateTimeOffset lastRun, DistributionPeriodTypeEnum periodType, string distributionPeriod)
{
var nextRun = lastRun;
//public DateTimeOffset GetNextDateForDistributionRun(DateTimeOffset lastRun, DistributionPeriodTypeEnum periodType, string distributionPeriod)
//{
// var nextRun = lastRun;
switch (periodType)
{
case (DistributionPeriodTypeEnum.Day):
nextRun = lastRun.AddDays(ParseInt(distributionPeriod));
break;
case (DistributionPeriodTypeEnum.Month):
nextRun = lastRun.AddMonths(ParseInt(distributionPeriod));
break;
case (DistributionPeriodTypeEnum.Year):
nextRun = lastRun.AddYears(ParseInt(distributionPeriod));
break;
}
// switch (periodType)
// {
// case (DistributionPeriodTypeEnum.Day):
// nextRun = lastRun.AddDays(ParseInt(distributionPeriod));
// break;
// case (DistributionPeriodTypeEnum.Month):
// nextRun = lastRun.AddMonths(ParseInt(distributionPeriod));
// break;
// case (DistributionPeriodTypeEnum.Year):
// nextRun = lastRun.AddYears(ParseInt(distributionPeriod));
// break;
// }
return nextRunModifierService.GetWorkDayAsync(nextRun).GetAwaiter().GetResult();
}
// return nextRunModifierService.GetWorkDayAsync(nextRun).GetAwaiter().GetResult();
//}
private DateTimeOffset GetPrevDateForDistributionRun(DateTimeOffset lastRun, DistributionPeriodTypeEnum periodType, string distributionPeriod)
{
switch (periodType)
{
case (DistributionPeriodTypeEnum.Day):
return lastRun.AddDays(-ParseInt(distributionPeriod));
//private DateTimeOffset GetPrevDateForDistributionRun(DateTimeOffset lastRun, DistributionPeriodTypeEnum periodType, string distributionPeriod)
//{
// switch (periodType)
// {
// case (DistributionPeriodTypeEnum.Day):
// return lastRun.AddDays(-ParseInt(distributionPeriod));
case (DistributionPeriodTypeEnum.Month):
return lastRun.AddMonths(-ParseInt(distributionPeriod));
// case (DistributionPeriodTypeEnum.Month):
// return lastRun.AddMonths(-ParseInt(distributionPeriod));
case (DistributionPeriodTypeEnum.Year):
return lastRun.AddYears(-ParseInt(distributionPeriod));
}
// case (DistributionPeriodTypeEnum.Year):
// return lastRun.AddYears(-ParseInt(distributionPeriod));
// }
return lastRun;
}
// return lastRun;
//}
public async Task<DateOnly> GetStartPeriodForDateAsync(Guid jobGroupId, DateTimeOffset date, DateTimeOffset referenceDate, DistributionPeriodTypeEnum periodType, string distributionPeriod)
{
var esppSchedule = await GetEsppScheduleAsync(jobGroupId);
//public async Task<DateOnly> GetStartPeriodForDateAsync(Guid jobGroupId, DateTimeOffset date, DateTimeOffset referenceDate, DistributionPeriodTypeEnum periodType, string distributionPeriod)
//{
// var esppSchedule = await GetEsppScheduleAsync(jobGroupId);
var currentStartPeriod = referenceDate;
var currentEndPeriod = GetNextDateForDistributionRun(currentStartPeriod, periodType, distributionPeriod);
// var currentStartPeriod = referenceDate;
// var currentEndPeriod = GetNextDateForDistributionRun(currentStartPeriod, periodType, distributionPeriod);
while (!(date >= currentStartPeriod && date < currentEndPeriod))
{
if (date > currentEndPeriod)
{
currentStartPeriod = currentEndPeriod;
currentEndPeriod = GetNextDateForDistributionRun(currentStartPeriod, periodType, distributionPeriod);
}
else
{
currentEndPeriod = currentStartPeriod;
currentStartPeriod = GetPrevDateForDistributionRun(currentStartPeriod, periodType, distributionPeriod);
}
}
// while (!(date >= currentStartPeriod && date < currentEndPeriod))
// {
// if (date > currentEndPeriod)
// {
// currentStartPeriod = currentEndPeriod;
// currentEndPeriod = GetNextDateForDistributionRun(currentStartPeriod, periodType, distributionPeriod);
// }
// else
// {
// currentEndPeriod = currentStartPeriod;
// currentStartPeriod = GetPrevDateForDistributionRun(currentStartPeriod, periodType, distributionPeriod);
// }
// }
return DateOnly.FromDateTime(currentStartPeriod.DateTime);
}
// return DateOnly.FromDateTime(currentStartPeriod.DateTime);
//}
private int ParseInt(string value)
@@ -507,12 +507,12 @@ namespace PARR.DAL.TransformServices
}
private DistributionPeriodTypeEnum ParseDistributionPeriodType(string value)
{
var result = (DistributionPeriodTypeEnum)Enum.Parse(typeof(DistributionPeriodTypeEnum), value);
//private DistributionPeriodTypeEnum ParseDistributionPeriodType(string value)
//{
// var result = (DistributionPeriodTypeEnum)Enum.Parse(typeof(DistributionPeriodTypeEnum), value);
return result;
}
// return result;
//}
}
}