diff --git a/HT.Cloud.Code/DefaultStartUp.cs b/HT.Cloud.Code/DefaultStartUp.cs index 2c840ac..7b1fdfc 100644 --- a/HT.Cloud.Code/DefaultStartUp.cs +++ b/HT.Cloud.Code/DefaultStartUp.cs @@ -83,18 +83,18 @@ namespace HT.Cloud.Code services.AddAntiforgery(options => options.HeaderName = "X-CSRF-TOKEN"); services.AddControllersWithViews().AddControllersAsServices(); //启用 Gzip 和 Brotil 压缩功能 - services.AddResponseCompression(options => - { - options.Providers.Add(); - options.Providers.Add(); - options.MimeTypes = - ResponseCompressionDefaults.MimeTypes.Concat( - new[] { "image/svg+xml" }); - }); - services.Configure(options => - { - options.Level = CompressionLevel.SmallestSize; - }); + //services.AddResponseCompression(options => + //{ + // options.Providers.Add(); + // options.Providers.Add(); + // options.MimeTypes = + // ResponseCompressionDefaults.MimeTypes.Concat( + // new[] { "image/svg+xml" }); + //}); + //services.Configure(options => + //{ + // options.Level = CompressionLevel.SmallestSize; + //}); services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(GlobalContext.HostingEnvironment.ContentRootPath + Path.DirectorySeparatorChar + "DataProtection")); } diff --git a/HT.Cloud.Code/Extend/Ext.Table.cs b/HT.Cloud.Code/Extend/Ext.Table.cs index b2ebd00..55c0a6d 100644 --- a/HT.Cloud.Code/Extend/Ext.Table.cs +++ b/HT.Cloud.Code/Extend/Ext.Table.cs @@ -5,7 +5,9 @@ * Website: *********************************************************************************/ +using System; using System.Data; +using System.Text; namespace HT.Cloud.Code { @@ -66,5 +68,44 @@ namespace HT.Cloud.Code return null; } } - } + + /// + /// 转换为json字符串 + /// + /// + /// + public static string ToJson(this DataTable dt) + { + StringBuilder jsonString = new StringBuilder(); + jsonString.Append("["); + DataRowCollection drc = dt.Rows; + for (int i = 0; i < drc.Count; i++) + { + jsonString.Append("{"); + for (int j = 0; j < dt.Columns.Count; j++) + { + string strKey = dt.Columns[j].ColumnName; + string strValue = drc[i][j].ToString(); + Type type = dt.Columns[j].DataType; + jsonString.Append("\"" + strKey + "\":"); + strValue = String.Format(strValue, type); + if (j < dt.Columns.Count - 1) + { + jsonString.Append(strValue + ","); + } + else + { + jsonString.Append(strValue); + } + } + jsonString.Append("},"); + } + if (jsonString.Length > 1) + { + jsonString.Remove(jsonString.Length - 1, 1); + } + jsonString.Append("]"); + return jsonString.ToString(); + } + } } \ No newline at end of file diff --git a/HT.Cloud.Domain/Entity/ReportManage/Ht_History_ReportEntity.cs b/HT.Cloud.Domain/Entity/ReportManage/Ht_History_ReportEntity.cs new file mode 100644 index 0000000..962ade7 --- /dev/null +++ b/HT.Cloud.Domain/Entity/ReportManage/Ht_History_ReportEntity.cs @@ -0,0 +1,71 @@ +using System; +using System.ComponentModel.DataAnnotations; +using SqlSugar; + +namespace HT.Cloud.Domain.ReportManage +{ + /// + /// 创 建:cdl + /// 日 期:2023-04-26 14:43 + /// 描 述:历史信息表实体类 + /// + [SugarTable("HT_HISTORY_REPORT")] + public class Ht_History_ReportEntity + { + /// + /// + /// + [SugarColumn(ColumnName="HNO", ColumnDescription = "",ColumnDataType = "int(10)",IsPrimaryKey = true)] + public int HNO { get; set; } + /// + /// + /// + [SugarColumn(ColumnName="HTAB", ColumnDescription = "",ColumnDataType = "nvarchar(50)")] + public string HTAB { get; set; } + /// + /// + /// + [SugarColumn(ColumnName="HALI", ColumnDescription = "",ColumnDataType = "nvarchar(10)")] + public string HALI { get; set; } + /// + /// + /// + [SugarColumn(ColumnName="HSYS", ColumnDescription = "",ColumnDataType = "nvarchar(100)", IsNullable = true)] + public string HSYS { get; set; } + /// + /// + /// + [SugarColumn(ColumnName="HPRO", ColumnDescription = "",ColumnDataType = "nvarchar(100)", IsNullable = true)] + public string HPRO { get; set; } + /// + /// + /// + [SugarColumn(ColumnName="HREQ", ColumnDescription = "",ColumnDataType = "nvarchar(50)", IsNullable = true)] + public string HREQ { get; set; } + /// + /// + /// + [SugarColumn(ColumnName="HSIG", ColumnDescription = "",ColumnDataType = "nvarchar(10)")] + public string HSIG { get; set; } + /// + /// + /// + [SugarColumn(ColumnName="HVAR", ColumnDescription = "",ColumnDataType = "nvarchar(80)")] + public string HVAR { get; set; } + /// + /// + /// + [SugarColumn(ColumnName="HFVAR", ColumnDescription = "",ColumnDataType = "nvarchar(80)", IsNullable = true)] + public string HFVAR { get; set; } + /// + /// + /// + [SugarColumn(ColumnName="HCON", ColumnDescription = "",ColumnDataType = "nvarchar(500)")] + public string HCON { get; set; } + /// + /// + /// + [SugarColumn(ColumnName="HFLAG", ColumnDescription = "",ColumnDataType = "int(10)")] + public int HFLAG { get; set; } + } +} diff --git a/HT.Cloud.Service/ReportManage/HistoryReportService.cs b/HT.Cloud.Service/ReportManage/HistoryReportService.cs index ca8dc17..afc03ed 100644 --- a/HT.Cloud.Service/ReportManage/HistoryReportService.cs +++ b/HT.Cloud.Service/ReportManage/HistoryReportService.cs @@ -9,6 +9,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using HT.Cloud.Domain.ReportManage; +using System.Reflection.PortableExecutable; +using Newtonsoft.Json; +using HT.Cloud.Code; +using HT.Cloud.Domain.DevicesManage; +using System.Text.RegularExpressions; +using Org.BouncyCastle.Asn1.X509; namespace HT.Cloud.Service.ReportManage { @@ -76,5 +82,57 @@ namespace HT.Cloud.Service.ReportManage //result.data = fileurl; return fileurl; } + + public async Task GetReportNew(string startdt, string enddt, int timeinterval) + { + SugarParameter[] sqlParameters ={ + new SugarParameter("@startdt",startdt), + new SugarParameter("@enddt",enddt), + new SugarParameter("@timeinterval",timeinterval) + }; + var Report = _context.Ado.UseStoredProcedure().GetDataTable("Query_Report_YL", sqlParameters); + Report.TableName = "Report"; + + //return JsonConvert.SerializeObject(Report); + return Report; + + } + public async Task GetReportFirstHead() + { + var list = _context.Queryable().ToList(); + List list_name_two = list.Select(t => t.HSYS).GroupBy(c => c).Select(c => c.First()).ToList(); + return list_name_two.ToJson(); + } + + public async Task GetReportSecondHead() + { + var list = _context.Queryable().ToList(); + List list_name_two = list.Select(t => t.HSYS).GroupBy(c => c).Select(c => c.First()).ToList(); + var relist = new List(); + foreach(var t in list_name_two) + { + var secondHead = new SecondHead(); + secondHead.HSYS = t; + var listHead = list.Where(x=> x.HSYS == t).ToList(); + var listHeadString = new List(); + var listTitleString = new List(); + foreach(var h in listHead) + { + listHeadString.Add(h.HPRO.ToString()); + listTitleString.Add(h.HVAR.ToString()); + } + secondHead.Head = listHeadString; + secondHead.Title = listTitleString; + relist.Add(secondHead); + } + return relist.ToJson(); + //return Report.ToJson(); + } + public class SecondHead + { + public string HSYS { get; set;} + public List Head { get; set;} + public List Title { get; set; } + } } } diff --git a/HT.Cloud.Web/Areas/ReportManage/Controllers/HistoryReportController.cs b/HT.Cloud.Web/Areas/ReportManage/Controllers/HistoryReportController.cs index 2a3124f..b62f89b 100644 --- a/HT.Cloud.Web/Areas/ReportManage/Controllers/HistoryReportController.cs +++ b/HT.Cloud.Web/Areas/ReportManage/Controllers/HistoryReportController.cs @@ -3,6 +3,11 @@ using System; using System.Threading.Tasks; using HT.Cloud.Service.ChartsManage; using HT.Cloud.Service.ReportManage; +using Newtonsoft.Json; +using System.Diagnostics.Metrics; +using System.Text; +using static System.Net.Mime.MediaTypeNames; +using Microsoft.AspNetCore.Mvc.Rendering; namespace HT.Cloud.Web.Areas.ReportManage.Controllers { @@ -22,6 +27,47 @@ namespace HT.Cloud.Web.Areas.ReportManage.Controllers var data = await _historyReportService.GetReportFileName(StartTime, EndTime, Interval); return Content(data); } + [HttpPost] + public async Task GetReportNew(Reportparam reportparam) + { + var t1 = DateTime.Now; + //var ob = JsonConvert.SerializeObject(reportparam); + var t2 = DateTime.Now; + Console.WriteLine($"第1次序列化,花费时间:{(t2 - t1).TotalMilliseconds}"); + //var StartTime = reportparam.StartTime.ToString("yyyy-MM-dd HH:mm:ss"); + //var EndTime = reportparam.EndTime.ToString("yyyy-MM-dd HH:mm:ss"); + var StartTime = Gettime(reportparam.StartTime.ToString()); + var EndTime = Gettime(reportparam.EndTime.ToString()); + var Interval = int.Parse(reportparam.Interval); + var t5 = DateTime.Now; + var data = await _historyReportService.GetReportNew(StartTime, EndTime, Interval); + var t6 = DateTime.Now; + Console.WriteLine($"调用service,花费时间:{(t6 - t5).TotalMilliseconds}"); + var t3 = DateTime.Now; + var con = JsonConvert.SerializeObject(data); + var t4 = DateTime.Now; + Console.WriteLine($"第2次序列化,花费时间:{(t4 - t3).TotalMilliseconds}"); + return Content(con, "text/html; charset=utf-8"); + //return Content(con); + } + [HttpGet] + public async Task GetReportFirstHead() + { + //var StartTime = reportparam.StartTime.ToString("yyyy-MM-dd HH:mm:ss"); + //var EndTime = reportparam.EndTime.ToString("yyyy-MM-dd HH:mm:ss"); + + var data = await _historyReportService.GetReportFirstHead(); + return Content(data); + } + [HttpGet] + public async Task GetReportSecondHead() + { + //var StartTime = reportparam.StartTime.ToString("yyyy-MM-dd HH:mm:ss"); + //var EndTime = reportparam.EndTime.ToString("yyyy-MM-dd HH:mm:ss"); + + var data = await _historyReportService.GetReportSecondHead(); + return Content(data); + } public string Gettime(string longtime) { diff --git a/HT.Cloud.Web/Areas/ReportManage/Views/HistoryReport/Index.cshtml b/HT.Cloud.Web/Areas/ReportManage/Views/HistoryReport/Index.cshtml index b07f73d..e04de86 100644 --- a/HT.Cloud.Web/Areas/ReportManage/Views/HistoryReport/Index.cshtml +++ b/HT.Cloud.Web/Areas/ReportManage/Views/HistoryReport/Index.cshtml @@ -127,7 +127,7 @@
-