[緊急應變] 設備清單取得 Niagara Alarm 原程序依時間昨天到今天取得,改為動態依據 variable 起始時間移動天數抓取 Alarm | 建立取得緊急應變取得Niagara Alarm時間範圍(起始移動天數,今日為0計算) API | GetDeviceGroup API SQL 調整 (device_group Table 棄用) | [緊急應變][View] ResetDeviceTable 程序調整

This commit is contained in:
dev01 2023-10-27 18:14:07 +08:00
parent 8b70a69ecd
commit 465a55f203
4 changed files with 90 additions and 25 deletions

View File

@ -54,6 +54,9 @@ namespace FrontendWebApi.ApiControllers
return BadRequest(apiResult); return BadRequest(apiResult);
} }
sqlString = $@"SELECT system_value FROM variable WHERE system_type = 'emergencyConfig' AND system_key = 'getNiagaraAlarmMoveDayNumStart' AND deleted = 0";
int moveDayNum = int.Parse((await frontendRepository.GetOneAsync<string>(sqlString)) ?? "-1");
string apiUrl = Path.Combine(baseApiUrl, "obix/config/Services/AlarmService/~alarmQuery/"); string apiUrl = Path.Combine(baseApiUrl, "obix/config/Services/AlarmService/~alarmQuery/");
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
@ -65,7 +68,7 @@ namespace FrontendWebApi.ApiControllers
client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded); client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded);
// 建構 XML 數據 // 建構 XML 數據
string xmlData = @$"<obj href='obix:AlarmFilter'> string xmlData = @$"<obj href='obix:AlarmFilter'>
<abstime name='start' val='{DateTime.Now.AddDays(-1).ToString("yyyy-MM-ddTHH:mm:ss.fff")}+08:00' /> <abstime name='start' val='{DateTime.Now.AddDays(moveDayNum).ToString("yyyy-MM-ddTHH:mm:ss.fff")}+08:00' />
<abstime name='end' val='{DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff")}+08:00'/> <abstime name='end' val='{DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff")}+08:00'/>
</obj>"; </obj>";
HttpContent content = new StringContent(xmlData, Encoding.UTF8, "application/xml"); HttpContent content = new StringContent(xmlData, Encoding.UTF8, "application/xml");

View File

