diff --git a/FrontendWebApi/ApiControllers/BuildController.cs b/FrontendWebApi/ApiControllers/BuildController.cs index ba17601..20bf402 100644 --- a/FrontendWebApi/ApiControllers/BuildController.cs +++ b/FrontendWebApi/ApiControllers/BuildController.cs @@ -359,12 +359,22 @@ namespace FrontendWebApi.ApiControllers var sub_system = await backendRepository.GetOneAsync(@$"select v.system_key subfull_name,me.* from building_menu me left join variable v on v.system_value = me.sub_system_tag and v.system_type = 'device_system_category_layer3' and v.deleted = 0 where me.building_tag = '{get.building_tag}' and me.main_system_tag = '{get.main_system_tag}' and me.sub_system_tag = '{get.sub_system_tag}' order by me.priority"); - - List Floors = new List(); + get.sub_system_tag = get.sub_system_tag == "P" ? $"'{get.sub_system_tag}','B'" : $"'{get.sub_system_tag}'"; // 巨蛋緊急壓扣(P)跟閃光喇吧被視為同一類 + List Floors = new List(); var floorsql = await backendRepository.GetAllAsync($@" - select * from (select * from sub_system_floor ssf where ssf.deleted = 0 and ssf.status = 0 and ssf.building_tag = '{get.building_tag}' and ssf.main_system_tag = '{get.main_system_tag}' and ssf.sub_system_tag = '{get.sub_system_tag}' and ssf.is_link = 1) a + select * from (select *, + CASE + WHEN ssf.sub_system_tag IN ({get.sub_system_tag}) THEN 'P_B' -- 將 'P' 和 'B' 合併為一個類 + ELSE ssf.sub_system_tag -- 其他保持原樣 + END AS merged_sub_system_tag + from sub_system_floor ssf where ssf.deleted = 0 and ssf.status = 0 + and ssf.building_tag = '{get.building_tag}' + and ssf.main_system_tag = '{get.main_system_tag}' + and ssf.sub_system_tag in ({get.sub_system_tag}) + and ssf.is_link = 1) a left join floor on floor.full_name = a.floor_tag and a.building_tag = floor.building_tag where floor.deleted = 0 + GROUP BY a.floor_tag, a.building_tag, a.merged_sub_system_tag order by floor.priority"); Sub_system sub_System = new Sub_system() { @@ -402,6 +412,7 @@ namespace FrontendWebApi.ApiControllers catch (Exception exception) { apiResult.Code = "9999"; + apiResult.Msg = "9999"; Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); return Ok(apiResult); } diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index ee9acd2..830a948 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -319,6 +319,7 @@ namespace FrontendWebApi.ApiControllers try { + input.EnableLimit = false; // CSV關閉5W筆限制 var apiData = await GetHistoryRealTime(input); if (apiData.Value == null) { @@ -1394,6 +1395,7 @@ namespace FrontendWebApi.ApiControllers ApiResult> apiResult = new ApiResult>(jwt_str); apiResult.Data = new List(); List noDataDevice = new List(); + if (!jwtlife) { apiResult.Code = "5000"; @@ -1439,41 +1441,40 @@ namespace FrontendWebApi.ApiControllers int totalRecordCount = 0; // 先計算總記錄數 - foreach (var hi in input.HistoryItems) + if (input.EnableLimit) { - 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)) + foreach (var hi in input.HistoryItems) { - var sqlCount = $@"select count(*) from {tableName} + 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; + 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; + if (totalRecordCount > 50000) + { + // 如果總記錄數超過5萬筆,返回提示信息 + apiResult.Code = "5000"; + apiResult.Msg = "資料量超過5萬筆,請減少選擇區間或設備"; + return apiResult; + } } } - else - { - noDataDevice.Add(hi.Device_number_point); - } } // 正式撈取資料 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 stationName = await backendRepository.GetOneAsync($"select distinct parent_path from import_niagara_item_history where device_number = '{device_number}' 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)) { @@ -1486,6 +1487,8 @@ namespace FrontendWebApi.ApiControllers // 檢查 valueFacets 是否包含 "range=E" string valueDisplaySql = string.Empty; + // 直接給千分位數值會讓前台套件顯示有問題,故頁面千分位顯示由前端處理,CSV千分位後端處理 + string DisplaySql = input.EnableLimit ? "ROUND(value, 2) AS Value" : " FORMAT(ROUND(value, 2), 'N2') AS Value"; if (valueFacets != null) { @@ -1531,6 +1534,8 @@ namespace FrontendWebApi.ApiControllers caseWhenStatements.Add($"when value = {correspondingValue} then '{chineseCharacters}'"); } } + + valueDisplaySql = $"Case {string.Join(" ", caseWhenStatements)} else 'Unknow' End as Value"; } // 處理 trueText 和 falseText 的部分 else if (valueFacets.Contains("trueText=s:") && valueFacets.Contains("falseText=s:")) @@ -1556,16 +1561,17 @@ namespace FrontendWebApi.ApiControllers // 添加 Case When 語句 caseWhenStatements.Add($"when value = 1 then '{trueTextPart}'"); caseWhenStatements.Add($"when value = 0 then '{falseTextPart}'"); + + valueDisplaySql = $"Case {string.Join(" ", caseWhenStatements)} else 'Unknow' End as Value"; } else { // 使用原始的顯示方式 valueDisplaySql = valueType.Equals("bit") ? "Case when value = 1 then 'true' when value = 0 then 'false' else 'Unknow' End as Value" - : "round(value, 2) as Value"; + : DisplaySql; } - // 最後的 SQL 語句 - valueDisplaySql = $"Case {string.Join(" ", caseWhenStatements)} else 'Unknow' End as Value"; + } @@ -1591,7 +1597,7 @@ namespace FrontendWebApi.ApiControllers apiResult.Code = "0000"; apiResult.Msg = @$"DB無資料的設備:{string.Join(".", noDataDevice)}"; - apiResult.Data = apiResult.Data.OrderBy(x => x.Device_number).ThenByDescending(x => x.Timestamp).ToList(); + apiResult.Data = apiResult.Data.OrderBy(x => x.Device_number).ThenBy(x => x.Points).ThenByDescending(x => x.Timestamp).ToList(); } catch (Exception exception) { diff --git a/FrontendWebApi/Models/Build.cs b/FrontendWebApi/Models/Build.cs index 0ecf5e2..00ce67d 100644 --- a/FrontendWebApi/Models/Build.cs +++ b/FrontendWebApi/Models/Build.cs @@ -197,6 +197,7 @@ namespace FrontendWebApi.Models public string point_name { get; set; } public string points { get; set; } public byte points_is_bool { get; set; } + public int is_RTSP { get; set; } // 巨蛋監視器控制項 public List Device_nodes { get; set; } public List deviceItems { get; set; } } diff --git a/FrontendWebApi/Models/HistoryClass.cs b/FrontendWebApi/Models/HistoryClass.cs index 9fdeb41..88adabd 100644 --- a/FrontendWebApi/Models/HistoryClass.cs +++ b/FrontendWebApi/Models/HistoryClass.cs @@ -259,6 +259,7 @@ namespace FrontendWebApi.Models { public string Start_timestamp { get; set; } public string End_timestamp { get; set; } + public bool EnableLimit { get; set; } = true; // 控制是否需要限制查詢筆數 public List HistoryItems { get; set; } }