From 9a3b098ee0927f2bd7225e6c7e1e3725737de325 Mon Sep 17 00:00:00 2001 From: dev01 Date: Sat, 23 Sep 2023 18:14:35 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=89=8D=E5=8F=B0API]=20=E5=A2=9E=E5=8A=A0=20?= =?UTF-8?q?GetDeviceListBySystem=20API=20=E5=B0=88=E9=96=80=E7=B5=A6?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E7=B4=80=E9=8C=84=E4=BD=9C=E6=A5=AD=E7=94=A8?= =?UTF-8?q?=E7=9A=84=20api=20=EF=BC=8C=E9=80=8F=E9=81=8E=E5=A4=9A=E7=AD=86?= =?UTF-8?q?=E5=A4=A7=E9=A1=9E=E8=88=87=E6=A3=9F=E5=88=A5=E5=8F=96=E5=BE=97?= =?UTF-8?q?=E8=A8=AD=E5=82=99=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/AlarmRecordController.cs | 3 +- .../ApiControllers/DeviceManageController.cs | 39 +++++++++++++++++++ FrontendWebApi/Models/Device.cs | 8 ++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/FrontendWebApi/ApiControllers/AlarmRecordController.cs b/FrontendWebApi/ApiControllers/AlarmRecordController.cs index 9739835..d25ba3c 100644 --- a/FrontendWebApi/ApiControllers/AlarmRecordController.cs +++ b/FrontendWebApi/ApiControllers/AlarmRecordController.cs @@ -51,7 +51,8 @@ namespace FrontendWebApi.ApiControllers b.full_name AS building_name, v1.system_value, v1.system_key - FROM building_menu bm + FROM + (SELECT * FROM building_menu ORDER BY priority) bm INNER JOIN ( SELECT ap.building_tag, ap.ShowView diff --git a/FrontendWebApi/ApiControllers/DeviceManageController.cs b/FrontendWebApi/ApiControllers/DeviceManageController.cs index 3f1f677..70b3dab 100644 --- a/FrontendWebApi/ApiControllers/DeviceManageController.cs +++ b/FrontendWebApi/ApiControllers/DeviceManageController.cs @@ -375,6 +375,45 @@ namespace FrontendWebApi.ApiControllers return Ok(apiResult); } + [HttpPost] + [Route("api/Device/GetDeviceListBySystem")] + public async Task>>> GetDeviceListBySystem(FindDevice fd) + { + ApiResult> apiResult = new ApiResult>(); + try + { + + List queryCollection = new List(); + if (!string.IsNullOrEmpty(fd.building_tag)) { + queryCollection.Add("device_building_tag = @building_tag"); + } + if (fd.main_system_tags != null && fd.main_system_tags.Count() > 0) + { + queryCollection.Add("device_system_tag IN @system_tags"); + } + queryCollection.Add("deleted = 0"); + + string query = string.Join(" AND ", queryCollection); + string sql = $@"SELECT * + FROM device + Where {query}"; + + var device = await backendRepository.GetAllAsync(sql, + new { building_tag = fd.building_tag , system_tags = fd.main_system_tags }); + + apiResult.Data = device; + apiResult.Code = "0000"; + } + catch (Exception exception) + { + + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + return Ok(apiResult); + } + return Ok(apiResult); + } + /// /// 獲取設備資料 /// diff --git a/FrontendWebApi/Models/Device.cs b/FrontendWebApi/Models/Device.cs index d17498a..21137de 100644 --- a/FrontendWebApi/Models/Device.cs +++ b/FrontendWebApi/Models/Device.cs @@ -12,6 +12,8 @@ namespace FrontendWebApi.Models public string floor_tag { get; set; } public string device_guid { get; set; } public string device_number { get; set; } + + public List main_system_tags { get; set; } = new List(); } public class BuildList @@ -194,5 +196,11 @@ namespace FrontendWebApi.Models } + public class DeviceFullList : DeviceBaseList + { + public string device_building_tag { get; set; } + public string device_system_tag { get; set; } + public string device_name_tag { get; set; } + } }