部分功能导出Excel新增忽略列

This commit is contained in:
不做码农 2021-12-04 13:15:57 +08:00
parent 13c08eac52
commit c46d5015d2
12 changed files with 55 additions and 67 deletions

View File

@ -9,6 +9,8 @@ using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using ZR.Admin.WebApi.Filters;
namespace ZR.Admin.WebApi.Controllers
@ -120,13 +122,13 @@ namespace ZR.Admin.WebApi.Controllers
//调试模式需要加上
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
Directory.CreateDirectory(Path.GetDirectoryName(newFileName));
using (ExcelPackage package = new ExcelPackage(new FileInfo(newFileName)))
using (ExcelPackage package = new(new FileInfo(newFileName)))
{
// 添加worksheet
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(sheetName);
//全部字段导出
worksheet.Cells.LoadFromCollection(list, true);
worksheet.Cells.LoadFromCollection(list, true, OfficeOpenXml.Table.TableStyles.Light13);
package.Save();
}

View File

@ -218,48 +218,10 @@ namespace ZR.Admin.WebApi.Controllers.System
[ActionPermissionFilter(Permission = "system:user:export")]
public IActionResult UserExport([FromQuery] SysUser user)
{
string sFileName = $"用户列表{DateTime.Now:yyyyMMddHHmmss}.xlsx";
string newFileName = Path.Combine(WebHostEnvironment.WebRootPath, "export", sFileName);
var list = UserService.SelectUserList(user, new PagerInfo(1, 10000));
//调试模式需要加上
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
Directory.CreateDirectory(Path.GetDirectoryName(newFileName));
using (ExcelPackage package = new ExcelPackage(new FileInfo(newFileName)))
{
// 添加worksheet
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("sysuser");
#region
//添加头
//worksheet.Cells[1, 1].Value = "用户id";
//worksheet.Cells[1, 2].Value = "用户名称";
//worksheet.Cells[1, 3].Value = "用户昵称";
//worksheet.Cells[1, 4].Value = "部门";
//worksheet.Cells[1, 5].Value = "手机号码";
//worksheet.Cells[1, 6].Value = "性别";
//worksheet.Cells[1, 7].Value = "状态";
//worksheet.Cells[1, 8].Value = "添加时间";
//worksheet.Cells[1, 9].Value = "登录IP";
//worksheet.Cells[1, 10].Value = "最后登录时间";
//for (int i = 0; i < list.Count; i++)
//{
// var item = list[i];
// //worksheet.Cells[i + 2, 1].Value = item.UserId;
// //worksheet.Cells[i + 2, 2].Value = item.UserName;
// //worksheet.Cells[i + 2, 3].Value = item.NickName;
// //worksheet.Cells[i + 2, 4].Value = item.DeptName;
// //worksheet.Cells[i + 2, 5].Value = item.Phonenumber;
// //worksheet.Cells[i + 2, 6].Value = item.Sex;
// //worksheet.Cells[i + 2, 7].Value = item.Status;
// //worksheet.Cells[i + 2, 8].Value = item.Create_time.ToString();
// //worksheet.Cells[i + 2, 9].Value = item.LoginIP;
// //worksheet.Cells[i + 2, 10].Value = item.LoginDate.ToString();
//}
#endregion
//全部字段导出
worksheet.Cells.LoadFromCollection(list, true);
package.Save();
}
string sFileName = ExportExcel(list, "user", "用户列表");
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
}
}

View File

@ -4,27 +4,33 @@ using System;
using System.Collections.Generic;
using System.Text;
using SqlSugar;
using OfficeOpenXml.Attributes;
namespace ZR.Model.System
{
[EpplusTable(PrintHeaders = true, AutofitColumns = true, AutoCalculate = true, ShowTotal = true)]
public class SysBase
{
[SugarColumn(IsOnlyIgnoreUpdate = true)]//设置后修改不会有此字段
[JsonProperty(propertyName: "CreateBy")]
[EpplusIgnore]
public string Create_by { get; set; }
[SugarColumn(IsOnlyIgnoreUpdate = true)]//设置后修改不会有此字段
[JsonProperty(propertyName: "CreateTime")]
[EpplusTableColumn(NumberFormat = "yyyy-MM-dd HH:mm:ss")]
public DateTime Create_time { get; set; } = DateTime.Now;
[JsonIgnore]
[JsonProperty(propertyName: "UpdateBy")]
[SugarColumn(IsOnlyIgnoreInsert = true)]
[EpplusIgnore]
public string Update_by { get; set; }
//[JsonIgnore]
[SugarColumn(IsOnlyIgnoreInsert = true)]//设置后插入数据不会有此字段
[JsonProperty(propertyName: "UpdateTime")]
[EpplusIgnore]
public DateTime? Update_time { get; set; }
public string Remark { get; set; }
@ -40,6 +46,7 @@ namespace ZR.Model.System
/// </summary>
[SugarColumn(IsIgnore = true)]
[JsonIgnore]
[EpplusIgnore]
public DateTime? BeginTime { get; set; }
/// <summary>
@ -47,6 +54,7 @@ namespace ZR.Model.System
/// </summary>
[SugarColumn(IsIgnore = true)]
[JsonIgnore]
[EpplusIgnore]
public DateTime? EndTime { get; set; }
}
}

