using System.Text.Json; using AnalyticsDAL.DTO.ReportConfig; using AnalyticsDAL.Query.ReportConfig; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace AnalyticsDAL.CustomCode.ReportConfig { public class ReportConfigDAL : IReportConfigDAL { private readonly IQueryExecutor _queryExecutor; public ReportConfigDAL(IQueryExecutor queryExecutor) { _queryExecutor = queryExecutor; } public async Task GetReportConfig(int reportConfigId, LoginDTO login, CancellationToken ct) { var dto = await _queryExecutor.QuerySingleAsync( login, ReportConfigQB.GET_REPORTCONFIG, new { ReportConfigId = reportConfigId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); return JsonSerializer.Serialize(dto); } public async Task GetReportConfigByReport(int reportId, LoginDTO login, CancellationToken ct) { var dto = await _queryExecutor.QuerySingleAsync( login, ReportConfigQB.GET_REPORTCONFIG_BY_REPORT, new { ReportId = reportId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); return JsonSerializer.Serialize(dto); } public async Task SaveReportConfig(ReportConfigDTO dto, LoginDTO login, CancellationToken ct) { await _queryExecutor.ExecuteAsync( login, ReportConfigQB.SAVE_REPORTCONFIG, new { dto.ReportConfigId, dto.ReportId, dto.DataSourceType, dto.WorkspaceId, dto.AsyncThresholdRows, dto.MaxExportRows, dto.EstimationQuery, dto.CacheDurationMinutes, dto.CacheKeyParams, dto.DefaultExportFormatId, dto.AllowedExportFormats, dto.ReportCategory, dto.PivotEngine, dto.IsSchedulable, dto.DefaultPriority, dto.ResultExpiryHours, dto.Remarks, dto.SortOrder, dto.SourceType, TenantId = login.ClientId, CreatedById = login.UserId, ModifiedById = login.UserId }, cancellationToken: ct).ConfigureAwait(false); return dto.ReportConfigId; } public async Task UpdateReportConfig(ReportConfigDTO dto, LoginDTO login, CancellationToken ct) { await _queryExecutor.ExecuteAsync( login, ReportConfigQB.UPDATE_REPORTCONFIG, new { dto.ReportConfigId, dto.DataSourceType, dto.WorkspaceId, dto.AsyncThresholdRows, dto.MaxExportRows, dto.EstimationQuery, dto.CacheDurationMinutes, dto.CacheKeyParams, dto.DefaultExportFormatId, dto.AllowedExportFormats, dto.ReportCategory, dto.PivotEngine, dto.IsSchedulable, dto.DefaultPriority, dto.ResultExpiryHours, dto.Remarks, dto.SortOrder, dto.Status, TenantId = login.ClientId, ModifiedById = login.UserId }, cancellationToken: ct).ConfigureAwait(false); } public async Task DeleteReportConfig(int reportConfigId, LoginDTO login, CancellationToken ct) { await _queryExecutor.ExecuteAsync( login, ReportConfigQB.DELETE_REPORTCONFIG, new { ReportConfigId = reportConfigId, TenantId = login.ClientId, ModifiedById = login.UserId }, cancellationToken: ct).ConfigureAwait(false); } public async Task IsDuplicateReport(int reportId, int excludeId, LoginDTO login, CancellationToken ct) { var count = await _queryExecutor.ExecuteScalarAsync( login, ReportConfigQB.CHECK_DUPLICATE_REPORT, new { ReportId = reportId, TenantId = login.ClientId, ReportConfigId = excludeId }, cancellationToken: ct).ConfigureAwait(false); return count > 0; } public async Task GetSelectListReportConfig(LoginDTO login, CancellationToken ct) { var list = await _queryExecutor.QueryAsync( login, ReportConfigQB.GET_SELECT_LIST_REPORTCONFIG, new { TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); return JsonSerializer.Serialize(list); } } }