using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using MMDAL.DTO.InspectionParamSetOverride; using MMDAL.Query.InspectionParamSetEngine; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace MMDAL.CustomCode.InspectionParamSetEngine { public class InspectionParamSetEngineDAL : IInspectionParamSetEngineDAL { private readonly IQueryExecutor _QueryExecutor; public InspectionParamSetEngineDAL(IQueryExecutor queryExecutor) { _QueryExecutor = queryExecutor; } public async Task> GetMatchingRulesAsync( int partyId, int itemId, int inspectionTypeId, DateTime asOfDate, LoginDTO loginDTO, CancellationToken ct) { try { return await _QueryExecutor.QueryAsync( loginDTO, InspectionParamSetEngineQB.GET_MATCHING_RULES, new { PartyId = partyId, ItemId = itemId, InspectionTypeId = inspectionTypeId, AsOfDate = asOfDate }, cancellationToken: ct); } catch (Exception ex) { throw new Exception($"Failed to resolve InspectionParamSet rules: {ex.Message}", ex); } } public async Task GetItemQualityParameterSetDefaultAsync( int itemId, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _QueryExecutor.QueryAsync( loginDTO, InspectionParamSetEngineQB.GET_ITEM_QUALITY_PARAMETERSET_DEFAULT, new { ItemId = itemId }, cancellationToken: ct); return result.FirstOrDefault(); } catch (Exception ex) { throw new Exception($"Failed to resolve Item QualityParameterSet default: {ex.Message}", ex); } } } }