feat(esppOrderLoader): изменено журналирвоание
This commit is contained in:
@@ -28,13 +28,28 @@ namespace PARR.DAL.Services.Implementations
|
||||
|
||||
public async Task<Template?> GetTemplateByNameAsync(string name)
|
||||
{
|
||||
return await GetWithIncludes()
|
||||
logger.LogDebug("Поиск шаблона по имени: {TemplateName}", name);
|
||||
|
||||
var template = await GetWithIncludes()
|
||||
.Include(t => t.RobotConfigurations)
|
||||
.FirstOrDefaultAsync(t => t.Name == name);
|
||||
|
||||
if (template != null)
|
||||
{
|
||||
logger.LogDebug("Шаблон найден: {TemplateId}, имя: {TemplateName}", template.Id, template.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogDebug("Шаблон с именем {TemplateName} не найден", name);
|
||||
}
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
public IQueryable<Template> GetWithIncludes()
|
||||
{
|
||||
logger.LogDebug("Получаю шаблоны с include связями");
|
||||
|
||||
return Get()
|
||||
.Include(h => h.Unit)
|
||||
.ThenInclude(t => t!.UnitValues)
|
||||
@@ -57,6 +72,8 @@ namespace PARR.DAL.Services.Implementations
|
||||
|
||||
public override Task<bool> CreateAsync(Template obj)
|
||||
{
|
||||
logger.LogDebug("Создание шаблона: {TemplateName}", obj.Name);
|
||||
|
||||
// добавление роботов для шаблона
|
||||
obj.RobotConfigurations = new List<RobotConfiguration>
|
||||
{
|
||||
@@ -86,12 +103,16 @@ namespace PARR.DAL.Services.Implementations
|
||||
}
|
||||
};
|
||||
|
||||
logger.LogDebug("Добавлены роботы для шаблона {TemplateName}", obj.Name);
|
||||
|
||||
return base.CreateAsync(obj);
|
||||
}
|
||||
|
||||
|
||||
public async Task<Guid?> ReserveUnusedTemplateAsync(Guid newUnitId, HistoryInitiator initiator)
|
||||
{
|
||||
logger.LogDebug("Резервирую неиспользуемый шаблон для UnitId: {UnitId}", newUnitId);
|
||||
|
||||
var sql = @"
|
||||
UPDATE ""Templates""
|
||||
SET ""StatusTypeId"" = @NewStatus,
|
||||
@@ -111,23 +132,43 @@ namespace PARR.DAL.Services.Implementations
|
||||
|
||||
var parameters = new[]
|
||||
{
|
||||
new NpgsqlParameter("@NewStatus", (int)TemplateStatusTypeEnum.Updating),
|
||||
new NpgsqlParameter("@DateModified", DateTimeOffset.UtcNow),
|
||||
new NpgsqlParameter("@InitiatorIp", initiator.InitiatorIp ?? (object)DBNull.Value),
|
||||
new NpgsqlParameter("@InitiatorComponent",
|
||||
initiator.InitiatorParrComponentId.HasValue
|
||||
? (object)(int)initiator.InitiatorParrComponentId.Value
|
||||
: DBNull.Value),
|
||||
new NpgsqlParameter("@InitiatorComment", initiator.InitiatorComment ?? (object)DBNull.Value),
|
||||
new NpgsqlParameter("@OldStatus", (int)TemplateStatusTypeEnum.Unused),
|
||||
new NpgsqlParameter("@NewUnitId", newUnitId)
|
||||
};
|
||||
new NpgsqlParameter("@NewStatus", (int)TemplateStatusTypeEnum.Updating),
|
||||
new NpgsqlParameter("@DateModified", DateTimeOffset.UtcNow),
|
||||
new NpgsqlParameter("@InitiatorIp", initiator.InitiatorIp ?? (object)DBNull.Value),
|
||||
new NpgsqlParameter("@InitiatorComponent",
|
||||
initiator.InitiatorParrComponentId.HasValue
|
||||
? (object)(int)initiator.InitiatorParrComponentId.Value
|
||||
: DBNull.Value),
|
||||
new NpgsqlParameter("@InitiatorComment", initiator.InitiatorComment ?? (object)DBNull.Value),
|
||||
new NpgsqlParameter("@OldStatus", (int)TemplateStatusTypeEnum.Unused),
|
||||
new NpgsqlParameter("@NewUnitId", newUnitId)
|
||||
};
|
||||
|
||||
var result = await dataContext.Database
|
||||
.SqlQueryRaw<Guid>(sql, parameters)
|
||||
.ToListAsync();
|
||||
try
|
||||
{
|
||||
var result = await dataContext.Database
|
||||
.SqlQueryRaw<Guid>(sql, parameters)
|
||||
.ToListAsync();
|
||||
|
||||
return result.FirstOrDefault();
|
||||
var reservedTemplateId = result.FirstOrDefault();
|
||||
|
||||
if (reservedTemplateId != default(Guid))
|
||||
{
|
||||
logger.LogInformation("Успешно зарезервирован шаблон с ID: {TemplateId} для UnitId: {UnitId}",
|
||||
reservedTemplateId, newUnitId);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogDebug("Не удалось зарезервировать шаблон для UnitId: {UnitId}", newUnitId);
|
||||
}
|
||||
|
||||
return reservedTemplateId;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Ошибка при резервировании шаблона для UnitId: {UnitId}", newUnitId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user