Browse Source

调整文件生成功能

guqiang 3 tuần trước cách đây
mục cha
commit
b9a4108597

+ 1 - 0
src/Hotline.Api/Controllers/EarlyController.cs

@@ -318,6 +318,7 @@ namespace Hotline.Api.Controllers
 
             //Title 热点汇总
             var reportHotDetail = result.GroupBy(x => x.OneHotspotName).ToList();
+            reportDto.ReportHotDetails = new List<ReportHotDetailDto>();
             reportHotDetail.ForEach(x =>
             {
                 reportDto.ReportHotDetails.Add(new ReportHotDetailDto()

+ 20 - 6
src/Hotline.Application/Early/EarlyReportProvider.cs

@@ -192,7 +192,7 @@ namespace Hotline.Application.Early
         {
             var tableDto = new TableDto
             {
-                CssStyle = "border-collapse: collapse;"
+                CssStyle = "border-collapse: collapse;width: 100%;"
             };
             tableDto.HeadDto.RowDtos.Add(new RowDto
             {
@@ -279,7 +279,7 @@ namespace Hotline.Application.Early
         {
             var tableDto = new TableDto
             {
-                CssStyle = "border-collapse: collapse;"
+                CssStyle = "border-collapse: collapse;width: 100%;"
             };
             tableDto.HeadDto.RowDtos.Add(new RowDto
             {
@@ -361,10 +361,10 @@ namespace Hotline.Application.Early
                 {
                     titleDto = new TitleDto
                     {
-                        Content = item.HotName,
+                        Content = $"{ToChineseNumber(index)}、{item.HotName}问题",
                         CssStyle = "text-indent: 2rem;font-weight: bolder;",
                     },
-                    Content = item.Content,
+                    Content = $"今日收到{item.HotName}问题{item.Count}件,主要涉及:{item.Content}",
                     CssStyle = "text-indent: 2rem;",
                     SortIndex = index
                 });
@@ -378,16 +378,30 @@ namespace Hotline.Application.Early
             var hotDetails = new List<string>();
             earlyReportDtoreportDto.ReportHotDetails.ForEach(item =>
             {
-                hotDetails.Add($"{item.HotName}{item.Content}件");
+                hotDetails.Add($"{item.HotName}{item.Count}件");
             });
             var areaDetails = new List<string>();
             earlyReportDtoreportDto.ReportAreaDetails.ForEach(item =>
             {
                 areaDetails.Add($"{item.AreaName}{item.Count}件");
             });
-            var summarize = $"{earlyReportDtoreportDto.ReportPushTime},市12345热线共受理重点领域问题{earlyReportDtoreportDto.ReportHotDetails.Sum(x => x.Count)}件,其中,{string.Join("、", hotDetails)}。从区域分布来看,{string.Join(",", areaDetails)}。";
+            var summarize = $"{earlyReportDtoreportDto.ReportPushTime.ToString("yyyy年MM月dd日 HH时mm分ss秒")},市12345热线共受理重点领域问题{earlyReportDtoreportDto.ReportHotDetails.Sum(x => x.Count)}件,其中,{string.Join("、", hotDetails)}。从区域分布来看,{string.Join(",", areaDetails)}。";
             return summarize;
         }
 
+        private static readonly string[] ChineseNumbers =
+             {
+        "零", "一", "二", "三", "四",
+        "五", "六", "七", "八", "九", "十"
+    };
+
+        public static string ToChineseNumber(int number)
+        {
+            if (number < 0 || number > 10)
+            {
+                throw new ArgumentOutOfRangeException(nameof(number), "输入数字必须在 0-10 范围内");
+            }
+            return ChineseNumbers[number];
+        }
     }
 }

+ 7 - 5
src/Hotline.Application/ExportWord/IWordExportTemplateExtensions.cs

@@ -110,7 +110,7 @@ namespace Hotline.Application.ExportWord
                     var attachment = string.Empty;
                     if (item.Title != null)
                     {
-                        attachment = $"<div style=\"{item.Title}\">{item.Content}</div>";
+                        attachment = $"<div style=\"{item.Title.CssStyle}\">{item.Title.Content}</div>";
                     }
 
                     if (item.SubTitleDtos != null && item.SubTitleDtos.Any())
@@ -127,7 +127,6 @@ namespace Hotline.Application.ExportWord
                         {
                             var body = $"";
                             var head = $"";
-                            var table = $"<table style=\"{tab.CssStyle}\">{head}{body}</div>";
                             if (tab.HeadDto != null)
                             {
                                 tab.HeadDto.RowDtos.ForEach(row =>
@@ -152,6 +151,9 @@ namespace Hotline.Application.ExportWord
                                 body = $"<tbody style=\"{tab.BodyDto.CssStyle}\">{body}</tbody>";
                             }
 
+                            var table = $"<div style=\"float: left;width: 100%; margin-bottom: 10px;\"><table style=\"{tab.CssStyle}\">{head}{body}</table></div>";
+
+                            attachment += table;
                         });
                     }
 
@@ -166,11 +168,11 @@ namespace Hotline.Application.ExportWord
         private static string CreateRow(RowDto row)
         {
             var colStr = $"";
-            var rowStr = $"<tr style=\"{row.CssStyle}\">{colStr}</tr>";
             row.ColumnDtos.ForEach(col =>
             {
                 colStr += $"<td style=\"{col.CssStyle}\">{col.Content}</td>";
             });
+            var rowStr = $"<tr style=\"{row.CssStyle}\">{colStr}</tr>";
             return rowStr;
         }
 
@@ -178,9 +180,9 @@ namespace Hotline.Application.ExportWord
         {
             if (reportDto.ContentDto != null)
             {
-                if(reportDto.Title != null)
+                if(reportDto.ContentDto.TitleDto != null)
                 {
-                    content = CreateTitle(reportDto.Title, content);
+                    content = CreateTitle(reportDto.ContentDto.TitleDto, content);
                 }
 
                 var paragraphes = string.Empty;

+ 14 - 0
src/Hotline.Share/Dtos/ExportWord/ReportDto.cs

@@ -87,6 +87,10 @@ namespace Hotline.Share.Dtos.ExportWord
 
     public class HeadDto : BaseReportDto
     {
+        public HeadDto()
+        {
+            RowDtos = new List<RowDto>();
+        }
         public List<RowDto> RowDtos { get; set; }
     }
 
@@ -101,6 +105,11 @@ namespace Hotline.Share.Dtos.ExportWord
 
     public class RowDto : BaseReportDto
     {
+        public RowDto()
+        {
+            ColumnDtos = new List<ColumnDto>();
+        }
+
         public List<ColumnDto> ColumnDtos;
     }
 
@@ -111,6 +120,11 @@ namespace Hotline.Share.Dtos.ExportWord
 
     public class BaseReportDto
     {
+        public BaseReportDto()
+        {
+            Children = new List<BaseReportDto>();
+        }
+
         public string Content { get; set; }
 
         public string CssStyle { get; set; }