报表速度提升

This commit is contained in:
dell
2023-04-27 15:02:45 +08:00
parent 13b0556370
commit 0da8710708
9 changed files with 455 additions and 20 deletions

View File

@ -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<BrotliCompressionProvider>();
options.Providers.Add<GzipCompressionProvider>();
options.MimeTypes =
ResponseCompressionDefaults.MimeTypes.Concat(
new[] { "image/svg+xml" });
});
services.Configure<BrotliCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.SmallestSize;
});
//services.AddResponseCompression(options =>
//{
// options.Providers.Add<BrotliCompressionProvider>();
// options.Providers.Add<GzipCompressionProvider>();
// options.MimeTypes =
// ResponseCompressionDefaults.MimeTypes.Concat(
// new[] { "image/svg+xml" });
//});
//services.Configure<BrotliCompressionProviderOptions>(options =>
//{
// options.Level = CompressionLevel.SmallestSize;
//});
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(GlobalContext.HostingEnvironment.ContentRootPath + Path.DirectorySeparatorChar + "DataProtection"));
}

View File

@ -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;
}
}
}
/// <summary>
/// 转换为json字符串
/// </summary>
/// <returns></returns>
///
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();
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.ComponentModel.DataAnnotations;
using SqlSugar;
namespace HT.Cloud.Domain.ReportManage
{
/// <summary>
/// 创 建cdl
/// 日 期2023-04-26 14:43
/// 描 述:历史信息表实体类
/// </summary>
[SugarTable("HT_HISTORY_REPORT")]
public class Ht_History_ReportEntity
{
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName="HNO", ColumnDescription = "",ColumnDataType = "int(10)",IsPrimaryKey = true)]
public int HNO { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName="HTAB", ColumnDescription = "",ColumnDataType = "nvarchar(50)")]
public string HTAB { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName="HALI", ColumnDescription = "",ColumnDataType = "nvarchar(10)")]
public string HALI { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName="HSYS", ColumnDescription = "",ColumnDataType = "nvarchar(100)", IsNullable = true)]
public string HSYS { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName="HPRO", ColumnDescription = "",ColumnDataType = "nvarchar(100)", IsNullable = true)]
public string HPRO { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName="HREQ", ColumnDescription = "",ColumnDataType = "nvarchar(50)", IsNullable = true)]
public string HREQ { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName="HSIG", ColumnDescription = "",ColumnDataType = "nvarchar(10)")]
public string HSIG { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName="HVAR", ColumnDescription = "",ColumnDataType = "nvarchar(80)")]
public string HVAR { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName="HFVAR", ColumnDescription = "",ColumnDataType = "nvarchar(80)", IsNullable = true)]
public string HFVAR { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName="HCON", ColumnDescription = "",ColumnDataType = "nvarchar(500)")]
public string HCON { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName="HFLAG", ColumnDescription = "",ColumnDataType = "int(10)")]
public int HFLAG { get; set; }
}
}

View File

@ -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<object> 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<string> GetReportFirstHead()
{
var list = _context.Queryable<Ht_History_ReportEntity>().ToList();
List<string> list_name_two = list.Select(t => t.HSYS).GroupBy(c => c).Select(c => c.First()).ToList();
return list_name_two.ToJson();
}
public async Task<string> GetReportSecondHead()
{
var list = _context.Queryable<Ht_History_ReportEntity>().ToList();
List<string> list_name_two = list.Select(t => t.HSYS).GroupBy(c => c).Select(c => c.First()).ToList();
var relist = new List<SecondHead>();
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<string>();
var listTitleString = new List<string>();
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<string> Head { get; set;}
public List<string> Title { get; set; }
}
}
}

View File

