Логика актуализации ЕСПП после разбора экспорта
This commit is contained in:
@@ -4,6 +4,6 @@ namespace PARR.EsppTemplateSync.Services
|
|||||||
{
|
{
|
||||||
internal interface IParserService
|
internal interface IParserService
|
||||||
{
|
{
|
||||||
Task<Template> ParseStringAsync(string str);
|
Template? ParseString(string str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
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
|
||||||
{
|
{
|
||||||
@@ -30,11 +33,25 @@ namespace PARR.EsppTemplateSync.Services
|
|||||||
public async Task<bool> ManageStringAsync(string str)
|
public async Task<bool> ManageStringAsync(string str)
|
||||||
{
|
{
|
||||||
bool isSuccess = true;
|
bool isSuccess = true;
|
||||||
////TODO: if (str == null || str.Length <= 2)
|
////TODO:
|
||||||
// тут обязательно нужна проверка, если str не того формата, возникает exception в ParseStringAsync
|
// тут обязательно нужна проверка, если str не того формата, возникает exception в ParseStringAsync
|
||||||
var template = await parserService.ParseStringAsync(str);
|
if (str == null || str.Trim().Length == 0)
|
||||||
////TODO: а если template==null???
|
return false;
|
||||||
await CheckChangesAsync(template);
|
|
||||||
|
var template = parserService.ParseString(str);
|
||||||
|
|
||||||
|
if (template == null) {
|
||||||
|
isSuccess = false;
|
||||||
|
logger.LogError($"Не удалось распознать строку({str}) в Template");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//если шаблон не аквтивен, пропускаем
|
||||||
|
if (!template.isActive)
|
||||||
|
{
|
||||||
|
return isSuccess;
|
||||||
|
}
|
||||||
|
await CheckChangesAsync(template);
|
||||||
|
}
|
||||||
|
|
||||||
//todo: only true?????
|
//todo: only true?????
|
||||||
return isSuccess;
|
return isSuccess;
|
||||||
@@ -54,56 +71,54 @@ namespace PARR.EsppTemplateSync.Services
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var resCreate = await templateService.CreateAsync(esppTemplate);
|
var template = await templateService.GetTemplateByNameAsync(esppTemplate.EK);
|
||||||
var resCommit = await templateService.CommitAsync();
|
//существует в ЕСПП но отсутствует в ПАРР.
|
||||||
|
//TODO деактивируем и видимо ещё что-то нужно
|
||||||
|
if (template == null)
|
||||||
|
{
|
||||||
|
esppTemplate.Status="Deactivating";
|
||||||
|
esppTemplate.isActive = false;
|
||||||
|
if (!await templateService.CreateAsync(esppTemplate) || !await templateService.CommitAsync())
|
||||||
|
{
|
||||||
|
logger.LogError($"Не удалось создать запись Template {esppTemplate.EK}({esppTemplate.ShortDescription})");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
logger.LogInformation($"----- Создана запись Template {esppTemplate.EK}({esppTemplate.ShortDescription}) -----");
|
||||||
|
//TODO написать проверку успешности деактивации и удаление строки из таблицы Templates
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var isChanged = false;
|
||||||
|
|
||||||
|
foreach (var prop in template.GetType().GetProperties())
|
||||||
|
{
|
||||||
|
if (prop.Name == "Id" ||
|
||||||
|
prop.Name == "Status" ||
|
||||||
|
prop.Name == "DateCreated" ||
|
||||||
|
prop.Name == "DateModified"
|
||||||
|
) continue;
|
||||||
|
|
||||||
|
if (!template.GetType().GetProperty(prop.Name).GetValue(template,null).Equals(
|
||||||
|
esppTemplate.GetType().GetProperty(prop.Name).GetValue(esppTemplate, null))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
isChanged = true; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isChanged)
|
||||||
|
{
|
||||||
|
logger.LogInformation($"----- Запись в ЕСПП отличается от Template {esppTemplate.EK}({esppTemplate.ShortDescription}) -----");
|
||||||
|
template.Status = "Updating";
|
||||||
|
if(!await templateService.CommitAsync())
|
||||||
|
logger.LogError($"Не удалось обновить запись Template {esppTemplate.EK}({esppTemplate.ShortDescription})");
|
||||||
|
else
|
||||||
|
logger.LogInformation($"----- Требуется обновление шаблона в ЕСПП роботом {esppTemplate.EK}({esppTemplate.ShortDescription}) -----");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// === end test ===
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//if (!await templateService.CreateAsync(esppTemplate) || !await templateService.CommitAsync())
|
|
||||||
//{
|
|
||||||
// logger.LogError($"Не удалось создать запись Template {esppTemplate.EK}({esppTemplate.ShortDescription})");
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
// logger.LogInformation($"----- Создана запись Template {esppTemplate.EK}({esppTemplate.ShortDescription}) -----");
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------
|
|
||||||
|
|
||||||
//using var dataContext = new DataContext(new Microsoft.EntityFrameworkCore.DbContextOptions<DataContext> { });
|
|
||||||
|
|
||||||
////using var dataContext = new DataContext(opt =>
|
|
||||||
//// opt.UseNpgsql("Server=10.99.253.184;Database=parr;User Id=app_parr; Password=PosdfkhT&)%sdfligL&%5546;"));
|
|
||||||
//dataContext.Templates.Add(esppTemplate);
|
|
||||||
//await dataContext.SaveChangesAsync();
|
|
||||||
// -----------------
|
|
||||||
|
|
||||||
|
|
||||||
//using (var scope = serviceProvider.CreateScope())
|
|
||||||
//{
|
|
||||||
// var services = scope.ServiceProvider;
|
|
||||||
// var templateService = services.GetService<ITemplateService>();
|
|
||||||
|
|
||||||
// if (templateService == null)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// var template = await templateService.GetTemplateByNameAsync(esppTemplate.EK);
|
|
||||||
// if (template == null)
|
|
||||||
// {
|
|
||||||
// esppTemplate.Status = "New";
|
|
||||||
// logger.LogInformation($"В ЕСПП активирован неизвестной шаблон: {esppTemplate.EK} секунд. краткое описание: {esppTemplate.ShortDescription}");
|
|
||||||
// if (!await templateService.CreateAsync(esppTemplate) || !await templateService.CommitAsync())
|
|
||||||
// {
|
|
||||||
// logger.LogError($"Не удалось создать запись Template {esppTemplate.EK}({esppTemplate.ShortDescription})");
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// logger.LogInformation($"----- Создана запись Template {esppTemplate.EK}({esppTemplate.ShortDescription}) -----");
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,14 @@ namespace PARR.EsppTemplateSync.Services
|
|||||||
return isSuccess;
|
return isSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Template> ParseStringAsync(string str)
|
public Template? ParseString(string str)
|
||||||
{
|
{
|
||||||
//TODO: а если формат нет тот? Все будет ок?
|
//TODO: а если формат нет тот? Все будет ок?
|
||||||
|
|
||||||
//TODO:
|
//TODO:
|
||||||
var splittedContent = str.Split(";");
|
var splittedContent = str.Split(";");
|
||||||
|
if (splittedContent.Length != 8) return null;
|
||||||
|
|
||||||
var ek = splittedContent[0].Trim().Substring(1, splittedContent[0].Length - 2);
|
var ek = splittedContent[0].Trim().Substring(1, splittedContent[0].Length - 2);
|
||||||
var isActive = splittedContent[1].Trim().Substring(1, splittedContent[1].Length - 2);
|
var isActive = splittedContent[1].Trim().Substring(1, splittedContent[1].Length - 2);
|
||||||
var workGroup = splittedContent[2].Trim().Substring(1, splittedContent[2].Length - 2);
|
var workGroup = splittedContent[2].Trim().Substring(1, splittedContent[2].Length - 2);
|
||||||
@@ -48,8 +50,8 @@ namespace PARR.EsppTemplateSync.Services
|
|||||||
ShortDescription = shortDescription,
|
ShortDescription = shortDescription,
|
||||||
Category = category,
|
Category = category,
|
||||||
//todo: EKDateCreated
|
//todo: EKDateCreated
|
||||||
//EKDateCreated = ConvertDateFromStr(ekDateCreatedStr+ " +03:00"),
|
EKDateCreated = ConvertDateFromStr(ekDateCreatedStr),
|
||||||
EKDateCreated = null,
|
//EKDateCreated = null,
|
||||||
Process = process,
|
Process = process,
|
||||||
SubProcess = subProcess,
|
SubProcess = subProcess,
|
||||||
Status = "Checking"
|
Status = "Checking"
|
||||||
@@ -63,11 +65,11 @@ namespace PARR.EsppTemplateSync.Services
|
|||||||
|
|
||||||
private DateTimeOffset? ConvertDateFromStr(string dateString)
|
private DateTimeOffset? ConvertDateFromStr(string dateString)
|
||||||
{
|
{
|
||||||
var format = "dd/MM/yy HH:mm:ss zzz";
|
var format = "dd/MM/yy HH:mm:ss";
|
||||||
var provider = CultureInfo.CurrentCulture;
|
var provider = CultureInfo.CurrentCulture;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = DateTimeOffset.ParseExact(dateString, format, provider);
|
var result = DateTimeOffset.ParseExact(dateString, format, provider).ToOffset(new TimeSpan(0));
|
||||||
logger.LogInformation($"{dateString} было преобразовано в {result.ToString()}.");
|
logger.LogInformation($"{dateString} было преобразовано в {result.ToString()}.");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace PARR.EsppTemplateSync
|
|||||||
|
|
||||||
logger.LogInformation($"Запущена проверка очереди {globalSettings.MqSettings!.QueueName}.");
|
logger.LogInformation($"Запущена проверка очереди {globalSettings.MqSettings!.QueueName}.");
|
||||||
|
|
||||||
GetMessages();
|
GetMessages();//TODO переименовать в какой-нибудь AttachListener
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ namespace PARR.EsppTemplateSyncWorker
|
|||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
templateSyncer.Start();
|
templateSyncer?.Start();
|
||||||
|
//TODO <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>. <20><> <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task StopAsync(CancellationToken cancellationToken)
|
public override Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user