新增加用户导入、Excel通用导入方法封装
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -8,7 +9,9 @@ using OfficeOpenXml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service;
|
||||
@@ -170,43 +173,37 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
return ToResponse(ToJson(result));
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 导入 ok
|
||||
///// </summary>
|
||||
///// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
||||
///// <returns></returns>
|
||||
//[HttpPost("importData")]
|
||||
//[Log(Title = "用户导入", BusinessType = BusinessType.IMPORT)]
|
||||
//[ActionPermissionFilter(Permission = "system:user:import")]
|
||||
//public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||||
//{
|
||||
// var mapper = new Mapper(formFile.OpenReadStream());// 从流获取
|
||||
// //读取的sheet信息
|
||||
// var rows = mapper.Take<SysUser>(0);
|
||||
// foreach (var item in rows)
|
||||
// {
|
||||
// SysUser u = item.Value;
|
||||
// }
|
||||
// //TODO 业务逻辑
|
||||
// return SUCCESS(1);
|
||||
//}
|
||||
/// <summary>
|
||||
/// 导入
|
||||
/// </summary>
|
||||
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("importData")]
|
||||
[Log(Title = "用户导入", BusinessType = BusinessType.IMPORT)]
|
||||
[ActionPermissionFilter(Permission = "system:user:import")]
|
||||
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||||
{
|
||||
IEnumerable<SysUser> users = ExcelHelper<SysUser>.ImportData(formFile.OpenReadStream());
|
||||
|
||||
///// <summary>
|
||||
///// 用户模板 ok
|
||||
///// </summary>
|
||||
///// <returns></returns>
|
||||
//[HttpGet("importTemplate")]
|
||||
//[Log(Title = "用户模板", BusinessType = BusinessType.EXPORT)]
|
||||
//[ActionPermissionFilter(Permission = "system:user:export")]
|
||||
//public IActionResult ImportTemplateExcel()
|
||||
//{
|
||||
// List<SysUser> user = new List<SysUser>();
|
||||
// var mapper = new Mapper();
|
||||
// MemoryStream stream = new MemoryStream();
|
||||
// mapper.Save(stream, user, "sheel1", overwrite: true, xlsx: true);
|
||||
// //Response.Headers.Append("content-disposition", "attachment;filename=sysUser.xlsx");
|
||||
// return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "sysUser.xlsx");
|
||||
//}
|
||||
//TODO 业务逻辑,自行插入数据到db
|
||||
return SUCCESS(users);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户导入模板下载
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("importTemplate")]
|
||||
[Log(Title = "用户模板", BusinessType = BusinessType.EXPORT)]
|
||||
[AllowAnonymous]
|
||||
public IActionResult ImportTemplateExcel()
|
||||
{
|
||||
List<SysUser> user = new List<SysUser>();
|
||||
MemoryStream stream = new MemoryStream();
|
||||
|
||||
string sFileName = DownloadImportTemplate(user, stream, "用户列表");
|
||||
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{sFileName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户导出
|
||||
|
||||
Reference in New Issue
Block a user