feat(dal,api): добавлен индекс в таблицу UnitInValues. В api изменены респонсы Template и Unit.

This commit is contained in:
Mikhail Trubnikov
2025-11-21 10:56:30 +10:00
parent 240d292cee
commit ddbae48973
11 changed files with 4063 additions and 23 deletions

View File

@@ -13,7 +13,7 @@
public int? MaxValueRelationships { get; set; }
public bool? isParentRelationships { get; set; }
public bool? IsParentRelationships { get; set; }
public required string TemplateNameMask { get; set; }

View File

@@ -32,7 +32,8 @@
public bool IsAutoDistributionEnabled { get; set; }
public UnitResponse? Unit { get; set; }
//public UnitResponse? Unit { get; set; }
public UnitWithAttributesResponse? Unit { get; set; }
public JobResponse? Job { get; set; }

View File

@@ -16,7 +16,7 @@
/// <summary>
/// Response с всеми аттребутами и их значениями
/// Response со всеми аттребутами и их значениями
/// </summary>
public class UnitWithAttributesResponse : UnitResponse
{
@@ -24,6 +24,13 @@
public List<AttributeResponse>? Attributes { get; set; }
//public List<UnitResponse>? Parents { get; set; }
//public List<UnitResponse>? Childrens { get; set; }
}
public class UnitRelationshipsAndAttributesResponse : UnitWithAttributesResponse
{
public List<UnitResponse>? Parents { get; set; }
public List<UnitResponse>? Childrens { get; set; }

View File

@@ -249,9 +249,9 @@ namespace PARR.API.Controllers.V1
changed = true;
}
if (orig.IsParentRelationships != request.isParentRelationships)
if (orig.IsParentRelationships != request.IsParentRelationships)
{
orig.IsParentRelationships = request.isParentRelationships;
orig.IsParentRelationships = request.IsParentRelationships;
changed = true;
}

View File

@@ -62,8 +62,11 @@ namespace PARR.API.Controllers.V1
if (!units.Any())
return NoContent();
var unitResponse = mapper.Map<List<UnitWithAttributesResponse>>(units);
var paginationResponse = new PagedResponse<UnitWithAttributesResponse>(unitResponse, true).GetPaginatedProps(paginationFilter, query);
//var unitResponse = mapper.Map<List<UnitWithAttributesResponse>>(units);
//var paginationResponse = new PagedResponse<UnitWithAttributesResponse>(unitResponse, true).GetPaginatedProps(paginationFilter, query);
var unitResponse = mapper.Map<List<UnitRelationshipsAndAttributesResponse>>(units);
var paginationResponse = new PagedResponse<UnitRelationshipsAndAttributesResponse>(unitResponse, true).GetPaginatedProps(paginationFilter, query);
return Ok(paginationResponse);
}
@@ -89,9 +92,13 @@ namespace PARR.API.Controllers.V1
if (unit == null)
return NotFound();
var response = mapper.Map<UnitWithAttributesResponse>(unit);
//var response = mapper.Map<UnitWithAttributesResponse>(unit);
return Ok(new Response<UnitWithAttributesResponse>(response, true));
//return Ok(new Response<UnitWithAttributesResponse>(response, true));
var response = mapper.Map<UnitRelationshipsAndAttributesResponse>(unit);
return Ok(new Response<UnitRelationshipsAndAttributesResponse>(response, true));
}

View File

