From d46e6ec094e9c933a9befa5abc7cac0993fd8f48 Mon Sep 17 00:00:00 2001 From: dev02 Date: Fri, 11 Nov 2022 17:38:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8D=80=E6=9D=B1=E6=A8=93ap?= =?UTF-8?q?i?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/OperationController.cs | 79 ++++++++++++++++--- 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/FrontendWebApi/ApiControllers/OperationController.cs b/FrontendWebApi/ApiControllers/OperationController.cs index 445851c..fb59396 100644 --- a/FrontendWebApi/ApiControllers/OperationController.cs +++ b/FrontendWebApi/ApiControllers/OperationController.cs @@ -96,22 +96,18 @@ namespace FrontendWebApi.ApiControllers } /// - /// 大樓列表 + /// 地區列表 /// /// [HttpPost] - public async Task>> BuiList() + public async Task>> AreaList() { ApiResult> apiResult = new ApiResult>(); List bl = new List(); try { - var sqlString = @$"select d.device_area_tag, d.device_building_tag, d.device_floor_tag, CONCAT(case when d.device_area_tag='TPE' then '台北市' else '新北市' end, b.full_name, d.device_floor_tag) as full_name - from device d - join building b on d.device_building_tag = b.building_tag - where d.deleted = 0 - group by d.device_area_tag, d.device_building_tag, d.device_floor_tag, b.full_name"; + var sqlString = @$"select system_key as area_name, system_value as device_area_tag from variable where deleted = 0 and system_type = 'area'"; bl = await backendRepository.GetAllAsync(sqlString); @@ -128,6 +124,71 @@ namespace FrontendWebApi.ApiControllers return apiResult; } + /// + /// 大樓列表 + /// + /// + [HttpPost] + public async Task>> BuiList([FromBody] BuildingList b) + { + ApiResult> apiResult = new ApiResult>(); + List bl = new List(); + + try + { + var sqlString = @$"select d.device_building_tag, b.full_name as building_name + from device d + join building b on d.device_building_tag = b.building_tag + where d.deleted = 0 and d.device_area_tag = @device_area_tag + group by b.building_name, d.device_building_tag"; + + bl = await backendRepository.GetAllAsync(sqlString, new { @device_area_tag = b.device_area_tag }); + + apiResult.Code = "0000"; + apiResult.Data = bl; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + + /// + /// 大樓列表 + /// + /// + [HttpPost] + public async Task>> FloList([FromBody] BuildingList b) + { + ApiResult> apiResult = new ApiResult>(); + List bl = new List(); + + try + { + var sqlString = @$"select d.device_floor_tag + from device d + where d.deleted = 0 and d.device_area_tag = @device_area_tag and d.device_building_tag = @device_building_tag + group by d.device_floor_tag"; + + bl = await backendRepository.GetAllAsync(sqlString, new { @device_area_tag = b.device_area_tag, @device_building_tag = b.device_building_tag }); + + apiResult.Code = "0000"; + apiResult.Data = bl; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + /// /// 設備列表 /// @@ -141,9 +202,9 @@ namespace FrontendWebApi.ApiControllers try { var sqlString = @$"select device_number, concat(device_floor_tag, ' ', device_last_name, ' ', device_serial_tag) as device_name - from device where deleted = 0 and device_building_tag = @device_building_tag and device_floor_tag = @device_floor_tag"; + from device where deleted = 0 and device_area_tag = @device_area_tag and device_building_tag = @device_building_tag and device_floor_tag = @device_floor_tag"; - var param = new { @device_building_tag = bl.device_building_tag, @device_floor_tag = bl.device_floor_tag }; + var param = new { @device_building_tag = bl.device_building_tag, @device_floor_tag = bl.device_floor_tag, @device_area_tag = bl.device_area_tag }; d = await backendRepository.GetAllAsync(sqlString, param);