feat(aihitMainSyncer): реализована логика синхронизации таблиц unit.* с данными из АИХ ИТ

This commit is contained in:
Mikhail Kuznetsov
2025-05-21 11:53:07 +10:00
parent 1ce8fcb284
commit 0fd0b4881f
13 changed files with 177 additions and 78 deletions

View File

@@ -12,8 +12,8 @@ using PARR.DAL.Context;
namespace PARR.DAL.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20250514051030_units")]
partial class units
[Migration("20250520021852_tblUnits")]
partial class tblUnits
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -2667,14 +2667,14 @@ namespace PARR.DAL.Migrations
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("VlaueId")
b.Property<Guid>("ValueId")
.HasColumnType("uuid");
b.HasKey("UnitId", "FieldId");
b.HasIndex("FieldId");
b.HasIndex("VlaueId");
b.HasIndex("ValueId");
b.ToTable("UnitInValues", "unit", t =>
{
@@ -3224,14 +3224,14 @@ namespace PARR.DAL.Migrations
.IsRequired();
b.HasOne("PARR.DAL.Models.Unit.Unit", "Unit")
.WithMany("UnitInValues")
.WithMany("UnitValues")
.HasForeignKey("UnitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.Unit.UnitFieldValue", "Value")
.WithMany("UnitInValues")
.HasForeignKey("VlaueId")
.HasForeignKey("ValueId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -3445,7 +3445,7 @@ namespace PARR.DAL.Migrations
{
b.Navigation("UnitFields");
b.Navigation("UnitInValues");
b.Navigation("UnitValues");
});
modelBuilder.Entity("PARR.DAL.Models.Unit.UnitField", b =>

View File

@@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class units : Migration
public partial class tblUnits : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@@ -127,7 +127,7 @@ namespace PARR.DAL.Migrations
{
UnitId = table.Column<Guid>(type: "uuid", nullable: false),
FieldId = table.Column<Guid>(type: "uuid", nullable: false),
VlaueId = table.Column<Guid>(type: "uuid", nullable: false),
ValueId = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
},
@@ -135,8 +135,8 @@ namespace PARR.DAL.Migrations
{
table.PrimaryKey("PK_UnitInValues", x => new { x.UnitId, x.FieldId });
table.ForeignKey(
name: "FK_UnitInValues_FieldValues_VlaueId",
column: x => x.VlaueId,
name: "FK_UnitInValues_FieldValues_ValueId",
column: x => x.ValueId,
principalSchema: "unit",
principalTable: "FieldValues",
principalColumn: "Id",
@@ -195,10 +195,10 @@ namespace PARR.DAL.Migrations
column: "FieldId");
migrationBuilder.CreateIndex(
name: "IX_UnitInValues_VlaueId",
name: "IX_UnitInValues_ValueId",
schema: "unit",
table: "UnitInValues",
column: "VlaueId");
column: "ValueId");
migrationBuilder.CreateIndex(
name: "IX_Units_Name",

View File

@@ -2664,14 +2664,14 @@ namespace PARR.DAL.Migrations
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("VlaueId")
b.Property<Guid>("ValueId")
.HasColumnType("uuid");
b.HasKey("UnitId", "FieldId");
b.HasIndex("FieldId");
b.HasIndex("VlaueId");
b.HasIndex("ValueId");
b.ToTable("UnitInValues", "unit", t =>
{
@@ -3221,14 +3221,14 @@ namespace PARR.DAL.Migrations
.IsRequired();
b.HasOne("PARR.DAL.Models.Unit.Unit", "Unit")
.WithMany("UnitInValues")
.WithMany("UnitValues")
.HasForeignKey("UnitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.Unit.UnitFieldValue", "Value")
.WithMany("UnitInValues")
.HasForeignKey("VlaueId")
.HasForeignKey("ValueId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -3442,7 +3442,7 @@ namespace PARR.DAL.Migrations
{
b.Navigation("UnitFields");
b.Navigation("UnitInValues");
b.Navigation("UnitValues");
});
modelBuilder.Entity("PARR.DAL.Models.Unit.UnitField", b =>

View File

@@ -30,6 +30,6 @@ namespace PARR.DAL.Models.Unit
public ICollection<UnitInField> UnitFields { get; set; } = new HashSet<UnitInField>();
public ICollection<UnitInValue> UnitInValues { get; set; } = new HashSet<UnitInValue>();
public ICollection<UnitInValue> UnitValues { get; set; } = new HashSet<UnitInValue>();
}
}

View File

@@ -15,7 +15,7 @@ namespace PARR.DAL.Models.Unit
public Guid FieldId { get; set; }
public Guid VlaueId { get; set; }
public Guid ValueId { get; set; }
public DateTimeOffset DateCreated { get; set; }
@@ -28,7 +28,7 @@ namespace PARR.DAL.Models.Unit
[ForeignKey(nameof(FieldId))]
public UnitField? Field { get; set; }
[ForeignKey(nameof(VlaueId))]
[ForeignKey(nameof(ValueId))]
public UnitFieldValue? Value { get; set; }
}
}

View File

@@ -19,5 +19,17 @@ namespace PARR.DAL.Services.Implementations.Unit
{
this.dataContext = dataContext;
}
public async Task<UnitFieldValue?> GetByValueNameAsync(string? value)
{
var query = EntitySet
.Include(v => v.FieldValues);
if (string.IsNullOrWhiteSpace(value))
return await query.FirstOrDefaultAsync(uf => uf.Value == null);
return await query.FirstOrDefaultAsync(uf => uf.Value!.ToLower() == value.ToLower());
}
}
}

View File

@@ -20,18 +20,20 @@ namespace PARR.DAL.Services.Implementations.Unit
}
public async Task<Models.Unit.Unit?> GetUnitWithFieldsAsync(string name)
public async Task<Models.Unit.Unit?> GetUnitByName(string name)
{
return await GetUnitWithIncludeFields()
return await GetUnitWithFieldsAndValues()
.FirstOrDefaultAsync(u => u.Name.ToLower() == name.ToLower());
}
private IQueryable<Models.Unit.Unit> GetUnitWithIncludeFields()
private IQueryable<Models.Unit.Unit> GetUnitWithFieldsAndValues()
{
return EntitySet
.Include(t => t.UnitFields)
.ThenInclude(f => f.UnitField);
.Include(u => u.UnitFields)
.ThenInclude(f => f.UnitField)
.Include(u => u.UnitValues)
.ThenInclude(v => v.Value);
}
}
}

View File

@@ -3,7 +3,8 @@ using PARR.DAL.Services.Interfaces.Base;
namespace PARR.DAL.Services.Interfaces.Unit
{
internal interface IUnitFieldValueService: IBaseService<UnitFieldValue>
public interface IUnitFieldValueService: IBaseService<UnitFieldValue>
{
Task<UnitFieldValue?> GetByValueNameAsync(string? value);
}
}

View File

@@ -4,6 +4,6 @@ namespace PARR.DAL.Services.Interfaces.Unit
{
public interface IUnitService : IBaseService<Models.Unit.Unit>
{
Task<Models.Unit.Unit?> GetUnitWithFieldsAsync(string name);
Task<Models.Unit.Unit?> GetUnitByName(string name);
}
}