using AnalyticsBLL.OEE; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AnalyticsSL.EndPoints.OEE { public class GetOEEReport : BaseEndpoint> { private readonly IOEECalculationEngine _oeeEngine; public GetOEEReport(IOEECalculationEngine oeeEngine) => _oeeEngine = oeeEngine; public override void Configure() { Get("/Analytics/GetOEEReport"); AllowAnonymous(); } public record GetOEEReportParameters( [property: FromHeader] string Login, [property: QueryParam] DateTime FromDate, [property: QueryParam] DateTime ToDate, [property: QueryParam] int WorkCenterId = -1 ); protected override string? GetCacheKey(GetOEEReportParameters req, LoginDTO login) => KeyGenerator.KeyGeneration( $"{req.WorkCenterId}_{req.FromDate:yyyyMMdd}_{req.ToDate:yyyyMMdd}", EntityConstant.OBJECTANALYSIS, CacheKeyLevel.CLIENT_LEVEL, login); protected override async Task> ExecuteAsync( GetOEEReportParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _oeeEngine.GetOEEReport(req.FromDate, req.ToDate, req.WorkCenterId, login, ct) .ConfigureAwait(false); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.CLIENT_LEVEL, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.CLIENT_LEVEL, login, ex.Message, 500); } } } }