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

@@ -9,5 +9,7 @@ namespace PARR.DAL.DomainServices
public interface IShortcodesService
{
Task<string> ApplyShortcodesAsync(string str, Guid unitId, Guid jobId);
bool isAnyShortcodes(string str);
}
}

View File

@@ -1,20 +1,14 @@
using Microsoft.EntityFrameworkCore;
using PARR.DAL.Contracts;
using PARR.DAL.Services.Implementations.Job;
using PARR.DAL.Services.Implementations.Unit;
using PARR.DAL.Services.Interfaces.Job;
using PARR.DAL.Services.Interfaces.Unit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace PARR.DAL.DomainServices
{
internal class ShortcodesService : IShortcodesService
{
private const string shortcodePattern = "%[^%\\s]+%";
private readonly SettingsFromDb settingsFromDb;
private readonly IJobService jobService;
private readonly IUnitService unitService;
@@ -41,7 +35,7 @@ namespace PARR.DAL.DomainServices
if (job != null && unit != null && job.TemplateNameMask != null)
{
var resultName = job.TemplateNameMask;
var resultName = str;
var shortcodesInMask = GetShortCodes(resultName);
@@ -72,6 +66,12 @@ namespace PARR.DAL.DomainServices
}
public bool isAnyShortcodes(string str)
{
return Regex.IsMatch(str, shortcodePattern);
}
private async Task<string> ReplaceFieldValues(Guid unitId, string resultName, List<Match> shortcodesInMask)
{
var unitWithFields = await unitService.Get()
@@ -120,7 +120,6 @@ namespace PARR.DAL.DomainServices
private static List<Match> GetShortCodes(string resultName)
{
var shortcodePattern = "%[^%\\s]+%";
var shortcodesInMask = Regex.Matches(resultName, shortcodePattern).ToList();
return shortcodesInMask;
}