From e3108f7382de5de687c27642b74aec63c74bcbd8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com>
Date: Tue, 2 Jan 2024 23:26:05 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90excel=E5=AF=BC?=
=?UTF-8?q?=E5=87=BA=E6=93=8D=E4=BD=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Middlewares/ApiInfoMiddleware.cs | 15 ++++++
.../YiCrudAppService.cs | 46 +++++++++++++------
.../Services/RoleService.cs | 4 +-
.../Services/UserService.cs | 18 ++++++--
Yi.Abp.Net8/src/Yi.Abp.Web/Yi.Abp.Web.csproj | 1 -
Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs | 5 +-
6 files changed, 66 insertions(+), 23 deletions(-)
diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore/Microsoft/AspNetCore/Middlewares/ApiInfoMiddleware.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore/Microsoft/AspNetCore/Middlewares/ApiInfoMiddleware.cs
index dca67aee..ab0f42a9 100644
--- a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore/Microsoft/AspNetCore/Middlewares/ApiInfoMiddleware.cs
+++ b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore/Microsoft/AspNetCore/Middlewares/ApiInfoMiddleware.cs
@@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Json;
+using Yi.Framework.Core.Extensions;
+using static System.Net.WebRequestMethods;
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)
{
+ 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);
+
+
+
}
}
}
diff --git a/Yi.Abp.Net8/framework/Yi.Framework.Ddd.Application/YiCrudAppService.cs b/Yi.Abp.Net8/framework/Yi.Framework.Ddd.Application/YiCrudAppService.cs
index 4a7f56dc..21e409b9 100644
--- a/Yi.Abp.Net8/framework/Yi.Framework.Ddd.Application/YiCrudAppService.cs
+++ b/Yi.Abp.Net8/framework/Yi.Framework.Ddd.Application/YiCrudAppService.cs
@@ -1,16 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc;
+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;
-using Volo.Abp.Validation;
namespace Yi.Framework.Ddd.Application
{
@@ -65,6 +59,11 @@ namespace Yi.Framework.Ddd.Application
{
}
+ ///
+ /// 多查
+ ///
+ ///
+ ///
public override async Task> GetListAsync(TGetListInput input)
{
List? entites = null;
@@ -84,7 +83,7 @@ namespace Yi.Framework.Ddd.Application
}
///
- /// 偷梁换柱
+ /// 多删
///
///
///
@@ -93,6 +92,12 @@ namespace Yi.Framework.Ddd.Application
{
await Repository.DeleteManyAsync(id);
}
+
+ ///
+ /// 偷梁换柱
+ ///
+ ///
+ ///
[RemoteService(isEnabled: false)]
public override Task DeleteAsync(TKey id)
{
@@ -100,8 +105,11 @@ namespace Yi.Framework.Ddd.Application
}
-
-
+ ///
+ /// 导出excel
+ ///
+ ///
+ ///
public virtual async Task GetExportExcelAsync(TGetListInput input)
{
if (input is IPagedResultRequest paged)
@@ -112,20 +120,28 @@ namespace Yi.Framework.Ddd.Application
var output = await this.GetListAsync(input);
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))
{
Directory.CreateDirectory(dirPath);
}
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()
+ ///
+ /// 导入excle
+ ///
+ ///
+ ///
+ public virtual async Task PostImportExcelAsync(List input)
{
-
-
+ var entities = input.Select(x => MapToEntity(x)).ToList();
+ await Repository.DeleteManyAsync(entities.Select(x => x.Id));
+ await Repository.InsertManyAsync(entities);
}
}
}
diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RoleService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RoleService.cs
index 9c1c1ae3..da59fbd2 100644
--- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RoleService.cs
+++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RoleService.cs
@@ -34,7 +34,7 @@ namespace Yi.Framework.Rbac.Application.Services
private ISqlSugarRepository _roleDeptRepository;
private ISqlSugarRepository _userRoleRepository;
- [UnitOfWork]
+
public async Task UpdateDataScpoceAsync(UpdateDataScpoceInput input)
{
//只有自定义的需要特殊处理
@@ -66,7 +66,6 @@ namespace Yi.Framework.Rbac.Application.Services
///
///
///
- [UnitOfWork]
public override async Task CreateAsync(RoleCreateInputVo input)
{
RoleGetOutputDto outputDto;
@@ -88,7 +87,6 @@ namespace Yi.Framework.Rbac.Application.Services
///
///
///
- [UnitOfWork]
public override async Task UpdateAsync(Guid id, RoleUpdateInputVo input)
{
var dto = new RoleGetOutputDto();
diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/UserService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/UserService.cs
index a8f3bf8c..c89dc26b 100644
--- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/UserService.cs
+++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/UserService.cs
@@ -3,7 +3,6 @@ using SqlSugar;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.EventBus.Local;
-using Volo.Abp.Uow;
using Volo.Abp.Users;
using Yi.Framework.Ddd.Application;
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
@@ -82,7 +81,7 @@ namespace Yi.Framework.Rbac.Application.Services
///
///
[OperLog("添加用户", OperEnum.Insert)]
- [UnitOfWork]
+ [Permission("system:user:add")]
public async override Task CreateAsync(UserCreateInputVo input)
{
if (string.IsNullOrEmpty(input.Password))
@@ -131,7 +130,7 @@ namespace Yi.Framework.Rbac.Application.Services
///
///
[OperLog("更新用户", OperEnum.Update)]
- [UnitOfWork]
+ [Permission("system:user:update")]
public async override Task UpdateAsync(Guid id, UserUpdateInputVo input)
{
if (await _repository.IsAnyAsync(u => input.UserName!.Equals(u.UserName) && !id.Equals(u.Id)))
@@ -180,6 +179,7 @@ namespace Yi.Framework.Rbac.Application.Services
///
[Route("user/{id}/{state}")]
[OperLog("更新用户状态", OperEnum.Update)]
+ [Permission("system:user:update")]
public async Task UpdateStateAsync([FromRoute] Guid id, [FromRoute] bool state)
{
var entity = await _repository.GetByIdAsync(id);
@@ -197,5 +197,17 @@ namespace Yi.Framework.Rbac.Application.Services
{
await base.DeleteAsync(id);
}
+
+ [Permission("system:user:export")]
+ public override Task GetExportExcelAsync(UserGetListInputVo input)
+ {
+ return base.GetExportExcelAsync(input);
+ }
+
+ [Permission("system:user:import")]
+ public override Task PostImportExcelAsync(List input)
+ {
+ return base.PostImportExcelAsync(input);
+ }
}
}
diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/Yi.Abp.Web.csproj b/Yi.Abp.Net8/src/Yi.Abp.Web/Yi.Abp.Web.csproj
index f8c4237c..73a70593 100644
--- a/Yi.Abp.Net8/src/Yi.Abp.Web/Yi.Abp.Web.csproj
+++ b/Yi.Abp.Net8/src/Yi.Abp.Web/Yi.Abp.Web.csproj
@@ -39,7 +39,6 @@
-
diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs
index 13dc515b..c8633dae 100644
--- a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs
+++ b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs
@@ -153,7 +153,10 @@ namespace Yi.Abp.Web
//swagger
app.UseYiSwagger();
-
+
+ //请求处理
+ app.UseYiApiHandlinge();
+
//静态资源
app.UseStaticFiles("/api/app/wwwroot");
app.UseDefaultFiles();