feat(api): applicationInWorks - статистика синхронизации шаблонов/расписаний
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
namespace PARR.API.Contracts.V1.Responses
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace PARR.API.Contracts.V1.Responses
|
||||||
{
|
{
|
||||||
public class ApplicationInWorkResponse
|
public class ApplicationInWorkResponse
|
||||||
{
|
{
|
||||||
@@ -34,6 +36,16 @@
|
|||||||
|
|
||||||
public int TemplatesCount { get; set; }
|
public int TemplatesCount { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
#region Статистика
|
||||||
|
|
||||||
|
public TemplateStats? TemplateStatistics { get; set; }
|
||||||
|
|
||||||
|
public ScheduleStats? ScheduleStatistics { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
public ApplicationInWorkScheduleResponse? Schedule { get; set; }
|
public ApplicationInWorkScheduleResponse? Schedule { get; set; }
|
||||||
|
|
||||||
public List<WorkGroupResponse>? WorkGroups { get; set; }
|
public List<WorkGroupResponse>? WorkGroups { get; set; }
|
||||||
@@ -49,4 +61,42 @@
|
|||||||
public List<EsppScheduleValResponse>? Values { get; set; }
|
public List<EsppScheduleValResponse>? Values { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class TemplateStats
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Активированных шаблонов
|
||||||
|
/// </summary>
|
||||||
|
public int Activated { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Синхронизировано шаблонов (TaskStatus = 30/Ok)
|
||||||
|
/// </summary>
|
||||||
|
public int Synchronized { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ошибок синхронизации (RobotStatus = 33/Error)
|
||||||
|
/// </summary>
|
||||||
|
public int Errors { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class ScheduleStats
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Активированных шаблонов
|
||||||
|
/// </summary>
|
||||||
|
public int Activated { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Синхронизировано шаблонов (TaskStatus = 30/Ok)
|
||||||
|
/// </summary>
|
||||||
|
public int Synchronized { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ошибок синхронизации (RobotStatus = 33/Error)
|
||||||
|
/// </summary>
|
||||||
|
public int Errors { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,12 @@ using PARR.API.Settings;
|
|||||||
using PARR.BLL.Domain.Mq;
|
using PARR.BLL.Domain.Mq;
|
||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
using PARR.Constants;
|
using PARR.Constants;
|
||||||
|
using PARR.DAL.Contracts;
|
||||||
using PARR.DAL.DomainModels;
|
using PARR.DAL.DomainModels;
|
||||||
using PARR.DAL.Models;
|
using PARR.DAL.Models;
|
||||||
using PARR.DAL.Services.Interfaces;
|
using PARR.DAL.Services.Interfaces;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using static PARR.API.Contracts.V1.ApiRoutes;
|
||||||
|
|
||||||
namespace PARR.API.Controllers.V1
|
namespace PARR.API.Controllers.V1
|
||||||
{
|
{
|
||||||
@@ -92,10 +94,13 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
if (filter.IsLight != true)
|
if (filter.IsLight != true)
|
||||||
{
|
{
|
||||||
//Если запрос не легкий, закгружаем кол-во шаблонов отдельно, это значительно ускоряет запрос
|
//Если запрос не легкий, загружаем кол-во шаблонов отдельно, это значительно ускоряет запрос
|
||||||
foreach (var item in response)
|
foreach (var item in response)
|
||||||
{
|
{
|
||||||
item.TemplatesCount = await templateService.Get().CountAsync(t => t.ApplicationInWorkId == item.Id);
|
item.TemplatesCount = await templateService.Get().CountAsync(t => t.ApplicationInWorkId == item.Id);
|
||||||
|
|
||||||
|
var statistics = await GetStatisticsAsync(item.Id);
|
||||||
|
BindStatistics(item, statistics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,6 +131,9 @@ namespace PARR.API.Controllers.V1
|
|||||||
var response = mapper.Map<ApplicationInWorkResponse>(applicationInWork);
|
var response = mapper.Map<ApplicationInWorkResponse>(applicationInWork);
|
||||||
response.TemplatesCount = await templateService.Get().CountAsync(t => t.ApplicationInWorkId == id);
|
response.TemplatesCount = await templateService.Get().CountAsync(t => t.ApplicationInWorkId == id);
|
||||||
|
|
||||||
|
var statistics = await GetStatisticsAsync(response.Id);
|
||||||
|
BindStatistics(response, statistics);
|
||||||
|
|
||||||
return Ok(new Response<ApplicationInWorkResponse>(response, true));
|
return Ok(new Response<ApplicationInWorkResponse>(response, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,6 +325,9 @@ namespace PARR.API.Controllers.V1
|
|||||||
var response = mapper.Map<ApplicationInWorkResponse>(updatedApplicationInWork);
|
var response = mapper.Map<ApplicationInWorkResponse>(updatedApplicationInWork);
|
||||||
response.TemplatesCount = await templateService.Get().CountAsync(t => t.ApplicationInWorkId == id);
|
response.TemplatesCount = await templateService.Get().CountAsync(t => t.ApplicationInWorkId == id);
|
||||||
|
|
||||||
|
var statistics = await GetStatisticsAsync(response.Id);
|
||||||
|
BindStatistics(response, statistics);
|
||||||
|
|
||||||
return Ok(new Response<ApplicationInWorkResponse>(response, true));
|
return Ok(new Response<ApplicationInWorkResponse>(response, true));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -392,5 +403,48 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
return isScheduleChanged;
|
return isScheduleChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Загрузка статистики
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="applicationInWorkId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<AppInWorkStatModel> GetStatisticsAsync(Guid applicationInWorkId)
|
||||||
|
{
|
||||||
|
var statResult = await applicationsInWorkService.Get()
|
||||||
|
.Include(t => t.Templates).ThenInclude(t => t.RobotConfigurations)
|
||||||
|
.Where(x => x.Id == applicationInWorkId)
|
||||||
|
.Select(t => new
|
||||||
|
{
|
||||||
|
TemplateActivated = t.Templates.Count(x => x.IsActiveTemplate),
|
||||||
|
TemplateSynchronized = t.Templates.Count(x => x.RobotConfigurations.Any(c => c.TaskStatusCode == (int)TaskStatusEnum.Ok && c.RobotCode == (int)RobotsEnum.TemplateOrder)),
|
||||||
|
TemplateErrors = t.Templates.Count(x => x.RobotConfigurations.Any(c => c.RobotStatusCode == (int)RobotStatusEnum.Error && c.RobotCode == (int)RobotsEnum.TemplateOrder)),
|
||||||
|
ScheduleActivated = t.Templates.Count(x => x.IsActiveSchedule),
|
||||||
|
ScheduleSynchronized = t.Templates.Count(x => x.RobotConfigurations.Any(c => c.TaskStatusCode == (int)TaskStatusEnum.Ok && c.RobotCode == (int)RobotsEnum.ScheduleOrder)),
|
||||||
|
ScheduleErrors = t.Templates.Count(x => x.RobotConfigurations.Any(c => c.RobotStatusCode == (int)RobotStatusEnum.Error && c.RobotCode == (int)RobotsEnum.ScheduleOrder))
|
||||||
|
|
||||||
|
}).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
return new AppInWorkStatModel
|
||||||
|
{
|
||||||
|
ScheduleStatistics = new ScheduleStats { Activated = statResult?.ScheduleActivated ?? 0, Errors = statResult?.ScheduleErrors ?? 0, Synchronized = statResult?.ScheduleSynchronized ?? 0 },
|
||||||
|
TemplateStatistics = new TemplateStats { Activated = statResult?.TemplateActivated ?? 0, Errors = statResult?.TemplateErrors ?? 0, Synchronized = statResult?.TemplateSynchronized ?? 0 }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void BindStatistics(ApplicationInWorkResponse applicationsInWork, AppInWorkStatModel statistics)
|
||||||
|
{
|
||||||
|
applicationsInWork.TemplateStatistics = new TemplateStats { Activated = statistics.TemplateStatistics.Activated, Errors = statistics.TemplateStatistics.Errors, Synchronized = statistics.TemplateStatistics.Synchronized };
|
||||||
|
applicationsInWork.ScheduleStatistics = new ScheduleStats { Activated = statistics.ScheduleStatistics.Activated, Errors = statistics.ScheduleStatistics.Errors, Synchronized = statistics.ScheduleStatistics.Synchronized };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AppInWorkStatModel
|
||||||
|
{
|
||||||
|
public TemplateStats TemplateStatistics { get; set; }
|
||||||
|
|
||||||
|
public ScheduleStats ScheduleStatistics { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ internal class TemplateActivator : ITemplateActivator
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновить состояние расписаний по запросу query на newState, без записи в БД. Возвращает количество расписаний требующих фиксацию в БД
|
/// Обновить состояние шаблонов по запросу query на newState, без записи в БД. Возвращает количество расписаний требующих фиксацию в БД
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="query"></param>
|
/// <param name="query"></param>
|
||||||
/// <param name="newState"></param>
|
/// <param name="newState"></param>
|
||||||
|
|||||||
Reference in New Issue
Block a user