feat: 完成excel导出操作
This commit is contained in:
@@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Volo.Abp.DependencyInjection;
|
using Volo.Abp.DependencyInjection;
|
||||||
using Volo.Abp.Json;
|
using Volo.Abp.Json;
|
||||||
|
using Yi.Framework.Core.Extensions;
|
||||||
|
using static System.Net.WebRequestMethods;
|
||||||
|
|
||||||
namespace Yi.Framework.AspNetCore.Microsoft.AspNetCore.Middlewares
|
namespace Yi.Framework.AspNetCore.Microsoft.AspNetCore.Middlewares
|
||||||
{
|
{
|
||||||
@@ -10,7 +12,20 @@ namespace Yi.Framework.AspNetCore.Microsoft.AspNetCore.Middlewares
|
|||||||
{
|
{
|
||||||
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
|
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
|
||||||
{
|
{
|
||||||
|
context.Response.OnStarting(() =>
|
||||||
|
{
|
||||||
|
if (context.Response.StatusCode == StatusCodes.Status200OK
|
||||||
|
&& context.Response.Headers["Content-Type"].ToString() == "application/vnd.ms-excel")
|
||||||
|
{
|
||||||
|
context.FileAttachmentHandle($"{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx");
|
||||||
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
|
});
|
||||||
|
|
||||||
await next(context);
|
await next(context);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
using System;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using MiniExcelLibs;
|
using MiniExcelLibs;
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.Application.Dtos;
|
using Volo.Abp.Application.Dtos;
|
||||||
using Volo.Abp.Application.Services;
|
using Volo.Abp.Application.Services;
|
||||||
using Volo.Abp.Domain.Entities;
|
using Volo.Abp.Domain.Entities;
|
||||||
using Volo.Abp.Domain.Repositories;
|
using Volo.Abp.Domain.Repositories;
|
||||||
using Volo.Abp.Validation;
|
|
||||||
|
|
||||||
namespace Yi.Framework.Ddd.Application
|
namespace Yi.Framework.Ddd.Application
|
||||||
{
|
{
|
||||||
@@ -65,6 +59,11 @@ namespace Yi.Framework.Ddd.Application
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 多查
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public override async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
|
public override async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
|
||||||
{
|
{
|
||||||
List<TEntity>? entites = null;
|
List<TEntity>? entites = null;
|
||||||
@@ -84,7 +83,7 @@ namespace Yi.Framework.Ddd.Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 偷梁换柱
|
/// 多删
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@@ -93,6 +92,12 @@ namespace Yi.Framework.Ddd.Application
|
|||||||
{
|
{
|
||||||
await Repository.DeleteManyAsync(id);
|
await Repository.DeleteManyAsync(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 偷梁换柱
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
[RemoteService(isEnabled: false)]
|
[RemoteService(isEnabled: false)]
|
||||||
public override Task DeleteAsync(TKey id)
|
public override Task DeleteAsync(TKey id)
|
||||||
{
|
{
|
||||||
@@ -100,8 +105,11 @@ namespace Yi.Framework.Ddd.Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导出excel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public virtual async Task<IActionResult> GetExportExcelAsync(TGetListInput input)
|
public virtual async Task<IActionResult> GetExportExcelAsync(TGetListInput input)
|
||||||
{
|
{
|
||||||
if (input is IPagedResultRequest paged)
|
if (input is IPagedResultRequest paged)
|
||||||
@@ -112,20 +120,28 @@ namespace Yi.Framework.Ddd.Application
|
|||||||
|
|
||||||
var output = await this.GetListAsync(input);
|
var output = await this.GetListAsync(input);
|
||||||
var dirPath = $"/wwwroot/temp";
|
var dirPath = $"/wwwroot/temp";
|
||||||
var filePath = $"{dirPath}/{Guid.NewGuid()}.xlsx";
|
|
||||||
|
var fileName = $"{typeof(TEntity).Name}_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}_{Guid.NewGuid()}";
|
||||||
|
var filePath = $"{dirPath}/{fileName}.xlsx";
|
||||||
if (!Directory.Exists(dirPath))
|
if (!Directory.Exists(dirPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(dirPath);
|
Directory.CreateDirectory(dirPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
MiniExcel.SaveAs(filePath, output.Items);
|
MiniExcel.SaveAs(filePath, output.Items);
|
||||||
return new FileStreamResult(File.OpenRead(filePath), "application/vnd.ms-excel");
|
return new PhysicalFileResult(filePath, "application/vnd.ms-excel");
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task PostImportExcelAsync()
|
/// <summary>
|
||||||
|
/// 导入excle
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task PostImportExcelAsync(List<TCreateInput> input)
|
||||||
{
|
{
|
||||||
|
var entities = input.Select(x => MapToEntity(x)).ToList();
|
||||||
|
await Repository.DeleteManyAsync(entities.Select(x => x.Id));
|
||||||
|
await Repository.InsertManyAsync(entities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
private ISqlSugarRepository<RoleDeptEntity> _roleDeptRepository;
|
private ISqlSugarRepository<RoleDeptEntity> _roleDeptRepository;
|
||||||
|
|
||||||
private ISqlSugarRepository<UserRoleEntity> _userRoleRepository;
|
private ISqlSugarRepository<UserRoleEntity> _userRoleRepository;
|
||||||
[UnitOfWork]
|
|
||||||
public async Task UpdateDataScpoceAsync(UpdateDataScpoceInput input)
|
public async Task UpdateDataScpoceAsync(UpdateDataScpoceInput input)
|
||||||
{
|
{
|
||||||
//只有自定义的需要特殊处理
|
//只有自定义的需要特殊处理
|
||||||
@@ -66,7 +66,6 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[UnitOfWork]
|
|
||||||
public override async Task<RoleGetOutputDto> CreateAsync(RoleCreateInputVo input)
|
public override async Task<RoleGetOutputDto> CreateAsync(RoleCreateInputVo input)
|
||||||
{
|
{
|
||||||
RoleGetOutputDto outputDto;
|
RoleGetOutputDto outputDto;
|
||||||
@@ -88,7 +87,6 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[UnitOfWork]
|
|
||||||
public override async Task<RoleGetOutputDto> UpdateAsync(Guid id, RoleUpdateInputVo input)
|
public override async Task<RoleGetOutputDto> UpdateAsync(Guid id, RoleUpdateInputVo input)
|
||||||
{
|
{
|
||||||
var dto = new RoleGetOutputDto();
|
var dto = new RoleGetOutputDto();
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using SqlSugar;
|
|||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.Application.Dtos;
|
using Volo.Abp.Application.Dtos;
|
||||||
using Volo.Abp.EventBus.Local;
|
using Volo.Abp.EventBus.Local;
|
||||||
using Volo.Abp.Uow;
|
|
||||||
using Volo.Abp.Users;
|
using Volo.Abp.Users;
|
||||||
using Yi.Framework.Ddd.Application;
|
using Yi.Framework.Ddd.Application;
|
||||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
||||||
@@ -82,7 +81,7 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[OperLog("添加用户", OperEnum.Insert)]
|
[OperLog("添加用户", OperEnum.Insert)]
|
||||||
[UnitOfWork]
|
[Permission("system:user:add")]
|
||||||
public async override Task<UserGetOutputDto> CreateAsync(UserCreateInputVo input)
|
public async override Task<UserGetOutputDto> CreateAsync(UserCreateInputVo input)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(input.Password))
|
if (string.IsNullOrEmpty(input.Password))
|
||||||
@@ -131,7 +130,7 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[OperLog("更新用户", OperEnum.Update)]
|
[OperLog("更新用户", OperEnum.Update)]
|
||||||
[UnitOfWork]
|
[Permission("system:user:update")]
|
||||||
public async override Task<UserGetOutputDto> UpdateAsync(Guid id, UserUpdateInputVo input)
|
public async override Task<UserGetOutputDto> UpdateAsync(Guid id, UserUpdateInputVo input)
|
||||||
{
|
{
|
||||||
if (await _repository.IsAnyAsync(u => input.UserName!.Equals(u.UserName) && !id.Equals(u.Id)))
|
if (await _repository.IsAnyAsync(u => input.UserName!.Equals(u.UserName) && !id.Equals(u.Id)))
|
||||||
@@ -180,6 +179,7 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[Route("user/{id}/{state}")]
|
[Route("user/{id}/{state}")]
|
||||||
[OperLog("更新用户状态", OperEnum.Update)]
|
[OperLog("更新用户状态", OperEnum.Update)]
|
||||||
|
[Permission("system:user:update")]
|
||||||
public async Task<UserGetOutputDto> UpdateStateAsync([FromRoute] Guid id, [FromRoute] bool state)
|
public async Task<UserGetOutputDto> UpdateStateAsync([FromRoute] Guid id, [FromRoute] bool state)
|
||||||
{
|
{
|
||||||
var entity = await _repository.GetByIdAsync(id);
|
var entity = await _repository.GetByIdAsync(id);
|
||||||
@@ -197,5 +197,17 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
{
|
{
|
||||||
await base.DeleteAsync(id);
|
await base.DeleteAsync(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Permission("system:user:export")]
|
||||||
|
public override Task<IActionResult> GetExportExcelAsync(UserGetListInputVo input)
|
||||||
|
{
|
||||||
|
return base.GetExportExcelAsync(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Permission("system:user:import")]
|
||||||
|
public override Task PostImportExcelAsync(List<UserCreateInputVo> input)
|
||||||
|
{
|
||||||
|
return base.PostImportExcelAsync(input);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="logs\" />
|
|
||||||
<Folder Include="wwwroot\icon\" />
|
<Folder Include="wwwroot\icon\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,10 @@ namespace Yi.Abp.Web
|
|||||||
|
|
||||||
//swagger
|
//swagger
|
||||||
app.UseYiSwagger();
|
app.UseYiSwagger();
|
||||||
|
|
||||||
|
//请求处理
|
||||||
|
app.UseYiApiHandlinge();
|
||||||
|
|
||||||
//静态资源
|
//静态资源
|
||||||
app.UseStaticFiles("/api/app/wwwroot");
|
app.UseStaticFiles("/api/app/wwwroot");
|
||||||
app.UseDefaultFiles();
|
app.UseDefaultFiles();
|
||||||
|
|||||||
Reference in New Issue
Block a user