using System.Text.Json; using GB5Shared.DTO.Framework.Login; using Microsoft.Extensions.Logging; using WiDAL.CustomCode.WiAnalytics; namespace WiBLL.WiAnalytics; public class WiAnalyticsBLL : IWiAnalyticsBLL { private readonly IWiAnalyticsDAL _dal; private readonly ILogger _logger; public WiAnalyticsBLL(IWiAnalyticsDAL dal, ILogger logger) { _dal = dal; _logger = logger; } public async Task GetExecutionHistoryAsync( int wiId, int workstationId, int employeeId, DateTime fromDate, DateTime toDate, LoginDTO login, CancellationToken ct) { try { var result = await _dal.GetExecutionHistoryAsync( wiId, workstationId, employeeId, fromDate, toDate, login, ct).ConfigureAwait(false); return JsonSerializer.Serialize(result); } catch (Exception ex) { _logger.LogError(ex, "GetExecutionHistoryAsync failed for WiId {WiId}", wiId); throw; } } public async Task GetTimeStudyAsync( int wiId, DateTime fromDate, DateTime toDate, LoginDTO login, CancellationToken ct) { try { var result = await _dal.GetTimeStudyAsync(wiId, fromDate, toDate, login, ct).ConfigureAwait(false); return JsonSerializer.Serialize(result); } catch (Exception ex) { _logger.LogError(ex, "GetTimeStudyAsync failed for WiId {WiId}", wiId); throw; } } public async Task GetComplianceSummaryAsync( int wiId, DateTime fromDate, DateTime toDate, LoginDTO login, CancellationToken ct) { try { var result = await _dal.GetComplianceSummaryAsync(wiId, fromDate, toDate, login, ct).ConfigureAwait(false); return JsonSerializer.Serialize(result); } catch (Exception ex) { _logger.LogError(ex, "GetComplianceSummaryAsync failed for WiId {WiId}", wiId); throw; } } }