From 465a55f203b14797002a6dec761525baaace5bc8 Mon Sep 17 00:00:00 2001 From: dev01 Date: Fri, 27 Oct 2023 18:14:07 +0800 Subject: [PATCH] =?UTF-8?q?[=E7=B7=8A=E6=80=A5=E6=87=89=E8=AE=8A]=20?= =?UTF-8?q?=E8=A8=AD=E5=82=99=E6=B8=85=E5=96=AE=E5=8F=96=E5=BE=97=20Niagar?= =?UTF-8?q?a=20Alarm=20=E5=8E=9F=E7=A8=8B=E5=BA=8F=E4=BE=9D=E6=99=82?= =?UTF-8?q?=E9=96=93=E6=98=A8=E5=A4=A9=E5=88=B0=E4=BB=8A=E5=A4=A9=E5=8F=96?= =?UTF-8?q?=E5=BE=97=EF=BC=8C=E6=94=B9=E7=82=BA=E5=8B=95=E6=85=8B=E4=BE=9D?= =?UTF-8?q?=E6=93=9A=20variable=20=E8=B5=B7=E5=A7=8B=E6=99=82=E9=96=93?= =?UTF-8?q?=E7=A7=BB=E5=8B=95=E5=A4=A9=E6=95=B8=E6=8A=93=E5=8F=96=20Alarm?= =?UTF-8?q?=20|=20=E5=BB=BA=E7=AB=8B=E5=8F=96=E5=BE=97=E7=B7=8A=E6=80=A5?= =?UTF-8?q?=E6=87=89=E8=AE=8A=E5=8F=96=E5=BE=97Niagara=20Alarm=E6=99=82?= =?UTF-8?q?=E9=96=93=E7=AF=84=E5=9C=8D(=E8=B5=B7=E5=A7=8B=E7=A7=BB?= =?UTF-8?q?=E5=8B=95=E5=A4=A9=E6=95=B8=EF=BC=8C=E4=BB=8A=E6=97=A5=E7=82=BA?= =?UTF-8?q?0=E8=A8=88=E7=AE=97)=20API=20|=20GetDeviceGroup=20API=20SQL=20?= =?UTF-8?q?=E8=AA=BF=E6=95=B4=20(device=5Fgroup=20Table=20=E6=A3=84?= =?UTF-8?q?=E7=94=A8)=20|=20[=E7=B7=8A=E6=80=A5=E6=87=89=E8=AE=8A][View]?= =?UTF-8?q?=20ResetDeviceTable=20=E7=A8=8B=E5=BA=8F=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/AlarmController.cs | 5 +- .../EmergencyDeviceController.cs | 84 ++++++++++++++++--- .../Views/EmergencyDeviceMenu/Index.cshtml | 13 +-- .../Views/EmergencyHardwareMenu/Index.cshtml | 13 +-- 4 files changed, 90 insertions(+), 25 deletions(-) diff --git a/FrontendWebApi/ApiControllers/AlarmController.cs b/FrontendWebApi/ApiControllers/AlarmController.cs index 924ab5a..a9bbf46 100644 --- a/FrontendWebApi/ApiControllers/AlarmController.cs +++ b/FrontendWebApi/ApiControllers/AlarmController.cs @@ -54,6 +54,9 @@ namespace FrontendWebApi.ApiControllers 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(sqlString)) ?? "-1"); + string apiUrl = Path.Combine(baseApiUrl, "obix/config/Services/AlarmService/~alarmQuery/"); using (HttpClient client = new HttpClient()) @@ -65,7 +68,7 @@ namespace FrontendWebApi.ApiControllers client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded); // 建構 XML 數據 string xmlData = @$" - + "; HttpContent content = new StringContent(xmlData, Encoding.UTF8, "application/xml"); diff --git a/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs b/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs index 6bad12b..fd1dc76 100644 --- a/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs +++ b/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs @@ -1,6 +1,7 @@ using FrontendWebApi.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using Newtonsoft.Json; using Repository.BackendRepository.Interface; using Repository.FrontendRepository.Interface; using System; @@ -496,17 +497,45 @@ namespace FrontendWebApi.ApiControllers try { getDeviceGroup = await backendRepository.GetAllAsync($@" - 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 - from ( - SELECT * - FROM device_group dg WHERE dg.device_disaster != 0) dg - join (select * from variable v where v.system_type = 'disaster' and v.deleted = 0) vd on vd.system_value = dg.device_disaster - join building b on b.building_tag = dg.device_building_tag - join floor f on f.floor_guid = dg.device_floor_guid - 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 - 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 - order by vd.system_priority,b.priority,f.priority,v2.system_priority,v3.system_priority"); - + SELECT + dd.device_system_value 'device_disaster', + d.device_building_tag, + f.floor_guid 'device_floor_guid', + d.device_area_tag 'device_area_tag', + d.device_system_tag 'device_system_category_layer2', + d.device_name_tag 'device_system_category_layer3', + count(*) device_amount, + 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' + 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); //finalDeviceGroup.disaster = new List(); foreach (var diss in dis) @@ -583,7 +612,7 @@ namespace FrontendWebApi.ApiControllers { apiResult.Code = "9999"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception); } return Ok(apiResult); @@ -629,5 +658,36 @@ namespace FrontendWebApi.ApiControllers } return Ok(apiResult); } + + /// + /// 取得緊急應變取得Niagara Alarm時間範圍(起始移動天數,今日為0計算) + /// + /// + /// + [HttpPost] + [Route("api/EmergencyDevice/GetNiagaraAlarmMoveDayStart")] + public async Task>> GetNiagaraAlarmMoveDayStart() + { + ApiResult apiResult = new ApiResult(); + + 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(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); + } } + } diff --git a/FrontendWebApi/Views/EmergencyDeviceMenu/Index.cshtml b/FrontendWebApi/Views/EmergencyDeviceMenu/Index.cshtml index 951d24f..152917a 100644 --- a/FrontendWebApi/Views/EmergencyDeviceMenu/Index.cshtml +++ b/FrontendWebApi/Views/EmergencyDeviceMenu/Index.cshtml @@ -1308,12 +1308,13 @@ return; } - if (changeBuilding != "" && changeBuilding != SelectedFilter.building_tag) { - alarmDeviceTable.clear().draw(); - } - else { - alarmDeviceTable.ajax.reload(null, false); - } + //if (changeBuilding != "" && changeBuilding != SelectedFilter.building_tag) { + // alarmDeviceTable.clear().draw(); + //} + //else { + // alarmDeviceTable.ajax.reload(null, false); + //} + alarmDeviceTable.ajax.reload(null, false); changeBuilding = SelectedFilter.building_tag; } //#endregion diff --git a/FrontendWebApi/Views/EmergencyHardwareMenu/Index.cshtml b/FrontendWebApi/Views/EmergencyHardwareMenu/Index.cshtml index e67fc7e..9688bed 100644 --- a/FrontendWebApi/Views/EmergencyHardwareMenu/Index.cshtml +++ b/FrontendWebApi/Views/EmergencyHardwareMenu/Index.cshtml @@ -1251,12 +1251,13 @@ return; } - if (changeBuilding != "" && changeBuilding != SelectedFilter.building_tag) { - alarmDeviceTable.clear().draw(); - } - else { - alarmDeviceTable.ajax.reload(null, false); - } + //if (changeBuilding != "" && changeBuilding != SelectedFilter.building_tag) { + // alarmDeviceTable.clear().draw(); + //} + //else { + // alarmDeviceTable.ajax.reload(null, false); + //} + alarmDeviceTable.ajax.reload(null, false); changeBuilding = SelectedFilter.building_tag; } //#endregion