using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using MMDAL.DTO.Inspection; using MMDAL.Query.Inspection; using Newtonsoft.Json; using System; using System.Threading; using System.Threading.Tasks; namespace MMDAL.CustomCode.Inspection { public class InspectionAnalyticsDAL : IInspectionAnalyticsDAL { private readonly IQueryExecutor _QueryExecutor; public InspectionAnalyticsDAL(IQueryExecutor queryExecutor) { _QueryExecutor = queryExecutor; } public async Task GetKpi(int ouId, int periodId, LoginDTO loginDTO, CancellationToken ct) { try { var dto = await _QueryExecutor.QuerySingleAsync( loginDTO, InspectionAnalyticsQB.GET_KPI, new { OUId = ouId, PeriodId = periodId }, cancellationToken: ct); return JsonConvert.SerializeObject(dto); } catch (Exception ex) { throw new Exception($"GetKpi failed: {ex.Message}", ex); } } public async Task GetTrend(int ouId, int months, LoginDTO loginDTO, CancellationToken ct) { try { var rows = await _QueryExecutor.QueryAsync( loginDTO, InspectionAnalyticsQB.GET_TREND, new { OUId = ouId, Months = months }, cancellationToken: ct); return JsonConvert.SerializeObject(rows); } catch (Exception ex) { throw new Exception($"GetTrend failed: {ex.Message}", ex); } } public async Task GetDefectPareto(int ouId, int periodId, LoginDTO loginDTO, CancellationToken ct) { try { var rows = await _QueryExecutor.QueryAsync( loginDTO, InspectionAnalyticsQB.GET_DEFECT_PARETO, new { OUId = ouId, PeriodId = periodId }, cancellationToken: ct); return JsonConvert.SerializeObject(rows); } catch (Exception ex) { throw new Exception($"GetDefectPareto failed: {ex.Message}", ex); } } public async Task GetProcessYield(int ouId, int periodId, LoginDTO loginDTO, CancellationToken ct) { try { var rows = await _QueryExecutor.QueryAsync( loginDTO, InspectionAnalyticsQB.GET_PROCESS_YIELD, new { OUId = ouId, PeriodId = periodId }, cancellationToken: ct); return JsonConvert.SerializeObject(rows); } catch (Exception ex) { throw new Exception($"GetProcessYield failed: {ex.Message}", ex); } } public async Task GetParamSummary(int inspectionId, LoginDTO loginDTO, CancellationToken ct) { try { var rows = await _QueryExecutor.QueryAsync( loginDTO, InspectionAnalyticsQB.GET_PARAM_SUMMARY, new { InspectionId = inspectionId }, cancellationToken: ct); return JsonConvert.SerializeObject(rows); } catch (Exception ex) { throw new Exception($"GetParamSummary failed: {ex.Message}", ex); } } } }