feat(esppOrderLoader): логика синхронизации
This commit is contained in:
@@ -46,6 +46,9 @@ namespace PARR.DAL.Context
|
|||||||
public DbSet<AgentHistory> AgentHistories { get; set; }
|
public DbSet<AgentHistory> AgentHistories { get; set; }
|
||||||
public DbSet<AgentHistoryLevel> AgentHistoryLevels { get; set; }
|
public DbSet<AgentHistoryLevel> AgentHistoryLevels { get; set; }
|
||||||
|
|
||||||
|
public DbSet<Order> Orders { get; set; }
|
||||||
|
public DbSet<OrderStatus> OrderStatuses { get; set; }
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
@@ -330,6 +333,17 @@ namespace PARR.DAL.Context
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<OrderStatus>(f =>
|
||||||
|
{
|
||||||
|
f.HasData(
|
||||||
|
new { Code = (int)OrderStatusEnum.New, Name = OrderStatusEnum.New.ToString(), Description = "1-Направлен в группу" },
|
||||||
|
new { Code = (int)OrderStatusEnum.InWork, Name = OrderStatusEnum.InWork.ToString(), Description = "2-В работе" },
|
||||||
|
new { Code = (int)OrderStatusEnum.Stop, Name = OrderStatusEnum.Stop.ToString(), Description = "3-Приостановлен" },
|
||||||
|
new { Code = (int)OrderStatusEnum.Complete, Name = OrderStatusEnum.Complete.ToString(), Description = "4-Выполнен" },
|
||||||
|
new { Code = (int)OrderStatusEnum.Closed, Name = OrderStatusEnum.Closed.ToString(), Description = "5-Закрыт" }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
30
PARR.DAL/Contracts/OrderStatusEnum.cs
Normal file
30
PARR.DAL/Contracts/OrderStatusEnum.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
namespace PARR.DAL.Contracts
|
||||||
|
{
|
||||||
|
public enum OrderStatusEnum
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 1-Направлен в группу
|
||||||
|
/// </summary>
|
||||||
|
New = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 2-В работе
|
||||||
|
/// </summary>
|
||||||
|
InWork = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 3-Приостановлен
|
||||||
|
/// </summary>
|
||||||
|
Stop = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 4-Выполнен
|
||||||
|
/// </summary>
|
||||||
|
Complete = 4,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 5-Закрыт
|
||||||
|
/// </summary>
|
||||||
|
Closed = 5
|
||||||
|
}
|
||||||
|
}
|
||||||
2625
PARR.DAL/Migrations/20231023052610_TblOrdersAndStatus.Designer.cs
generated
Normal file
2625
PARR.DAL/Migrations/20231023052610_TblOrdersAndStatus.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
91
PARR.DAL/Migrations/20231023052610_TblOrdersAndStatus.cs
Normal file
91
PARR.DAL/Migrations/20231023052610_TblOrdersAndStatus.cs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
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 TblOrdersAndStatus : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "OrderStatuses",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Code = 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_OrderStatuses", x => x.Code);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Orders",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||||
|
Number = table.Column<string>(type: "text", nullable: false),
|
||||||
|
WorkGroup = table.Column<string>(type: "text", nullable: true),
|
||||||
|
TemplateId = table.Column<Guid>(type: "uuid", nullable: true),
|
||||||
|
OrderStatusCode = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Orders_OrderStatuses_OrderStatusCode",
|
||||||
|
column: x => x.OrderStatusCode,
|
||||||
|
principalTable: "OrderStatuses",
|
||||||
|
principalColumn: "Code",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Orders_Templates_TemplateId",
|
||||||
|
column: x => x.TemplateId,
|
||||||
|
principalTable: "Templates",
|
||||||
|
principalColumn: "Id");
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.InsertData(
|
||||||
|
table: "OrderStatuses",
|
||||||
|
columns: new[] { "Code", "Description", "Name" },
|
||||||
|
values: new object[,]
|
||||||
|
{
|
||||||
|
{ 1, "1-Направлен в группу", "New" },
|
||||||
|
{ 2, "2-В работе", "InWork" },
|
||||||
|
{ 3, "3-Приостановлен", "Stop" },
|
||||||
|
{ 4, "4-Выполнен", "Complete" },
|
||||||
|
{ 5, "5-Закрыт", "Closed" }
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Orders_OrderStatusCode",
|
||||||
|
table: "Orders",
|
||||||
|
column: "OrderStatusCode");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Orders_TemplateId",
|
||||||
|
table: "Orders",
|
||||||
|
column: "TemplateId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "OrderStatuses");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1547,6 +1547,90 @@ namespace PARR.DAL.Migrations
|
|||||||
b.ToTable("Hosts");
|
b.ToTable("Hosts");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PARR.DAL.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Number")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("OrderStatusCode")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<Guid?>("TemplateId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("WorkGroup")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("OrderStatusCode");
|
||||||
|
|
||||||
|
b.HasIndex("TemplateId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PARR.DAL.Models.OrderStatus", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Code")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Code"));
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Code");
|
||||||
|
|
||||||
|
b.ToTable("OrderStatuses");
|
||||||
|
|
||||||
|
b.HasData(
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Code = 1,
|
||||||
|
Description = "1-Направлен в группу",
|
||||||
|
Name = "New"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Code = 2,
|
||||||
|
Description = "2-В работе",
|
||||||
|
Name = "InWork"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Code = 3,
|
||||||
|
Description = "3-Приостановлен",
|
||||||
|
Name = "Stop"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Code = 4,
|
||||||
|
Description = "4-Выполнен",
|
||||||
|
Name = "Complete"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Code = 5,
|
||||||
|
Description = "5-Закрыт",
|
||||||
|
Name = "Closed"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.Process", b =>
|
modelBuilder.Entity("PARR.DAL.Models.Process", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@@ -2278,6 +2362,23 @@ namespace PARR.DAL.Migrations
|
|||||||
b.Navigation("ResponseArea");
|
b.Navigation("ResponseArea");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PARR.DAL.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("PARR.DAL.Models.OrderStatus", "OrderStatus")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("OrderStatusCode")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("PARR.DAL.Models.Template", "Template")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("TemplateId");
|
||||||
|
|
||||||
|
b.Navigation("OrderStatus");
|
||||||
|
|
||||||
|
b.Navigation("Template");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.RobotConfiguration", b =>
|
modelBuilder.Entity("PARR.DAL.Models.RobotConfiguration", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("PARR.DAL.Models.Robot", "Robot")
|
b.HasOne("PARR.DAL.Models.Robot", "Robot")
|
||||||
@@ -2450,6 +2551,11 @@ namespace PARR.DAL.Migrations
|
|||||||
b.Navigation("Templates");
|
b.Navigation("Templates");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PARR.DAL.Models.OrderStatus", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.Process", b =>
|
modelBuilder.Entity("PARR.DAL.Models.Process", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Subprocesses");
|
b.Navigation("Subprocesses");
|
||||||
@@ -2496,6 +2602,8 @@ namespace PARR.DAL.Migrations
|
|||||||
{
|
{
|
||||||
b.Navigation("AgentHistories");
|
b.Navigation("AgentHistories");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
|
||||||
b.Navigation("RobotConfigurations");
|
b.Navigation("RobotConfigurations");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
35
PARR.DAL/Models/Order.cs
Normal file
35
PARR.DAL/Models/Order.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using PARR.DAL.Models.Base;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace PARR.DAL.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Наряды ЕСПП
|
||||||
|
/// </summary>
|
||||||
|
[Table("Orders")]
|
||||||
|
public class Order : IBase
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset DateCreated { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public DateTimeOffset? DateModified { get; set; }
|
||||||
|
|
||||||
|
public required string Number { get; set; }
|
||||||
|
|
||||||
|
public string? WorkGroup { get; set; }
|
||||||
|
|
||||||
|
public Guid? TemplateId { get; set; }
|
||||||
|
|
||||||
|
public int OrderStatusCode { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(TemplateId))]
|
||||||
|
public Template? Template { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(OrderStatusCode))]
|
||||||
|
public OrderStatus? OrderStatus { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
18
PARR.DAL/Models/OrderStatus.cs
Normal file
18
PARR.DAL/Models/OrderStatus.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace PARR.DAL.Models
|
||||||
|
{
|
||||||
|
[Table("OrderStatuses")]
|
||||||
|
public class OrderStatus
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int Code { get; set; }
|
||||||
|
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public required string Description { get; set; }
|
||||||
|
|
||||||
|
public ICollection<Order> Orders { get; set; } = new HashSet<Order>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,5 +53,7 @@ namespace PARR.DAL.Models
|
|||||||
|
|
||||||
public ICollection<AgentHistory> AgentHistories { get; set; } = new HashSet<AgentHistory>();
|
public ICollection<AgentHistory> AgentHistories { get; set; } = new HashSet<AgentHistory>();
|
||||||
|
|
||||||
|
public ICollection<Order> Orders { get; set; } = new HashSet<Order>();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ namespace PARR.DAL
|
|||||||
services.AddTransient<IRobotHistoryService, RobotHistoryService>();
|
services.AddTransient<IRobotHistoryService, RobotHistoryService>();
|
||||||
services.AddTransient<IEsppSchTypeConfigService, EsppSchTypeConfigService>();
|
services.AddTransient<IEsppSchTypeConfigService, EsppSchTypeConfigService>();
|
||||||
services.AddTransient<IAgentHistoryService, AgentHistoryService>();
|
services.AddTransient<IAgentHistoryService, AgentHistoryService>();
|
||||||
|
services.AddTransient<IOrderService, OrderService>();
|
||||||
|
services.AddTransient<IOrderStatusService, OrderStatusService>();
|
||||||
|
|
||||||
|
|
||||||
// TransformServices
|
// TransformServices
|
||||||
|
|||||||
23
PARR.DAL/Services/Implementations/OrderService.cs
Normal file
23
PARR.DAL/Services/Implementations/OrderService.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 OrderService : BaseService<Order>, IOrderService
|
||||||
|
{
|
||||||
|
private readonly DataContext dataContext;
|
||||||
|
|
||||||
|
public OrderService(DataContext dataContext, ILogger<OrderService> logger) : base(logger)
|
||||||
|
{
|
||||||
|
this.dataContext = dataContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DbSet<Order> EntitySet => dataContext.Orders;
|
||||||
|
|
||||||
|
protected override DataContext EntitiContext => dataContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
PARR.DAL/Services/Implementations/OrderStatusService.cs
Normal file
21
PARR.DAL/Services/Implementations/OrderStatusService.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using PARR.DAL.Context;
|
||||||
|
using PARR.DAL.Models;
|
||||||
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace PARR.DAL.Services.Implementations
|
||||||
|
{
|
||||||
|
internal class OrderStatusService : IOrderStatusService
|
||||||
|
{
|
||||||
|
private readonly DataContext dataContext;
|
||||||
|
|
||||||
|
public OrderStatusService(DataContext dataContext)
|
||||||
|
{
|
||||||
|
this.dataContext = dataContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQueryable<OrderStatus> Get()
|
||||||
|
{
|
||||||
|
return dataContext.OrderStatuses;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
PARR.DAL/Services/Interfaces/IOrderService.cs
Normal file
9
PARR.DAL/Services/Interfaces/IOrderService.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using PARR.DAL.Models;
|
||||||
|
using PARR.DAL.Services.Interfaces.Base;
|
||||||
|
|
||||||
|
namespace PARR.DAL.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface IOrderService : IBaseService<Order>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
9
PARR.DAL/Services/Interfaces/IOrderStatusService.cs
Normal file
9
PARR.DAL/Services/Interfaces/IOrderStatusService.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using PARR.DAL.Models;
|
||||||
|
|
||||||
|
namespace PARR.DAL.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface IOrderStatusService
|
||||||
|
{
|
||||||
|
IQueryable<OrderStatus> Get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,5 +8,9 @@
|
|||||||
public string Number { get; set; } = string.Empty;
|
public string Number { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string? WorkGroup { get; set; }
|
public string? WorkGroup { get; set; }
|
||||||
|
|
||||||
|
public string Status { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string ShortName { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.DAL.Contracts;
|
using PARR.DAL.Contracts;
|
||||||
using PARR.EsppApi;
|
using PARR.EsppApi;
|
||||||
|
using PARR.EsppApi.Models;
|
||||||
using PARR.EsppApi.Models.Query;
|
using PARR.EsppApi.Models.Query;
|
||||||
|
using PARR.EsppOrderLoader.Services;
|
||||||
using PARR.EsppOrderLoader.Settings;
|
using PARR.EsppOrderLoader.Settings;
|
||||||
|
|
||||||
namespace PARR.EsppOrderLoader
|
namespace PARR.EsppOrderLoader
|
||||||
@@ -12,20 +15,24 @@ namespace PARR.EsppOrderLoader
|
|||||||
private readonly ILogger<EsppOrderLoader> logger;
|
private readonly ILogger<EsppOrderLoader> logger;
|
||||||
private readonly IEsppApiService esppApiService;
|
private readonly IEsppApiService esppApiService;
|
||||||
private readonly SettingsFromDb settingsFromDb;
|
private readonly SettingsFromDb settingsFromDb;
|
||||||
|
private readonly IServiceProvider serviceProvider;
|
||||||
|
|
||||||
public EsppOrderLoader(
|
public EsppOrderLoader(
|
||||||
WorkerSettings settings,
|
WorkerSettings settings,
|
||||||
ILogger<EsppOrderLoader> logger,
|
ILogger<EsppOrderLoader> logger,
|
||||||
IEsppApiService esppApiService,
|
IEsppApiService esppApiService,
|
||||||
SettingsFromDb settingsFromDb
|
SettingsFromDb settingsFromDb,
|
||||||
|
IServiceProvider serviceProvider
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.esppApiService = esppApiService;
|
this.esppApiService = esppApiService;
|
||||||
this.settingsFromDb = settingsFromDb;
|
this.settingsFromDb = settingsFromDb;
|
||||||
|
this.serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task StartAsync()
|
public async Task StartAsync()
|
||||||
{
|
{
|
||||||
logger.LogInformation("Запуск сервиса загрузки нарядов из ЕСПП.");
|
logger.LogInformation("Запуск сервиса загрузки нарядов из ЕСПП.");
|
||||||
@@ -55,6 +62,27 @@ namespace PARR.EsppOrderLoader
|
|||||||
// если в бд не добавляю, пишу в лог, что нет такого шаблона, в бд не добавляю
|
// если в бд не добавляю, пишу в лог, что нет такого шаблона, в бд не добавляю
|
||||||
|
|
||||||
private async Task DownloadOrdersAsync()
|
private async Task DownloadOrdersAsync()
|
||||||
|
{
|
||||||
|
var esppObjs = await GetOrdersAsync();
|
||||||
|
|
||||||
|
if (esppObjs == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var item in esppObjs)
|
||||||
|
{
|
||||||
|
using (var scope = serviceProvider.CreateScope())
|
||||||
|
{
|
||||||
|
var orderItemService = scope.ServiceProvider.GetService<IOrderItemService>();
|
||||||
|
if (orderItemService == null)
|
||||||
|
throw new Exception("Не смог получить серивс IOrderItemService, scope.ServiceProvider.GetService<IOrderItemService>()");
|
||||||
|
|
||||||
|
await orderItemService.WriteOrderAsync(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async Task<IEnumerable<EsppOrder>?> GetOrdersAsync()
|
||||||
{
|
{
|
||||||
var searchQuery = new FindOrdersQuery { ShortDescriptionContains = settingsFromDb.TemplatePrefixName, DateEnd = DateTime.Now.Add(settingsFromDb.OrderSearchDeltaDate) };
|
var searchQuery = new FindOrdersQuery { ShortDescriptionContains = settingsFromDb.TemplatePrefixName, DateEnd = DateTime.Now.Add(settingsFromDb.OrderSearchDeltaDate) };
|
||||||
var downloadResult = await esppApiService.FindOrdersAsync(searchQuery);
|
var downloadResult = await esppApiService.FindOrdersAsync(searchQuery);
|
||||||
@@ -62,18 +90,12 @@ namespace PARR.EsppOrderLoader
|
|||||||
if (!downloadResult.IsSuccess)
|
if (!downloadResult.IsSuccess)
|
||||||
{
|
{
|
||||||
logger.LogError(downloadResult.Exception, "Ошибка загрузки списка нарядов из ЕСПП");
|
logger.LogError(downloadResult.Exception, "Ошибка загрузки списка нарядов из ЕСПП");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.LogInformation($"Получено нарядов из ЕСПП: {downloadResult.Data?.Count()}");
|
logger.LogInformation($"Получено нарядов из ЕСПП: {downloadResult.Data?.Count()}");
|
||||||
|
|
||||||
if (downloadResult.Data == null)
|
return downloadResult.Data;
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var item in downloadResult.Data)
|
|
||||||
{
|
|
||||||
//todo:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using PARR.BLL;
|
using PARR.BLL;
|
||||||
using PARR.DAL;
|
using PARR.DAL;
|
||||||
using PARR.EsppApi;
|
using PARR.EsppApi;
|
||||||
|
using PARR.EsppOrderLoader.Services;
|
||||||
using PARR.EsppOrderLoader.Settings;
|
using PARR.EsppOrderLoader.Settings;
|
||||||
|
|
||||||
namespace PARR.EsppOrderLoader
|
namespace PARR.EsppOrderLoader
|
||||||
@@ -20,6 +21,7 @@ namespace PARR.EsppOrderLoader
|
|||||||
services.AddSingleton(settings);
|
services.AddSingleton(settings);
|
||||||
|
|
||||||
services.AddTransient<IEsppOrderLoader, EsppOrderLoader>();
|
services.AddTransient<IEsppOrderLoader, EsppOrderLoader>();
|
||||||
|
services.AddTransient<IOrderItemService, OrderItemService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IConfigurationBuilder AddEsppOrderLoaderConfigurations(this IConfigurationBuilder builder, IServiceCollection services)
|
public static IConfigurationBuilder AddEsppOrderLoaderConfigurations(this IConfigurationBuilder builder, IServiceCollection services)
|
||||||
|
|||||||
9
PARR.EsppOrderLoader/Services/IOrderItemService.cs
Normal file
9
PARR.EsppOrderLoader/Services/IOrderItemService.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using PARR.EsppApi.Models;
|
||||||
|
|
||||||
|
namespace PARR.EsppOrderLoader.Services
|
||||||
|
{
|
||||||
|
internal interface IOrderItemService
|
||||||
|
{
|
||||||
|
Task WriteOrderAsync(EsppOrder esppOrder);
|
||||||
|
}
|
||||||
|
}
|
||||||
50
PARR.EsppOrderLoader/Services/OrderItemService.cs
Normal file
50
PARR.EsppOrderLoader/Services/OrderItemService.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
using PARR.EsppApi.Models;
|
||||||
|
|
||||||
|
namespace PARR.EsppOrderLoader.Services
|
||||||
|
{
|
||||||
|
internal class OrderItemService : IOrderItemService
|
||||||
|
{
|
||||||
|
private readonly ILogger<OrderItemService> logger;
|
||||||
|
private readonly IOrderService orderService;
|
||||||
|
private readonly ITemplateService templateService;
|
||||||
|
|
||||||
|
public OrderItemService(
|
||||||
|
ILogger<OrderItemService> logger,
|
||||||
|
IOrderService orderService,
|
||||||
|
ITemplateService templateService
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.orderService = orderService;
|
||||||
|
this.templateService = templateService;
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task WriteOrderAsync(EsppOrder esppOrder)
|
||||||
|
{
|
||||||
|
// В цикле проверяю каждый наряд, есть ли он в БД + по имени ищу есть ли такой шаблон
|
||||||
|
// Если наряда такого нет в БД и есть шаблон, добавляю в БД
|
||||||
|
// если в бд не добавляю, пишу в лог, что нет такого шаблона, в бд не добавляю
|
||||||
|
|
||||||
|
var existOrder = await orderService.Get().FirstOrDefaultAsync(t => t.Number.ToLower() == esppOrder.Number.ToLower());
|
||||||
|
if (existOrder != null)
|
||||||
|
{
|
||||||
|
logger.LogInformation($"Наряд {esppOrder.Number} уже есть в БД. Пропускаю.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var template = await templateService.Get().FirstOrDefaultAsync(t => t.Name.ToLower() == esppOrder.ShortName.ToLower());
|
||||||
|
if (template == null)
|
||||||
|
{
|
||||||
|
logger.LogInformation($"Не найден шаблон для наряда {esppOrder.Number}, краткое описание наряда: {esppOrder.ShortName}. Пропускаю.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//todo: добавляю в БД!
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user