@@ -114,25 +114,41 @@ namespace PARR.API.MappingProfiles
CreateMap<Unit, UnitResponse>()
.Include<Unit, UnitWithAttributesResponse>()
.Include<Unit, UnitRelationshipsAndAttributesResponse>()
.ForMember(d => d.Name, o => o.MapFrom(s => s.Name));
CreateMap<Unit, UnitWithAttributesResponse>()
.ForMember(d => d.Childrens, o => o.MapFrom(s => s.ChildUnits.Select(t => t.ChildUnit).OrderBy(t => t.Name)))
.ForMember(d => d.Parents, o => o.MapFrom(s => s.ParentUnits.Select(t => t.ParentUnit).OrderBy(t => t.Name)))
.Include<Unit, UnitRelationshipsAndAttributesResponse>()
.ForMember(d => d.Attributes, o => o.MapFrom(s => s.UnitValues.GroupBy(g => g.Field)
.Select(fieldGroup => new AttributeResponse
.Select(fieldGroup => new AttributeResponse
{
Field = new FieldResponse
{
Field = new FieldResponse
{
Id = fieldGroup.Key!.Id,
Name = string.IsNullOrEmpty(fieldGroup.Key.DisplayName) ? fieldGroup.Key.AihitName : fieldGroup.Key.DisplayName,
IsMultipleValue = fieldGroup.Key.IsMultipleValue
},
Values = fieldGroup.Select(s => new UnitFieldValueResponse { Id = s.ValueId, Value = s.Value!.Value }).ToList()
}
Id = fieldGroup.Key!.Id,
Name = string.IsNullOrEmpty(fieldGroup.Key.DisplayName) ? fieldGroup.Key.AihitName : fieldGroup.Key.DisplayName,
IsMultipleValue = fieldGroup.Key.IsMultipleValue
},
Values = fieldGroup.Select(s => new UnitFieldValueResponse { Id = s.ValueId, Value = s.Value!.Value }).ToList()
}
).OrderBy(o => o.Field.Name)
));
CreateMap<Unit, UnitRelationshipsAndAttributesResponse>()
.ForMember(d => d.Childrens, o => o.MapFrom(s => s.ChildUnits.Select(t => t.ChildUnit).OrderBy(t => t.Name)))
.ForMember(d => d.Parents, o => o.MapFrom(s => s.ParentUnits.Select(t => t.ParentUnit).OrderBy(t => t.Name)));
//.ForMember(d => d.Attributes, o => o.MapFrom(s => s.UnitValues.GroupBy(g => g.Field)
// .Select(fieldGroup => new AttributeResponse
// {
// Field = new FieldResponse
// {
// Id = fieldGroup.Key!.Id,
// Name = string.IsNullOrEmpty(fieldGroup.Key.DisplayName) ? fieldGroup.Key.AihitName : fieldGroup.Key.DisplayName,
// IsMultipleValue = fieldGroup.Key.IsMultipleValue
// },
// Values = fieldGroup.Select(s => new UnitFieldValueResponse { Id = s.ValueId, Value = s.Value!.Value }).ToList()
// }
// ).OrderBy(o => o.Field.Name)
//));
#endregion
#region WorkGroup

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class tbkUnitInValueAddIndexes : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_UnitInValues_FieldId",
schema: "unit",
table: "UnitInValues");
migrationBuilder.CreateIndex(
name: "IX_UnitInValues_FieldId_ValueId",
schema: "unit",
table: "UnitInValues",
columns: new[] { "FieldId", "ValueId" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_UnitInValues_FieldId_ValueId",
schema: "unit",
table: "UnitInValues");
migrationBuilder.CreateIndex(
name: "IX_UnitInValues_FieldId",
schema: "unit",
table: "UnitInValues",
column: "FieldId");
}
}
}

View File

@@ -2980,10 +2980,10 @@ namespace PARR.DAL.Migrations
b.HasKey("UnitId", "FieldId", "ValueId");
b.HasIndex("FieldId");
b.HasIndex("ValueId");
b.HasIndex("FieldId", "ValueId");
b.ToTable("UnitInValues", "unit", t =>
{
t.HasComment("Таблица связи ЭК с полями и со значениями");

View File

@@ -9,6 +9,7 @@ namespace PARR.DAL.Models.Unit
[Table("UnitInValues", Schema = DataContextSettings.Unit)]
[Comment("Таблица связи ЭК с полями и со значениями")]
[PrimaryKey(nameof(UnitId), nameof(FieldId), nameof(ValueId))]
[Index(nameof(FieldId), nameof(ValueId))]
public class UnitInValue : IBaseDateModified, IBaseDateCreated
{
public Guid UnitId { get; set; }

View File

@@ -9,6 +9,7 @@
<DockerServiceName>parr.api</DockerServiceName>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.template-matcher.yml" />
<None Include="docker-compose.template-task-generator.yml" />
<None Include="docker-compose.template-generator.yml" />
<None Include="docker-compose.aihit-loader.yml" />