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