feat(EsppSync): доработка логики

This commit is contained in:
Mikhail Trubnikov
2023-11-22 12:04:33 +10:00
parent fffdb134c6
commit ede7075eb5
14 changed files with 43 additions and 14 deletions

View File

@@ -1,4 +1,5 @@
using PARR.DAL.Contracts;
using PARR.Constants;
using PARR.DAL.Contracts;
namespace PARR.API.Contracts.V1.Requests.Queries
{

View File

@@ -5,6 +5,7 @@ using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Responses;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces;

View File

@@ -9,6 +9,7 @@ using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using PARR.API.Extensions;
using PARR.BLL.Helpers;
using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.DomainModels;
using PARR.DAL.Models;

View File

@@ -1,4 +1,4 @@
namespace PARR.DAL.Contracts
namespace PARR.Constants
{
/// <summary>
/// Список роботов

View File

@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.Constants;
using PARR.DAL.Context;
using PARR.DAL.Contracts;
using PARR.DAL.Models;

View File

@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.Constants;
using PARR.DAL.Context;
using PARR.DAL.Contracts;
using PARR.DAL.Models;

View File

@@ -1,4 +1,5 @@
using PARR.DAL.Contracts;
using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces.Base;

View File

@@ -0,0 +1,16 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.DAL;
namespace PARR.EsppSync
{
public static class EsppSyncInstaller
{
public static void InstallEsppSyncServices<EsppObject>(this IServiceCollection services, IConfiguration configuration) where EsppObject : class, IEsppObject
{
services.InstallDalServices(configuration);
services.AddTransient<ISyncService<EsppObject>, SyncService<EsppObject>>();
}
}
}

View File

@@ -1,7 +1,11 @@
namespace PARR.EsppSync
using PARR.Constants;
namespace PARR.EsppSync
{
public interface IEsppObject
{
public string TemplateName { get; set; }
public RobotsEnum Robot { get; set; }
}
}

View File

@@ -1,4 +1,4 @@
using PARR.DAL.Contracts;
using PARR.Constants;
using PARR.DAL.Models;
namespace PARR.EsppSync
@@ -21,6 +21,6 @@ namespace PARR.EsppSync
public interface ISyncService<EsppObject> where EsppObject : class, IEsppObject
{
Task SyncEsppObjectAsync(string str, ParserHandlerDelegate<EsppObject> parser, ConvertDbObjToComparisonObjHandlerDelegate<EsppObject> converterToEsppObject, RobotsEnum robot);
Task SyncEsppObjectAsync(string str, ParserHandlerDelegate<EsppObject> parser, ConvertDbObjToComparisonObjHandlerDelegate<EsppObject> converterToEsppObject);
}
}

View File

@@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces;
@@ -24,8 +25,7 @@ namespace PARR.EsppSync
public async Task SyncEsppObjectAsync(
string str,
ParserHandlerDelegate<EsppObject> parser,
ConvertDbObjToComparisonObjHandlerDelegate<EsppObject> converterToEsppObject,
RobotsEnum robot
ConvertDbObjToComparisonObjHandlerDelegate<EsppObject> converterToEsppObject
)
{
logger.LogDebug($"Получил строку. Начинаю работать. Строка: {str}");
@@ -65,25 +65,25 @@ namespace PARR.EsppSync
if (isChanged)
{
SetUpdateStatus(ref template, robotConfigurationService, robot);
SetUpdateStatus(ref template, robotConfigurationService, esppObject.Robot);
if (!await templateService.CommitAsync())
logger.LogError($"Не удалось изменить запись Template {template.Name}, Robot: {robot}");
logger.LogError($"Не удалось изменить запись Template {template.Name}, Robot: {esppObject.Robot}");
else
logger.LogInformation($"Установлен принудительный статус {TaskStatusEnum.Updating}, Template {template.Name}, Robot: {robot}");
logger.LogInformation($"Установлен принудительный статус {TaskStatusEnum.Updating}, Template {template.Name}, Robot: {esppObject.Robot}");
}//надо ли проверять если не изменился, но был статус Updating не понятно. Доверяем роботу пока, что после окончания работ он точно сообщит
else
{
//если все поля совпали
//проверяем, какой был статус предыдущий статус в БД, если он был не Ок, то ставим ему ОК
var robotConfig = robotConfigurationService.GetFromTemplateByRobotCode(robot, ref template);
var robotConfig = robotConfigurationService.GetFromTemplateByRobotCode(esppObject.Robot, ref template);
if (robotConfig.TaskStatusCode != (int)TaskStatusEnum.Ok)
{
robotConfigurationService.ChangeTaskStatus(TaskStatusEnum.Ok, ref robotConfig);
if (!await templateService.CommitAsync())
logger.LogError($"Не удалось изменить запись Template {template.Name}, Robot: {robot}");
logger.LogError($"Не удалось изменить запись Template {template.Name}, Robot: {esppObject.Robot}");
else
logger.LogInformation($"Установлен принудительный статус {TaskStatusEnum.Ok}, Template {template.Name}, Robot: {robot}");
logger.LogInformation($"Установлен принудительный статус {TaskStatusEnum.Ok}, Template {template.Name}, Robot: {esppObject.Robot}");
}
}
}

View File

@@ -14,6 +14,7 @@
<ItemGroup>
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
<ProjectReference Include="..\PARR.EsppSync\PARR.EsppSync.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,7 @@
using AutoMapper;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces;

View File

@@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using PARR.BLL.Domain.Mq;
using PARR.BLL.Helpers;
using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces;