feat(esppScheduleSync): метод ParseStrToEsppObject
This commit is contained in:
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Тип повторения: Регулярно, Ежегодно...
|
||||
/// </summary>
|
||||
public EsppSchTypeScheduleEnum TypeSchedule { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Интервал времени: Ежедневно, 1 00:00:00
|
||||
/// </summary>
|
||||
public string Interval { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Еженедельно: Каждый понедельник
|
||||
/// </summary>
|
||||
public string Dayofweek { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Ежемесячно: Каждое 23
|
||||
/// </summary>
|
||||
public string Dayofmonth { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Ежемесячно-2: Каждый Первый
|
||||
/// </summary>
|
||||
public string Md1 { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Ежемесячно-2: Каждый Понедельник
|
||||
/// </summary>
|
||||
public string Md2 { get; set; } = string.Empty;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ежегодно: Каждый Январь
|
||||
/// </summary>
|
||||
public string Annualm { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Ежегодно: Каждый 12
|
||||
/// </summary>
|
||||
public string Annualday { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Ежегодно-2: Каждый Первый
|
||||
/// </summary>
|
||||
public string An1 { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Ежегодно-2: Каждый Понедельник
|
||||
/// </summary>
|
||||
public string An2 { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Ежегодно-2: Каждый Января
|
||||
/// </summary>
|
||||
public string An3 { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Тип исключения: Нет исключений
|
||||
/// </summary>
|
||||
public string TypeV60calendar { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Следующее срабатывание: 16/10/23 17:00:00
|
||||
/// </summary>
|
||||
public required string Scheduled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// В каком часовом поясе: MSK
|
||||
/// </summary>
|
||||
public required string Timezone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Тип прекращения, Отсутствует дата завершения: Выбран radio button forever
|
||||
/// </summary>
|
||||
public required string TerminationType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Завершение после: 0
|
||||
/// </summary>
|
||||
public string CompleteAfter { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Рабочий график
|
||||
/// </summary>
|
||||
public string V60calendar { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,8 +84,183 @@ namespace PARR.EsppScheduleSync
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Проверка имени шаблона и расписание на соответствие префиксу из настроек
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Очистка полей которые не нуждаются в синхронизации
|
||||
/// </summary>
|
||||
/// <param name="esppObject"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user