feat(dal): EsppScheduleTransformService реализован метод GetNextSchedule, расписание на сегодня
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.DAL.Contracts;
|
using PARR.DAL.Contracts;
|
||||||
using PARR.DAL.DomainModels;
|
using PARR.DAL.DomainModels;
|
||||||
|
using PARR.DAL.Extensions;
|
||||||
using PARR.DAL.Services.Interfaces;
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
|
||||||
namespace PARR.DAL.TransformServices
|
namespace PARR.DAL.TransformServices
|
||||||
@@ -58,6 +59,7 @@ namespace PARR.DAL.TransformServices
|
|||||||
//если больше текущего вернуть lastRun. Это и есть следующая дата
|
//если больше текущего вернуть lastRun. Это и есть следующая дата
|
||||||
if (lastRun > DateTimeOffset.UtcNow)
|
if (lastRun > DateTimeOffset.UtcNow)
|
||||||
return lastRun;
|
return lastRun;
|
||||||
|
|
||||||
switch (esppSchedule.TypeSchedule.Id)
|
switch (esppSchedule.TypeSchedule.Id)
|
||||||
{
|
{
|
||||||
case (int)EsppSchTypeScheduleEnum.Regularly:
|
case (int)EsppSchTypeScheduleEnum.Regularly:
|
||||||
@@ -81,11 +83,34 @@ namespace PARR.DAL.TransformServices
|
|||||||
{
|
{
|
||||||
// расписание на оставшееся на сегодня время. его так мало...
|
// расписание на оставшееся на сегодня время. его так мало...
|
||||||
var schedules = new List<DateTimeOffset>();
|
var schedules = new List<DateTimeOffset>();
|
||||||
|
var curTime = lastRun;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
//todo:
|
schedules.Add(curTime);
|
||||||
schedules.Add(lastRun);
|
}
|
||||||
|
schedules.RemoveAll(s => s > DateTimeOffset.UtcNow.EndOfDay());
|
||||||
|
|
||||||
|
|
||||||
return schedules.OrderBy(t => t).ToList();
|
return schedules.OrderBy(t => t).ToList();
|
||||||
}
|
}
|
||||||
@@ -119,7 +144,7 @@ namespace PARR.DAL.TransformServices
|
|||||||
{
|
{
|
||||||
var regDict = new Dictionary<string, int>
|
var regDict = new Dictionary<string, int>
|
||||||
{
|
{
|
||||||
{"Каждые 1 часа",1},
|
{"Каждый час",1},
|
||||||
{"Каждые 2 часа",2},
|
{"Каждые 2 часа",2},
|
||||||
{"Каждые 3 часа", 3},
|
{"Каждые 3 часа", 3},
|
||||||
{"Каждые 4 часа", 4},
|
{"Каждые 4 часа", 4},
|
||||||
@@ -140,14 +165,14 @@ namespace PARR.DAL.TransformServices
|
|||||||
|
|
||||||
var regNum = regDict[values[0].Value.Value];
|
var regNum = regDict[values[0].Value.Value];
|
||||||
|
|
||||||
var calcDay = new DateTimeOffset(DateTimeOffset.UtcNow.Year, DateTimeOffset.UtcNow.Month, DateTimeOffset.UtcNow.Day, lastRun.Hour, lastRun.Minute, lastRun.Second, lastRun.Offset);
|
var calcDay = lastRun.AddHours(regNum);
|
||||||
|
|
||||||
|
|
||||||
//TODO: вот это повторяется от метода к методу
|
//TODO: вот это повторяется от метода к методу
|
||||||
//Если итоговая дата указывает на прошлое, то повторяем расчёт и ухоим в рекурсию
|
//Если итоговая дата указывает на прошлое, то повторяем расчёт и ухоим в рекурсию
|
||||||
if (calcDay < DateTimeOffset.UtcNow)
|
if (calcDay < DateTimeOffset.UtcNow)
|
||||||
{
|
|
||||||
calcDay = calcDay.AddHours(regNum);
|
|
||||||
calcDay = GetNextDateRegularly(values, calcDay);
|
calcDay = GetNextDateRegularly(values, calcDay);
|
||||||
}
|
|
||||||
|
|
||||||
return calcDay;
|
return calcDay;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user