diff --git a/Learn.Archives.API/Controllers/StudentController.cs b/Learn.Archives.API/Controllers/StudentController.cs index 0ed1d5a..616ffb8 100644 --- a/Learn.Archives.API/Controllers/StudentController.cs +++ b/Learn.Archives.API/Controllers/StudentController.cs @@ -261,19 +261,8 @@ namespace Learn.Archives.API.Controllers [HttpLogEnable] public async Task Import(IFormFile? file) { - - var fl = file != null ? file : _httpContextAccessor.HttpContext?.Request.Form.Files[0]; - if (fl == null) Oh.ModelError("传入无效的数据"); - if (!Path.GetExtension(fl.FileName).Equals(".xlsx", StringComparison.OrdinalIgnoreCase)) - Oh.ModelError("请选择导入文件为.xlsx的后缀名!"); - //分析excel - IEnumerable dataList; - using var stream = new MemoryStream(); - { - await fl.CopyToAsync(stream); - dataList = stream.Query() - .Where(s => !string.IsNullOrEmpty(s.School)); - } + var dataList = await _httpContextAccessor.ParsingExcelAsync(); + dataList = dataList.Where(s => !string.IsNullOrEmpty(s.School)).ToArray(); if (dataList == null || dataList.Count() == 0) Oh.ModelError("导入失败:无有效数据"); var insertInfo = new List();