diff --git a/PARR.EsppScheduleSync/Domain/EsppObjectSchedule.cs b/PARR.EsppScheduleSync/Domain/EsppObjectSchedule.cs
index 6bad89ae..099c52dc 100644
--- a/PARR.EsppScheduleSync/Domain/EsppObjectSchedule.cs
+++ b/PARR.EsppScheduleSync/Domain/EsppObjectSchedule.cs
@@ -1,14 +1,111 @@
using PARR.Constants;
+using PARR.DAL.Contracts;
using PARR.EsppSync;
namespace PARR.EsppScheduleSync.Domain
{
internal class EsppObjectSchedule : IEsppObject
{
- public required string TemplateName { get; set; }
+ //Все поля описаны в документации по роботам: http://gitlab.dvgd.oao.rzd/devptk/parr/parr_api/-/wikis/EsppRobots
public RobotsEnum Robot => RobotsEnum.ScheduleOrder;
- //todo:
+ public required string TemplateName { get; set; }
+
+ public string Code { get; set; } = string.Empty;
+
+ public string ScheduleName { get; set; } = string.Empty;
+
+ public bool IsActive { get; set; }
+
+ public string ResponseArea { get; set; } = string.Empty;
+
+ public string WorkGroup { get; set; } = string.Empty;
+
+ ///
+ /// Тип повторения: Регулярно, Ежегодно...
+ ///
+ public EsppSchTypeScheduleEnum TypeSchedule { get; set; }
+
+ ///
+ /// Интервал времени: Ежедневно, 1 00:00:00
+ ///
+ public string Interval { get; set; } = string.Empty;
+
+ ///
+ /// Еженедельно: Каждый понедельник
+ ///
+ public string Dayofweek { get; set; } = string.Empty;
+
+ ///
+ /// Ежемесячно: Каждое 23
+ ///
+ public string Dayofmonth { get; set; } = string.Empty;
+
+ ///
+ /// Ежемесячно-2: Каждый Первый
+ ///
+ public string Md1 { get; set; } = string.Empty;
+
+ ///
+ /// Ежемесячно-2: Каждый Понедельник
+ ///
+ public string Md2 { get; set; } = string.Empty;
+
+
+ ///
+ /// Ежегодно: Каждый Январь
+ ///
+ public string Annualm { get; set; } = string.Empty;
+
+ ///
+ /// Ежегодно: Каждый 12
+ ///
+ public string Annualday { get; set; } = string.Empty;
+
+ ///
+ /// Ежегодно-2: Каждый Первый
+ ///
+ public string An1 { get; set; } = string.Empty;
+
+ ///
+ /// Ежегодно-2: Каждый Понедельник
+ ///
+ public string An2 { get; set; } = string.Empty;
+
+ ///
+ /// Ежегодно-2: Каждый Января
+ ///
+ public string An3 { get; set; } = string.Empty;
+
+ ///
+ /// Тип исключения: Нет исключений
+ ///
+ public string TypeV60calendar { get; set; } = string.Empty;
+
+ ///
+ /// Следующее срабатывание: 16/10/23 17:00:00
+ ///
+ public required string Scheduled { get; set; }
+
+ ///
+ /// В каком часовом поясе: MSK
+ ///
+ public required string Timezone { get; set; }
+
+ ///
+ /// Тип прекращения, Отсутствует дата завершения: Выбран radio button forever
+ ///
+ public required string TerminationType { get; set; }
+
+ ///
+ /// Завершение после: 0
+ ///
+ public string CompleteAfter { get; set; } = string.Empty;
+
+ ///
+ /// Рабочий график
+ ///
+ public string V60calendar { get; set; } = string.Empty;
}
}
diff --git a/PARR.EsppScheduleSync/ScheduleSyncher.cs b/PARR.EsppScheduleSync/ScheduleSyncher.cs
index b0c53ca0..91f2f049 100644
--- a/PARR.EsppScheduleSync/ScheduleSyncher.cs
+++ b/PARR.EsppScheduleSync/ScheduleSyncher.cs
@@ -84,8 +84,183 @@ namespace PARR.EsppScheduleSync
///
private EsppObjectSchedule? ParseStrToEsppObject(string str)
{
- //todo:
- throw new NotImplementedException();
+ var splittedContent = str.Split(globalSettings.ParsingSeparator);
+ if (splittedContent.Length != 23)
+ {
+ logger.LogError($"Входная строка после сплита не содержит 23 объекта (факт: {splittedContent.Length}).");
+ return null;
+ }
+
+ var templateName = splittedContent[6];
+ var scheduleName = splittedContent[2];
+
+ if (!IsValidName(templateName) || !IsValidName(scheduleName))
+ return null;
+
+ bool.TryParse(splittedContent[1].Trim(), out var isActive);
+
+ var esppObject = new EsppObjectSchedule
+ {
+ TemplateName = templateName,
+ Code = splittedContent[0],
+ ScheduleName = scheduleName,
+ IsActive = isActive,
+ ResponseArea = splittedContent[5],
+ WorkGroup = splittedContent[3],
+ //TODO:!!!
+ //TypeSchedule = splittedContent[7],
+ Interval = splittedContent[8],
+ Dayofweek = splittedContent[15],
+ Dayofmonth = splittedContent[14],
+ Md1 = splittedContent[16],
+ Md2 = splittedContent[17],
+ Annualm = splittedContent[13],
+ Annualday = splittedContent[12],
+ An1 = splittedContent[9],
+ An2 = splittedContent[10],
+ An3 = splittedContent[11],
+ TypeV60calendar = splittedContent[21],
+ Scheduled = splittedContent[4],
+ Timezone = splittedContent[18],
+ TerminationType = splittedContent[19],
+ CompleteAfter = splittedContent[20],
+ V60calendar = splittedContent[22]
+ };
+
+ return ClearOptionalFields(esppObject);
}
+
+
+ ///
+ /// Проверка имени шаблона и расписание на соответствие префиксу из настроек
+ ///
+ ///
+ ///
+ private bool IsValidName(string name)
+ {
+ var currentCulture = Thread.CurrentThread.CurrentCulture;
+
+ if (!string.IsNullOrEmpty(settingsFromDb.TemplatePrefixName) && name.StartsWith(settingsFromDb.TemplatePrefixName, true, currentCulture))
+ return true;
+
+ logger.LogWarning($"Имя шаблона или расписания не соответствует обязательному префиксу({settingsFromDb.TemplatePrefixName}). {name} игнорирован");
+
+ return false;
+ }
+
+
+ ///
+ /// Очистка полей которые не нуждаются в синхронизации
+ ///
+ ///
+ ///
+ private EsppObjectSchedule ClearOptionalFields(EsppObjectSchedule esppObject)
+ {
+ esppObject.Code = string.Empty;
+ esppObject.ScheduleName = string.Empty;
+ esppObject.ResponseArea = string.Empty;
+ esppObject.WorkGroup = string.Empty;
+ esppObject.CompleteAfter = string.Empty;
+
+ // В ЕСПП, при изменении "Повторять задачу", остаются предыдущие значения, их не нужно синхронизировать (касается только данных полученных из ЕСПП, в БД все ок)
+ // т.е. если стояло Ежедненвно:понедельник, а изменили например на Еженедельно..., то в ежедневно значения останутся, но будут отрабатывать значения из Еженедельно.
+ // Т е значения из Ежедненвно проверять не нужно, вот их и будем очищать
+
+ //TODO: сделать миграцию в БД: Еженежельно
+
+ //TODO:!!!
+ ////Regularly, Регулярно (значение в ЕСПП и в БД не совпадают, в бд Regularly, в ЕСПП simple)
+ //if (esppObject.TypeSchedule.ToLower() == "simple" || esppObject.TypeSchedule.ToLower() == EsppSchTypeScheduleEnum.Regularly.ToString().ToLower())
+ //{
+ // //esppObject.Interval = string.Empty;
+ // esppObject.Dayofweek = string.Empty;
+ // esppObject.Dayofmonth = string.Empty;
+ // esppObject.Md1 = string.Empty;
+ // esppObject.Md2 = string.Empty;
+ // esppObject.Annualm = string.Empty;
+ // esppObject.Annualday = string.Empty;
+ // esppObject.An1 = string.Empty;
+ // esppObject.An2 = string.Empty;
+ // esppObject.An3 = string.Empty;
+ //}
+
+ ////Weekly, Еженедельно
+ //if (esppObject.TypeSchedule == "weekly")
+ //{
+ // esppObject.Interval = string.Empty;
+ // //esppObject.Dayofweek = string.Empty;
+ // esppObject.Dayofmonth = string.Empty;
+ // esppObject.Md1 = string.Empty;
+ // esppObject.Md2 = string.Empty;
+ // esppObject.Annualm = string.Empty;
+ // esppObject.Annualday = string.Empty;
+ // esppObject.An1 = string.Empty;
+ // esppObject.An2 = string.Empty;
+ // esppObject.An3 = string.Empty;
+ //}
+
+ ////Monthly, Ежемесячно
+ //if (esppObject.TypeSchedule == "monthly")
+ //{
+ // esppObject.Interval = string.Empty;
+ // esppObject.Dayofweek = string.Empty;
+ // //esppObject.Dayofmonth = string.Empty;
+ // esppObject.Md1 = string.Empty;
+ // esppObject.Md2 = string.Empty;
+ // esppObject.Annualm = string.Empty;
+ // esppObject.Annualday = string.Empty;
+ // esppObject.An1 = string.Empty;
+ // esppObject.An2 = string.Empty;
+ // esppObject.An3 = string.Empty;
+ //}
+
+ ////Monthly2, Ежемесячно-2
+ //if (esppObject.TypeSchedule == "monthly2")
+ //{
+ // esppObject.Interval = string.Empty;
+ // esppObject.Dayofweek = string.Empty;
+ // esppObject.Dayofmonth = string.Empty;
+ // //esppObject.Md1 = string.Empty;
+ // //esppObject.Md2 = string.Empty;
+ // esppObject.Annualm = string.Empty;
+ // esppObject.Annualday = string.Empty;
+ // esppObject.An1 = string.Empty;
+ // esppObject.An2 = string.Empty;
+ // esppObject.An3 = string.Empty;
+ //}
+
+ ////Annually, Ежегодно
+ //if (esppObject.TypeSchedule == "annually")
+ //{
+ // esppObject.Interval = string.Empty;
+ // esppObject.Dayofweek = string.Empty;
+ // esppObject.Dayofmonth = string.Empty;
+ // esppObject.Md1 = string.Empty;
+ // esppObject.Md2 = string.Empty;
+ // //esppObject.Annualm = string.Empty;
+ // //esppObject.Annualday = string.Empty;
+ // esppObject.An1 = string.Empty;
+ // esppObject.An2 = string.Empty;
+ // esppObject.An3 = string.Empty;
+ //}
+
+ ////Annually2, Ежегодно-2
+ //if (esppObject.TypeSchedule == "annually2")
+ //{
+ // esppObject.Interval = string.Empty;
+ // esppObject.Dayofweek = string.Empty;
+ // esppObject.Dayofmonth = string.Empty;
+ // esppObject.Md1 = string.Empty;
+ // esppObject.Md2 = string.Empty;
+ // esppObject.Annualm = string.Empty;
+ // esppObject.Annualday = string.Empty;
+ // //esppObject.An1 = string.Empty;
+ // //esppObject.An2 = string.Empty;
+ // //esppObject.An3 = string.Empty;
+ //}
+
+ return esppObject;
+ }
+
}
}
diff --git a/PARR.EsppSync/SyncService.cs b/PARR.EsppSync/SyncService.cs
index d6ff6a68..57107ac3 100644
--- a/PARR.EsppSync/SyncService.cs
+++ b/PARR.EsppSync/SyncService.cs
@@ -65,6 +65,8 @@ namespace PARR.EsppSync
if (isChanged)
{
+ logger.LogInformation($"Есть изменения, требуется обновление. {esppObject.TemplateName}");
+
SetUpdateStatus(ref template, robotConfigurationService, esppObject.Robot);
if (!await templateService.CommitAsync())
@@ -74,6 +76,8 @@ namespace PARR.EsppSync
}//надо ли проверять если не изменился, но был статус Updating не понятно. Доверяем роботу пока, что после окончания работ он точно сообщит
else
{
+ logger.LogInformation($"Нет изменений, обновление не требуется. {esppObject.TemplateName}");
+
//если все поля совпали
//проверяем, какой был статус предыдущий статус в БД, если он был не Ок, то ставим ему ОК
var robotConfig = robotConfigurationService.GetFromTemplateByRobotCode(esppObject.Robot, ref template);
diff --git a/PARR.EsppTemplateSync/TemplateMQSyncer.cs b/PARR.EsppTemplateSync/TemplateMQSyncer.cs
index ec251bd4..6c633aed 100644
--- a/PARR.EsppTemplateSync/TemplateMQSyncer.cs
+++ b/PARR.EsppTemplateSync/TemplateMQSyncer.cs
@@ -108,7 +108,7 @@ namespace PARR.EsppTemplateSync
var templateName = splittedContent[0].Trim();
var currentCulture = Thread.CurrentThread.CurrentCulture;
- if (!string.IsNullOrEmpty(settingsFromDb.TemplatePrefixName) && !templateName.StartsWith(settingsFromDb.TemplatePrefixName, true, currentCulture))
+ if (!string.IsNullOrEmpty(settingsFromDb.TemplatePrefixName) || !templateName.StartsWith(settingsFromDb.TemplatePrefixName, true, currentCulture))
{
logger.LogWarning($"Имя шаблона не соответствует обязательному префиксу({settingsFromDb.TemplatePrefixName}). Шаблон {templateName} игнорирован");
return null;