From 4796a494de1a7901a479dfee86391eb6b04ad693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= Date: Wed, 28 Sep 2022 16:54:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=85=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/UserController.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index 376c3be0..abd465df 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -75,14 +75,19 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// [HttpGet] [AllowAnonymous] - public async Task Import() + public async Task Import([FromForm(Name = "file")] IFormFile formFile) { - throw null; - //var users = await _iUserService._repository.GetListAsync(); - //var fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + nameof(UserEntity) + PathConst.DataExport; - //var path = ExcelHelper.ExportExcel(users, fileName, Path.Combine(PathConst.wwwroot, PathEnum.Temp.ToString())); - //var file = System.IO.File.OpenRead(path); - //return File(file, "text/plain", $"{ fileName }.xlsx"); + List users = ExcelHelper.ImportData(formFile.OpenReadStream()); + + var _repository = _iUserService._repository; + + //全量删除在重新插入 + var res = await _repository.UseTranAsync(async () => + { + await _repository.DeleteAsync(u => true); + await _repository.InsertRangeAsync(users); + }); + return Result.Success().SetStatus(res); } ///