PARR.EsppTemplateSyncWorker small fix
This commit is contained in:
@@ -40,9 +40,9 @@ namespace PARR.EsppTemplateSync.Services
|
||||
if (str == null || str.Trim().Length == 0)
|
||||
return false;
|
||||
|
||||
var template = parserService.ParseString(str);
|
||||
var esppTemplate = parserService.ParseString(str);
|
||||
|
||||
if (template == null)
|
||||
if (esppTemplate == null)
|
||||
{
|
||||
isSuccess = false;
|
||||
logger.LogError($"Не удалось распознать строку({str}) в Template");
|
||||
@@ -50,24 +50,86 @@ namespace PARR.EsppTemplateSync.Services
|
||||
else
|
||||
{
|
||||
//если шаблон не аквтивен, пропускаем
|
||||
if (!template.IsActive)
|
||||
if (!esppTemplate.IsActive)
|
||||
{
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
//TODO: !!! тут метод называет чек, но он же и сохраняет. По идее надо чтобы чек че то вернул, а исходя из этого дургой метод сохранит или ченить изменит
|
||||
// и опять же, saccess всегда true получается??? или это норм.
|
||||
await CheckChangesAsync(template);
|
||||
await SyncTemplateAsync(esppTemplate);
|
||||
// var template = await GetTemplateAsync(esppTemplate);
|
||||
//var isChanged = false;
|
||||
//if (template == null)
|
||||
//{
|
||||
// // создает запись-шаблон из ЕСПП в ПАРР. Возможно избыточно так как эталон в ПАРР
|
||||
// ////esppTemplate.StatusCode = "Deactivating";
|
||||
// ////---
|
||||
// //esppTemplate.StatusCode = (int)StatusTemplateEnum.Ok;
|
||||
// //esppTemplate.IsActive = false;
|
||||
// //if (!await templateService.CreateAsync(esppTemplate) || !await templateService.CommitAsync())
|
||||
// //{
|
||||
// // logger.LogError($"Не удалось создать запись Template {esppTemplate.Name}({esppTemplate.ShortDescription})");
|
||||
// //}
|
||||
// //else
|
||||
// // logger.LogInformation($"----- Создана запись Template {esppTemplate.Name}({esppTemplate.ShortDescription}) -----");
|
||||
// //---
|
||||
// logger.LogWarning($"----- Найден шаблон ЕСПП незарегистрированный в ПАРР {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}) -----");
|
||||
// return false;
|
||||
//}
|
||||
//else isChanged = await CheckChangesAsync(esppTemplate, template);
|
||||
////if (isChanged)
|
||||
|
||||
////var isChanged = await UpdateIfNeedAsync(template);
|
||||
|
||||
// //if (isChanged)
|
||||
// //{
|
||||
// // logger.LogInformation($"----- Запись в ЕСПП отличается от Template {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}) -----");
|
||||
|
||||
// // //template.Status = "Updating";
|
||||
// // template.StatusCode = (int)StatusTemplateEnum.Updating;
|
||||
|
||||
// // if (!await templateService.CommitAsync())
|
||||
// // logger.LogError($"Не удалось обновить запись Template {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription})");
|
||||
// // else
|
||||
// // logger.LogInformation($"----- Требуется обновление шаблона в ЕСПП роботом {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}) -----");
|
||||
// //}
|
||||
// //else
|
||||
// //{
|
||||
// // //if (template.Status != "Ok")
|
||||
// // if (template.StatusCode != (int)StatusTemplateEnum.Ok)
|
||||
// // {
|
||||
// // template.DateModified = DateTimeOffset.UtcNow;
|
||||
// // template.StatusCode = (int)StatusTemplateEnum.Ok;
|
||||
|
||||
// // if (!await templateService.CommitAsync())
|
||||
// // logger.LogInformation($"Шаблон в ЕСПП соответствует шаблону в ПАРР {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}). Установлен статус {StatusTemplateEnum.Ok}");
|
||||
// // }
|
||||
// //}
|
||||
}
|
||||
|
||||
//todo: only true?????
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
private async Task CheckChangesAsync(Template esppTemplate)
|
||||
private async Task<Template?> GetTemplateAsync(Template esppTemplate)
|
||||
{
|
||||
// --- test ---
|
||||
using (var scope = serviceProvider.CreateScope())
|
||||
{
|
||||
var services = scope.ServiceProvider;
|
||||
|
||||
var templateService = services.GetService<ITemplateService>();
|
||||
|
||||
if (templateService == null)
|
||||
{
|
||||
throw new Exception($"Не найден сервис: {nameof(ITemplateService)}");
|
||||
// return;
|
||||
}
|
||||
|
||||
return await templateService.GetTemplateByNameAsync(esppTemplate.Name);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SyncTemplateAsync(Template esppTemplate)
|
||||
{
|
||||
using (var scope = serviceProvider.CreateScope())
|
||||
{
|
||||
var services = scope.ServiceProvider;
|
||||
@@ -98,64 +160,53 @@ namespace PARR.EsppTemplateSync.Services
|
||||
// logger.LogInformation($"----- Создана запись Template {esppTemplate.Name}({esppTemplate.ShortDescription}) -----");
|
||||
//---
|
||||
logger.LogWarning($"----- Найден шаблон ЕСПП незарегистрированный в ПАРР {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}) -----");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var isChanged = false;
|
||||
//var ignoreTemplateFieldsList = globalSettings.IgnoreTemplateFields?.Split(",").ToList().Select(t => t.Trim().ToLower());
|
||||
var isChanged = IsChanged(template,esppTemplate);
|
||||
|
||||
if (isChanged)
|
||||
{
|
||||
SetUpdateStatus(template);
|
||||
|
||||
if (!await templateService.CommitAsync())
|
||||
{
|
||||
logger.LogError($"Не удалось изменить запись Template {template.Name}");
|
||||
}
|
||||
else
|
||||
logger.LogInformation($"----- Установлен принудительный статус обновления Template {template.Name} -----");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private void SetUpdateStatus(Template template)
|
||||
{
|
||||
template.StatusCode = (int)StatusTemplateEnum.Updating;
|
||||
}
|
||||
|
||||
private bool IsChanged(Template template, Template esppTemplate)
|
||||
{
|
||||
foreach (var prop in template.GetType().GetProperties())
|
||||
{
|
||||
if (prop == null) continue;
|
||||
|
||||
if (globalSettings.IgnoreTemplateFields != null && globalSettings.IgnoreTemplateFields.Contains(prop.Name)) continue;
|
||||
//if (prop.Name == "Id" ||
|
||||
// prop.Name == "Status" ||
|
||||
// prop.Name == "DateCreated" ||
|
||||
// prop.Name == "DateModified" ||
|
||||
// prop.Name == "StatusCode"
|
||||
// ) continue;
|
||||
|
||||
var parrValue = template.GetType().GetProperty(prop.Name)?.GetValue(template, null);
|
||||
var esppValue = esppTemplate.GetType().GetProperty(prop.Name)?.GetValue(esppTemplate, null);
|
||||
|
||||
if (parrValue == null || esppValue == null) continue;
|
||||
if (parrValue == null || esppValue == null)
|
||||
continue;
|
||||
|
||||
if (parrValue!.ToString()!.ToLower() != esppValue!.ToString()!.ToLower())
|
||||
{
|
||||
isChanged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isChanged)
|
||||
{
|
||||
logger.LogInformation($"----- Запись в ЕСПП отличается от Template {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}) -----");
|
||||
|
||||
//template.Status = "Updating";
|
||||
template.StatusCode = (int)StatusTemplateEnum.Updating;
|
||||
|
||||
if (!await templateService.CommitAsync())
|
||||
logger.LogError($"Не удалось обновить запись Template {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription})");
|
||||
else
|
||||
logger.LogInformation($"----- Требуется обновление шаблона в ЕСПП роботом {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}) -----");
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (template.Status != "Ok")
|
||||
if (template.StatusCode != (int)StatusTemplateEnum.Ok)
|
||||
{
|
||||
template.DateModified = DateTimeOffset.UtcNow;
|
||||
template.StatusCode = (int)StatusTemplateEnum.Ok;
|
||||
|
||||
if (!await templateService.CommitAsync())
|
||||
logger.LogInformation($"Шаблон в ЕСПП соответствует шаблону в ПАРР {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}). Установлен статус {StatusTemplateEnum.Ok}");
|
||||
}
|
||||
}
|
||||
}
|
||||
//if (parrValue!.ToString()!.ToLower() != esppValue!.ToString()!.ToLower())
|
||||
//return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ namespace PARR.EsppTemplateSync.Services
|
||||
{
|
||||
//TODO: а если формат нет тот? Все будет ок?
|
||||
|
||||
//TODO:
|
||||
var splittedContent = str.Split(globalSettings.ParsingSeparator);
|
||||
if (splittedContent.Length != 17)
|
||||
{
|
||||
@@ -61,35 +60,15 @@ namespace PARR.EsppTemplateSync.Services
|
||||
var work = splittedContent[15].Trim();
|
||||
var worker = splittedContent[16].Trim();
|
||||
|
||||
//logger.LogInformation($"Получено сообщение: {ek}");
|
||||
var template = new Template
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
DateCreated = DateTime.UtcNow,
|
||||
Name = name,
|
||||
IsActive = bool.Parse(isActive),
|
||||
//WorkGroup = workGroup,
|
||||
//ShortDescription = shortDescription,
|
||||
//Category = category,
|
||||
//ResponseArea = responseArea,
|
||||
//Duration = duration,
|
||||
//EK = ek,
|
||||
//Initiator = initiator,
|
||||
//FullDescription = fullDescription,
|
||||
//ClosingCode = closingCode,
|
||||
//Solution = solution,
|
||||
//Process = process,
|
||||
//SubProcess = subProcess,
|
||||
//TNK = tnk,
|
||||
//Work = work,
|
||||
//Worker = worker,
|
||||
//Status = "Checking"
|
||||
StatusCode = (int)StatusTemplateEnum.Ok
|
||||
};
|
||||
|
||||
//bool isSuccess = true;
|
||||
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"StorageSettings": {
|
||||
"CheckIntervalSeconds": 30
|
||||
},
|
||||
"IgnoreTemplateFields": [ "Id", "Status", "DateCreated", "DateModified", "StatusCode" ],
|
||||
"IgnoreTemplateFields": [ "Id", "Status", "Name", "DateCreated", "DateModified", "StatusCode" ],
|
||||
"ParsingSeparator": "<|>"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"StorageSettings": {
|
||||
"CheckIntervalSeconds": 30
|
||||
},
|
||||
"IgnoreTemplateFields": [ "Id", "Status", "DateCreated", "DateModified", "StatusCode" ],
|
||||
"IgnoreTemplateFields": [ "Id", "Status", "Name", "DateCreated", "DateModified", "StatusCode" ],
|
||||
"ParsingSeparator": "<|>"
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user