feat(api): AgentTask, AgentHistory
This commit is contained in:
@@ -43,6 +43,9 @@ namespace PARR.DAL.Context
|
||||
public DbSet<EsppSchTypeSchedule> EsppSchTypeSchedules { get; set; }
|
||||
public DbSet<EsppSchValue> EsppSchValues { get; set; }
|
||||
|
||||
public DbSet<AgentHistory> AgentHistories { get; set; }
|
||||
public DbSet<AgentHistoryLevel> AgentHistoryLevels { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
@@ -318,6 +321,14 @@ namespace PARR.DAL.Context
|
||||
|
||||
#endregion
|
||||
|
||||
modelBuilder.Entity<AgentHistoryLevel>(f =>
|
||||
{
|
||||
f.HasData(
|
||||
new { Id = (int)AgentHistoryLevelEnum.Start, Name = AgentHistoryLevelEnum.Start.ToString(), Description= "Агент начал выполнять задание" },
|
||||
new { Id = (int)AgentHistoryLevelEnum.End, Name = AgentHistoryLevelEnum.End.ToString(), Description = "Агент завершил выполнение задания" }
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
21
PARR.DAL/Contracts/AgentHistoryLevelEnum.cs
Normal file
21
PARR.DAL/Contracts/AgentHistoryLevelEnum.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace PARR.DAL.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Уровень истории работы агента
|
||||
/// </summary>
|
||||
public enum AgentHistoryLevelEnum
|
||||
{
|
||||
// При добавлении новых значений, добавить в валидатор AgentHistoryRequestValidator
|
||||
|
||||
/// <summary>
|
||||
/// Агент начал выполнять задание
|
||||
/// </summary>
|
||||
Start = 1,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Агент завершил выполнение задания
|
||||
/// </summary>
|
||||
End = 5
|
||||
}
|
||||
}
|
||||
2511
PARR.DAL/Migrations/20231018235601_TblAgentHistory.Designer.cs
generated
Normal file
2511
PARR.DAL/Migrations/20231018235601_TblAgentHistory.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
88
PARR.DAL/Migrations/20231018235601_TblAgentHistory.cs
Normal file
88
PARR.DAL/Migrations/20231018235601_TblAgentHistory.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
|
||||
|
||||
namespace PARR.DAL.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class TblAgentHistory : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AgentHistoryLevels",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Description = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AgentHistoryLevels", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AgentHistories",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
Message = table.Column<string>(type: "text", nullable: true),
|
||||
HistoryLevelId = table.Column<int>(type: "integer", nullable: false),
|
||||
TemplateId = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AgentHistories", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AgentHistories_AgentHistoryLevels_HistoryLevelId",
|
||||
column: x => x.HistoryLevelId,
|
||||
principalTable: "AgentHistoryLevels",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_AgentHistories_Templates_TemplateId",
|
||||
column: x => x.TemplateId,
|
||||
principalTable: "Templates",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AgentHistoryLevels",
|
||||
columns: new[] { "Id", "Description", "Name" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 1, "Агент начал выполнять задание", "Start" },
|
||||
{ 5, "Агент завершил выполнение задания", "End" }
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AgentHistories_HistoryLevelId",
|
||||
table: "AgentHistories",
|
||||
column: "HistoryLevelId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AgentHistories_TemplateId",
|
||||
table: "AgentHistories",
|
||||
column: "TemplateId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AgentHistories");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AgentHistoryLevels");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -369,6 +369,68 @@ namespace PARR.DAL.Migrations
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.AgentHistory", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("DateCreated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("HistoryLevelId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("TemplateId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("HistoryLevelId");
|
||||
|
||||
b.HasIndex("TemplateId");
|
||||
|
||||
b.ToTable("AgentHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.AgentHistoryLevel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("AgentHistoryLevels");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = 1,
|
||||
Description = "Агент начал выполнять задание",
|
||||
Name = "Start"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 5,
|
||||
Description = "Агент завершил выполнение задания",
|
||||
Name = "End"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.Application", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -2066,6 +2128,25 @@ namespace PARR.DAL.Migrations
|
||||
b.ToTable("Works");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.AgentHistory", b =>
|
||||
{
|
||||
b.HasOne("PARR.DAL.Models.AgentHistoryLevel", "AgentHistoryLevel")
|
||||
.WithMany("AgentHistories")
|
||||
.HasForeignKey("HistoryLevelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PARR.DAL.Models.Template", "Template")
|
||||
.WithMany("AgentHistories")
|
||||
.HasForeignKey("TemplateId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("AgentHistoryLevel");
|
||||
|
||||
b.Navigation("Template");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.Application", b =>
|
||||
{
|
||||
b.HasOne("PARR.DAL.Models.ApplicationType", "ApplicationType")
|
||||
@@ -2305,6 +2386,11 @@ namespace PARR.DAL.Migrations
|
||||
b.Navigation("Tnk");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.AgentHistoryLevel", b =>
|
||||
{
|
||||
b.Navigation("AgentHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.Application", b =>
|
||||
{
|
||||
b.Navigation("ApplicationsInHosts");
|
||||
@@ -2402,6 +2488,8 @@ namespace PARR.DAL.Migrations
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.Template", b =>
|
||||
{
|
||||
b.Navigation("AgentHistories");
|
||||
|
||||
b.Navigation("RobotConfigurations");
|
||||
});
|
||||
|
||||
|
||||
33
PARR.DAL/Models/AgentHistory.cs
Normal file
33
PARR.DAL/Models/AgentHistory.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using PARR.DAL.Models.Base;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PARR.DAL.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// История работы агентов
|
||||
/// </summary>
|
||||
[Table("AgentHistories")]
|
||||
public class AgentHistory : IBase
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public DateTimeOffset DateCreated { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public DateTimeOffset? DateModified { get; set; }
|
||||
|
||||
public string? Message { get; set; }
|
||||
|
||||
public int HistoryLevelId { get; set; }
|
||||
|
||||
public Guid TemplateId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(TemplateId))]
|
||||
public Template? Template { get; set; }
|
||||
|
||||
[ForeignKey(nameof(HistoryLevelId))]
|
||||
public AgentHistoryLevel? AgentHistoryLevel { get; set; }
|
||||
}
|
||||
}
|
||||
19
PARR.DAL/Models/AgentHistoryLevel.cs
Normal file
19
PARR.DAL/Models/AgentHistoryLevel.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PARR.DAL.Models
|
||||
{
|
||||
[Table("AgentHistoryLevels")]
|
||||
public class AgentHistoryLevel
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public required string Name { get; set; }
|
||||
|
||||
public required string Description { get; set; }
|
||||
|
||||
|
||||
public ICollection<AgentHistory> AgentHistories { get; set; } = new HashSet<AgentHistory>();
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace PARR.DAL.Models
|
||||
/// <summary>
|
||||
/// Номер расписания еспп
|
||||
/// </summary>
|
||||
public string? ScheduleEsppId { get; set; }
|
||||
public string? ScheduleEsppId { get; set; }
|
||||
|
||||
|
||||
///// <summary>
|
||||
@@ -51,5 +51,7 @@ namespace PARR.DAL.Models
|
||||
|
||||
public ICollection<RobotConfiguration> RobotConfigurations { get; set; } = new HashSet<RobotConfiguration>();
|
||||
|
||||
public ICollection<AgentHistory> AgentHistories { get; set; } = new HashSet<AgentHistory>();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace PARR.DAL
|
||||
services.AddTransient<IRobotConfigurationService, RobotConfigurationService>();
|
||||
services.AddTransient<IRobotHistoryService, RobotHistoryService>();
|
||||
services.AddTransient<IEsppSchTypeConfigService, EsppSchTypeConfigService>();
|
||||
services.AddTransient<IAgentHistoryService, AgentHistoryService>();
|
||||
|
||||
|
||||
// TransformServices
|
||||
|
||||
23
PARR.DAL/Services/Implementations/AgentHistoryService.cs
Normal file
23
PARR.DAL/Services/Implementations/AgentHistoryService.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Abstracts;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.DAL.Services.Implementations
|
||||
{
|
||||
internal class AgentHistoryService : BaseService<AgentHistory>, IAgentHistoryService
|
||||
{
|
||||
private readonly DataContext dataContext;
|
||||
|
||||
public AgentHistoryService(DataContext dataContext, ILogger<AgentHistoryService> logger) : base(logger)
|
||||
{
|
||||
this.dataContext = dataContext;
|
||||
}
|
||||
|
||||
protected override DbSet<AgentHistory> EntitySet => dataContext.AgentHistories;
|
||||
|
||||
protected override DataContext EntitiContext => dataContext;
|
||||
}
|
||||
}
|
||||
9
PARR.DAL/Services/Interfaces/IAgentHistoryService.cs
Normal file
9
PARR.DAL/Services/Interfaces/IAgentHistoryService.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces.Base;
|
||||
|
||||
namespace PARR.DAL.Services.Interfaces
|
||||
{
|
||||
public interface IAgentHistoryService : IBaseService<AgentHistory>
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user