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