feat(esppScheduleSync, esppSync): подключена логика INextRunServiceV2
This commit is contained in:
@@ -5,14 +5,13 @@ using PARR.BLL.Helpers;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.DomainServices.Shortcodes;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.NextRunServices;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Schedule;
|
||||
using PARR.EsppScheduleSync.Domain;
|
||||
using PARR.EsppScheduleSync.Settings;
|
||||
using PARR.EsppSync;
|
||||
using PARR.EsppSync.Domain;
|
||||
|
||||
namespace PARR.EsppScheduleSync
|
||||
{
|
||||
@@ -26,7 +25,6 @@ namespace PARR.EsppScheduleSync
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly IScheduleResponseAreaTimeOffsetService scheduleResponseAreaTimeOffsetService;
|
||||
private string noneExcludeCalendarEsppValue;
|
||||
//private Dictionary<string, string> responseAreaTimeOffsetDict;
|
||||
|
||||
|
||||
public ScheduleSyncher(
|
||||
@@ -46,7 +44,6 @@ namespace PARR.EsppScheduleSync
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
this.serviceProvider = serviceProvider;
|
||||
this.scheduleResponseAreaTimeOffsetService = scheduleResponseAreaTimeOffsetService;
|
||||
//this.responseAreaTimeOffsetDict = new Dictionary<string, string>();
|
||||
this.noneExcludeCalendarEsppValue = string.Empty;
|
||||
|
||||
if (globalSettings.MqSettings == null)
|
||||
@@ -66,8 +63,7 @@ namespace PARR.EsppScheduleSync
|
||||
if (string.IsNullOrEmpty(noneExcludeCalendarEsppValue))
|
||||
await GetNoneExcludeCalendarEsppValueAsync();
|
||||
|
||||
//if (responseAreaTimeOffsetDict.Count == 0)
|
||||
// await GetResponseAreaTimeOffsetsAsync();
|
||||
|
||||
|
||||
var isConnected = await mqService.InitConsumerAsync(globalSettings!.MqSettings!, SyncScheduleAsync);
|
||||
|
||||
@@ -77,13 +73,7 @@ namespace PARR.EsppScheduleSync
|
||||
logger.LogInformation("Запущена проверка очереди {QueueName}.", globalSettings.MqSettings!.QueueName);
|
||||
}
|
||||
|
||||
//private async Task GetResponseAreaTimeOffsetsAsync()
|
||||
//{
|
||||
// using var scope = serviceProvider.CreateScope();
|
||||
// var service = scope.ServiceProvider.GetRequiredService<IScheduleResponseAreaTimeOffsetService>();
|
||||
|
||||
// responseAreaTimeOffsetDict = await service.Get().ToDictionaryAsync(t => t.ResponseArea, t => t.TimeOffset);
|
||||
//}
|
||||
|
||||
private async Task GetNoneExcludeCalendarEsppValueAsync()
|
||||
{
|
||||
@@ -253,10 +243,10 @@ namespace PARR.EsppScheduleSync
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private EsppObjectSchedule ConvertDbObjToEsppObj(Template template)
|
||||
{
|
||||
//дефолтное значение, изменится в сервисе nextRunModifierService
|
||||
var nextRunWithTimeZone = DateTimeOffset.MinValue;
|
||||
// дефолтное значение, изменится в ApplyShortcodesAsync
|
||||
var responseArea = "%ЗО_РГ%";
|
||||
//дефолтное значение, nextRun в часовом поясе робота ЕСПП
|
||||
var nextRunWithEsppTz = DateTimeOffset.MinValue;
|
||||
//// дефолтное значение, изменится в ApplyShortcodesAsync
|
||||
//var responseArea = "%ЗО_РГ%";
|
||||
|
||||
using (var scope = serviceProvider.CreateScope())
|
||||
{
|
||||
@@ -266,11 +256,11 @@ namespace PARR.EsppScheduleSync
|
||||
|
||||
//nextRunWithTimeZone = nextRunModifierService.GetNextRunByAccountRobotTimeZone(template.NextRun);
|
||||
|
||||
var nextRunService = scope.ServiceProvider.GetRequiredService<INextRunService>();
|
||||
var shortcodeService = scope.ServiceProvider.GetRequiredService<IShortcodesService>();
|
||||
var nextRunService = scope.ServiceProvider.GetRequiredService<INextRunServiceV2>();
|
||||
//var shortcodeService = scope.ServiceProvider.GetRequiredService<IShortcodesService>();
|
||||
|
||||
responseArea = shortcodeService.ApplyShortcodesAsync(template.Job!.ResponseAreaMask, template).GetAwaiter().GetResult();
|
||||
nextRunWithTimeZone = nextRunService.GetNextRunWithTimezoneEsppAndResponseArea(template.NextRun, template.Job?.Group?.IsResponseAreaTimezone, responseArea);
|
||||
//responseArea = shortcodeService.ApplyShortcodesAsync(template.Job!.ResponseAreaMask, template).GetAwaiter().GetResult();
|
||||
nextRunWithEsppTz = template.NextRun.Add(nextRunService.GetEsppAccountOffset());
|
||||
}
|
||||
|
||||
var esppObjectFromDb = new EsppObjectSchedule
|
||||
@@ -289,9 +279,9 @@ namespace PARR.EsppScheduleSync
|
||||
//Scheduled = EsppScheduleHelpers.GetNextRun(template.NextRun),
|
||||
//Scheduled = EsppScheduleHelpers.GetNextRun(nextRunModifierService.GetNextRunByAccountRobotTimeZone(template.NextRun)),
|
||||
//BasisTime = EsppScheduleHelpers.GetGenerationTime(nextRunModifierService.GetNextRunByAccountRobotTimeZone(template.NextRun)),
|
||||
Scheduled = EsppScheduleHelpers.GetNextRun(nextRunWithTimeZone),
|
||||
BasisTime = EsppScheduleHelpers.GetGenerationTime(nextRunWithTimeZone),
|
||||
Timezone = GetTimezone(template, responseArea),
|
||||
Scheduled = EsppScheduleHelpers.GetNextRun(nextRunWithEsppTz),
|
||||
BasisTime = EsppScheduleHelpers.GetGenerationTime(nextRunWithEsppTz),
|
||||
Timezone = GetTimezone(/*template, responseArea*/),
|
||||
//Мы решили, что для всех расписаний "Отсутствует дата завершения", если что-то поменяется, тут нужно переделать
|
||||
TerminationType = settingsFromDb.ScheduleRepeatRange == "Отсутствует дата завершения" ? "forever" : "",
|
||||
CompleteAfter = ""
|
||||
@@ -301,34 +291,38 @@ namespace PARR.EsppScheduleSync
|
||||
return ClearOptionalFields(esppObjectFromDb);
|
||||
}
|
||||
|
||||
private string GetTimezone(Template template, string responseArea)
|
||||
private string GetTimezone(/*Template template, string responseArea*/)
|
||||
{
|
||||
// договорились, что у роботоа ТЗ МСК
|
||||
return settingsFromDb.EsppScheduleTimezone;
|
||||
|
||||
//if (template.Job?.Group?.IsWorkGroupTimezone != true)
|
||||
// return settingsFromDb.ScheduleTimezone;
|
||||
#region old
|
||||
////if (template.Job?.Group?.IsWorkGroupTimezone != true)
|
||||
//// return settingsFromDb.ScheduleTimezone;
|
||||
|
||||
if (template.Job?.Group?.IsResponseAreaTimezone != true)
|
||||
return scheduleResponseAreaTimeOffsetService.GetDefault.EsppValue;
|
||||
//if (template.Job?.Group?.IsResponseAreaTimezone != true)
|
||||
// return scheduleResponseAreaTimeOffsetService.GetDefault.EsppValue;
|
||||
|
||||
//var responseArea = template.Unit?.BaseFields?.ResponseArea;
|
||||
////var responseArea = template.Unit?.BaseFields?.ResponseArea;
|
||||
|
||||
//if (string.IsNullOrEmpty(responseArea))
|
||||
//{
|
||||
// throw new InvalidOperationException(
|
||||
// $"У шаблона Id={template.Id}, Name='{template.Name}' не задана ResponseArea в Unit.BaseFields, " +
|
||||
// "но включена настройка 'использовать часовой пояс рабочей группы'.");
|
||||
//}
|
||||
////if (string.IsNullOrEmpty(responseArea))
|
||||
////{
|
||||
//// throw new InvalidOperationException(
|
||||
//// $"У шаблона Id={template.Id}, Name='{template.Name}' не задана ResponseArea в Unit.BaseFields, " +
|
||||
//// "но включена настройка 'использовать часовой пояс рабочей группы'.");
|
||||
////}
|
||||
|
||||
//if (!responseAreaTimeOffsetDict.TryGetValue(responseArea, out var offset))
|
||||
//{
|
||||
// throw new InvalidOperationException(
|
||||
// $"Не найдено временное смещение для ResponseArea '{responseArea}' у шаблона Id={template.Id}, Name='{template.Name}'. " +
|
||||
// "Проверьте наличие записи в таблице ScheduleResponseAreaTimeOffset.");
|
||||
//}
|
||||
////if (!responseAreaTimeOffsetDict.TryGetValue(responseArea, out var offset))
|
||||
////{
|
||||
//// throw new InvalidOperationException(
|
||||
//// $"Не найдено временное смещение для ResponseArea '{responseArea}' у шаблона Id={template.Id}, Name='{template.Name}'. " +
|
||||
//// "Проверьте наличие записи в таблице ScheduleResponseAreaTimeOffset.");
|
||||
////}
|
||||
|
||||
//return offset;
|
||||
////return offset;
|
||||
|
||||
return scheduleResponseAreaTimeOffsetService.GetByResponseAreaOrDefault(responseArea).EsppValue;
|
||||
//return scheduleResponseAreaTimeOffsetService.GetByResponseAreaOrDefault(responseArea).EsppValue;
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -373,20 +367,6 @@ namespace PARR.EsppScheduleSync
|
||||
logger.LogDebug("Для шаблона шаблона {TemplateName}, {TemplateId} тип исключения \"{Name}\", EsppValue: {EsppValue}", template.Name, template.Id, template.Job.Group.ScheduleExcludeType.Title, template.Job.Group.ScheduleExcludeType.EsppValue);
|
||||
|
||||
return template.Job.Group.ScheduleExcludeType.EsppValue;
|
||||
|
||||
|
||||
#region old logic
|
||||
//// Это костыль, нужно придумать как это хранить в БД.
|
||||
//switch (settingsFromDb.ScheduleExcludeType.ToLower())
|
||||
//{
|
||||
// case ("нет исключений"):
|
||||
// return "NONE";
|
||||
// case ("выполнить только в указанном календаре"):
|
||||
// return "ONLY";
|
||||
// default:
|
||||
// return "";
|
||||
//}
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -426,17 +406,7 @@ namespace PARR.EsppScheduleSync
|
||||
esppObject.Dayofweek = esppSchedule.Values.First(t => t.Order == 0).Value.EsppExportValue;
|
||||
break;
|
||||
case EsppSchTypeScheduleEnum.Monthly:
|
||||
//если включено автораспределение, подставляем дату месяца из NextRun
|
||||
//if (template.ApplicationsInWork?.IsAutoDistributionEnabled == true)//TODO Migration to job
|
||||
//{
|
||||
// var nextRunByRobotTimeZone = nextRunModifierService.GetNextRunByAccountRobotTimeZone(template.NextRun);
|
||||
// esppObject.Dayofmonth = nextRunByRobotTimeZone.Day.ToString();
|
||||
// // esppObject.Dayofmonth = template.NextRun.Day.ToString();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
esppObject.Dayofmonth = esppSchedule.Values.First(t => t.Order == 0).Value.EsppExportValue;
|
||||
//}
|
||||
break;
|
||||
case EsppSchTypeScheduleEnum.Monthly2:
|
||||
esppObject.Md1 = esppSchedule.Values.First(t => t.Order == 0).Value.EsppExportValue;
|
||||
@@ -452,8 +422,6 @@ namespace PARR.EsppScheduleSync
|
||||
esppObject.An3 = esppSchedule.Values.First(t => t.Order == 2).Value.EsppExportValue;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user