feat(all): в таблицу Order добавлено поле ExpirationDate, обновлены сервисы для записи этого поля. Начало логики закрытия нарядов в ЕСПП.
This commit is contained in:
@@ -8,7 +8,8 @@ namespace PARR.BLL
|
|||||||
{
|
{
|
||||||
public static class ParrBllInstaller
|
public static class ParrBllInstaller
|
||||||
{
|
{
|
||||||
public static void InstallBllServices(this IServiceCollection services, IConfiguration configuration) {
|
public static void InstallBllServices(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
|
||||||
var storageSettings = new StorageSettings();
|
var storageSettings = new StorageSettings();
|
||||||
configuration.GetSection(nameof(StorageSettings)).Bind(storageSettings);
|
configuration.GetSection(nameof(StorageSettings)).Bind(storageSettings);
|
||||||
@@ -17,6 +18,7 @@ namespace PARR.BLL
|
|||||||
|
|
||||||
services.AddTransient<IFileService, FileService>();
|
services.AddTransient<IFileService, FileService>();
|
||||||
services.AddTransient<IMqService, MqService>();
|
services.AddTransient<IMqService, MqService>();
|
||||||
|
services.AddTransient<ITransformService, TransformService>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PARR.BLL.Services.Interfaces;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace PARR.GeneratorTemplates.Services
|
namespace PARR.BLL.Services.Implementations
|
||||||
{
|
{
|
||||||
internal class TransformService : ITransformService
|
internal class TransformService: ITransformService
|
||||||
{
|
{
|
||||||
private readonly ILogger<TransformService> logger;
|
private readonly ILogger<TransformService> logger;
|
||||||
|
|
||||||
7
PARR.BLL/Services/Interfaces/ITransformService.cs
Normal file
7
PARR.BLL/Services/Interfaces/ITransformService.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PARR.BLL.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface ITransformService
|
||||||
|
{
|
||||||
|
T? GetModelFromJson<T>(string str);
|
||||||
|
}
|
||||||
|
}
|
||||||
2667
PARR.DAL/Migrations/20231117055726_TblOrdersAddExpDate.Designer.cs
generated
Normal file
2667
PARR.DAL/Migrations/20231117055726_TblOrdersAddExpDate.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
PARR.DAL/Migrations/20231117055726_TblOrdersAddExpDate.cs
Normal file
30
PARR.DAL/Migrations/20231117055726_TblOrdersAddExpDate.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PARR.DAL.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class TblOrdersAddExpDate : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||||
|
name: "ExpirationDate",
|
||||||
|
table: "Orders",
|
||||||
|
type: "timestamp with time zone",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ExpirationDate",
|
||||||
|
table: "Orders");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1564,6 +1564,9 @@ namespace PARR.DAL.Migrations
|
|||||||
b.Property<DateTimeOffset?>("DateModified")
|
b.Property<DateTimeOffset?>("DateModified")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("ExpirationDate")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<DateTimeOffset?>("GenerateDate")
|
b.Property<DateTimeOffset?>("GenerateDate")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ namespace PARR.DAL.Models
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTimeOffset? GenerateDate { get; set; }
|
public DateTimeOffset? GenerateDate { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset ExpirationDate { get; set; }
|
||||||
|
|
||||||
[ForeignKey(nameof(TemplateId))]
|
[ForeignKey(nameof(TemplateId))]
|
||||||
public Template? Template { get; set; }
|
public Template? Template { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ namespace PARR.EsppOrderLoader.Services
|
|||||||
StatusCode = (int)orderStatusService.GetOrderStatusByName(esppOrder.Status),
|
StatusCode = (int)orderStatusService.GetOrderStatusByName(esppOrder.Status),
|
||||||
GenerateDate = template == null ?
|
GenerateDate = template == null ?
|
||||||
null
|
null
|
||||||
: CalcGenerationDate(esppOrder.ExpirationDateUTC, template.ApplicationsInWork!.TemplateDurationTimeSpan)
|
: CalcGenerationDate(esppOrder.ExpirationDateUTC, template.ApplicationsInWork!.TemplateDurationTimeSpan),
|
||||||
|
ExpirationDate = esppOrder.ExpirationDateUTC
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!await orderService.CreateAsync(newOrder) || !await orderService.CommitAsync())
|
if (!await orderService.CreateAsync(newOrder) || !await orderService.CommitAsync())
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PARR.BLL.Domain.Mq;
|
||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.DAL.Models;
|
||||||
|
using PARR.DAL.Services.Interfaces;
|
||||||
using PARR.EsppOrderManager.Settings;
|
using PARR.EsppOrderManager.Settings;
|
||||||
|
|
||||||
namespace PARR.EsppOrderManager
|
namespace PARR.EsppOrderManager
|
||||||
@@ -9,24 +13,35 @@ namespace PARR.EsppOrderManager
|
|||||||
private readonly MqSettings mqSettings;
|
private readonly MqSettings mqSettings;
|
||||||
private readonly IMqService mqService;
|
private readonly IMqService mqService;
|
||||||
private readonly ILogger<EsppOrderManager> logger;
|
private readonly ILogger<EsppOrderManager> logger;
|
||||||
|
private readonly ITransformService transformService;
|
||||||
|
private readonly IOrderService orderService;
|
||||||
|
|
||||||
public EsppOrderManager(
|
public EsppOrderManager(
|
||||||
MqSettings mqSettings,
|
MqSettings mqSettings,
|
||||||
IMqService mqService,
|
IMqService mqService,
|
||||||
ILogger<EsppOrderManager> logger
|
ILogger<EsppOrderManager> logger,
|
||||||
|
ITransformService transformService,
|
||||||
|
IOrderService orderService
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.mqSettings = mqSettings;
|
this.mqSettings = mqSettings;
|
||||||
this.mqService = mqService;
|
this.mqService = mqService;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.transformService = transformService;
|
||||||
|
this.orderService = orderService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public async void Start()
|
||||||
{
|
{
|
||||||
var isConnected = mqService.InitConsumer(mqSettings, ManageOrder);
|
// логика работы описана в документации
|
||||||
|
|
||||||
if (!isConnected)
|
//var isConnected = mqService.InitConsumer(mqSettings, ManageOrder);
|
||||||
throw new Exception("Ошибка при подключении к RabbitMq");
|
|
||||||
|
//if (!isConnected)
|
||||||
|
// throw new Exception("Ошибка при подключении к RabbitMq");
|
||||||
|
|
||||||
|
//test, and remove async in method name
|
||||||
|
await ManageOrder("{\"OrderId\":\"77eeccfb-4ca0-443e-8cc7-f6aa9dc774b7\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
@@ -39,9 +54,55 @@ namespace PARR.EsppOrderManager
|
|||||||
{
|
{
|
||||||
logger.LogDebug($"Получили сообщение: {msg}");
|
logger.LogDebug($"Получили сообщение: {msg}");
|
||||||
|
|
||||||
//тут по идее берет в работу / выполняет
|
var obj = transformService.GetModelFromJson<OrderManageMq>(msg);
|
||||||
|
if (obj == null)
|
||||||
|
return;
|
||||||
|
|
||||||
//todo:
|
var order = await orderService.Get()
|
||||||
|
.Include(t => t.AgentHistories).ThenInclude(t => t.AgentHistoryLevel)
|
||||||
|
.Include(t => t.OrderStatus)
|
||||||
|
.Include(t => t.NextStatus)
|
||||||
|
.FirstOrDefaultAsync(t => t.Id == obj.OrderId);
|
||||||
|
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
logger.LogError($"Не найден наряд с OrderId: {obj.OrderId}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (order.StatusCode == order.NextStatusCode)
|
||||||
|
{
|
||||||
|
logger.LogInformation($"У наряда {order.Id}, {order.Number} статусы равны, ничего не делаем. Статус: {order.OrderStatus!.Description}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var resultMsg = GenerateResultMsg(order);
|
||||||
|
|
||||||
|
//todo:!!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Генерирует текс поля Решение, в зависимости от статуса наряда и от истории Агента
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="order"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private string GenerateResultMsg(Order order)
|
||||||
|
{
|
||||||
|
var agentHistory = order.AgentHistories
|
||||||
|
.OrderBy(t => t.DateCreated)
|
||||||
|
.Select(t => $"{t.DateCreated} :: {t.AgentHistoryLevel?.Name} :: {t.Message}");
|
||||||
|
|
||||||
|
string msgAgent = "Работы выполнены средствами автоматизации. \r\n" +
|
||||||
|
"Журнал работы: \r\n" +
|
||||||
|
$"{string.Join("\r\n", agentHistory)}";
|
||||||
|
|
||||||
|
string msgAgentEmpty = "Работы должны были выполниться средствами автоматизации. " +
|
||||||
|
"Но от средств автоматизации не поступило сообщений. " +
|
||||||
|
"Работы не выполнены.";
|
||||||
|
|
||||||
|
return agentHistory.Any() ? msgAgent : msgAgentEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,8 @@
|
|||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"MqSettings": {
|
||||||
|
"HostName": "10.99.253.216"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ namespace PARR.GeneratorTemplates
|
|||||||
|
|
||||||
if (!await validatorService.IsValidApplicationAndWorksAsync(query.ApplicationId, query.WorkId))
|
if (!await validatorService.IsValidApplicationAndWorksAsync(query.ApplicationId, query.WorkId))
|
||||||
{
|
{
|
||||||
logger.LogError($"Невалидны параметры {nameof(query.ApplicationId)}: {query.ApplicationId}, " +
|
logger.LogError($"Не валидны параметры {nameof(query.ApplicationId)}: {query.ApplicationId}, " +
|
||||||
$"{nameof(query.WorkId)}: {query.WorkId}," +
|
$"{nameof(query.WorkId)}: {query.WorkId}," +
|
||||||
$" нет таких значений или они не связаны в таблице ${nameof(ApplicationsInWork)}");
|
$" нет таких значений или они не связаны в таблице ${nameof(ApplicationsInWork)}");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ namespace PARR.GeneratorTemplates
|
|||||||
|
|
||||||
//add other services
|
//add other services
|
||||||
services.AddTransient<IGeneratorTemplate, GeneratorTemplate>();
|
services.AddTransient<IGeneratorTemplate, GeneratorTemplate>();
|
||||||
services.AddTransient<ITransformService, TransformService>();
|
|
||||||
services.AddTransient<IValidatorService, ValidatorService>();
|
services.AddTransient<IValidatorService, ValidatorService>();
|
||||||
services.AddTransient<ITemplateManager, TemplateManager>();
|
services.AddTransient<ITemplateManager, TemplateManager>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace PARR.GeneratorTemplates.Services
|
|
||||||
{
|
|
||||||
internal interface ITransformService
|
|
||||||
{
|
|
||||||
T? GetModelFromJson<T>(string str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -135,8 +135,6 @@ namespace PARR.Master.Services
|
|||||||
if (!allHistory.Any())
|
if (!allHistory.Any())
|
||||||
{
|
{
|
||||||
logger.LogInformation($"Для наряда {order.Id}, {order.Number} нет истории агента. Ничего не делаем.");
|
logger.LogInformation($"Для наряда {order.Id}, {order.Number} нет истории агента. Ничего не делаем.");
|
||||||
|
|
||||||
//TODO: тут бы помечать эти наряды, у которых крайний срок вышел и нет истории
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await orderService.CommitAsync())
|
if (!await orderService.CommitAsync())
|
||||||
@@ -253,6 +251,7 @@ namespace PARR.Master.Services
|
|||||||
&& t.GenerateDate.HasValue
|
&& t.GenerateDate.HasValue
|
||||||
&& t.Template!.ApplicationsInWork!.AgentTimeOutSec.HasValue
|
&& t.Template!.ApplicationsInWork!.AgentTimeOutSec.HasValue
|
||||||
&& string.IsNullOrEmpty(t.Template!.ApplicationsInWork!.TemplateDuration) == false
|
&& string.IsNullOrEmpty(t.Template!.ApplicationsInWork!.TemplateDuration) == false
|
||||||
|
&& t.ExpirationDate > DateTimeOffset.UtcNow
|
||||||
).OrderBy(t => t.DateCreated);
|
).OrderBy(t => t.DateCreated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user