feat(templateDistributor): логика распределения шаблонов по периоду

This commit is contained in:
Mikhail Kuznetsov
2024-07-05 15:17:48 +10:00
parent cf5a465546
commit 21a175d197
8 changed files with 370 additions and 19 deletions

View File

@@ -3,6 +3,7 @@ using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.DomainModels;
using PARR.DAL.Extensions;
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.TransformServices
@@ -10,6 +11,7 @@ namespace PARR.DAL.TransformServices
internal class EsppScheduleTransformService : IEsppScheduleTransformService
{
private readonly IEsppSchTypeConfigService esppSchTypeConfigService;
private readonly IApplicationsInWorkService applicationsInWorkService;
private readonly ILogger<EsppScheduleTransformService> logger;
private readonly Dictionary<string, int> monthDict = new Dictionary<string, int>()
@@ -49,11 +51,14 @@ namespace PARR.DAL.TransformServices
};
public EsppScheduleTransformService(
ILogger<EsppScheduleTransformService> logger,
IEsppSchTypeConfigService esppSchTypeConfigService,
ILogger<EsppScheduleTransformService> logger
IApplicationsInWorkService applicationsInWorkService
)
{
this.esppSchTypeConfigService = esppSchTypeConfigService;
this.applicationsInWorkService = applicationsInWorkService;
this.logger = logger;
}
@@ -130,7 +135,9 @@ namespace PARR.DAL.TransformServices
public async Task<DateTimeOffset> GetNextDateAsync(Guid applicationInWorkId, DateTimeOffset lastRun)
{
return GetNextDate(await GetEsppScheduleAsync(applicationInWorkId), lastRun);
var esppSchedule = await GetEsppScheduleAsync(applicationInWorkId);
return GetNextDate(esppSchedule, lastRun);
}
@@ -337,10 +344,6 @@ namespace PARR.DAL.TransformServices
case (DistributionPeriodTypeEnum.Year):
return lastRun.AddYears(ParseInt(distributionPeriod));
//case (DistributionPeriodTypeEnum.TimeSpan):
// var timeSpan = ParseTimeSpan(distributionPeriod);
// return timeSpan.Days > 0 ? startPeriod.AddDays();
}
@@ -348,6 +351,23 @@ namespace PARR.DAL.TransformServices
return lastRun;
}
public async Task<DateOnly> GetStartPeriodForDateAsync(Guid applicationInWorkId, DateTimeOffset date, DateTimeOffset refrenceDate, DistributionPeriodTypeEnum periodType, string distributionPeriod)
{
var esppSchedule = await GetEsppScheduleAsync(applicationInWorkId);
var currentStartPeriod = refrenceDate;
var currentEndPeriod = GetNextDateForDistributionRun(currentStartPeriod,periodType,distributionPeriod);
while (!(date>=currentStartPeriod && date< currentEndPeriod))
{
currentStartPeriod = currentEndPeriod;
currentEndPeriod = GetNextDateForDistributionRun(currentStartPeriod, periodType, distributionPeriod);
}
return DateOnly.FromDateTime(currentStartPeriod.DateTime);
}
private int ParseInt(string value)
{

View File

@@ -49,5 +49,14 @@ namespace PARR.DAL.TransformServices
/// <param name="distributionPeriod"></param>
/// <returns></returns>
DateTimeOffset GetNextDateForDistributionRun(DateTimeOffset lastRun, DistributionPeriodTypeEnum periodType, string distributionPeriod);
/// <summary>
/// Получить дату начала периода распределения относительно опорной даты (Reference Date)
/// </summary>
/// <param name="applicationInWorkId"></param>
/// <param name="date"></param>
/// <returns></returns>
Task<DateOnly> GetStartPeriodForDateAsync(Guid applicationInWorkId, DateTimeOffset date, DateTimeOffset refrenceDate, DistributionPeriodTypeEnum periodType, string distributionPeriod);
}
}