@ -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<ActionResult> 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<ActionResult> 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<ActionResult> 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)
{

View File

@ -127,7 +127,7 @@
<div id="bottom_5" class="layui-form-item active" data-id="bottom_5" data-tag="bottom"
data-index="0">
<div class="layui-input-block" style="margin-left: 0px;">
<button id="btn_search" type="button" class="layui-btn custom-zc" ; onclick="GetReportView()">
<button id="btn_search" type="button" class="layui-btn custom-zc" ; onclick="GetReportViewNew()">
<i class="layui-icon ">
</i>
确定
@ -582,10 +582,199 @@
}
async function downloadreport() {
window.open(filepath);
}
async function GetReportViewNew() {
debugger;
showLoading();
var datetimestart = $('#dateReStartTime')[0].value;
var datetimeend = $('#dateReEndTime')[0].value;
var timeInterval = 0;
switch ($('[name="selectint"]')[0].value) {
case "tensec":
timeInterval = 10
break
case "twentysec":
timeInterval = 20
break
case "thirtysec":
timeInterval = 30
break
case "onemin":
timeInterval = 60
break
case "fivemin":
timeInterval = 300
break
case "tenmin":
timeInterval = 600
break
case "thirtymin":
timeInterval = 1800
break
case "onehour":
timeInterval = 3600
break
default:
timeInterval = 3600
};
debugger;
//showLoading();
var datapa = {
"StartTime": Date.parse(new Date(datetimestart)), "EndTime": Date.parse(new Date(datetimeend)), "Interval": timeInterval
};
//var datapa = { "StartTime": datetimestart, "EndTime": datetimeend, "Interval": timeInterval };
debugger;
let result = "";
let first = "";
let second = "";
var start1 = Date.now();
await $.ajax({
url: "/ReportManage/HistoryReport/GetReportNew",
type: "POST",
//dataType: "json",
//async: false,
data: datapa,
dataType: "text",
//contentType:"text/html",
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("accept-encoding", "gzip");
XMLHttpRequest.setRequestHeader("accept", "text/html; charset=utf-8");
},
success: function (redata) {
var start = Date.now();
result = JSON.parse(redata);
var end = Date.now();
console.log(end - start);
debugger;
}
});
var end1 = Date.now();
console.log(end1 - start1);
await $.ajax({
url: "/ReportManage/HistoryReport/GetReportFirstHead",
type: "GET",
//dataType: "json",
//async: false,
//data: datapa,
success: function (refirst) {
first = JSON.parse(refirst);
debugger;
}
});
await $.ajax({
url: "/ReportManage/HistoryReport/GetReportSecondHead",
type: "GET",
//dataType: "json",
//async: false,
//data: datapa,
success: function (resecond) {
second = JSON.parse(resecond);
debugger;
}
});
let firstHead = new Array();
let secondHead = new Array();
let timeHead = {
field: 'HDATETIME',
title: '时间',
align: 'center',
width: 200,
rowspan: 2,
}
firstHead.push(timeHead);
for (var si = 0; si < second.length; si++) {
let head = {
align: 'center',
title: second[si].HSYS,
colspan: second[si].Head.length,
}
firstHead.push(head);
for(var hi = 0; hi < second[si].Head.length;hi++){
let shead = {
field: second[si].Title[hi],
title: second[si].Head[hi],
align: 'center',
width: 80,
}
secondHead.push(shead);
}
}
debugger;
var ingd =0;
var table = layui.table;
table.render({
elem: '#result',
height: 'full-200',
data: result,
//editTrigger:'dblclick',
cols: [
firstHead,
secondHead,
],
page:true,
limit:15,
done: function (res, curr, count) {
debugger;
// console.log(res)
//var donestyle = "<style>.layui - table - cell { height: auto;overflow: visible;text - overflow: inherit;white - space: normal;word -break: break-all;}.layui - table - cell a {text- decoration: underline;}.layui - table - cell div {white - space: nowrap;overflow: hidden;text - overflow: ellipsis;min - height: 30px;line - height: 30px;}</style>"
//var oDiv = document.querySelector("#tdemo");
//oDiv.style.cssText = donestyle;
//layui-table-cell laytable-cell-group
//layui-table-cell laytable-cell-1-1-0
//$(".layui-table-cell"). [800].style
////解决表头宽度不够自动换行问题
//$(".layui-table-cell").each(function (index, val) {
// $(".layui-table-cell")[index].style.lineHeight = "20px !importanr";
// $(".layui-table-cell")[index].style.verticalAlign = "middle";
// $(".layui-table-cell")[index].style.height = "auto";
// $(".layui-table-cell")[index].style.overflow = "visible";
// $(".layui-table-cell")[index].style.textOverflow = "inherit";
// $(".layui-table-cell")[index].style.whiteSpace = "normal";
//});
////解决操作栏因为内容过多换行问题
//$(".layui-table-main tr").each(function (index, val) {
// $($(".layui-table-fixed-l .layui-table-body tbody tr")[index]).height($(val).height());
// $($(".layui-table-fixed-r .layui-table-body tbody tr")[index]).height($(val).height());
//});
////解决fixed固定而导致的th高度不一致
//$(".layui-table-header tr").each(function (index, val) {
// $(".layui-table-fixed").each(function () {
// $($(this).find(".layui-table-header thead th")[index]).height($(val).height());
// });
//});
//$(".layui-table-header tr").each(function (index, val) {
// $(".layui-table-fixed").each(function () {
// $($(this).find(".layui-table-header thead tr")[index]).height($(val).height());
// });
//});
//$(".layui-table-main tr").each(function (index, val) {
// $(".layui-table-fixed").each(function () {
// $($(this).find(".layui-table-body tbody tr")[index]).height($(val).height());
// });
//});
//$(".layui-table-main tr").each(function (index, val) {
// $(".layui-table-fixed").each(function () {
// $($(this).find(".layui-table-body tbody th")[index]).height($(val).height());
// });
//});
$('.layui-laypage-limits').hide();
}
});
debugger;
completeLoading();
};
async function GetReportView() {
debugger;
showLoading();

View File

@ -9,6 +9,10 @@ using System;
using System.Reflection;
using HT.Cloud.Code;
using HT.Cloud.Service;
using Microsoft.AspNetCore.ResponseCompression;
using System.IO.Compression;
using System.Net.Sockets;
using System.Linq;
namespace HT.Cloud.Web
{
@ -20,7 +24,30 @@ namespace HT.Cloud.Web
public override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
services.Configure<BrotliCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.Fastest;
}).Configure<GzipCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.Fastest;
}).AddResponseCompression(options =>
{
options.EnableForHttps = true;
options.Providers.Add<BrotliCompressionProvider>();
options.Providers.Add<GzipCompressionProvider>();
options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
{
//"text/html",
"json/html; charset=utf-8",
"text/html; charset=utf-8",
"application/xhtml+xml",
"application/atom+xml",
"image/svg+xml"
});
});
base.ConfigureServices(services);
services.AddDefaultSwaggerGen(Assembly.GetExecutingAssembly().GetName().Name)
.AddSqlSugar()
.AddQuartz()
@ -41,6 +68,9 @@ namespace HT.Cloud.Web
// 返回数据首字母不小写CamelCasePropertyNamesContractResolver是小写
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
//调试前端可更新
services.AddControllersWithViews().AddRazorRuntimeCompilation();
//清理缓存
@ -57,8 +87,8 @@ namespace HT.Cloud.Web
public override void Configure(IApplicationBuilder app)
{
base.Configure(app);
//MVC路由
app.UseMiddleware(typeof(GlobalExceptionMiddleware))
//MVC路由
app.UseMiddleware(typeof(GlobalExceptionMiddleware))
.AddDefaultSwaggerGen()
.UseEndpoints(endpoints =>
{

View File

@ -12,7 +12,7 @@
"LoginMultiple": false, // 是否允许一个账户在多处登录
"AllowCorsSite": "http://localhost:8058", // 允许的其他站点访问Api
"DBProvider": "SqlServer", //SqlServer //Oracle
"DBConnectionString": "Data Source=192.168.110.36;Initial Catalog=HTSCADA;User Id= sa;Password= Sa1qaz;Integrated Security=False;Encrypt=True;TrustServerCertificate=True;",
"DBConnectionString": "Data Source=192.168.110.32;Initial Catalog=SCADA;User Id= sa;Password= Sa1qaz;Integrated Security=False;Encrypt=True;TrustServerCertificate=True;",
"DBCommandTimeout": 180, // 数据库超时时间,单位秒
"CacheProvider": "Memory", // 缓存使用方式 Redis/Memory
"RedisConnectionString": "127.0.0.1:6379", //docker部署 172.17.0.1

Binary file not shown.