View File

@ -1,8 +1,5 @@
//using Dapper.Contrib.Extensions;
using OfficeOpenXml.Attributes;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace ZR.Model.System
{
@ -30,6 +27,7 @@ namespace ZR.Model.System
/// <summary>
/// 状态 0、正常 1、停用
/// </summary>
[EpplusIgnore]
public string Status { get; set; }
}
}

View File

@ -1,4 +1,5 @@
//using Dapper.Contrib.Extensions;
using OfficeOpenXml.Attributes;
using SqlSugar;
using System;
@ -52,6 +53,7 @@ namespace ZR.Model.System
/// <summary>
/// 访问时间
/// </summary>
[EpplusTableColumn(NumberFormat = "yyyy-MM-dd HH:mm:ss")]
public DateTime loginTime { get; set; } = DateTime.Now;
}
}

View File

@ -3,6 +3,7 @@ using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using OfficeOpenXml.Attributes;
namespace ZR.Model.System
{
@ -26,11 +27,11 @@ namespace ZR.Model.System
/** 请求方法 */
//@Excel(name = "请求方法")
public String method { get; set; }
public string method { get; set; }
/** 请求方式 */
//@Excel(name = "请求方式")
public String requestMethod { get; set; }
public string requestMethod { get; set; }
/** 操作类别0其它 1后台用户 2手机端用户 */
//@Excel(name = "操作类别", readConverterExp = "0=其它,1=后台用户,2=手机端用户")
@ -38,31 +39,31 @@ namespace ZR.Model.System
/** 操作人员 */
//@Excel(name = "操作人员")
public String operName { get; set; }
public string operName { get; set; }
/** 部门名称 */
//@Excel(name = "部门名称")
public String deptName { get; set; }
public string deptName { get; set; }
/** 请求url */
//@Excel(name = "请求地址")
public String operUrl { get; set; }
public string operUrl { get; set; }
/** 操作地址 */
//@Excel(name = "操作地址")
public String operIp { get; set; }
public string operIp { get; set; }
/** 操作地点 */
//@Excel(name = "操作地点")
public String operLocation { get; set; }
public string operLocation { get; set; }
/** 请求参数 */
//@Excel(name = "请求参数")
public String operParam { get; set; }
public string operParam { get; set; }
/** 返回参数 */
//@Excel(name = "返回参数")
public String jsonResult { get; set; }
public string jsonResult { get; set; }
/** 操作状态0正常 1异常 */
//@Excel(name = "状态", readConverterExp = "0=正常,1=异常")
@ -70,13 +71,14 @@ namespace ZR.Model.System
/** 错误消息 */
//@Excel(name = "错误消息")
public String errorMsg { get; set; }
public string errorMsg { get; set; }
/** 操作时间 */
//@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
//[DataType]
[JsonConverter(typeof(JsonDateConverter))]
[EpplusTableColumn(NumberFormat = "yyyy-MM-dd HH:mm:ss")]
public DateTime? operTime { get; set; }
/// <summary>
/// 操作用时

View File

@ -1,19 +1,22 @@
using SqlSugar;
using OfficeOpenXml.Attributes;
using SqlSugar;
namespace ZR.Model.System
{
[SugarTable("sys_post")]
[Tenant("0")]
public class SysPost: SysBase
public class SysPost : SysBase
{
/// <summary>
/// 岗位Id
/// </summary>
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public long PostId { get; set; }
public string PostCode { get; set; }
public string PostName { get; set; }
[EpplusIgnore]
public int PostSort { get; set; }
[EpplusIgnore]
public string Status { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using SqlSugar;
using OfficeOpenXml.Attributes;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
@ -15,7 +16,7 @@ namespace ZR.Model.System
/// <summary>
/// 日志Id
/// </summary>
[SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public long JobLogId { get; set; }
/// <summary>
/// 任务Id
@ -39,6 +40,8 @@ namespace ZR.Model.System
/// 调用目标字符串
/// </summary>
public string InvokeTarget { get; set; }
[EpplusTableColumn(NumberFormat = "yyyy-MM-dd HH:mm:ss")]
public DateTime CreateTime { get; set; }
/// <summary>
/// 执行用时,毫秒

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json;
using OfficeOpenXml.Attributes;
using SqlSugar;
using System;
using System.Collections.Generic;
@ -29,12 +30,13 @@ namespace ZR.Model.System
//[JsonProperty(propertyName: "userType")]
//public string User_type { get; set; } = "";
[SugarColumn(IsOnlyIgnoreInsert = true)]
[EpplusIgnore]
public string Avatar { get; set; }
public string Email { get; set; }
[JsonIgnore]
//[ColName("用户密码")]
[EpplusIgnore]
public string Password { get; set; }
//[ColName("手机号")]
@ -48,6 +50,7 @@ namespace ZR.Model.System
/// <summary>
/// 帐号状态0正常 1停用
/// </summary>
[EpplusIgnore]
public string Status { get; set; }
/// <summary>
@ -66,6 +69,7 @@ namespace ZR.Model.System
/// 最后登录时间
/// </summary>
[SugarColumn(IsOnlyIgnoreInsert = true)]
[EpplusTableColumn(NumberFormat = "yyyy-MM-dd HH:mm:ss")]
public DateTime LoginDate { get; set; }
/// <summary>
@ -94,14 +98,17 @@ namespace ZR.Model.System
/// 角色id集合
/// </summary>
[SugarColumn(IsIgnore = true)]
[EpplusIgnore]
public int[] RoleIds { get; set; }
/// <summary>
/// 岗位集合
/// </summary>
[SugarColumn(IsIgnore = true)]
[EpplusIgnore]
public int[] PostIds { get; set; }
[SugarColumn(IsIgnore = true)]
[EpplusIgnore]
public List<SysRole> Roles { get; set; }
#endregion

View File

@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EPPlus" Version="5.8.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.0.4.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />

View File

@ -16,11 +16,11 @@ namespace ZR.Service.System
/// 代码生成表
/// </summary>
[AppService(ServiceType = typeof(IGenTableService), ServiceLifetime = LifeTime.Transient)]
public class GenTableService : IGenTableService
public class GenTableService : BaseService<GenTable>, IGenTableService
{
private GenTableRepository GenTableRepository;
private IGenTableColumnService GenTableColumnService;
public GenTableService(IGenTableColumnService genTableColumnService, GenTableRepository genTableRepository)
public GenTableService(IGenTableColumnService genTableColumnService, GenTableRepository genTableRepository) : base(genTableRepository)
{
GenTableColumnService = genTableColumnService;
GenTableRepository = genTableRepository;
@ -127,11 +127,11 @@ namespace ZR.Service.System
/// 代码生成表列
/// </summary>
[AppService(ServiceType = typeof(IGenTableColumnService), ServiceLifetime = LifeTime.Transient)]
public class GenTableColumnService : IGenTableColumnService
public class GenTableColumnService : BaseService<GenTableColumn>, IGenTableColumnService
{
private GenTableColumnRepository GetTableColumnRepository;
public GenTableColumnService(GenTableColumnRepository genTableColumnRepository)
public GenTableColumnService(GenTableColumnRepository genTableColumnRepository) : base(genTableColumnRepository)
{
GetTableColumnRepository = genTableColumnRepository;
}

View File

@ -4,7 +4,7 @@ using ZR.Model.System.Generate;
namespace ZR.Service.System.IService
{
public interface IGenTableService
public interface IGenTableService: IBaseService<GenTable>
{
List<GenTable> SelectDbTableListByNamess(string[] tableNames);
@ -17,7 +17,7 @@ namespace ZR.Service.System.IService
int UpdateGenTable(GenTable genTable);
}
public interface IGenTableColumnService
public interface IGenTableColumnService: IBaseService<GenTableColumn>
{
int InsertGenTableColumn(List<GenTableColumn> tableColumn);