using System.Data.Common; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using QMSDAL.DTO; using QMSDAL.Query.PcsCardStage; namespace QMSDAL.CustomCode.PcsCardStage { public class PcsCardStageDAL : IPcsCardStageDAL { private readonly IQueryExecutor _QueryExecutor; public PcsCardStageDAL(IQueryExecutor queryExecutor) { _QueryExecutor = queryExecutor; } public async Task> GetByCardIdAsync( int pcsCardId, LoginDTO login, CancellationToken ct = default) { try { var param = new { PcsCardId = pcsCardId }; var result = await _QueryExecutor .QueryAsync(login, PcsCardStageQB.GET_PCSCARDSTAGE_BY_CARD, param, cancellationToken: ct) .ConfigureAwait(false); return result ?? Enumerable.Empty(); } catch (Exception) { throw; } } public async Task GetByIdAsync( int pcsCardStaeId, LoginDTO login, CancellationToken ct = default) { try { var param = new { PcsCardStaeId = pcsCardStaeId }; return await _QueryExecutor .QuerySingleAsync(login, PcsCardStageQB.GET_PCSCARDSTAGE, param, cancellationToken: ct) .ConfigureAwait(false); } catch (Exception) { throw; } } public async Task InsertManyAsync( IEnumerable stages, LoginDTO login, DbTransaction tx, CancellationToken ct = default) { try { foreach (var stage in stages) { await _QueryExecutor .ExecuteAsync(login, PcsCardStageQB.INSERT_PCSCARDSTAGE, stage, tx, ct) .ConfigureAwait(false); } } catch (Exception) { throw; } } public async Task OpenStageAsync( int pcsCardStaeId, int operatorId, LoginDTO login, DbTransaction tx, CancellationToken ct = default) { try { var param = new { PcsCardStaeId = pcsCardStaeId, OperatorId = operatorId }; await _QueryExecutor .ExecuteAsync(login, PcsCardStageQB.UPDATE_PCSCARDSTAGE_OPEN, param, tx, ct) .ConfigureAwait(false); } catch (Exception) { throw; } } public async Task SetChecklistLogIdAsync( int pcsCardStaeId, int checklistLogId, LoginDTO login, DbTransaction tx, CancellationToken ct = default) { try { var param = new { PcsCardStaeId = pcsCardStaeId, ChecklistLogId = checklistLogId }; await _QueryExecutor .ExecuteAsync(login, PcsCardStageQB.UPDATE_PCSCARDSTAGE_CHECKLISTLOGID, param, tx, ct) .ConfigureAwait(false); } catch (Exception) { throw; } } public async Task CompleteStageAsync( int pcsCardStaeId, int supervisorId, byte stageResult, string? remarks, LoginDTO login, DbTransaction tx, CancellationToken ct = default) { try { var param = new { PcsCardStaeId = pcsCardStaeId, SupervisorId = supervisorId, StageResult = stageResult, Remarks = remarks }; await _QueryExecutor .ExecuteAsync(login, PcsCardStageQB.UPDATE_PCSCARDSTAGE_COMPLETE, param, tx, ct) .ConfigureAwait(false); } catch (Exception) { throw; } } public async Task SetNcrStatusAsync( int pcsCardStaeId, string description, LoginDTO login, DbTransaction tx, CancellationToken ct = default) { try { var param = new { PcsCardStaeId = pcsCardStaeId, Description = description }; await _QueryExecutor .ExecuteAsync(login, PcsCardStageQB.UPDATE_PCSCARDSTAGE_NCR, param, tx, ct) .ConfigureAwait(false); } catch (Exception) { throw; } } public async Task SkipStageAsync( int pcsCardStaeId, int supervisorId, string reason, LoginDTO login, DbTransaction tx, CancellationToken ct = default) { try { var param = new { PcsCardStaeId = pcsCardStaeId, SupervisorId = supervisorId, Reason = reason }; await _QueryExecutor .ExecuteAsync(login, PcsCardStageQB.UPDATE_PCSCARDSTAGE_SKIP, param, tx, ct) .ConfigureAwait(false); } catch (Exception) { throw; } } public async Task GetCompletedCountAsync( int pcsCardId, LoginDTO login, CancellationToken ct = default) { try { var param = new { PcsCardId = pcsCardId }; return await _QueryExecutor .ExecuteScalarAsync(login, PcsCardStageQB.GET_PCSCARDSTAGE_COMPLETED_COUNT, param) .ConfigureAwait(false); } catch (Exception) { throw; } } public async Task GetNextPendingAsync( int pcsCardId, short afterStageno, LoginDTO login, CancellationToken ct = default) { try { var param = new { PcsCardId = pcsCardId, AfterStageno = afterStageno }; return await _QueryExecutor .QuerySingleAsync(login, PcsCardStageQB.GET_PCSCARDSTAGE_NEXT_PENDING, param, cancellationToken: ct) .ConfigureAwait(false); } catch (Exception) { throw; } } public async Task> GetRoutingDetailForSkuAsync( int routingId, int routingVersionId, LoginDTO login, CancellationToken ct = default) { try { var param = new { RoutingId = routingId, RoutingVersionId = routingVersionId }; var result = await _QueryExecutor .QueryAsync(login, PcsCardStageQB.GET_MROUTINGDETAIL_FOR_SKU, param, cancellationToken: ct) .ConfigureAwait(false); return result ?? Enumerable.Empty(); } catch (Exception) { throw; } } } }