feat(dal,api): IMatchingStatusService - управление статусами matcher`a. Отображение статусов в АПИ, нельзя повторно из апи отправить задание мэтчеру если сейчас идет matching

This commit is contained in:
Mikhail Trubnikov
2026-01-16 11:04:26 +10:00
parent 3205c1db8e
commit 99a491ede8
14 changed files with 303 additions and 91 deletions

View File

@@ -16,6 +16,7 @@ using PARR.BLL.Domain.Mq;
using PARR.BLL.Services.Interfaces;
using PARR.Common.Domain;
using PARR.Constants;
using PARR.DAL.Cache.Services;
using PARR.DAL.Contracts;
using PARR.DAL.DomainModels;
using PARR.DAL.DomainServices.Interfaces;
@@ -24,7 +25,6 @@ using PARR.DAL.Models.Job;
using PARR.DAL.Services.Interfaces;
using PARR.DAL.Services.Interfaces.Job;
using PARR.DAL.Services.Interfaces.Unit;
using System.Net;
using System.Text.Json;
namespace PARR.API.Controllers.V1
@@ -45,6 +45,7 @@ namespace PARR.API.Controllers.V1
private readonly MqSettings mqSettings;
private readonly IClientService clientService;
private readonly IJobAutoControlService jobAutoControlService;
private readonly IMatchingStatusService matchingStatusService;
public JobController(
ILogger<JobController> logger,
@@ -59,7 +60,8 @@ namespace PARR.API.Controllers.V1
IMqService mqService,
MqSettings mqSettings,
IClientService clientService,
IJobAutoControlService jobAutoControlService
IJobAutoControlService jobAutoControlService,
IMatchingStatusService matchingStatusService
)
{
this.logger = logger;
@@ -72,6 +74,7 @@ namespace PARR.API.Controllers.V1
this.mqSettings = mqSettings;
this.clientService = clientService;
this.jobAutoControlService = jobAutoControlService;
this.matchingStatusService = matchingStatusService;
}
/// <summary>
@@ -124,6 +127,11 @@ namespace PARR.API.Controllers.V1
{
//jobResponse.TemplatesCount = await templateService.Get().CountAsync(t => t.JobId == jobResponse.Id);
jobResponse.TemplatesCount = await GetCountTemplatesAsync(jobResponse.Id);
if (filter.IsFull)
{
jobResponse.MatchingStatus = await GetMatchingStatusAsync(jobResponse.Id);
}
}
var paginationResponse = new PagedResponse<JobResponse>(response, true).GetPaginatedProps(paginationFilter, query);
@@ -159,6 +167,7 @@ namespace PARR.API.Controllers.V1
var response = mapper.Map<JobResponse>(job);
response.TemplatesCount = await GetCountTemplatesAsync(id); //await templateService.Get().CountAsync(t => t.JobId == id);
response.MatchingStatus = await GetMatchingStatusAsync(id);
//var statistics = await GetStatisticsAsync(response.Id);
//BindStatistics(response, statistics);
@@ -234,6 +243,7 @@ namespace PARR.API.Controllers.V1
var response = mapper.Map<JobResponse>(createdJob);
// так как мы только что создали Job, то у него нет шаблонов, смело ставим = 0 (ускоряем запрос)
response.TemplatesCount = 0;
response.MatchingStatus = await GetMatchingStatusAsync(response.Id);
return Created(locationUri, new Response<JobResponse>(response, true));
}
@@ -355,6 +365,7 @@ namespace PARR.API.Controllers.V1
var response = mapper.Map<JobResponse>(updatedJob);
response.TemplatesCount = await GetCountTemplatesAsync(id); //await templateService.Get().CountAsync(t => t.JobId == id);
response.MatchingStatus = await GetMatchingStatusAsync(id);
//не используется
//var statistics = await GetStatisticsAsync(response.Id);
@@ -657,6 +668,18 @@ namespace PARR.API.Controllers.V1
return await templateService.Get().CountAsync(t => t.JobId == jobId && t.StatusTypeId == TemplateStatusTypeEnum.Used);
}
/// <summary>
/// Получить статус matching`a
/// </summary>
/// <param name="jobId"></param>
/// <returns></returns>
private async Task<MatchingStatusResponse?> GetMatchingStatusAsync(Guid jobId)
{
var statusMatching = await matchingStatusService.GetStatusAsync(jobId, SyncTaskEntityTypeEnum.Job);
return mapper.Map<MatchingStatusResponse>(statusMatching);
}
}

