[Webapi]修正緊急壓扣少樓層問題,歷史資料加上千分位
This commit is contained in:
parent
9f2a1b4825
commit
4895975a46
@ -359,12 +359,22 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
var sub_system = await backendRepository.GetOneAsync<BuildMenuSql>(@$"select v.system_key subfull_name,me.* from building_menu me
|
var sub_system = await backendRepository.GetOneAsync<BuildMenuSql>(@$"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
|
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");
|
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");
|
||||||
|
get.sub_system_tag = get.sub_system_tag == "P" ? $"'{get.sub_system_tag}','B'" : $"'{get.sub_system_tag}'"; // 巨蛋緊急壓扣(P)跟閃光喇吧被視為同一類
|
||||||
List<Floor> Floors = new List<Floor>();
|
List <Floor> Floors = new List<Floor>();
|
||||||
var floorsql = await backendRepository.GetAllAsync<Floorsql>($@"
|
var floorsql = await backendRepository.GetAllAsync<Floorsql>($@"
|
||||||
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
|
left join floor on floor.full_name = a.floor_tag and a.building_tag = floor.building_tag
|
||||||
where floor.deleted = 0
|
where floor.deleted = 0
|
||||||
|
GROUP BY a.floor_tag, a.building_tag, a.merged_sub_system_tag
|
||||||
order by floor.priority");
|
order by floor.priority");
|
||||||
Sub_system sub_System = new Sub_system()
|
Sub_system sub_System = new Sub_system()
|
||||||
{
|
{
|
||||||
@ -402,6 +412,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
apiResult.Code = "9999";
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = "9999";
|
||||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||||
return Ok(apiResult);
|
return Ok(apiResult);
|
||||||
}
|
}
|
||||||
|
@ -319,6 +319,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
input.EnableLimit = false; // CSV關閉5W筆限制
|
||||||
var apiData = await GetHistoryRealTime(input);
|
var apiData = await GetHistoryRealTime(input);
|
||||||
if (apiData.Value == null)
|
if (apiData.Value == null)
|
||||||
{
|
{
|
||||||
@ -1394,6 +1395,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
ApiResult<List<HistoryRawData>> apiResult = new ApiResult<List<HistoryRawData>>(jwt_str);
|
ApiResult<List<HistoryRawData>> apiResult = new ApiResult<List<HistoryRawData>>(jwt_str);
|
||||||
apiResult.Data = new List<HistoryRawData>();
|
apiResult.Data = new List<HistoryRawData>();
|
||||||
List<string> noDataDevice = new List<string>();
|
List<string> noDataDevice = new List<string>();
|
||||||
|
|
||||||
if (!jwtlife)
|
if (!jwtlife)
|
||||||
{
|
{
|
||||||
apiResult.Code = "5000";
|
apiResult.Code = "5000";
|
||||||
@ -1439,41 +1441,40 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
int totalRecordCount = 0;
|
int totalRecordCount = 0;
|
||||||
|
|
||||||
// 先計算總記錄數
|
// 先計算總記錄數
|
||||||
foreach (var hi in input.HistoryItems)
|
if (input.EnableLimit)
|
||||||
{
|
{
|
||||||
var device_number = hi.Device_number_point.Split(":")[0];
|
foreach (var hi in input.HistoryItems)
|
||||||
var point = hi.Device_number_point.Split(":")[1];
|
|
||||||
var stationName = await backendRepository.GetOneAsync<string>($"select distinct parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split('_')[0]}' limit 1");
|
|
||||||
var tableName = await backgroundServiceMsSqlRepository.GetOneAsync<string>($"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}
|
var device_number = hi.Device_number_point.Split(":")[0];
|
||||||
|
var point = hi.Device_number_point.Split(":")[1];
|
||||||
|
var stationName = await backendRepository.GetOneAsync<string>($"select distinct parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split('_')[0]}' limit 1");
|
||||||
|
var tableName = await backgroundServiceMsSqlRepository.GetOneAsync<string>($"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
|
where replace(convert(varchar, [timestamp], 111), '/', '-') >= @startTime
|
||||||
and replace(convert(varchar, [timestamp], 111), '/', '-') <= @endTime";
|
and replace(convert(varchar, [timestamp], 111), '/', '-') <= @endTime";
|
||||||
|
|
||||||
var recordCount = await backgroundServiceMsSqlRepository.GetOneAsync<int>(sqlCount, new { startTime = input.Start_timestamp, endTime = input.End_timestamp });
|
var recordCount = await backgroundServiceMsSqlRepository.GetOneAsync<int>(sqlCount, new { startTime = input.Start_timestamp, endTime = input.End_timestamp });
|
||||||
totalRecordCount += recordCount;
|
totalRecordCount += recordCount;
|
||||||
|
|
||||||
if (totalRecordCount > 50000)
|
if (totalRecordCount > 50000)
|
||||||
{
|
{
|
||||||
// 如果總記錄數超過5萬筆,返回提示信息
|
// 如果總記錄數超過5萬筆,返回提示信息
|
||||||
apiResult.Code = "5000";
|
apiResult.Code = "5000";
|
||||||
apiResult.Msg = "資料量超過5萬筆,請減少選擇區間或設備";
|
apiResult.Msg = "資料量超過5萬筆,請減少選擇區間或設備";
|
||||||
return apiResult;
|
return apiResult;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
noDataDevice.Add(hi.Device_number_point);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 正式撈取資料
|
// 正式撈取資料
|
||||||
foreach (var hi in input.HistoryItems)
|
foreach (var hi in input.HistoryItems)
|
||||||
{
|
{
|
||||||
var device_number = hi.Device_number_point.Split(":")[0];
|
var device_number = hi.Device_number_point.Split(":")[0];
|
||||||
var point = hi.Device_number_point.Split(":")[1];
|
var point = hi.Device_number_point.Split(":")[1];
|
||||||
var stationName = await backendRepository.GetOneAsync<string>($"select distinct parent_path from import_niagara_item_history where device_building_tag = '{device_number.Split('_')[0]}' limit 1");
|
var stationName = await backendRepository.GetOneAsync<string>($"select distinct parent_path from import_niagara_item_history where device_number = '{device_number}' limit 1");
|
||||||
var tableName = await backgroundServiceMsSqlRepository.GetOneAsync<string>($"select table_name from INFORMATION_SCHEMA.TABLES where table_name like '%{stationName}_{device_number}_{point}%'");
|
var tableName = await backgroundServiceMsSqlRepository.GetOneAsync<string>($"select table_name from INFORMATION_SCHEMA.TABLES where table_name like '%{stationName}_{device_number}_{point}%'");
|
||||||
if (!string.IsNullOrEmpty(tableName))
|
if (!string.IsNullOrEmpty(tableName))
|
||||||
{
|
{
|
||||||
@ -1486,6 +1487,8 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
|
|
||||||
// 檢查 valueFacets 是否包含 "range=E"
|
// 檢查 valueFacets 是否包含 "range=E"
|
||||||
string valueDisplaySql = string.Empty;
|
string valueDisplaySql = string.Empty;
|
||||||
|
// 直接給千分位數值會讓前台套件顯示有問題,故頁面千分位顯示由前端處理,CSV千分位後端處理
|
||||||
|
string DisplaySql = input.EnableLimit ? "ROUND(value, 2) AS Value" : " FORMAT(ROUND(value, 2), 'N2') AS Value";
|
||||||
|
|
||||||
if (valueFacets != null)
|
if (valueFacets != null)
|
||||||
{
|
{
|
||||||
@ -1531,6 +1534,8 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
caseWhenStatements.Add($"when value = {correspondingValue} then '{chineseCharacters}'");
|
caseWhenStatements.Add($"when value = {correspondingValue} then '{chineseCharacters}'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
valueDisplaySql = $"Case {string.Join(" ", caseWhenStatements)} else 'Unknow' End as Value";
|
||||||
}
|
}
|
||||||
// 處理 trueText 和 falseText 的部分
|
// 處理 trueText 和 falseText 的部分
|
||||||
else if (valueFacets.Contains("trueText=s:") && valueFacets.Contains("falseText=s:"))
|
else if (valueFacets.Contains("trueText=s:") && valueFacets.Contains("falseText=s:"))
|
||||||
@ -1556,16 +1561,17 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
// 添加 Case When 語句
|
// 添加 Case When 語句
|
||||||
caseWhenStatements.Add($"when value = 1 then '{trueTextPart}'");
|
caseWhenStatements.Add($"when value = 1 then '{trueTextPart}'");
|
||||||
caseWhenStatements.Add($"when value = 0 then '{falseTextPart}'");
|
caseWhenStatements.Add($"when value = 0 then '{falseTextPart}'");
|
||||||
|
|
||||||
|
valueDisplaySql = $"Case {string.Join(" ", caseWhenStatements)} else 'Unknow' End as Value";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 使用原始的顯示方式
|
// 使用原始的顯示方式
|
||||||
valueDisplaySql = valueType.Equals("bit")
|
valueDisplaySql = valueType.Equals("bit")
|
||||||
? "Case when value = 1 then 'true' when value = 0 then 'false' else 'Unknow' End as Value"
|
? "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.Code = "0000";
|
||||||
apiResult.Msg = @$"DB無資料的設備:{string.Join(".", noDataDevice)}";
|
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)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
@ -197,6 +197,7 @@ namespace FrontendWebApi.Models
|
|||||||
public string point_name { get; set; }
|
public string point_name { get; set; }
|
||||||
public string points { get; set; }
|
public string points { get; set; }
|
||||||
public byte points_is_bool { get; set; }
|
public byte points_is_bool { get; set; }
|
||||||
|
public int is_RTSP { get; set; } // 巨蛋監視器控制項
|
||||||
public List<DeviceNode> Device_nodes { get; set; }
|
public List<DeviceNode> Device_nodes { get; set; }
|
||||||
public List<DeviceItem> deviceItems { get; set; }
|
public List<DeviceItem> deviceItems { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -259,6 +259,7 @@ namespace FrontendWebApi.Models
|
|||||||
{
|
{
|
||||||
public string Start_timestamp { get; set; }
|
public string Start_timestamp { get; set; }
|
||||||
public string End_timestamp { get; set; }
|
public string End_timestamp { get; set; }
|
||||||
|
public bool EnableLimit { get; set; } = true; // 控制是否需要限制查詢筆數
|
||||||
public List<HistoryItem> HistoryItems { get; set; }
|
public List<HistoryItem> HistoryItems { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user