Files
Yi.Admin/Yi.Abp.Net8/framework/Yi.Framework.Ddd.Application/YiCrudAppService.cs

132 lines
4.6 KiB
C#
Raw Normal View History

2023-12-11 09:55:12 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2024-01-02 18:32:38 +08:00
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
2023-12-11 09:55:12 +08:00
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
2024-01-02 18:32:38 +08:00
using Volo.Abp.Validation;
2023-12-11 09:55:12 +08:00
namespace Yi.Framework.Ddd.Application
{
public abstract class YiCrudAppService<TEntity, TEntityDto, TKey> : YiCrudAppService<TEntity, TEntityDto, TKey, PagedAndSortedResultRequestDto>
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
{
protected YiCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
{
}
}
public abstract class YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput>
: YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TEntityDto>
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
{
protected YiCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
{
}
}
public abstract class YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput>
: YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TCreateInput>
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
{
protected YiCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
{
}
}
public abstract class YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
: YiCrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
{
protected YiCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
{
}
}
public abstract class YiCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
: CrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TKey>
where TGetOutputDto : IEntityDto<TKey>
where TGetListOutputDto : IEntityDto<TKey>
{
protected YiCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
{
}
2023-12-14 14:15:56 +08:00
public override async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
2023-12-11 22:14:13 +08:00
{
2023-12-14 14:15:56 +08:00
List<TEntity>? entites = null;
//区分多查还是批量查
if (input is IPagedResultRequest pagedInput)
{
entites = await Repository.GetPagedListAsync(pagedInput.SkipCount, pagedInput.MaxResultCount, string.Empty);
}
else
{
entites = await Repository.GetListAsync();
}
var total = await Repository.CountAsync();
var output = await MapToGetListOutputDtosAsync(entites);
return new PagedResultDto<TGetListOutputDto>(total, output);
//throw new NotImplementedException($"【{typeof(TEntity)}】实体的CrudAppService查询为具体业务通用查询几乎无实际场景请重写实现");
2023-12-11 22:14:13 +08:00
}
2023-12-11 09:55:12 +08:00
/// <summary>
/// 偷梁换柱
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[RemoteService(isEnabled: true)]
2024-01-02 18:32:38 +08:00
public virtual async Task DeleteAsync(IEnumerable<TKey> id)
2023-12-11 09:55:12 +08:00
{
await Repository.DeleteManyAsync(id);
}
2023-12-11 22:14:13 +08:00
[RemoteService(isEnabled: false)]
2023-12-11 09:55:12 +08:00
public override Task DeleteAsync(TKey id)
{
return base.DeleteAsync(id);
}
2024-01-02 18:32:38 +08:00
public virtual async Task<IActionResult> GetExportExcelAsync(TGetListInput input)
{
if (input is IPagedResultRequest paged)
{
paged.SkipCount = 0;
paged.MaxResultCount = LimitedResultRequestDto.MaxMaxResultCount;
}
var output = await this.GetListAsync(input);
var dirPath = $"/wwwroot/temp";
var filePath = $"{dirPath}/{Guid.NewGuid()}.xlsx";
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
MiniExcel.SaveAs(filePath, output.Items);
return new FileStreamResult(File.OpenRead(filePath), "application/vnd.ms-excel");
}
public virtual async Task PostImportExcelAsync()
{
}
2023-12-11 09:55:12 +08:00
}
}