feat(esppScheduleSync): доделал синхронизацию расписаний. dal: обновлена таблица EsppSchTypeValue
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.BLL.Helpers;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.EsppScheduleSync.Domain;
|
||||
using PARR.EsppScheduleSync.Settings;
|
||||
using PARR.EsppSync;
|
||||
@@ -15,13 +18,15 @@ namespace PARR.EsppScheduleSync
|
||||
private readonly IMqService mqService;
|
||||
private readonly ISyncService<EsppObjectSchedule> syncService;
|
||||
private readonly SettingsFromDb settingsFromDb;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
|
||||
public ScheduleSyncher(
|
||||
ILogger<ScheduleSyncher> logger,
|
||||
GlobalSettings globalSettings,
|
||||
IMqService mqService,
|
||||
ISyncService<EsppObjectSchedule> syncService,
|
||||
SettingsFromDb settingsFromDb
|
||||
SettingsFromDb settingsFromDb,
|
||||
IServiceProvider serviceProvider
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
@@ -29,7 +34,7 @@ namespace PARR.EsppScheduleSync
|
||||
this.mqService = mqService;
|
||||
this.syncService = syncService;
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
|
||||
this.serviceProvider = serviceProvider;
|
||||
if (globalSettings.MqSettings == null)
|
||||
{
|
||||
logger.LogError("Нет секции настроек хранилища. MqSettings, EsppTemplates");
|
||||
@@ -71,8 +76,83 @@ namespace PARR.EsppScheduleSync
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private EsppObjectSchedule ConvertDbObjToEsppObj(Template template)
|
||||
{
|
||||
//todo:
|
||||
throw new NotImplementedException();
|
||||
var esppObjectFromDb = new EsppObjectSchedule
|
||||
{
|
||||
TemplateName = template.Name,
|
||||
Code = template.ScheduleEsppId ?? "",
|
||||
ScheduleName = template.Name,
|
||||
IsActive = template.IsActiveSchedule,
|
||||
ResponseArea = template.Host!.ResponseArea!.Name,
|
||||
WorkGroup = template.Host!.WorkGroup!,
|
||||
//Мы решили, что для всех расписаний "Нет исключений", если что-то поменяется, тут нужно переделать
|
||||
TypeV60calendar = settingsFromDb.ScheduleExclude == "Нет исключений" ? "NONE" : "",
|
||||
Scheduled = EsppScheduleHelpers.GetNextRun(template.ApplicationsInWork!.NextRun),
|
||||
Timezone = settingsFromDb.ScheduleTimezone,
|
||||
//Мы решили, что для всех расписаний "Отсутствует дата завершения", если что-то поменяется, тут нужно переделать
|
||||
TerminationType = settingsFromDb.ScheduleRepeatRange == "Отсутствует дата завершения" ? "forever" : "",
|
||||
CompleteAfter = "",
|
||||
V60calendar = ""
|
||||
};
|
||||
|
||||
FillScheduleFromDb(template, ref esppObjectFromDb);
|
||||
|
||||
return ClearOptionalFields(esppObjectFromDb);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Заполнить расписание из БД
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private void FillScheduleFromDb(Template template, ref EsppObjectSchedule esppObject)
|
||||
{
|
||||
using (var scope = serviceProvider.CreateScope())
|
||||
{
|
||||
var esppSchTypeConfigService = scope.ServiceProvider.GetService<IEsppSchTypeConfigService>();
|
||||
if (esppSchTypeConfigService == null)
|
||||
throw new Exception($"Не найден сервис: {nameof(IEsppSchTypeConfigService)}");
|
||||
|
||||
var esppSchedule = esppSchTypeConfigService.GetEsppScheduleDto(template.ApplicationInWorkId);
|
||||
if (esppSchedule == null)
|
||||
{
|
||||
logger.LogError($"Не смог получить расписание из БД для шаблона templateId: {template.Id}, {template.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
var typeSchedule = GetTypeScheduleByString(esppSchedule.TypeSchedule.Name);
|
||||
if (!typeSchedule.HasValue)
|
||||
return;
|
||||
|
||||
//тип повторения
|
||||
esppObject.TypeSchedule = typeSchedule.Value;
|
||||
|
||||
//в зависимости от типа, присваиваем значения
|
||||
switch (esppObject.TypeSchedule)
|
||||
{
|
||||
case EsppSchTypeScheduleEnum.Regularly:
|
||||
esppObject.Interval = esppSchedule.Values.First(t => t.Order == 0).Value.EsppExportValue;
|
||||
break;
|
||||
case EsppSchTypeScheduleEnum.Weekly:
|
||||
esppObject.Dayofweek = esppSchedule.Values.First(t => t.Order == 0).Value.EsppExportValue;
|
||||
break;
|
||||
case EsppSchTypeScheduleEnum.Monthly:
|
||||
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;
|
||||
esppObject.Md2 = esppSchedule.Values.First(t => t.Order == 1).Value.EsppExportValue;
|
||||
break;
|
||||
case EsppSchTypeScheduleEnum.Annually:
|
||||
esppObject.Annualm = esppSchedule.Values.First(t => t.Order == 0).Value.EsppExportValue;
|
||||
esppObject.Annualday = esppSchedule.Values.First(t => t.Order == 1).Value.EsppExportValue;
|
||||
break;
|
||||
case EsppSchTypeScheduleEnum.Annually2:
|
||||
esppObject.An1 = esppSchedule.Values.First(t => t.Order == 0).Value.EsppExportValue;
|
||||
esppObject.An2 = esppSchedule.Values.First(t => t.Order == 1).Value.EsppExportValue;
|
||||
esppObject.An3 = esppSchedule.Values.First(t => t.Order == 2).Value.EsppExportValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -198,6 +278,7 @@ namespace PARR.EsppScheduleSync
|
||||
esppObject.ResponseArea = string.Empty;
|
||||
esppObject.WorkGroup = string.Empty;
|
||||
esppObject.CompleteAfter = string.Empty;
|
||||
esppObject.V60calendar = string.Empty;
|
||||
|
||||
// В ЕСПП, при изменении "Повторять задачу", остаются предыдущие значения, их не нужно синхронизировать (касается только данных полученных из ЕСПП, в БД все ок)
|
||||
// т.е. если стояло Ежедненвно:понедельник, а изменили например на Еженедельно..., то в ежедневно значения останутся, но будут отрабатывать значения из Еженедельно.
|
||||
|
||||
Reference in New Issue
Block a user