Browse Source

主从的个性化导出

master
郑渤旭[Irelia] 1 year ago
parent
commit
4dcbcd0b81
  1. 36
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application/AppBase/ZbxBase.cs

36
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application/AppBase/ZbxBase.cs

@ -17,6 +17,7 @@ using Faster.Zheng.Winin.Localization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using NPOI.POIFS.Macros;
using NPOI.SS.Formula.Functions; using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
@ -295,23 +296,18 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
var mainAllProperties = typeof(TEntityDto).GetProperties(); var mainAllProperties = typeof(TEntityDto).GetProperties();
var mainProperties= mainAllProperties.Where(p=>p.Name!= "Details").ToArray();//去除details属性否则导出时会带出来 var mainProperties= mainAllProperties.Where(p=>p.Name!= "Details").ToArray();//去除details属性否则导出时会带出来
#region 用户个性导出 #region 用户个性导出 主表
//获取个导出的字段 //获取个导出的字段
var show = await _exportCustomUserSettingAppService.GetByUserIdAndExportTableNameAsync(userId, typeof(TEntity).Name); var mainUserColumn = await _exportCustomUserSettingAppService.GetByUserIdAndExportTableNameAsync(userId, typeof(TEntity).Name);
var notShowUserColumn = show.Where(p => p.CustomUserSetting == Enum_ExportCustomUserSetting.No).Select(p => p.ExportColumnName).ToList(); var mainNotShowUserColumn = mainUserColumn.Where(p => p.CustomUserSetting == Enum_ExportCustomUserSetting.No).Select(p => p.ExportColumnName).ToList();
if (show.Count == 0) if (mainUserColumn.Any())
{ {
//如果没有就都导出 mainProperties = mainProperties.Where(p => !mainNotShowUserColumn.Contains(p.Name)).ToArray();
}
else
{
mainProperties = mainProperties.Where(p =>!notShowUserColumn.Contains(p.Name)).ToArray();//去除details属性否则导出时会带出来
} }
#endregion #endregion
IRow headerRow = sheet.CreateRow(0); IRow headerRow = sheet.CreateRow(0);
for (int i = 0; i < mainProperties.Length; i++) for (int i = 0; i < mainProperties.Length; i++)
{ {
@ -323,6 +319,9 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
// 获取从表的属性 创建从表 表头 // 获取从表的属性 创建从表 表头
var detailProperties = typeof(TEntityDto).GetProperty("Details")?.PropertyType.GetGenericArguments()[0].GetProperties(); var detailProperties = typeof(TEntityDto).GetProperty("Details")?.PropertyType.GetGenericArguments()[0].GetProperties();
#region 用户个性导出 主表
#endregion
if (detailProperties != null) if (detailProperties != null)
{ {
isHasDetail = true; isHasDetail = true;
@ -334,6 +333,21 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
if (isHasDetail) if (isHasDetail)
{ {
headerRow.CreateCell(mainProperties.Length ).SetCellValue("---分割---"); headerRow.CreateCell(mainProperties.Length ).SetCellValue("---分割---");
#region 用户个性导出 从表
//获取个性导出的字段
var detailDtoName = mainAllProperties.First(p => p.Name == "Details");
var detailUserColumn = await _exportCustomUserSettingAppService.GetByUserIdAndExportTableNameAsync(
userId, detailDtoName.PropertyType.GenericTypeArguments.First().Name.Replace("Dto", ""));
var detailNotShowUserColumn = detailUserColumn.Where(p => p.CustomUserSetting == Enum_ExportCustomUserSetting.No).Select(p => p.ExportColumnName).ToList();
if (detailUserColumn.Any())
{
detailProperties = detailProperties.Where(p => !detailNotShowUserColumn.Contains(p.Name)).ToArray();
}
#endregion
for (int i = 0; i < detailProperties.Length; i++) for (int i = 0; i < detailProperties.Length; i++)
{ {
headerRow.CreateCell(mainProperties.Length + splitDetailsColumnNumber + i) headerRow.CreateCell(mainProperties.Length + splitDetailsColumnNumber + i)

Loading…
Cancel
Save