using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; namespace Erp.Reports.ReportDefinitions; public class ReportDefinitionAppService : ApplicationService, IReportDefinitionAppService { private readonly IRepository _reportDefinitionRepository; public ReportDefinitionAppService(IRepository reportDefinitionRepository) { _reportDefinitionRepository = reportDefinitionRepository; } public async Task GetAsync(Guid id) { var report = await _reportDefinitionRepository.GetAsync(id); return ObjectMapper.Map(report); } public async Task GetByNameAsync(string name) { var report = await _reportDefinitionRepository.FirstOrDefaultAsync(x => x.Name == name); if (report == null) { throw new Volo.Abp.UserFriendlyException($"Report '{name}' not found"); } return ObjectMapper.Map(report); } public async Task GetContentAsync(string name) { var report = await _reportDefinitionRepository.FirstOrDefaultAsync(x => x.Name == name); if (report == null) { throw new Volo.Abp.UserFriendlyException($"Report '{name}' not found"); } return report.Content; } public async Task CreateAsync(CreateReportDefinitionDto input) { var report = new ReportDefinition( GuidGenerator.Create(), input.Name, input.DisplayName, input.Content ); await _reportDefinitionRepository.InsertAsync(report); return ObjectMapper.Map(report); } public async Task UpdateAsync(Guid id, UpdateReportDefinitionDto input) { var report = await _reportDefinitionRepository.GetAsync(id); if (!string.IsNullOrEmpty(input.DisplayName)) { report.DisplayName = input.DisplayName; } if (input.Content != null && input.Content.Length > 0) { report.UpdateContent(input.Content); } await _reportDefinitionRepository.UpdateAsync(report); return ObjectMapper.Map(report); } public async Task DeleteAsync(Guid id) { await _reportDefinitionRepository.DeleteAsync(id); } }