View File

@@ -14,6 +14,7 @@ using PARR.API.Services.Interfaces;
using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.DomainModels;
using PARR.DAL.DomainServices.Interfaces;
using PARR.DAL.Models;
using PARR.DAL.Models.Job;
using PARR.DAL.Services.Interfaces;
@@ -36,6 +37,7 @@ namespace PARR.API.Controllers.V1
private readonly IValidator<JobGroupRequest> validator;
private readonly IJobGroupTypeService jobGroupTypeService;
private readonly SettingsFromDb settingsFromDb;
private readonly IMatchingStatusService matchingStatusService;
public JobGroupController(
ILogger<JobController> logger,
@@ -46,7 +48,8 @@ namespace PARR.API.Controllers.V1
IEsppSchTypeConfigService esppConfigService,
IValidator<JobGroupRequest> validator,
IJobGroupTypeService jobGroupTypeService,
SettingsFromDb settingsFromDb
SettingsFromDb settingsFromDb,
IMatchingStatusService matchingStatusService
)
{
this.logger = logger;
@@ -58,6 +61,7 @@ namespace PARR.API.Controllers.V1
this.validator = validator;
this.jobGroupTypeService = jobGroupTypeService;
this.settingsFromDb = settingsFromDb;
this.matchingStatusService = matchingStatusService;
}
@@ -366,7 +370,7 @@ namespace PARR.API.Controllers.V1
/// <summary>
/// Заполнить поля планировщика
/// Заполнить обязательные поля
/// </summary>
/// <param name="jobGroupResponse"></param>
/// <returns></returns>
@@ -390,6 +394,8 @@ namespace PARR.API.Controllers.V1
jobGroupResponse.Schedule = scheduleResponse;
jobGroupResponse.JobsCount = await jobService.Get().CountAsync(t => t.GroupId == jobGroupResponse.Id);
jobGroupResponse.MatchingStatus = await GetMatchingStatusAsync(jobGroupResponse.Id);
}
@@ -419,5 +425,18 @@ namespace PARR.API.Controllers.V1
return null;
}
}
/// <summary>
/// Получить статус matching`a
/// </summary>
/// <param name="jobGroupId"></param>
/// <returns></returns>
private async Task<MatchingStatusResponse?> GetMatchingStatusAsync(Guid jobGroupId)
{
var statusMatching = await matchingStatusService.GetStatusAsync(jobGroupId, SyncTaskEntityTypeEnum.JobGroup);
return mapper.Map<MatchingStatusResponse>(statusMatching);
}
}
}

View File

@@ -9,6 +9,8 @@ using PARR.BLL.Domain.Mq;
using PARR.BLL.Services.Interfaces;
using PARR.Common.Domain;
using PARR.Constants;
using PARR.DAL.Cache.Services;
using PARR.DAL.DomainServices.Interfaces;
using System.Text.Json;
namespace PARR.API.Controllers.V1
@@ -20,13 +22,15 @@ namespace PARR.API.Controllers.V1
private readonly IUriService uriService;
private readonly MqSettings mqSettings;
private readonly IClientService clientService;
private readonly IMatchingStatusService matchingStatusService;
public SyncTaskController(
ILogger<SyncTaskController> logger,
IMqService mqService,
IUriService uriService,
MqSettings mqSettings,
IClientService clientService
IClientService clientService,
IMatchingStatusService matchingStatusService
)
{
this.logger = logger;
@@ -34,6 +38,7 @@ namespace PARR.API.Controllers.V1
this.uriService = uriService;
this.mqSettings = mqSettings;
this.clientService = clientService;
this.matchingStatusService = matchingStatusService;
}
/// <summary>
@@ -45,6 +50,14 @@ namespace PARR.API.Controllers.V1
//todo: Валидатор! Валидатор то забыли!!!
// проверяем, если уже идет синхронизация по этому объекту, то ахтунг, ошибка
var matchingStatus = await matchingStatusService.GetStatusAsync(request.ObjectId, request.EntityType);
if (matchingStatus.IsMatchingObject)
{
logger.LogWarning("Прекращена попытка повторного формирования задания для matcher. objectId: {objectId}, entityType: {entityType}, action: {action}", request.ObjectId, request.EntityType, request.Action);
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Уже выполняется задание синхронизации этого объекта" } }));
}
//24b3529a-dd43-444a-b10e-ac54fefd046a
var matchTemplateTask = new TemplateMatcherMq
{