|
@ -33,8 +33,6 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
where TEntityDto : IEntityDto<TKey> |
|
|
where TEntityDto : IEntityDto<TKey> |
|
|
{ |
|
|
{ |
|
|
private readonly IRepository<TEntity, TKey> _repository; |
|
|
private readonly IRepository<TEntity, TKey> _repository; |
|
|
private readonly IMapper _mapper; |
|
|
|
|
|
private Func<TCreateInput, Entity> _mapFunc; |
|
|
|
|
|
|
|
|
|
|
|
protected IStringLocalizer<WininResource> _localizer => |
|
|
protected IStringLocalizer<WininResource> _localizer => |
|
|
LazyServiceProvider.LazyGetRequiredService<IStringLocalizer<WininResource>>(); |
|
|
LazyServiceProvider.LazyGetRequiredService<IStringLocalizer<WininResource>>(); |
|
@ -42,7 +40,6 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
protected ExportCustomUserSettingAppService _exportCustomUserSettingAppService => |
|
|
protected ExportCustomUserSettingAppService _exportCustomUserSettingAppService => |
|
|
LazyServiceProvider.LazyGetRequiredService<ExportCustomUserSettingAppService>(); |
|
|
LazyServiceProvider.LazyGetRequiredService<ExportCustomUserSettingAppService>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ZbxBase(IRepository<TEntity, TKey> repository) : base(repository) |
|
|
public ZbxBase(IRepository<TEntity, TKey> repository) : base(repository) |
|
|
{ |
|
|
{ |
|
|
_repository = repository; |
|
|
_repository = repository; |
|
@ -61,6 +58,8 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
public async Task<PagedResultDto<TEntityDto>> GetPageListByFilterAsync(SfsRequestInputBase sfsRequestInputBase, |
|
|
public async Task<PagedResultDto<TEntityDto>> GetPageListByFilterAsync(SfsRequestInputBase sfsRequestInputBase, |
|
|
bool includeDetails = false, CancellationToken cancellationToken = default) |
|
|
bool includeDetails = false, CancellationToken cancellationToken = default) |
|
|
{ |
|
|
{ |
|
|
|
|
|
await CheckGetListPolicyAsync(); |
|
|
|
|
|
|
|
|
var expression = sfsRequestInputBase.Condition.Filters?.Count > 0 |
|
|
var expression = sfsRequestInputBase.Condition.Filters?.Count > 0 |
|
|
? sfsRequestInputBase.Condition.Filters.ToLambda<TEntity>() |
|
|
? sfsRequestInputBase.Condition.Filters.ToLambda<TEntity>() |
|
|
: p => true; |
|
|
: p => true; |
|
@ -286,7 +285,10 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
IWorkbook workbook = new XSSFWorkbook(); |
|
|
IWorkbook workbook = new XSSFWorkbook(); |
|
|
var sheet = workbook.CreateSheet(typeof(TEntityDto).Name); |
|
|
var sheet = workbook.CreateSheet(typeof(TEntityDto).Name); |
|
|
var splitDetailsColumnNumber = 1; //分割主表和从表的列数量
|
|
|
var splitDetailsColumnNumber = 1; //分割主表和从表的列数量
|
|
|
var excelDetailsColor = SetExcelDetailsColor(workbook); //字表样式
|
|
|
var excelDetailsCellStyle = SetExcelDetailsCellStyle(workbook); //子表单元格样式
|
|
|
|
|
|
var excelSplitCellStyle = SetSplitCellStyle(workbook); //分割单元格样式
|
|
|
|
|
|
var excelOnlyMainCellStyle = SetExcelOnlyMainCellStyle(workbook); |
|
|
|
|
|
var excelHeadCellStyle = SetExcelHeadCellStyle(workbook); |
|
|
|
|
|
|
|
|
// 获取主表的属性 创建主表 表头
|
|
|
// 获取主表的属性 创建主表 表头
|
|
|
var mainAllProperties = typeof(TEntityDto).GetProperties(); |
|
|
var mainAllProperties = typeof(TEntityDto).GetProperties(); |
|
@ -306,13 +308,15 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
|
|
|
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
var headerRow = sheet.CreateRow(0); |
|
|
var headerRow = sheet.CreateRow(0);//标头列
|
|
|
for (var i = 0; i < mainProperties.Length; i++) |
|
|
for (var i = 0; i < mainProperties.Length; i++) |
|
|
{ |
|
|
{ |
|
|
var englishName = mainProperties[i].Name; |
|
|
var englishName = mainProperties[i].Name; |
|
|
//本地化
|
|
|
//本地化
|
|
|
var localizerName = _localizer[typeof(TEntity).Name + englishName]; |
|
|
var localizerName = _localizer[typeof(TEntity).Name + englishName]; |
|
|
headerRow.CreateCell(i).SetCellValue(localizerName); |
|
|
var headCell = headerRow.CreateCell(i); |
|
|
|
|
|
headCell.SetCellValue(localizerName); |
|
|
|
|
|
headCell.CellStyle = excelHeadCellStyle; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 获取从表的属性 创建从表 表头
|
|
|
// 获取从表的属性 创建从表 表头
|
|
@ -333,7 +337,7 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
|
|
|
|
|
|
if (isHasDetail) |
|
|
if (isHasDetail) |
|
|
{ |
|
|
{ |
|
|
headerRow.CreateCell(mainProperties.Length).SetCellValue("---分割---"); |
|
|
headerRow.CreateCell(mainProperties.Length).SetCellValue("---【分割】---"); |
|
|
|
|
|
|
|
|
#region 用户个性导出 从表
|
|
|
#region 用户个性导出 从表
|
|
|
|
|
|
|
|
@ -356,7 +360,7 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
headerRow.CreateCell(mainProperties.Length + splitDetailsColumnNumber + i) |
|
|
headerRow.CreateCell(mainProperties.Length + splitDetailsColumnNumber + i) |
|
|
.SetCellValue(detailProperties[i].Name); |
|
|
.SetCellValue(detailProperties[i].Name); |
|
|
var headCell = headerRow.GetCell(mainProperties.Length + splitDetailsColumnNumber + i); |
|
|
var headCell = headerRow.GetCell(mainProperties.Length + splitDetailsColumnNumber + i); |
|
|
headCell.CellStyle = excelDetailsColor; |
|
|
headCell.CellStyle = excelHeadCellStyle; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -369,7 +373,7 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
{ |
|
|
{ |
|
|
// 获取从表数据
|
|
|
// 获取从表数据
|
|
|
var detailsIndex = mainAllProperties.FindIndex(p => p.Name == "Details"); |
|
|
var detailsIndex = mainAllProperties.FindIndex(p => p.Name == "Details"); |
|
|
//从表
|
|
|
// 子表
|
|
|
var detailList = (IEnumerable<object>)mainAllProperties[detailsIndex].GetValue(mainDto); |
|
|
var detailList = (IEnumerable<object>)mainAllProperties[detailsIndex].GetValue(mainDto); |
|
|
var startMainRowIndex = rowIndex; |
|
|
var startMainRowIndex = rowIndex; |
|
|
for (var datailCount = 0; datailCount < detailList.Count(); datailCount++) |
|
|
for (var datailCount = 0; datailCount < detailList.Count(); datailCount++) |
|
@ -408,13 +412,17 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
{ |
|
|
{ |
|
|
//填充子表数据
|
|
|
//填充子表数据
|
|
|
var detailRow = sheet.GetRow(startMainRowIndex); |
|
|
var detailRow = sheet.GetRow(startMainRowIndex); |
|
|
|
|
|
|
|
|
|
|
|
var splitCell = detailRow.CreateCell(mainProperties.Length); |
|
|
|
|
|
splitCell.CellStyle = excelSplitCellStyle; |
|
|
|
|
|
|
|
|
for (var i = 0; i < detailProperties.Length; i++) |
|
|
for (var i = 0; i < detailProperties.Length; i++) |
|
|
{ |
|
|
{ |
|
|
var value = detailProperties[i].GetValue(detail); |
|
|
var value = detailProperties[i].GetValue(detail); |
|
|
detailRow.CreateCell(mainProperties.Length + splitDetailsColumnNumber + i) |
|
|
detailRow.CreateCell(mainProperties.Length + splitDetailsColumnNumber + i) |
|
|
.SetCellValue(value?.ToString()); |
|
|
.SetCellValue(value?.ToString()); |
|
|
var detailCell = detailRow.GetCell(mainProperties.Length + splitDetailsColumnNumber + i); |
|
|
var detailCell = detailRow.GetCell(mainProperties.Length + splitDetailsColumnNumber + i); |
|
|
detailCell.CellStyle = excelDetailsColor; |
|
|
detailCell.CellStyle = excelDetailsCellStyle; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -430,6 +438,10 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
var value = mainProperties[i].GetValue(mainDto); |
|
|
var value = mainProperties[i].GetValue(mainDto); |
|
|
dataRow.CreateCell(i).SetCellValue(value?.ToString()); |
|
|
dataRow.CreateCell(i).SetCellValue(value?.ToString()); |
|
|
} |
|
|
} |
|
|
|
|
|
if (rowIndex % 2 == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
dataRow.RowStyle = excelOnlyMainCellStyle; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//添加1个空行将2条数据分割开
|
|
|
//添加1个空行将2条数据分割开
|
|
@ -441,9 +453,11 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
if (isHasDetail) |
|
|
if (isHasDetail) |
|
|
{ |
|
|
{ |
|
|
// 自动调整列宽
|
|
|
// 自动调整列宽
|
|
|
for (var i = 0; i < mainProperties.Length + detailProperties.Length; i++) |
|
|
for (var i = 0; i < mainProperties.Length + splitDetailsColumnNumber + detailProperties.Length; i++) |
|
|
{ |
|
|
{ |
|
|
sheet.AutoSizeColumn(i + splitDetailsColumnNumber); |
|
|
sheet.AutoSizeColumn(i); |
|
|
|
|
|
sheet.SetColumnWidth(i, Math.Max(sheet.GetColumnWidth(i) + 150, 265 * 15)); |
|
|
|
|
|
sheet.SetColumnWidth(mainProperties.Length, 3600); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
@ -452,6 +466,7 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
for (var i = 0; i < mainProperties.Length; i++) |
|
|
for (var i = 0; i < mainProperties.Length; i++) |
|
|
{ |
|
|
{ |
|
|
sheet.AutoSizeColumn(i); |
|
|
sheet.AutoSizeColumn(i); |
|
|
|
|
|
sheet.SetColumnWidth(i, Math.Max(sheet.GetColumnWidth(i) + 150, 265 * 15)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -491,6 +506,7 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
bool includeDetails = false, CancellationToken cancellationToken = default) |
|
|
bool includeDetails = false, CancellationToken cancellationToken = default) |
|
|
{ |
|
|
{ |
|
|
var query = await Repository.WithDetailsAsync(); |
|
|
var query = await Repository.WithDetailsAsync(); |
|
|
|
|
|
//var query = await Repository.GetQueryableAsync();
|
|
|
|
|
|
|
|
|
var entities = query.Where(expression); |
|
|
var entities = query.Where(expression); |
|
|
entities = GetSortingQueryable(entities, sorting); |
|
|
entities = GetSortingQueryable(entities, sorting); |
|
@ -549,7 +565,53 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="workbook"></param>
|
|
|
/// <param name="workbook"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
private static ICellStyle SetExcelDetailsColor(IWorkbook workbook) |
|
|
private static ICellStyle SetExcelDetailsCellStyle(IWorkbook workbook) |
|
|
|
|
|
{ |
|
|
|
|
|
var cellStyle = workbook.CreateCellStyle(); |
|
|
|
|
|
cellStyle.FillBackgroundColor = IndexedColors.Grey25Percent.Index; |
|
|
|
|
|
cellStyle.FillForegroundColor = IndexedColors.Grey25Percent.Index; |
|
|
|
|
|
cellStyle.FillPattern = FillPattern.SolidForeground; |
|
|
|
|
|
return cellStyle; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 导出设置只有主表时的交替行 单元格样式
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="workbook"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private static ICellStyle SetExcelOnlyMainCellStyle(IWorkbook workbook) |
|
|
|
|
|
{ |
|
|
|
|
|
var cellStyle = workbook.CreateCellStyle(); |
|
|
|
|
|
cellStyle.FillBackgroundColor = IndexedColors.Grey25Percent.Index; |
|
|
|
|
|
cellStyle.FillForegroundColor = IndexedColors.Grey25Percent.Index; |
|
|
|
|
|
cellStyle.FillPattern = FillPattern.SolidForeground; |
|
|
|
|
|
return cellStyle; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置分割单元格的演示
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="workbook"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private static ICellStyle SetSplitCellStyle(IWorkbook workbook) |
|
|
|
|
|
{ |
|
|
|
|
|
var cellStyle = workbook.CreateCellStyle(); |
|
|
|
|
|
cellStyle.BorderLeft = BorderStyle.MediumDashed; |
|
|
|
|
|
cellStyle.BorderRight = BorderStyle.MediumDashed; |
|
|
|
|
|
cellStyle.LeftBorderColor = IndexedColors.BrightGreen.Index; |
|
|
|
|
|
cellStyle.RightBorderColor = IndexedColors.Grey25Percent.Index; |
|
|
|
|
|
cellStyle.FillBackgroundColor = IndexedColors.White.Index; |
|
|
|
|
|
cellStyle.FillForegroundColor = IndexedColors.White.Index; |
|
|
|
|
|
cellStyle.FillPattern = FillPattern.ThickVerticalBands; |
|
|
|
|
|
return cellStyle; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 导出设置表头单元格样式
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="workbook"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private static ICellStyle SetExcelHeadCellStyle(IWorkbook workbook) |
|
|
{ |
|
|
{ |
|
|
var cellStyle = workbook.CreateCellStyle(); |
|
|
var cellStyle = workbook.CreateCellStyle(); |
|
|
cellStyle.FillBackgroundColor = IndexedColors.LightOrange.Index; |
|
|
cellStyle.FillBackgroundColor = IndexedColors.LightOrange.Index; |
|
@ -559,4 +621,5 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
} |
|
|
} |
|
|
} |