diff --git a/PARR.EsppSync/Domain/EsppObjectSchedule.cs b/PARR.EsppScheduleSync/Domain/EsppObjectSchedule.cs
similarity index 89%
rename from PARR.EsppSync/Domain/EsppObjectSchedule.cs
rename to PARR.EsppScheduleSync/Domain/EsppObjectSchedule.cs
index f047cec6..a2f45892 100644
--- a/PARR.EsppSync/Domain/EsppObjectSchedule.cs
+++ b/PARR.EsppScheduleSync/Domain/EsppObjectSchedule.cs
@@ -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
///
/// ИД расписания
+ /// Не сраваниваем ЕСПП ИД, потому что У НАС РЕАЛЬНЫЙ ЕСПП ИД И ЕСПП ИД В БД МОГУ РАСХОДИТЬСЯ!!! УЖАССС!!!
///
+ [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;
///
@@ -103,6 +110,7 @@ namespace PARR.EsppSync.Domain
///
/// Завершение после: 0
///
+ [SkipComparison]
public string CompleteAfter { get; set; } = string.Empty;
///
diff --git a/PARR.EsppScheduleSync/EsppScheduleSyncInstaller.cs b/PARR.EsppScheduleSync/EsppScheduleSyncInstaller.cs
index 4dfc8041..4a0e01a9 100644
--- a/PARR.EsppScheduleSync/EsppScheduleSyncInstaller.cs
+++ b/PARR.EsppScheduleSync/EsppScheduleSyncInstaller.cs
@@ -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
{
diff --git a/PARR.EsppScheduleSync/ScheduleSyncher.cs b/PARR.EsppScheduleSync/ScheduleSyncher.cs
index 6fc936b9..d3410738 100644
--- a/PARR.EsppScheduleSync/ScheduleSyncher.cs
+++ b/PARR.EsppScheduleSync/ScheduleSyncher.cs
@@ -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();
- 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 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
///
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;
diff --git a/PARR.EsppSync/Attributes/SkipComparisonAttribute.cs b/PARR.EsppSync/Attributes/SkipComparisonAttribute.cs
new file mode 100644
index 00000000..7dc521fb
--- /dev/null
+++ b/PARR.EsppSync/Attributes/SkipComparisonAttribute.cs
@@ -0,0 +1,11 @@
+namespace PARR.EsppSync.Attributes
+{
+ ///
+ /// Атрибут для исключения свойства из сравнения в EsppSync в методе IsChanged.
+ /// Применяется к свойствам можели, которые не должны участвовать в проверке изменений.
+ ///
+ [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
+ public sealed class SkipComparisonAttribute : Attribute
+ {
+ }
+}
diff --git a/PARR.EsppSync/SyncService.cs b/PARR.EsppSync/SyncService.cs
index bbedd2f3..7757e8f3 100644
--- a/PARR.EsppSync/SyncService.cs
+++ b/PARR.EsppSync/SyncService.cs
@@ -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;
diff --git a/PARR.EsppTemplateSync/Domain/EsppObjectTemplate.cs b/PARR.EsppTemplateSync/Domain/EsppObjectTemplate.cs
index 2f80845f..934a705b 100644
--- a/PARR.EsppTemplateSync/Domain/EsppObjectTemplate.cs
+++ b/PARR.EsppTemplateSync/Domain/EsppObjectTemplate.cs
@@ -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; }
+ ///
+ /// Исполнитель
+ ///
+ public required string Worker { get; set; }
}
}
diff --git a/PARR.EsppTemplateSync/TemplateMQSyncer.cs b/PARR.EsppTemplateSync/TemplateMQSyncer.cs
index 90a593d4..0dcdcd61 100644
--- a/PARR.EsppTemplateSync/TemplateMQSyncer.cs
+++ b/PARR.EsppTemplateSync/TemplateMQSyncer.cs
@@ -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;