feat(api, dal): поиск групп работ, работ, теперь по маске. Статистика по шаблонам по StatusType. Добавлены индексы в Template, RobotConfiguration
This commit is contained in:
@@ -235,6 +235,11 @@
|
|||||||
public const string GetForPeriod = BaseStat + "/templates/period";
|
public const string GetForPeriod = BaseStat + "/templates/period";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class StatStatusTypeTemplates
|
||||||
|
{
|
||||||
|
public const string Get = BaseStat + "/status-type-templates/";
|
||||||
|
}
|
||||||
|
|
||||||
public static class StatTemplateAutoControl
|
public static class StatTemplateAutoControl
|
||||||
{
|
{
|
||||||
public const string GetForPeriod = BaseStat + "/template-auto-controls/";
|
public const string GetForPeriod = BaseStat + "/template-auto-controls/";
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace PARR.API.Contracts.V1.Requests.Queries
|
|||||||
public class JobGroupQuery: FullQuery
|
public class JobGroupQuery: FullQuery
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поиск по имени
|
/// Поиск по имени. Например: "ДВС-*"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace PARR.API.Contracts.V1.Requests.Queries
|
|||||||
public class JobQuery : FullQuery
|
public class JobQuery : FullQuery
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поиск по имени
|
/// Поиск по имени. Например: "ДВС-*"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace PARR.API.Contracts.V1.Responses.Statistics
|
||||||
|
{
|
||||||
|
public class StatStatusTypeTemplatesResponse
|
||||||
|
{
|
||||||
|
public required TemplateStatusTypeResponse StatusType { get; set; }
|
||||||
|
|
||||||
|
public int TemplateCount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ using PARR.API.Extensions;
|
|||||||
using PARR.API.Services.Interfaces;
|
using PARR.API.Services.Interfaces;
|
||||||
using PARR.API.Settings;
|
using PARR.API.Settings;
|
||||||
using PARR.BLL.Domain.Mq;
|
using PARR.BLL.Domain.Mq;
|
||||||
|
using PARR.BLL.Helpers;
|
||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
using PARR.Common.Domain;
|
using PARR.Common.Domain;
|
||||||
using PARR.Constants;
|
using PARR.Constants;
|
||||||
@@ -92,7 +93,11 @@ namespace PARR.API.Controllers.V1
|
|||||||
query = query.OrderBy(t => t.Name);
|
query = query.OrderBy(t => t.Name);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(filter.Name))
|
if (!string.IsNullOrEmpty(filter.Name))
|
||||||
query = query.Where(t => t.Name.ToLower().Contains(filter.Name.ToLower()));
|
{
|
||||||
|
//query = query.Where(t => t.Name.ToLower().Contains(filter.Name.ToLower()));
|
||||||
|
query = query.Where(t=>EF.Functions.Like(t.Name.ToLower(), SqlHelpers.RegexToLike(filter.Name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (filter.GroupId.HasValue)
|
if (filter.GroupId.HasValue)
|
||||||
query = query.Where(t => t.GroupId == filter.GroupId.Value);
|
query = query.Where(t => t.GroupId == filter.GroupId.Value);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using PARR.API.Contracts.V1.Responses.Base;
|
|||||||
using PARR.API.Controllers.V1.Base;
|
using PARR.API.Controllers.V1.Base;
|
||||||
using PARR.API.Extensions;
|
using PARR.API.Extensions;
|
||||||
using PARR.API.Services.Interfaces;
|
using PARR.API.Services.Interfaces;
|
||||||
|
using PARR.BLL.Helpers;
|
||||||
using PARR.Constants;
|
using PARR.Constants;
|
||||||
using PARR.DAL.Contracts;
|
using PARR.DAL.Contracts;
|
||||||
using PARR.DAL.DomainModels;
|
using PARR.DAL.DomainModels;
|
||||||
@@ -83,7 +84,10 @@ namespace PARR.API.Controllers.V1
|
|||||||
query = query.OrderBy(t => t.GroupName);
|
query = query.OrderBy(t => t.GroupName);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(filter.Name))
|
if (!string.IsNullOrEmpty(filter.Name))
|
||||||
query = query.Where(t => t.GroupName.ToLower().Contains(filter.Name.ToLower()));
|
{
|
||||||
|
//query = query.Where(t => t.GroupName.ToLower().Contains(filter.Name.ToLower()));
|
||||||
|
query = query.Where(t => EF.Functions.Like(t.GroupName.ToLower(), SqlHelpers.RegexToLike(filter.Name)));
|
||||||
|
}
|
||||||
|
|
||||||
if (filter.IsFull)
|
if (filter.IsFull)
|
||||||
query = query
|
query = query
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PARR.API.Contracts.V1;
|
||||||
|
using PARR.API.Contracts.V1.Responses;
|
||||||
|
using PARR.API.Contracts.V1.Responses.Base;
|
||||||
|
using PARR.API.Contracts.V1.Responses.Statistics;
|
||||||
|
using PARR.API.Controllers.V1.Base;
|
||||||
|
using PARR.Constants;
|
||||||
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace PARR.API.Controllers.V1.Statistics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Статистика шаблонов по типам статусов ПАРР
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||||
|
public class StatStatusTypeTemplates : BaseApiController
|
||||||
|
{
|
||||||
|
private readonly ITemplateService templateService;
|
||||||
|
private readonly ITemplateStatusTypeService templateStatusTypeService;
|
||||||
|
private readonly IMapper mapper;
|
||||||
|
|
||||||
|
public StatStatusTypeTemplates(
|
||||||
|
ITemplateService templateService,
|
||||||
|
ITemplateStatusTypeService templateStatusTypeService,
|
||||||
|
IMapper mapper
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.templateService = templateService;
|
||||||
|
this.templateStatusTypeService = templateStatusTypeService;
|
||||||
|
this.mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Статистика шаблонов по StatusType
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet(ApiRoutes.StatStatusTypeTemplates.Get)]
|
||||||
|
public async Task<IActionResult> Get()
|
||||||
|
{
|
||||||
|
var templateStatistics = await templateService.Get()
|
||||||
|
.AsNoTracking()
|
||||||
|
.GroupBy(t => t.StatusTypeId)
|
||||||
|
.Select(t => new
|
||||||
|
{
|
||||||
|
StatusTypeId = t.Key,
|
||||||
|
TempaltesCount = t.Count()
|
||||||
|
})
|
||||||
|
.ToDictionaryAsync(t => t.StatusTypeId, t => t.TempaltesCount);
|
||||||
|
|
||||||
|
var statusTypes = await templateStatusTypeService.Get()
|
||||||
|
.AsNoTracking()
|
||||||
|
.OrderBy(t => t.Id)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var response = statusTypes.Select(t => new StatStatusTypeTemplatesResponse
|
||||||
|
{
|
||||||
|
StatusType = mapper.Map<TemplateStatusTypeResponse>(t),
|
||||||
|
TemplateCount = templateStatistics.TryGetValue(t.Id, out int count) ? count : 0
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
return Ok(new Response<List<StatStatusTypeTemplatesResponse>>(response, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
|
|
||||||
using PARR.API.Contracts.V1;
|
using PARR.API.Contracts.V1;
|
||||||
using PARR.API.Contracts.V1.Requests.BaseRequests;
|
using PARR.API.Contracts.V1.Requests.BaseRequests;
|
||||||
using PARR.API.Contracts.V1.Responses.Base;
|
using PARR.API.Contracts.V1.Responses.Base;
|
||||||
|
|||||||
4141
PARR.DAL/Migrations/20260201232301_tblTemplatesAndRobotConfigurationsAddINdexes.Designer.cs
generated
Normal file
4141
PARR.DAL/Migrations/20260201232301_tblTemplatesAndRobotConfigurationsAddINdexes.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PARR.DAL.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class tblTemplatesAndRobotConfigurationsAddINdexes : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_RobotConfigurations_TemplateId_RobotStatusCode",
|
||||||
|
table: "RobotConfigurations",
|
||||||
|
columns: new[] { "TemplateId", "RobotStatusCode" });
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_RobotConfigurations_TemplateId_TaskStatusCode",
|
||||||
|
table: "RobotConfigurations",
|
||||||
|
columns: new[] { "TemplateId", "TaskStatusCode" });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_RobotConfigurations_TemplateId_RobotStatusCode",
|
||||||
|
table: "RobotConfigurations");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_RobotConfigurations_TemplateId_TaskStatusCode",
|
||||||
|
table: "RobotConfigurations");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2284,6 +2284,10 @@ namespace PARR.DAL.Migrations
|
|||||||
b.HasIndex("TemplateId", "RobotCode")
|
b.HasIndex("TemplateId", "RobotCode")
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("TemplateId", "RobotStatusCode");
|
||||||
|
|
||||||
|
b.HasIndex("TemplateId", "TaskStatusCode");
|
||||||
|
|
||||||
b.ToTable("RobotConfigurations");
|
b.ToTable("RobotConfigurations");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ namespace PARR.DAL.Models
|
|||||||
{
|
{
|
||||||
[Table("RobotConfigurations")]
|
[Table("RobotConfigurations")]
|
||||||
[Index(nameof(TemplateId), nameof(RobotCode), IsUnique = true)]
|
[Index(nameof(TemplateId), nameof(RobotCode), IsUnique = true)]
|
||||||
|
[Index(nameof(TemplateId), nameof(TaskStatusCode))]
|
||||||
|
[Index(nameof(TemplateId), nameof(RobotStatusCode))]
|
||||||
public class RobotConfiguration : IBase
|
public class RobotConfiguration : IBase
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
|||||||
Reference in New Issue
Block a user