@ -1,6 +1,7 @@
using FrontendWebApi.Models; using FrontendWebApi.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Repository.BackendRepository.Interface; using Repository.BackendRepository.Interface;
using Repository.FrontendRepository.Interface; using Repository.FrontendRepository.Interface;
using System; using System;
@ -496,17 +497,45 @@ namespace FrontendWebApi.ApiControllers
try try
{ {
getDeviceGroup = await backendRepository.GetAllAsync<EmergencyDeviceGroup>($@" getDeviceGroup = await backendRepository.GetAllAsync<EmergencyDeviceGroup>($@"
select dg.*,vd.system_key disater_name,b.full_name building_name,f.full_name floor_name,v2.system_key system_category_layer2,v3.system_key system_category_layer3 SELECT
from ( dd.device_system_value 'device_disaster',
SELECT * d.device_building_tag,
FROM device_group dg WHERE dg.device_disaster != 0) dg f.floor_guid 'device_floor_guid',
join (select * from variable v where v.system_type = 'disaster' and v.deleted = 0) vd on vd.system_value = dg.device_disaster d.device_area_tag 'device_area_tag',
join building b on b.building_tag = dg.device_building_tag d.device_system_tag 'device_system_category_layer2',
join floor f on f.floor_guid = dg.device_floor_guid d.device_name_tag 'device_system_category_layer3',
join (select * from variable v where v.system_type = 'device_system_category_layer2' and v.deleted = 0) v2 on v2.system_value = dg.device_system_category_layer2 count(*) device_amount,
join (select * from variable v where v.system_type = 'device_system_category_layer3' and v.deleted = 0) v3 on v3.system_value = dg.device_system_category_layer3 vd.system_key 'disater_name',
order by vd.system_priority,b.priority,f.priority,v2.system_priority,v3.system_priority"); b.full_name 'building_name',
f.full_name 'floor_name',
v2.system_key 'system_category_layer2',
v3.system_key 'system_category_layer3'
FROM
device_disaster dd
JOIN ( SELECT * FROM variable WHERE system_type = 'disaster' ) vd ON dd.device_system_value = vd.system_value
JOIN floor f ON f.full_name = dd.device_floor_tag
AND f.building_tag = dd.device_building_tag
JOIN device d ON d.device_number = dd.device_number
JOIN building b ON b.building_tag = d.device_building_tag
JOIN ( SELECT * FROM variable v WHERE v.system_type = 'device_system_category_layer2' AND v.deleted = 0 ) v2 ON v2.system_value = d.device_system_tag
JOIN ( SELECT * FROM variable v WHERE v.system_type = 'device_system_category_layer3' AND v.deleted = 0 ) v3 ON v3.system_value = d.device_name_tag
WHERE
d.deleted = 0
AND f.deleted = 0
AND b.deleted = 0
GROUP BY
dd.device_system_value,
d.device_building_tag,
device_floor_guid,
device_area_tag,
device_system_category_layer2,
device_system_category_layer3,
d.device_name_tag,
building_name,
floor_name,
disater_name,
system_category_layer2,
system_category_layer3");
var dis = getDeviceGroup.GroupBy(a => a.device_disaster); var dis = getDeviceGroup.GroupBy(a => a.device_disaster);
//finalDeviceGroup.disaster = new List<KeyValue>(); //finalDeviceGroup.disaster = new List<KeyValue>();
foreach (var diss in dis) foreach (var diss in dis)
@ -583,7 +612,7 @@ namespace FrontendWebApi.ApiControllers
{ {
apiResult.Code = "9999"; apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception);
} }
return Ok(apiResult); return Ok(apiResult);
@ -629,5 +658,36 @@ namespace FrontendWebApi.ApiControllers
} }
return Ok(apiResult); return Ok(apiResult);
} }
/// <summary>
/// 取得緊急應變取得Niagara Alarm時間範圍(起始移動天數今日為0計算)
/// </summary>
/// <param name="account"></param>
/// <returns></returns>
[HttpPost]
[Route("api/EmergencyDevice/GetNiagaraAlarmMoveDayStart")]
public async Task<ActionResult<ApiResult<int>>> GetNiagaraAlarmMoveDayStart()
{
ApiResult<int> apiResult = new ApiResult<int>();
try
{
var sqlString = $@"SELECT system_value FROM variable WHERE system_type = 'emergencyConfig' AND system_key = 'getNiagaraAlarmMoveDayNumStart' AND deleted = 0";
int moveDayNum = int.Parse((await frontendRepository.GetOneAsync<string>(sqlString)) ?? "-1");
apiResult.Code = "0000";
apiResult.Data = moveDayNum;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception);
return Ok(apiResult);
}
return Ok(apiResult);
}
} }
} }

View File

@ -1308,12 +1308,13 @@
return; return;
} }
if (changeBuilding != "" && changeBuilding != SelectedFilter.building_tag) { //if (changeBuilding != "" && changeBuilding != SelectedFilter.building_tag) {
alarmDeviceTable.clear().draw(); // alarmDeviceTable.clear().draw();
} //}
else { //else {
alarmDeviceTable.ajax.reload(null, false); // alarmDeviceTable.ajax.reload(null, false);
} //}
alarmDeviceTable.ajax.reload(null, false);
changeBuilding = SelectedFilter.building_tag; changeBuilding = SelectedFilter.building_tag;
} }
//#endregion //#endregion

View File

@ -1251,12 +1251,13 @@
return; return;
} }
if (changeBuilding != "" && changeBuilding != SelectedFilter.building_tag) { //if (changeBuilding != "" && changeBuilding != SelectedFilter.building_tag) {
alarmDeviceTable.clear().draw(); // alarmDeviceTable.clear().draw();
} //}
else { //else {
alarmDeviceTable.ajax.reload(null, false); // alarmDeviceTable.ajax.reload(null, false);
} //}
alarmDeviceTable.ajax.reload(null, false);
changeBuilding = SelectedFilter.building_tag; changeBuilding = SelectedFilter.building_tag;
} }
//#endregion //#endregion