From e78f5936fee9ab4fff600515bb20a41a28f329c4 Mon Sep 17 00:00:00 2001
From: ningshuxia <ningshuxia0927@outlook.com>
Date: 星期一, 12 十二月 2022 10:20:46 +0800
Subject: [PATCH] 更改报表测试接口 文件utf 8

---
 Application/IStation.Application.OpenApi/test/report/Report_ShysController.cs |    2 +-
 Application/IStation.Application.OpenApi/test/report/dto/LogSummary.cs        |    2 +-
 Application/IStation.Application.OpenApi/test/report/helper/XmlHelper.cs      |   43 ++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/Application/IStation.Application.OpenApi/test/report/Report_ShysController.cs b/Application/IStation.Application.OpenApi/test/report/Report_ShysController.cs
index 2d0eb75..a48ecc3 100644
--- a/Application/IStation.Application.OpenApi/test/report/Report_ShysController.cs
+++ b/Application/IStation.Application.OpenApi/test/report/Report_ShysController.cs
@@ -47,7 +47,7 @@
             dto.LoginLogList = new List<LoginLogItem>();
             dto.LoginStatisticsList = new List<LoginStatistics>();
             dto.TotalUsers = users.Count;
-            dto.LogSummaryList = logs.GroupBy(x => x.LoginTime.Date).Select(x => new LogSummary() { DateTime = x.Key, Visitors = x.Count() }).ToList();
+            dto.LogSummaryList = logs.GroupBy(x => x.LoginTime.Date).Select(x => new LogSummary() {Date = x.Key.ToString("d"), Visitors = x.Count() }).ToList();
        
         var uniqueVisitorList = logs.DistinctBy(x => x.UserID).ToList();
             var today = DateTime.Today;
diff --git a/Application/IStation.Application.OpenApi/test/report/dto/LogSummary.cs b/Application/IStation.Application.OpenApi/test/report/dto/LogSummary.cs
index ce765ec..f418ecb 100644
--- a/Application/IStation.Application.OpenApi/test/report/dto/LogSummary.cs
+++ b/Application/IStation.Application.OpenApi/test/report/dto/LogSummary.cs
@@ -14,7 +14,7 @@
         /// <summary>
         /// 鏃ユ湡
         /// </summary>	
-        public DateTime DateTime { get; set; }
+        public string Date { get; set; }
 
         /// <summary>
         /// 璁垮閲�
diff --git a/Application/IStation.Application.OpenApi/test/report/helper/XmlHelper.cs b/Application/IStation.Application.OpenApi/test/report/helper/XmlHelper.cs
index f6f2ecb..c1147b4 100644
--- a/Application/IStation.Application.OpenApi/test/report/helper/XmlHelper.cs
+++ b/Application/IStation.Application.OpenApi/test/report/helper/XmlHelper.cs
@@ -1,4 +1,5 @@
-锘縰sing System;
+锘縰sing Microsoft.AspNetCore.Mvc.ViewFeatures;
+using System;
 using System.IO;
 using System.Text;
 using System.Xml;
@@ -18,10 +19,10 @@
         /// </summary>
         public string ObjectToXml(T obj)
         {
-            using (StringWriter writer = new StringWriter())
+            using (TextWriter writer = new StringWriter())
             {
                 XmlSerializer serializer = new XmlSerializer(obj.GetType());
-                serializer.Serialize(writer, obj);
+                serializer.Serialize(writer, obj) ;
                 return writer.ToString();
             }
         }
@@ -49,12 +50,44 @@
 
 
         /// <summary>
+        /// 鏁版嵁杈撳嚭锛屽簭鍒楀寲xml鏂囨湰 
+        /// </summary>
+        /// <returns></returns>
+        public static string FileOutput(T obj)
+        {
+            var xml = string.Empty;
+            try
+            {
+                using (MemoryStream ms = new MemoryStream())
+                {
+                    var setting = new XmlWriterSettings()
+                    {
+                        Encoding = new UTF8Encoding(false),
+                        Indent = true,
+                    };
+                    using (XmlWriter writer = XmlWriter.Create(ms, setting))
+                    {
+                        XmlSerializer xmlSearializer = new XmlSerializer(obj.GetType());
+                        xmlSearializer.Serialize(writer, obj);
+                        xml= Encoding.UTF8.GetString(ms.ToArray());
+                    }
+                }
+            }
+            catch (Exception)
+            {
+                LogHelper.Error("鎶ヨ〃Json鏂囦欢鏍煎紡鍖栧け璐�! ");
+            }
+            return xml;
+        }
+
+        /// <summary>
         /// 淇濆瓨瀵硅薄鍒皒ml鏂囦欢涓�
         /// </summary>
         public static void SaveObjectXmlFile<T>(string fileName, T t) where T : class
         {
-            var str = new XmlHelper<T>().ObjectToXml(t);
-            File.WriteAllText(fileName, str, Encoding.UTF8);
+            var str = XmlHelper<T>.FileOutput(t);
+            UTF8Encoding utf8 = new UTF8Encoding(false);
+            File.WriteAllText(fileName, str, utf8);
         }
 
 

--
Gitblit v1.9.3