|
@@ -3,9 +3,12 @@ using Aspose.Cells;
|
|
|
using Aspose.Words;
|
|
|
using Aspose.Words.Layout;
|
|
|
using Aspose.Words.Saving;
|
|
|
+using Aspose.Words.Tables;
|
|
|
+using Dm.util;
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
using Microsoft.International.Converters.PinYinConverter;
|
|
|
using NodaTime;
|
|
|
+using NPOI.OpenXmlFormats.Vml;
|
|
|
using OASystem.API.OAMethodLib.File;
|
|
|
using OASystem.API.OAMethodLib.Hub.HubClients;
|
|
|
using OASystem.API.OAMethodLib.Hub.Hubs;
|
|
@@ -20,6 +23,7 @@ using OASystem.Domain.Entities.Groups;
|
|
|
using OASystem.Domain.ViewModels.Financial;
|
|
|
using OASystem.Domain.ViewModels.Groups;
|
|
|
using OASystem.Domain.ViewModels.JuHeExchangeRate;
|
|
|
+using OASystem.Domain.ViewModels.Statistics;
|
|
|
using OASystem.Infrastructure.Repositories.CRM;
|
|
|
using OASystem.Infrastructure.Repositories.Groups;
|
|
|
using System.Data;
|
|
@@ -5820,7 +5824,6 @@ namespace OASystem.API.OAMethodLib
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
-
|
|
|
#region Excel导出服务
|
|
|
#region 类
|
|
|
public class FileExportSettings
|
|
@@ -6213,7 +6216,306 @@ namespace OASystem.API.OAMethodLib
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
+ #region 动态构架word表格
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 设置表格样式
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="builder"></param>
|
|
|
+ public static void SetupDocumentStyles(DocumentBuilder builder)
|
|
|
+ {
|
|
|
+ builder.Font.Name = "微软雅黑";
|
|
|
+ builder.Font.Size = 10;
|
|
|
+ builder.ParagraphFormat.SpaceAfter = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 添加标题
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="builder"></param>
|
|
|
+ /// <param name="title"></param>
|
|
|
+ public static void AddTitle(DocumentBuilder builder, string title)
|
|
|
+ {
|
|
|
+ // 主标题
|
|
|
+ builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
|
|
|
+ builder.Font.Size = 16;
|
|
|
+ builder.Font.Bold = true;
|
|
|
+ builder.Font.Color = System.Drawing.Color.DarkBlue;
|
|
|
+ builder.Writeln(title);
|
|
|
+
|
|
|
+ // 空行
|
|
|
+ builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
|
|
|
+ builder.Font.Size = 10;
|
|
|
+ builder.Font.Bold = false;
|
|
|
+ builder.Font.Color = System.Drawing.Color.Black;
|
|
|
+ builder.Writeln();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 生成酒机票表格信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="builder"></param>
|
|
|
+ /// <param name="airInfos"></param>
|
|
|
+ /// <param name="footerText"></param>
|
|
|
+ public static void AddAirInfoSections(DocumentBuilder builder, List<Grp_AirTicketReservations> airInfos, string? footerText)
|
|
|
+ {
|
|
|
+ if (airInfos == null || !airInfos.Any())
|
|
|
+ {
|
|
|
+ builder.Writeln("暂无机票航班信息。");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int airCount = 0;
|
|
|
+ const int maxAirPerPage = 3; // 每页最多显示3个酒店,确保有足够空间
|
|
|
+
|
|
|
+ for (int i = 0; i < airInfos.Count; i++)
|
|
|
+ {
|
|
|
+ var info = airInfos[i];
|
|
|
+
|
|
|
+ // 检查是否需要分页
|
|
|
+ if (airCount > 0 && airCount > maxAirPerPage)
|
|
|
+ {
|
|
|
+ builder.InsertBreak(BreakType.PageBreak);
|
|
|
+ airCount = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ airCount++;
|
|
|
+
|
|
|
+ // 为每个酒店创建详细信息表格
|
|
|
+ CreateAirDetailTable(builder, info);
|
|
|
+
|
|
|
+ // 酒店之间添加间距,但不是最后一个
|
|
|
+ if (i < airInfos.Count() - 1)
|
|
|
+ {
|
|
|
+ AddSpacingBetweenHotels(builder);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否达到每页最大酒店数量
|
|
|
+ if (airCount >= maxAirPerPage && (i < airInfos.Count - 1 || i < airInfos.Count() - 1))
|
|
|
+ {
|
|
|
+ builder.InsertBreak(BreakType.PageBreak);
|
|
|
+ airCount = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(footerText))
|
|
|
+ {
|
|
|
+ AddFooter(builder, footerText);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 生成酒店表格信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="builder"></param>
|
|
|
+ /// <param name="hotelInfos"></param>
|
|
|
+ /// <param name="footerText"></param>
|
|
|
+ public static void AddHotelInfoSections(DocumentBuilder builder, List<Grp_HotelReservations> hotelInfos, string? footerText)
|
|
|
+ {
|
|
|
+ if (hotelInfos == null || !hotelInfos.Any())
|
|
|
+ {
|
|
|
+ builder.Writeln("暂无酒店信息");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int hotelCount = 0;
|
|
|
+ const int maxHotelsPerPage = 3; // 每页最多显示3个酒店,确保有足够空间
|
|
|
+
|
|
|
+ for (int i = 0; i < hotelInfos.Count; i++)
|
|
|
+ {
|
|
|
+ var info = hotelInfos[i];
|
|
|
+
|
|
|
+ // 检查是否需要分页
|
|
|
+ if (hotelCount > 0 && hotelCount > maxHotelsPerPage)
|
|
|
+ {
|
|
|
+ builder.InsertBreak(BreakType.PageBreak);
|
|
|
+ hotelCount = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ hotelCount++;
|
|
|
+
|
|
|
+ AddCityHeader(builder, info.City);
|
|
|
+
|
|
|
+ // 为每个酒店创建详细信息表格
|
|
|
+ CreateHotelDetailTable(builder, info);
|
|
|
+
|
|
|
+ // 酒店之间添加间距,但不是最后一个
|
|
|
+ if (i < hotelInfos.Count() - 1)
|
|
|
+ {
|
|
|
+ AddSpacingBetweenHotels(builder);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否达到每页最大酒店数量
|
|
|
+ if (hotelCount >= maxHotelsPerPage && (i < hotelInfos.Count - 1 || i < hotelInfos.Count() - 1))
|
|
|
+ {
|
|
|
+ builder.InsertBreak(BreakType.PageBreak);
|
|
|
+ hotelCount = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(footerText))
|
|
|
+ {
|
|
|
+ AddFooter(builder, footerText);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void AddSpacingBetweenHotels(DocumentBuilder builder)
|
|
|
+ {
|
|
|
+ builder.Writeln();
|
|
|
+ builder.InsertBreak(BreakType.LineBreak);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void AddCityHeader(DocumentBuilder builder, string cityName)
|
|
|
+ {
|
|
|
+ builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
|
|
|
+ builder.Font.Size = 14;
|
|
|
+ builder.Font.Bold = true;
|
|
|
+ builder.Font.Color = System.Drawing.Color.DarkGreen;
|
|
|
+ builder.Writeln($"城市:{cityName}");
|
|
|
+
|
|
|
+ builder.Font.Size = 10;
|
|
|
+ builder.Font.Bold = false;
|
|
|
+ builder.Font.Color = System.Drawing.Color.Black;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void CreateHotelDetailTable(DocumentBuilder builder, Grp_HotelReservations hotel)
|
|
|
+ {
|
|
|
+ // 设置表格不允许跨页断行,确保整个表格在一页上
|
|
|
+ Table table = builder.StartTable();
|
|
|
+ //table.AllowBreakAcrossPages = false; // 关键设置:不允许表格跨页
|
|
|
+
|
|
|
+ // 设置表格样式
|
|
|
+ ApplyTableStyle(table);
|
|
|
+
|
|
|
+ // 添加酒店基本信息行
|
|
|
+ AddTableRow(builder, "酒店名称", hotel.HotelName ?? "-", true);
|
|
|
+ AddTableRow(builder, "联系电话", hotel.HotelTel ?? "-");
|
|
|
+ AddTableRow(builder, "酒店地址", hotel.HotelAddress ?? "-");
|
|
|
+ AddTableRow(builder, "确认号码", hotel.DetermineNo ?? "-");
|
|
|
+ AddTableRow(builder, "入住日期", hotel.CheckInDate);
|
|
|
+ AddTableRow(builder, "离店日期", hotel.CheckOutDate);
|
|
|
+ AddTableRow(builder, "房间信息", hotel.RoomExplanation ?? "-");
|
|
|
+
|
|
|
+ builder.EndTable();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void CreateAirDetailTable(DocumentBuilder builder, Grp_AirTicketReservations air)
|
|
|
+ {
|
|
|
+ // 设置表格不允许跨页断行,确保整个表格在一页上
|
|
|
+ Table table = builder.StartTable();
|
|
|
+ //table.AllowBreakAcrossPages = false; // 关键设置:不允许表格跨页
|
|
|
+
|
|
|
+ // 设置表格样式
|
|
|
+ ApplyTableStyle(table);
|
|
|
+
|
|
|
+ // 添加酒店基本信息行
|
|
|
+ AddTableRow(builder, "城市(A-B)", air.FlightsCity ?? "-", true);
|
|
|
+ AddTableRow(builder, "航班日期", air.FlightsDate + " " + air.FlightsTime ?? "-");
|
|
|
+ AddTableRow(builder, "机票票号", air.TicketNumber ?? "-");
|
|
|
+ AddTableRow(builder, "航班简述", air.FlightsCode ?? "-");
|
|
|
+ AddTableRow(builder, "航班描述", air.FlightsDescription);
|
|
|
+
|
|
|
+ builder.EndTable();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static void AddTableRow(DocumentBuilder builder, string title, string value, bool isHeaderRow = false)
|
|
|
+ {
|
|
|
+ // 左边单元格 - 标题
|
|
|
+ builder.InsertCell();
|
|
|
+ //builder.CellFormat.BackColor = isHeaderRow ? System.Drawing.Color.LightBlue : System.Drawing.Color.LightGray;
|
|
|
+ builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
|
|
|
+ builder.CellFormat.Width = 60;
|
|
|
+ builder.Font.Bold = true;
|
|
|
+ builder.Font.Size = isHeaderRow ? 12 : 10;
|
|
|
+ builder.Font.Color = isHeaderRow ? System.Drawing.Color.DarkBlue : System.Drawing.Color.Black;
|
|
|
+ builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
|
|
|
+ builder.Write(title);
|
|
|
+
|
|
|
+ // 右边单元格 - 值
|
|
|
+ builder.InsertCell();
|
|
|
+ //builder.CellFormat.BackColor = System.Drawing.Color.White;
|
|
|
+ builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
|
|
|
+ builder.CellFormat.Width = 200;
|
|
|
+ builder.Font.Bold = isHeaderRow;
|
|
|
+ builder.Font.Size = isHeaderRow ? 12 : 10;
|
|
|
+ builder.Font.Color = System.Drawing.Color.Black;
|
|
|
+ builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
|
|
|
+ builder.Write(value);
|
|
|
+
|
|
|
+ builder.EndRow();
|
|
|
+
|
|
|
+ // 重置单元格格式(除了宽度)
|
|
|
+ //builder.CellFormat.BackColor = System.Drawing.Color.White;
|
|
|
+ builder.Font.Bold = false;
|
|
|
+ builder.Font.Size = 10;
|
|
|
+ builder.Font.Color = System.Drawing.Color.Black;
|
|
|
+ builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void ApplyTableStyle(Table table)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 设置表格边框
|
|
|
+ table.SetBorders(LineStyle.Single, 1.0, System.Drawing.Color.Gray);
|
|
|
+
|
|
|
+ // 设置表格属性
|
|
|
+ table.LeftPadding = 5;
|
|
|
+ table.RightPadding = 5;
|
|
|
+ table.TopPadding = 3;
|
|
|
+ table.BottomPadding = 3;
|
|
|
+
|
|
|
+ table.Alignment = TableAlignment.Left;
|
|
|
+ table.AllowAutoFit = false;
|
|
|
+ //table.AllowBreakAcrossPages = true;
|
|
|
+
|
|
|
+ // 设置表格宽度
|
|
|
+ table.PreferredWidth = PreferredWidth.FromPoints(400);
|
|
|
+
|
|
|
+ // 设置列宽
|
|
|
+ if (table.FirstRow != null && table.FirstRow.Cells.Count == 2)
|
|
|
+ {
|
|
|
+ table.FirstRow.Cells[0].CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);
|
|
|
+ table.FirstRow.Cells[1].CellFormat.PreferredWidth = PreferredWidth.FromPercent(80);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ //_logger.LogWarning(ex, "设置表格样式时发生错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void AddFooter(DocumentBuilder builder, string footerText)
|
|
|
+ {
|
|
|
+ builder.InsertBreak(BreakType.ParagraphBreak);
|
|
|
+ builder.Writeln();
|
|
|
+ builder.Writeln();
|
|
|
+
|
|
|
+ // 添加分隔线
|
|
|
+ builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
|
|
|
+ builder.Font.Size = 8;
|
|
|
+ builder.Font.Color = System.Drawing.Color.LightGray;
|
|
|
+ //builder.Writeln("────────────────────────────────────");
|
|
|
+
|
|
|
+ builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
|
|
|
+ builder.Font.Size = 9;
|
|
|
+ builder.Font.Italic = true;
|
|
|
+ builder.Font.Color = System.Drawing.Color.Gray;
|
|
|
+ builder.Writeln(footerText);
|
|
|
+ builder.Writeln($"文档生成时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
|
|
|
+
|
|
|
+ builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
|
|
|
+ builder.Font.Size = 10;
|
|
|
+ builder.Font.Italic = false;
|
|
|
+ builder.Font.Color = System.Drawing.Color.Black;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+ #endregion
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|