Логига синхронизации
This commit is contained in:
@@ -2,9 +2,6 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.DAL.Models;
|
using PARR.DAL.Models;
|
||||||
using PARR.DAL.Services.Interfaces;
|
using PARR.DAL.Services.Interfaces;
|
||||||
using System.Collections;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace PARR.EsppTemplateSync.Services
|
namespace PARR.EsppTemplateSync.Services
|
||||||
{
|
{
|
||||||
@@ -76,15 +73,17 @@ namespace PARR.EsppTemplateSync.Services
|
|||||||
//TODO деактивируем и видимо ещё что-то нужно
|
//TODO деактивируем и видимо ещё что-то нужно
|
||||||
if (template == null)
|
if (template == null)
|
||||||
{
|
{
|
||||||
esppTemplate.Status="Deactivating";
|
//создает запись-шаблон из ЕСПП в ПАРР. Возможно избыточно так как эталон в ПАРР
|
||||||
esppTemplate.isActive = false;
|
//esppTemplate.Status="Deactivating";
|
||||||
if (!await templateService.CreateAsync(esppTemplate) || !await templateService.CommitAsync())
|
//esppTemplate.isActive = false;
|
||||||
{
|
//if (!await templateService.CreateAsync(esppTemplate) || !await templateService.CommitAsync())
|
||||||
logger.LogError($"Не удалось создать запись Template {esppTemplate.Name}({esppTemplate.ShortDescription})");
|
//{
|
||||||
}
|
// logger.LogError($"Не удалось создать запись Template {esppTemplate.Name}({esppTemplate.ShortDescription})");
|
||||||
else
|
//}
|
||||||
logger.LogInformation($"----- Создана запись Template {esppTemplate.Name}({esppTemplate.ShortDescription}) -----");
|
//else
|
||||||
//TODO написать проверку успешности деактивации и удаление строки из таблицы Templates
|
// logger.LogInformation($"----- Создана запись Template {esppTemplate.Name}({esppTemplate.ShortDescription}) -----");
|
||||||
|
logger.LogWarning($"----- Найден шаблон ЕСПП незарегистрированный в ПАРР {esppTemplate.Name}({esppTemplate.ShortDescription}) -----");
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -92,28 +91,47 @@ namespace PARR.EsppTemplateSync.Services
|
|||||||
|
|
||||||
foreach (var prop in template.GetType().GetProperties())
|
foreach (var prop in template.GetType().GetProperties())
|
||||||
{
|
{
|
||||||
|
if (prop == null) continue;
|
||||||
|
|
||||||
if (prop.Name == "Id" ||
|
if (prop.Name == "Id" ||
|
||||||
prop.Name == "Status" ||
|
prop.Name == "Status" ||
|
||||||
prop.Name == "DateCreated" ||
|
prop.Name == "DateCreated" ||
|
||||||
prop.Name == "DateModified"
|
prop.Name == "DateModified" ||
|
||||||
|
prop.Name == "Status"
|
||||||
) continue;
|
) continue;
|
||||||
|
|
||||||
if (!template.GetType().GetProperty(prop.Name).GetValue(template,null).Equals(
|
var parrValue = template.GetType().GetProperty(prop.Name)?.GetValue(template, null);
|
||||||
esppTemplate.GetType().GetProperty(prop.Name).GetValue(esppTemplate, null))
|
var esppValue = esppTemplate.GetType().GetProperty(prop.Name)?.GetValue(template, null);
|
||||||
|
|
||||||
|
if (parrValue == null || esppValue == null) continue;
|
||||||
|
|
||||||
|
if (parrValue!.ToString()!.ToLower().Equals(
|
||||||
|
esppValue!.ToString()!.ToLower())
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
isChanged = true; break;
|
isChanged = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isChanged)
|
if (isChanged)
|
||||||
{
|
{
|
||||||
logger.LogInformation($"----- Запись в ЕСПП отличается от Template {esppTemplate.EK}({esppTemplate.ShortDescription}) -----");
|
logger.LogInformation($"----- Запись в ЕСПП отличается от Template {esppTemplate.Name}({esppTemplate.ShortDescription}) -----");
|
||||||
template.Status = "Updating";
|
template.Status = "Updating";
|
||||||
if(!await templateService.CommitAsync())
|
if(!await templateService.CommitAsync())
|
||||||
logger.LogError($"Не удалось обновить запись Template {esppTemplate.EK}({esppTemplate.ShortDescription})");
|
logger.LogError($"Не удалось обновить запись Template {esppTemplate.Name}({esppTemplate.ShortDescription})");
|
||||||
else
|
else
|
||||||
logger.LogInformation($"----- Требуется обновление шаблона в ЕСПП роботом {esppTemplate.EK}({esppTemplate.ShortDescription}) -----");
|
logger.LogInformation($"----- Требуется обновление шаблона в ЕСПП роботом {esppTemplate.Name}({esppTemplate.ShortDescription}) -----");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (template.Status != "Ok")
|
||||||
|
{
|
||||||
|
template.DateModified = DateTimeOffset.UtcNow;
|
||||||
|
template.Status = "Ok";
|
||||||
|
if (!await templateService.CommitAsync())
|
||||||
|
logger.LogInformation($"Шаблон в ЕСПП соответствует шаблону в ПАРР {esppTemplate.Name}({esppTemplate.ShortDescription}). Установлен статус Ok");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user