From 101b6d21f943b3957d9e2ac668c24f8252630ff8 Mon Sep 17 00:00:00 2001 From: "jay.chang" Date: Mon, 12 Aug 2024 10:57:15 +0800 Subject: [PATCH] =?UTF-8?q?[WebApi]=E6=AD=B7=E5=8F=B2=E8=B3=87=E6=96=99?= =?UTF-8?q?=E6=9F=A5=E8=A9=A2=E5=8A=A0=E5=85=A55=E8=90=AC=E7=AD=86?= =?UTF-8?q?=E9=99=90=E5=88=B6(=E8=B6=85=E9=81=8E=E5=AE=B9=E6=98=93?= =?UTF-8?q?=E7=B6=B2=E9=A0=81=E5=B4=A9=E6=BD=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/HistoryController.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index 143ee8f..b0ceef2 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -1436,6 +1436,35 @@ namespace FrontendWebApi.ApiControllers inner join variable v2 on temp.device_name_tag COLLATE utf8mb4_unicode_ci = v2.system_value and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3' order by b.priority, v1.system_priority, v2.system_priority, temp.priority;"; + int totalRecordCount = 0; + + // 先計算總記錄數 + foreach (var hi in input.HistoryItems) + { + var device_number = hi.Device_number_point.Split(":")[0]; + var point = hi.Device_number_point.Split(":")[1]; + var stationName = await backendRepository.GetOneAsync($"select distinct parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split('_')[0]}' limit 1"); + var tableName = await backgroundServiceMsSqlRepository.GetOneAsync($"select table_name from INFORMATION_SCHEMA.TABLES where table_name like '%{stationName}_{device_number}_{point}%'"); + + if (!string.IsNullOrEmpty(tableName)) + { + var sqlCount = $@"select count(*) from {tableName} + where replace(convert(varchar, [timestamp], 111), '/', '-') >= @startTime + and replace(convert(varchar, [timestamp], 111), '/', '-') <= @endTime"; + + var recordCount = await backgroundServiceMsSqlRepository.GetOneAsync(sqlCount, new { startTime = input.Start_timestamp, endTime = input.End_timestamp }); + totalRecordCount += recordCount; + + if (totalRecordCount > 50000) + { + // 如果總記錄數超過5萬筆,返回提示信息 + apiResult.Code = "5000"; + apiResult.Msg = "資料量超過5萬筆,請減少選擇區間或設備"; + return apiResult; + } + } + } + foreach (var hi in input.HistoryItems) { var device_number = hi.Device_number_point.Split(":")[0];