feat(dal, templateMatcher): изменена логика работы Shortcodes сервиса в сторону самостоятельной дозагрузки данных из БД, в Template сервис добавлен метод атомарного резервирования шаблона для TemplateMatcher
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Npgsql;
|
||||
using PARR.Common.Domain;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.Contracts;
|
||||
@@ -46,7 +48,7 @@ namespace PARR.DAL.Services.Implementations
|
||||
.ThenInclude(p => p!.Process)
|
||||
.Include(t => t.Job)
|
||||
.ThenInclude(t => t!.Group)
|
||||
.ThenInclude(t=>t.GroupType);
|
||||
.ThenInclude(t => t!.GroupType);
|
||||
}
|
||||
|
||||
public override Task<bool> CreateAsync(Template obj)
|
||||
@@ -82,5 +84,46 @@ namespace PARR.DAL.Services.Implementations
|
||||
|
||||
return base.CreateAsync(obj);
|
||||
}
|
||||
|
||||
|
||||
public async Task<Guid?> ReserveUnusedTemplateAsync(Guid newUnitId, HistoryInitiator initiator)
|
||||
{
|
||||
var sql = @"
|
||||
UPDATE ""Templates""
|
||||
SET ""StatusTypeId"" = @NewStatus,
|
||||
""DateModified"" = @DateModified,
|
||||
""InitiatorIp"" = @InitiatorIp,
|
||||
""InitiatorParrComponentId"" = @InitiatorComponent,
|
||||
""InitiatorComment"" = @InitiatorComment
|
||||
WHERE ""Id"" = (
|
||||
SELECT ""Id""
|
||||
FROM ""Templates""
|
||||
WHERE ""StatusTypeId"" = @OldStatus
|
||||
AND ""UnitId"" != @NewUnitId
|
||||
ORDER BY ""DateCreated"" ASC
|
||||
LIMIT 1
|
||||
)
|
||||
RETURNING ""Id"";";
|
||||
|
||||
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)
|
||||
};
|
||||
|
||||
var result = await dataContext.Database
|
||||
.SqlQueryRaw<Guid>(sql, parameters)
|
||||
.ToListAsync();
|
||||
|
||||
return result.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user