feat(api,dal,esppSync,esppTemplateSync,esppScheduleSync): Реализован сервис ShortcodesService подменяющий динамические составляющие в полях шаблонов и расписаний. В API контроллер выдачи заданий роботу теперь выдаёт значение полй в новом виде, реализуя Shortcodes.

This commit is contained in:
Mikhail Kuznetsov
2025-08-06 10:33:55 +10:00
parent 46a96c666e
commit f351a8863a
11 changed files with 106 additions and 58 deletions

View File

@@ -1,13 +1,11 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PARR.BLL.Services.Interfaces;
using PARR.DAL.Contracts;
using PARR.DAL.DomainServices;
using PARR.DAL.Extensions;
using PARR.DAL.Models;
using PARR.EsppSync;
using PARR.EsppTemplateSync.Domain;
using PARR.EsppTemplateSync.Settings;
using System.Threading.Tasks;
namespace PARR.EsppTemplateSync
{
@@ -16,25 +14,22 @@ namespace PARR.EsppTemplateSync
private readonly ILogger<TemplateMQSyncer> logger;
private readonly GlobalSettings globalSettings;
private readonly IMqService mqService;
private readonly ISyncService<EsppObjectTemplate> syncService;
private readonly SettingsFromDb settingsFromDb;
private readonly IShortcodesService shortcodesService;
private readonly IServiceProvider serviceProvider;
public TemplateMQSyncer(
ILogger<TemplateMQSyncer> logger,
GlobalSettings globalSettings,
IMqService mqService,
ISyncService<EsppObjectTemplate> syncService,
SettingsFromDb settingsFromDb,
IShortcodesService shortcodesService
IServiceProvider serviceProvider
)
{
this.logger = logger;
this.globalSettings = globalSettings;
this.mqService = mqService;
this.syncService = syncService;
this.settingsFromDb = settingsFromDb;
this.shortcodesService = shortcodesService;
this.serviceProvider = serviceProvider;
if (globalSettings.MqSettings == null)
{
logger.LogError("Нет секции настроек хранилища. MqSettings, EsppTemplates");
@@ -44,6 +39,7 @@ namespace PARR.EsppTemplateSync
public void Start()
{
var isConnected = mqService.InitConsumer(globalSettings!.MqSettings!, SyncTemplateAsync);
if (!isConnected)
@@ -62,7 +58,16 @@ namespace PARR.EsppTemplateSync
private async Task SyncTemplateAsync(string str)
{
await syncService.SyncEsppObjectAsync(str, ParseStrToEsppObject, ConvertDbObjToEsppObjAsync);
using (var scope = serviceProvider.CreateScope())
{
var syncService = scope.ServiceProvider.GetService<ISyncService<EsppObjectTemplate>>();
if (syncService == null)
throw new Exception($"Не смог получить серивс {nameof(ITemplateSyncer)}");
await syncService.SyncEsppObjectAsync(str, ParseStrToEsppObject, ConvertDbObjToEsppObj);
}
}
@@ -71,7 +76,7 @@ namespace PARR.EsppTemplateSync
/// </summary>
/// <param name="template">template должен обязательно содержать в себе информацию о Job+Group и Unit+BaseFields</param>
/// <returns></returns>
private async Task<EsppObjectTemplate> ConvertDbObjToEsppObjAsync(Template template)
private EsppObjectTemplate ConvertDbObjToEsppObj(Template template)
{
var templateFromDb = new EsppObjectTemplate
{
@@ -80,7 +85,7 @@ namespace PARR.EsppTemplateSync
//WorkGroup = template.Host!.WorkGroup!,
WorkGroup = template.Unit!.BaseFields!.WorkGroup!,
//ShortDescription = Normalize(template.Job.Group.ShortDescription.ApplyShortcode(Constants.Shortcodes.ShortcodeEnum.EK,template.Unit.Name)),
ShortDescription = Normalize(await shortcodesService.ApplyShortcodesAsync(template.Job!.Group!.ShortDescription,template.UnitId,template.JobId)),//TODO Вынести в переменную
ShortDescription = Normalize(template.Job!.Group!.ShortDescription),//TODO Вынести в переменную
//ResponseArea = template.Host!.ResponseArea!.Name,
//ЗО берем РГ а не хоста
ResponseArea = template.Unit.BaseFields.ResponseArea!,
@@ -91,8 +96,8 @@ namespace PARR.EsppTemplateSync
Process = template.Job.Tnk!.Subprocess!.Process!.Name,
SubProcess = template.Job.Tnk.Subprocess.Name,
//TNK = template.Job.Tnk.Name.ApplyShortcode(Constants.Shortcodes.ShortcodeEnum.EK, template.Unit.Name),
TNK = Normalize(await shortcodesService.ApplyShortcodesAsync(template.Job.Tnk.Name, template.UnitId, template.JobId)),
Work = Normalize(await shortcodesService.ApplyShortcodesAsync(template.Job.WorkName, template.UnitId, template.JobId)),
TNK = template.Job.Tnk.Name,
Work = template.Job.WorkName,
Initiator = settingsFromDb.Initiator
};