using Microsoft.AspNetCore.Mvc; using MiniExcelLibs; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; namespace NPin.Framework.Ddd.Application; public abstract class NPinCrudAppService : NPinCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto { protected NPinCrudAppService(IRepository repository) : base(repository) { } } public abstract class NPinCrudAppService : NPinCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto { protected NPinCrudAppService(IRepository repository) : base(repository) { } } public abstract class NPinCrudAppService : NPinCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto { protected NPinCrudAppService(IRepository repository) : base(repository) { } } public abstract class NPinCrudAppService : NPinCrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto { protected NPinCrudAppService(IRepository repository) : base(repository) { } } public abstract class NPinCrudAppService : CrudAppService where TEntity : class, IEntity where TGetOutputDto : IEntityDto where TGetListOutputDto : IEntityDto { protected NPinCrudAppService(IRepository repository) : base(repository) { } /// /// 多查/批量查 /// /// /// public override async Task> GetListAsync(TGetListInput input) { List entities; // 区分查/批量查 if (input is IPagedResultRequest pagedInput) { entities = await Repository.GetPagedListAsync(pagedInput.SkipCount, pagedInput.MaxResultCount, string.Empty); } else { entities = await Repository.GetListAsync(); } var total = await Repository.GetCountAsync(); var output = await MapToGetListOutputDtosAsync(entities); return new PagedResultDto(total, output); } /// /// 多删 /// /// [RemoteService(isEnabled: true)] public virtual async Task DeleteAsync(IEnumerable ids) { await Repository.DeleteManyAsync(ids); } /// /// 单删(覆盖) /// /// /// [RemoteService(isEnabled: false)] public override Task DeleteAsync(TKey id) { return base.DeleteAsync(id); } /// /// 导出Excel /// /// /// public virtual async Task GetExportExcelAsync(TGetListInput input) { if (input is IPagedResultRequest paged) { // 不进行分页 paged.SkipCount = 0; paged.MaxResultCount = LimitedResultRequestDto.MaxMaxResultCount; } var output = await this.GetListAsync(input); var dirPath = $"/temp"; var filename = $"{typeof(TEntity).Name}_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{Guid.NewGuid()}"; var filePath = $"{dirPath}/{filename}.xlsx"; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } await MiniExcel.SaveAsAsync(filePath, output.Items); return new PhysicalFileResult(filePath, "application/vnd.ms-excel"); } /// /// 导入Excel /// /// public virtual async Task PostImportExcelAsync(List input) { // var entities = input.Select(MapToEntity).ToList(); // await Repository.InsertManyAsync(entities); // 需子类自行实现 throw new NotImplementedException(); } }