feat(dal,api): в таблицу Tnk, добавлено поле ShortName

This commit is contained in:
Mikhail Trubnikov
2025-12-09 10:25:41 +10:00
parent 24759bb3e0
commit f74776cdf7
9 changed files with 4021 additions and 20 deletions

View File

@@ -3,7 +3,8 @@
public class TnkRequest
{
public required string Name { get; set; }
public int EsppId { get; set; }
public string? ShortName { get; set; }
public int? EsppId { get; set; }
public Guid SubprocessId { get; set; }
}
}

View File

@@ -6,7 +6,9 @@
public required string Name { get; set; }
public int EsppId { get; set; }
public string? ShortName { get; set; }
public int? EsppId { get; set; }
public Guid SubprocessId { get; set; }
}

View File

@@ -135,16 +135,17 @@ namespace PARR.API.Controllers.V1
if (existName != null)
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(request.Name), Message = $"Вид работы с именем \"{request.Name}\" уже существует." } }));
var existEsppId = await tnkService.Get().FirstOrDefaultAsync(t => t.EsppId == request.EsppId);
if (existEsppId != null)
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(request.EsppId), Message = $"ТНК с EsppId: {request.EsppId} уже существует." } }));
//var existEsppId = await tnkService.Get().FirstOrDefaultAsync(t => t.EsppId == request.EsppId);
//if (existEsppId != null)
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(request.EsppId), Message = $"ТНК с EsppId: {request.EsppId} уже существует." } }));
var tnk = new Tnk
{
Id = Guid.NewGuid(),
Name = request.Name.Trim(),
EsppId = request.EsppId,
SubprocessId = request.SubprocessId,
ShortName = request.ShortName?.Trim(),
SubprocessId = request.SubprocessId
};
if (!await tnkService.CreateAsync(tnk) || !await tnkService.CommitAsync())
@@ -171,10 +172,10 @@ namespace PARR.API.Controllers.V1
if (!resultValidate.IsValid)
return BadRequest(new Response(resultValidate.Errors));
//проверка на уникальность esppId
var existEsppId = await tnkService.Get().FirstOrDefaultAsync(t => t.Id != id && t.EsppId == request.EsppId);
if (existEsppId != null)
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(request.EsppId), Message = $"Уже есть ТНК с EsppId: {request.EsppId}" } }));
////проверка на уникальность esppId
//var existEsppId = await tnkService.Get().FirstOrDefaultAsync(t => t.Id != id && t.EsppId == request.EsppId);
//if (existEsppId != null)
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(request.EsppId), Message = $"Уже есть ТНК с EsppId: {request.EsppId}" } }));
var orig = await tnkService.Get()
.FirstOrDefaultAsync(t => t.Id == id);
@@ -185,6 +186,7 @@ namespace PARR.API.Controllers.V1
orig.Name = request.Name.Trim();
orig.EsppId = request.EsppId;
orig.SubprocessId = request.SubprocessId;
orig.ShortName = request.ShortName?.Trim();
orig.DateModified = DateTimeOffset.UtcNow;
if (!await tnkService.CommitAsync())

View File

@@ -210,7 +210,11 @@ namespace PARR.API.MappingProfiles
.ForMember(d => d.SubprocessName, o => o.MapFrom(s => s.Template!.Job!.Tnk!.Subprocess!.Name))
.ForMember(d => d.SubprocessEsppId, o => o.MapFrom(s => s.Template!.Job!.Tnk!.Subprocess!.EsppId))
.ForMember(d => d.TnkName, o => o.MapFrom(s => s.Template!.Job!.Tnk!.Name))
.ForMember(d => d.TnkEsppId, o => o.MapFrom(s => s.Template!.Job!.Tnk!.EsppId))
.ForMember(d => d.TnkEsppId, o => o.MapFrom(s =>
s.Template!.Job!.Tnk!.EsppId.HasValue
? s.Template!.Job!.Tnk!.EsppId.Value.ToString()
: string.Empty
))
.ForMember(d => d.WorkName, o => o.MapFrom(s => s.Template!.Job!.WorkName))
//.ForMember(d => d.WorkEsppId, o => o.MapFrom(s => s.Template!.Job!.EsppId))
.ForMember(d => d.ScheduleEsppId, o => o.MapFrom(s => s.Template!.ScheduleEsppId));

View File

@@ -17,7 +17,7 @@ namespace PARR.API.Validators
RuleFor(t => t.Name).NotEmpty().NotNull();
RuleFor(t => t.EsppId).NotEmpty().NotNull().WithMessage("EsppId не может быть пустым");
//RuleFor(t => t.EsppId).NotEmpty().NotNull().WithMessage("EsppId не может быть пустым");
RuleFor(t => t.SubprocessId).NotEmpty().NotNull();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,56 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class tblTnkAddShortName : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Tnks_EsppId",
table: "Tnks");
migrationBuilder.AlterColumn<int>(
name: "EsppId",
table: "Tnks",
type: "integer",
nullable: true,
oldClrType: typeof(int),
oldType: "integer");
migrationBuilder.AddColumn<string>(
name: "ShortName",
table: "Tnks",
type: "text",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ShortName",
table: "Tnks");
migrationBuilder.AlterColumn<int>(
name: "EsppId",
table: "Tnks",
type: "integer",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "integer",
oldNullable: true);
migrationBuilder.CreateIndex(
name: "IX_Tnks_EsppId",
table: "Tnks",
column: "EsppId",
unique: true);
}
}
}

View File

@@ -2777,21 +2777,21 @@ namespace PARR.DAL.Migrations
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<int>("EsppId")
b.Property<int?>("EsppId")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ShortName")
.HasColumnType("text");
b.Property<Guid>("SubprocessId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("EsppId")
.IsUnique();
b.HasIndex("SubprocessId");
b.ToTable("Tnks");

View File

@@ -1,12 +1,11 @@
using Microsoft.EntityFrameworkCore;
using PARR.DAL.Models.Base;
using PARR.DAL.Models.Base;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PARR.DAL.Models
{
[Table("Tnks")]
[Index(nameof(EsppId), IsUnique = true)]
//[Index(nameof(EsppId), IsUnique = true)]
public class Tnk : IBase
{
[Key]
@@ -18,7 +17,12 @@ namespace PARR.DAL.Models
public required string Name { get; set; }
public int EsppId { get; set; }
/// <summary>
/// Краткое наименование, применяется в шорткоде "%ТНК-КРАТКО%"
/// </summary>
public string? ShortName { get; set; }
public int? EsppId { get; set; }
public Guid SubprocessId { get; set; }