using AutomationDAL.DTO.DocumentFlow; using AutomationDAL.Query.DocumentFlow; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace AutomationDAL.CustomCode.DocumentFlow; public class DocumentFlowDAL : IDocumentFlowDAL { private readonly IQueryExecutor _qe; public DocumentFlowDAL(IQueryExecutor qe) => _qe = qe; public async Task GetByOrderStage(string orderId, string stage, LoginDTO login, CancellationToken ct) { var rows = await _qe.QueryAsync(login, DocumentFlowQB.GET_BY_ORDER_STAGE, new { OrderId = orderId, Stage = stage, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); return rows.FirstOrDefault(); } public async Task> GetByOrder(string orderId, LoginDTO login, CancellationToken ct) => await _qe.QueryAsync(login, DocumentFlowQB.GET_BY_ORDER, new { OrderId = orderId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); public async Task UpsertPending(string orderId, string stage, long runId, string? ackCallbackUrl, LoginDTO login, CancellationToken ct) => await _qe.ExecuteAsync(login, DocumentFlowQB.UPSERT_PENDING, new { OrderId = orderId, Stage = stage, RunId = runId, AckCallbackUrl = ackCallbackUrl, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); public async Task UpdateStatusByRunId(long runId, string status, LoginDTO login, CancellationToken ct) => await _qe.ExecuteAsync(login, DocumentFlowQB.UPDATE_STATUS_BY_RUNID, new { RunId = runId, Status = status }, cancellationToken: ct).ConfigureAwait(false); public async Task GetByRunId(long runId, LoginDTO login, CancellationToken ct) { var rows = await _qe.QueryAsync(login, DocumentFlowQB.GET_BY_RUNID, new { RunId = runId }, cancellationToken: ct).ConfigureAwait(false); return rows.FirstOrDefault(); } }