feat(esppScheduleSync, esppTemplateSync): в шаблонах синхронизируется поле Исполнитель. В расписаниях исправлена логика поиска связанного шаблона. Добавлен атрибут SkipComparision - исключить поля для сравнения
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.EsppSync;
|
||||
using PARR.EsppSync.Attributes;
|
||||
|
||||
namespace PARR.EsppSync.Domain
|
||||
namespace PARR.EsppScheduleSync.Domain
|
||||
{
|
||||
public class EsppObjectSchedule : IEsppObject
|
||||
internal class EsppObjectSchedule : IEsppObject
|
||||
{
|
||||
//Все поля описаны в документации по роботам: http://gitlab.dvgd.oao.rzd/devptk/parr/parr_api/-/wikis/EsppRobots
|
||||
|
||||
@@ -13,15 +15,20 @@ namespace PARR.EsppSync.Domain
|
||||
|
||||
/// <summary>
|
||||
/// ИД расписания
|
||||
/// Не сраваниваем ЕСПП ИД, потому что У НАС РЕАЛЬНЫЙ ЕСПП ИД И ЕСПП ИД В БД МОГУ РАСХОДИТЬСЯ!!! УЖАССС!!!
|
||||
/// </summary>
|
||||
[SkipComparison]
|
||||
public string Code { get; set; } = string.Empty;
|
||||
|
||||
[SkipComparison]
|
||||
public string ScheduleName { get; set; } = string.Empty;
|
||||
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
[SkipComparison]
|
||||
public string ResponseArea { get; set; } = string.Empty;
|
||||
|
||||
[SkipComparison]
|
||||
public string WorkGroup { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
@@ -103,6 +110,7 @@ namespace PARR.EsppSync.Domain
|
||||
/// <summary>
|
||||
/// Завершение после: 0
|
||||
/// </summary>
|
||||
[SkipComparison]
|
||||
public string CompleteAfter { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
@@ -2,9 +2,9 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PARR.BLL;
|
||||
using PARR.DAL;
|
||||
using PARR.EsppScheduleSync.Domain;
|
||||
using PARR.EsppScheduleSync.Settings;
|
||||
using PARR.EsppSync;
|
||||
using PARR.EsppSync.Domain;
|
||||
|
||||
namespace PARR.EsppScheduleSync
|
||||
{
|
||||
|
||||
@@ -10,9 +10,9 @@ using PARR.DAL.Models;
|
||||
using PARR.DAL.NextRunServices;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Schedule;
|
||||
using PARR.EsppScheduleSync.Domain;
|
||||
using PARR.EsppScheduleSync.Settings;
|
||||
using PARR.EsppSync;
|
||||
using PARR.EsppSync.Domain;
|
||||
using PARR.EsppSync.Helpers;
|
||||
|
||||
namespace PARR.EsppScheduleSync
|
||||
@@ -125,10 +125,24 @@ namespace PARR.EsppScheduleSync
|
||||
using var scope = serviceProvider.CreateScope();
|
||||
var templateService = scope.ServiceProvider.GetRequiredService<ITemplateService>();
|
||||
|
||||
var candidates = await templateService.Get()
|
||||
.Include(t => t.RobotConfigurations)
|
||||
.Where(t => t.Name == esppTemplateName || t.ScheduleEsppId == esppScheduleId)
|
||||
.ToListAsync();
|
||||
// это не очень, так как esppScheduleId может быть null или empty, а в БД таких значений может быть много
|
||||
//var candidates = await templateService.Get()
|
||||
// .Include(t => t.RobotConfigurations)
|
||||
// .Where(t => t.Name == esppTemplateName || t.ScheduleEsppId == esppScheduleId)
|
||||
// .ToListAsync();
|
||||
|
||||
IQueryable<Template> query = templateService.Get().Include(t => t.RobotConfigurations);
|
||||
if (string.IsNullOrEmpty(esppScheduleId))
|
||||
{
|
||||
query = query.Where(t => t.Name == esppTemplateName);
|
||||
}
|
||||
else
|
||||
{
|
||||
//ScheduleEsppId не нулл и не пустой, поизем по нему тоже
|
||||
query = query.Where(t => t.Name == esppTemplateName || t.ScheduleEsppId == esppScheduleId);
|
||||
}
|
||||
|
||||
var candidates = await query.ToListAsync();
|
||||
|
||||
var templateByName = candidates.FirstOrDefault(t => t.Name == esppTemplateName);
|
||||
var templateByScheduleId = candidates.FirstOrDefault(t => t.ScheduleEsppId == esppScheduleId);
|
||||
@@ -592,11 +606,14 @@ namespace PARR.EsppScheduleSync
|
||||
/// <returns></returns>
|
||||
private EsppObjectSchedule ClearOptionalFields(EsppObjectSchedule esppObject)
|
||||
{
|
||||
esppObject.Code = string.Empty;
|
||||
esppObject.ScheduleName = string.Empty;
|
||||
esppObject.ResponseArea = string.Empty;
|
||||
esppObject.WorkGroup = string.Empty;
|
||||
esppObject.CompleteAfter = string.Empty;
|
||||
#region Отключение синхронизации не нужных полей настраивается через атрибут SkipComparison в моделе
|
||||
// Обнуляем ЕСПП ИД, потому что У НАС РЕАЛЬНЫЙ ЕСПП ИД И ЕСПП ИД В БД МОГУ РАСХОДИТЬСЯ!!! УЖАССС!!!
|
||||
//esppObject.Code = string.Empty;
|
||||
//esppObject.ScheduleName = string.Empty;
|
||||
//esppObject.ResponseArea = string.Empty;
|
||||
//esppObject.WorkGroup = string.Empty;
|
||||
//esppObject.CompleteAfter = string.Empty;
|
||||
#endregion
|
||||
|
||||
if (esppObject.TypeV60calendar == noneExcludeCalendarEsppValue)
|
||||
esppObject.V60calendar = string.Empty;
|
||||
|
||||
11
PARR.EsppSync/Attributes/SkipComparisonAttribute.cs
Normal file
11
PARR.EsppSync/Attributes/SkipComparisonAttribute.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace PARR.EsppSync.Attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// Атрибут для исключения свойства из сравнения в EsppSync в методе IsChanged.
|
||||
/// Применяется к свойствам можели, которые не должны участвовать в проверке изменений.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class SkipComparisonAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using PARR.DAL.Contracts;
|
||||
using PARR.DAL.DomainServices.Shortcodes;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.EsppSync.Attributes;
|
||||
using PARR.EsppSync.Helpers;
|
||||
using System.Reflection;
|
||||
|
||||
@@ -260,6 +261,13 @@ namespace PARR.EsppSync
|
||||
{
|
||||
foreach (var prop in dbObj.GetType().GetProperties())
|
||||
{
|
||||
// Пропускаем свойства, помеченные атрибутом SkipComparison
|
||||
if (Attribute.IsDefined(prop, typeof(SkipComparisonAttribute)))
|
||||
{
|
||||
logger.LogDebug("Пропущено сравнение поля {PropertyName} (помечено [SkipComparison]). Шаблон: {TemplateName}", prop.Name, templateName);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prop == null)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -8,7 +8,10 @@ namespace PARR.EsppTemplateSync.Domain
|
||||
public required string TemplateName { get; set; }
|
||||
|
||||
public RobotsEnum Robot => RobotsEnum.TemplateOrder;
|
||||
|
||||
|
||||
|
||||
// Если нужно исключить поля из синхронизации, использовать атрибут [SkipComparison]
|
||||
|
||||
public bool IsActive { get; set; }
|
||||
public required string WorkGroup { get; set; }
|
||||
public required string ShortDescription { get; set; }
|
||||
@@ -23,6 +26,9 @@ namespace PARR.EsppTemplateSync.Domain
|
||||
public required string SubProcess { get; set; }
|
||||
public required string TNK { get; set; }
|
||||
public required string Work { get; set; }
|
||||
//public required string Worker { get; set; }
|
||||
/// <summary>
|
||||
/// Исполнитель
|
||||
/// </summary>
|
||||
public required string Worker { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,9 @@ namespace PARR.EsppTemplateSync
|
||||
//TNK = template.Job.Tnk.Name.ApplyShortcode(Constants.Shortcodes.ShortcodeEnum.EK, template.Unit.Name),
|
||||
TNK = template.Job.Tnk.Name,
|
||||
Work = template.Job.WorkName,
|
||||
Initiator = settingsFromDb.Initiator
|
||||
Initiator = settingsFromDb.Initiator,
|
||||
// Исполнитель, мы хотим чтобы он всегда был пустой
|
||||
Worker = string.Empty
|
||||
};
|
||||
|
||||
return templateFromDb;
|
||||
@@ -159,8 +161,8 @@ namespace PARR.EsppTemplateSync
|
||||
Process = process,
|
||||
SubProcess = subProcess,
|
||||
TNK = tnk,
|
||||
Work = work
|
||||
//Worker = worker
|
||||
Work = work,
|
||||
Worker = worker
|
||||
};
|
||||
|
||||
return templateFromEspp;
|
||||
|
||||
Reference in New Issue
Block a user