feat(dal,api): расширена таблица Job, добавлеа маска рабочей группы. Теперь можно генерировать шаблоны с единой экстерриториальной группой
This commit is contained in:
@@ -1,128 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.DomainServices.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PARR.DAL.DomainServices.Implementations
|
||||
{
|
||||
internal class TemplateNameGeneratorService : ITemplateNameGeneratorService
|
||||
{
|
||||
private readonly SettingsFromDb settingsFromDb;
|
||||
private readonly IJobService jobService;
|
||||
private readonly IUnitService unitService;
|
||||
|
||||
public TemplateNameGeneratorService(
|
||||
SettingsFromDb settingsFromDb,
|
||||
IJobService jobService,
|
||||
IUnitService unitService
|
||||
)
|
||||
{
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
this.jobService = jobService;
|
||||
this.unitService = unitService;
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> GetTemplateNameAsync(Guid jobId, Guid unitId)
|
||||
{
|
||||
var nameConstants = settingsFromDb.TemplateNameConstantPartsList;
|
||||
|
||||
var job = await jobService.Get().AsNoTracking().FirstOrDefaultAsync(t => t.Id == jobId);
|
||||
var unit = await unitService.Get().AsNoTracking().FirstOrDefaultAsync(t => t.Id == unitId);
|
||||
|
||||
if (job != null && unit != null && job.TemplateNameMask != null)
|
||||
{
|
||||
var resultName = job.TemplateNameMask;
|
||||
|
||||
var shortcodesInMask = GetShortCodes(resultName);
|
||||
|
||||
//Проверяем и меняем наличие статичных частей в маске имени шаблона
|
||||
if (shortcodesInMask.Any(x => nameConstants.Select(x => "%" + x.Name + "%").ToList().Contains(x.Value)))
|
||||
{
|
||||
resultName = ReplaceConstants(nameConstants, resultName);
|
||||
}
|
||||
|
||||
//Проверяем и меняем Shortcodes в маске имени шаблона
|
||||
var shortCodes = GetShortcodesNames();
|
||||
if (shortcodesInMask.Any(x => shortCodes.Select(x => x).ToList().Contains(x.Value)))
|
||||
{
|
||||
resultName = ReplaceShortcodes(job, unit, resultName, shortcodesInMask);
|
||||
}
|
||||
|
||||
//Если остались %переменные% проверяем совпадение по имени поля
|
||||
shortcodesInMask = GetShortCodes(resultName);
|
||||
if (shortcodesInMask.Count > 0)
|
||||
{
|
||||
resultName = await ReplaceFieldValues(unitId, resultName, shortcodesInMask);
|
||||
}
|
||||
|
||||
return resultName;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private async Task<string> ReplaceFieldValues(Guid unitId, string resultName, List<Match> shortcodesInMask)
|
||||
{
|
||||
var unitWithFields = await unitService.Get()
|
||||
.AsNoTracking()
|
||||
.Include(u => u.UnitValues)
|
||||
.ThenInclude(uv => uv.Field)
|
||||
.Include(u => u.UnitValues)
|
||||
.ThenInclude(uv => uv.Value)
|
||||
.FirstOrDefaultAsync(t => t.Id == unitId);
|
||||
|
||||
foreach (var item in shortcodesInMask)
|
||||
{
|
||||
var fieldName = item.Value.Replace("%", "").ToUpper();
|
||||
|
||||
var value = unitWithFields!.UnitValues!.FirstOrDefault(t => t.Field!.AihitName!.ToUpper() == fieldName!);
|
||||
|
||||
if (value != null)
|
||||
resultName = resultName.Replace(item.Value, value!.Value!.Value);
|
||||
}
|
||||
|
||||
return resultName;
|
||||
}
|
||||
|
||||
private static string ReplaceShortcodes(Models.Job.Job job, Models.Unit.Unit unit, string resultName, List<Match> shortcodesInMask)
|
||||
{
|
||||
if (shortcodesInMask.Any(x => x.Value == "%РАБОТА%"))
|
||||
resultName = resultName.Replace("%РАБОТА%", job.WorkName);
|
||||
|
||||
if (shortcodesInMask.Any(x => x.Value == "%ЭК%"))
|
||||
resultName = resultName.Replace("%ЭК%", unit.Name);
|
||||
return resultName;
|
||||
}
|
||||
|
||||
private static string ReplaceConstants(List<BLL.Domain.TemplateNameConstantPart> nameConstants, string resultName)
|
||||
{
|
||||
foreach (var item in nameConstants)
|
||||
{
|
||||
resultName = resultName.Replace($"%{item.Name}%", item.Value);
|
||||
}
|
||||
|
||||
return resultName;
|
||||
}
|
||||
|
||||
private static List<Match> GetShortCodes(string resultName)
|
||||
{
|
||||
var shortcodePattern = "%[^%\\s]+%";
|
||||
var shortcodesInMask = Regex.Matches(resultName, shortcodePattern).ToList();
|
||||
return shortcodesInMask;
|
||||
}
|
||||
|
||||
private List<string> GetShortcodesNames()
|
||||
{
|
||||
var result = new List<string> {
|
||||
"%ЭК%",
|
||||
"%ЗО%",
|
||||
"%РАБОТА%"
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,8 +97,12 @@ namespace PARR.DAL.DomainServices.Implementations
|
||||
}
|
||||
|
||||
if (job.Group?.IsUmbrella == true)
|
||||
query = query.Where(t => t.ChildUnits.Count() >= job.MinValueRelationships && t.ChildUnits.Count() <= job.MaxValueRelationships);
|
||||
|
||||
{
|
||||
if (job.isParentRelationships == true)
|
||||
query = query.Where(t => t.ParentUnits.Count() >= job.MinValueRelationships && t.ParentUnits.Count() <= job.MaxValueRelationships);
|
||||
else
|
||||
query = query.Where(t => t.ChildUnits.Count() >= job.MinValueRelationships && t.ChildUnits.Count() <= job.MaxValueRelationships);
|
||||
}
|
||||
var newUnits = await query.Select(t => t.Id).ToListAsync();
|
||||
result.AddRange(newUnits);
|
||||
}
|
||||
|
||||
3837
PARR.DAL/Migrations/20250822004054_tblJobAddClmnisParentRelationshipsAndWorkGroupMask.Designer.cs
generated
Normal file
3837
PARR.DAL/Migrations/20250822004054_tblJobAddClmnisParentRelationshipsAndWorkGroupMask.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,63 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PARR.DAL.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class tblJobAddClmnisParentRelationshipsAndWorkGroupMask : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "TemplateNameMask",
|
||||
schema: "job",
|
||||
table: "Jobs",
|
||||
type: "text",
|
||||
nullable: false,
|
||||
defaultValue: "",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "WorkGroupMask",
|
||||
schema: "job",
|
||||
table: "Jobs",
|
||||
type: "text",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "isParentRelationships",
|
||||
schema: "job",
|
||||
table: "Jobs",
|
||||
type: "boolean",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "WorkGroupMask",
|
||||
schema: "job",
|
||||
table: "Jobs");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "isParentRelationships",
|
||||
schema: "job",
|
||||
table: "Jobs");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "TemplateNameMask",
|
||||
schema: "job",
|
||||
table: "Jobs",
|
||||
type: "text",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1602,15 +1602,23 @@ namespace PARR.DAL.Migrations
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("TemplateNameMask")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("TnkId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("WorkGroupMask")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("WorkName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool?>("isParentRelationships")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
@@ -27,21 +27,34 @@ namespace PARR.DAL.Models.Job
|
||||
/// </summary>
|
||||
public required string WorkName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Минимальное значение дочерних связей группового ЭК
|
||||
/// Минимальное значение дочерних или родительских связей группового ЭК
|
||||
/// </summary>
|
||||
public int? MinValueRelationships { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Максимальное значение дочерних связей группового ЭК
|
||||
/// Максимальное значение дочерних или родительских связей группового ЭК
|
||||
/// </summary>
|
||||
public int? MaxValueRelationships { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Для подсчёта связей групового ЭК использовать родительсике или дочерние связи
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// true - диапазон связей относится к родительским связям<br/>
|
||||
/// false, null - диапазон относится к дочерним связям
|
||||
/// </value>
|
||||
public bool? isParentRelationships { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Маска для динамического формирования имени шаблона
|
||||
/// </summary>
|
||||
public string? TemplateNameMask { get; set; }
|
||||
public required string TemplateNameMask { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Маска для динамического формирования рабочей группы исполнителей шаблона
|
||||
/// </summary
|
||||
public required string WorkGroupMask { get; set; }
|
||||
|
||||
public Guid TnkId { get; set; }
|
||||
|
||||
|
||||
@@ -100,7 +100,6 @@ namespace PARR.DAL
|
||||
services.AddTransient<IUnitService, UnitService>();
|
||||
services.AddTransient<IUnitFieldValueService, UnitFieldValueService>();
|
||||
services.AddTransient<IUnitFieldService, UnitFieldService>();
|
||||
services.AddTransient<IUnitFilterService, UnitFilterService>();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -119,8 +118,8 @@ namespace PARR.DAL
|
||||
services.AddTransient<INextRunModifierService, NextRunModifierService>();
|
||||
|
||||
#region DomainServces
|
||||
services.AddTransient<ITemplateNameGeneratorService, TemplateNameGeneratorService>();
|
||||
services.AddTransient<IShortcodesService, ShortcodesService>();
|
||||
services.AddTransient<IUnitFilterService, UnitFilterService>();
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user