feat(dal): Заготовка для IEsppScheduleTransformService

This commit is contained in:
Mikhail Trubnikov
2023-10-17 09:42:18 +10:00
parent 4423b07742
commit 0eed4315ff
5 changed files with 150 additions and 1 deletions

View File

@@ -50,6 +50,13 @@
public static class Test
{
public const string GetMyIp = Base + "/tests/my-ip";
public const string GetNextScheduleDate = Base + "/tests/next-schedule-date/" + paramApplicationInWorkId + "/" + paramDate;
public const string GetNextSchedule = Base + "/tests/next-schedule/" + paramApplicationInWorkId + "/" + paramDate;
public const string paramDate = "{lastRunDate}";
public const string paramApplicationInWorkId = "{applicationInWorkId}";
}
public static class Template

View File

@@ -3,16 +3,19 @@ using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using PARR.API.Services.Interfaces;
using PARR.DAL.TransformServices;
namespace PARR.API.Controllers.V1
{
public class TestController : BaseApiController
{
private readonly IClientService clientService;
private readonly IEsppScheduleTransformService esppScheduleTransformService;
public TestController(IClientService clientService)
public TestController(IClientService clientService, IEsppScheduleTransformService esppScheduleTransformService)
{
this.clientService = clientService;
this.esppScheduleTransformService = esppScheduleTransformService;
}
@@ -31,5 +34,33 @@ namespace PARR.API.Controllers.V1
return Ok(new Response<object>(new { ip }, true));
}
/// <summary>
/// Получить следующую дату запуска
/// </summary>
/// <param name="applicationInWorkId"></param>
/// <param name="lastRunDate"></param>
/// <returns></returns>
[HttpGet(ApiRoutes.Test.GetNextScheduleDate)]
public async Task<IActionResult> GetNextScheduleDate([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate)
{
var result = await esppScheduleTransformService.GetNextDateAsync(applicationInWorkId, lastRunDate);
return Ok(result);
}
/// <summary>
/// Получить следующее расписание
/// </summary>
/// <param name="applicationInWorkId"></param>
/// <param name="lastRunDate"></param>
/// <returns></returns>
[HttpGet(ApiRoutes.Test.GetNextSchedule)]
public async Task<IActionResult> GetNextSchedule([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate)
{
var result = await esppScheduleTransformService.GetNextScheduleAsync(applicationInWorkId, lastRunDate);
return Ok(result);
}
}
}

View File

@@ -11,6 +11,7 @@ using PARR.DAL.Services.Implementations.V1;
using PARR.DAL.Services.Interfaces;
using PARR.DAL.Services.Interfaces.AIHIT;
using PARR.DAL.Services.Interfaces.V1;
using PARR.DAL.TransformServices;
namespace PARR.DAL
{
@@ -56,6 +57,10 @@ namespace PARR.DAL
services.AddTransient<IRobotConfigurationService, RobotConfigurationService>();
services.AddTransient<IRobotHistoryService, RobotHistoryService>();
services.AddTransient<IEsppSchTypeConfigService, EsppSchTypeConfigService>();
// TransformServices
services.AddTransient<IEsppScheduleTransformService, EsppScheduleTransformService>();
}
/// <summary>

View File

@@ -0,0 +1,64 @@
using Microsoft.Extensions.Logging;
using PARR.DAL.DomainModels;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.TransformServices
{
internal class EsppScheduleTransformService : IEsppScheduleTransformService
{
private readonly IEsppSchTypeConfigService esppSchTypeConfigService;
private readonly ILogger<EsppScheduleTransformService> logger;
public EsppScheduleTransformService(IEsppSchTypeConfigService esppSchTypeConfigService, ILogger<EsppScheduleTransformService> logger)
{
this.esppSchTypeConfigService = esppSchTypeConfigService;
this.logger = logger;
}
public DateTimeOffset GetNextDate(EsppScheduleDto esppSchedule, DateTimeOffset lastRun)
{
//todo:
return lastRun;
}
public List<DateTimeOffset> GetNextSchedule(EsppScheduleDto esppSchedule, DateTimeOffset lastRun)
{
var schedules = new List<DateTimeOffset>();
//todo:
schedules.Add(lastRun);
return schedules.OrderBy(t => t).ToList();
}
public async Task<DateTimeOffset> GetNextDateAsync(Guid applicationInWorkId, DateTimeOffset lastRun)
{
return GetNextDate(await GetEsppSchedule(applicationInWorkId), lastRun);
}
public async Task<List<DateTimeOffset>> GetNextScheduleAsync(Guid applicationInWorkId, DateTimeOffset lastRun)
{
return GetNextSchedule(await GetEsppSchedule(applicationInWorkId), lastRun);
}
private async Task<EsppScheduleDto> GetEsppSchedule(Guid applicationInWorkId)
{
var esppSchedule = await esppSchTypeConfigService.GetEsppScheduleDtoAsync(applicationInWorkId);
if (esppSchedule == null)
{
logger.LogError($"Не найдено расписание в БД, applicationInWorkId: {applicationInWorkId}");
throw new Exception($"Не найдено расписание в БД, applicationInWorkId: {applicationInWorkId}");
}
return esppSchedule;
}
}
}

View File

@@ -0,0 +1,42 @@
using PARR.DAL.DomainModels;
namespace PARR.DAL.TransformServices
{
/// <summary>
/// Сервис трансформации расписания ЕСПП в дату/расписание
/// </summary>
public interface IEsppScheduleTransformService
{
/// <summary>
/// Получить следующую дату согласно расписания
/// </summary>
/// <param name="esppSchedule"></param>
/// <param name="lastRun"></param>
/// <returns></returns>
DateTimeOffset GetNextDate(EsppScheduleDto esppSchedule, DateTimeOffset lastRun);
/// <summary>
/// Получить расписание
/// </summary>
/// <param name="esppSchedule"></param>
/// <param name="lastRun"></param>
/// <returns></returns>
List<DateTimeOffset> GetNextSchedule(EsppScheduleDto esppSchedule, DateTimeOffset lastRun);
/// <summary>
/// Получить следующую дату по applicationInWorkId
/// </summary>
/// <param name="applicationInWorkId"></param>
/// <param name="lastRun"></param>
/// <returns></returns>
Task<DateTimeOffset> GetNextDateAsync(Guid applicationInWorkId, DateTimeOffset lastRun);
/// <summary>
/// Получить расписание по applicationInWorkId
/// </summary>
/// <param name="applicationInWorkId"></param>
/// <param name="lastRun"></param>
/// <returns></returns>
Task<List<DateTimeOffset>> GetNextScheduleAsync(Guid applicationInWorkId, DateTimeOffset lastRun);
}
}