From 0fe5ad831cf678bfc6bd8edf9056c9a531897b61 Mon Sep 17 00:00:00 2001 From: dev02 Date: Mon, 4 Mar 2024 17:44:13 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9jsonob?= =?UTF-8?q?ject=20=E7=8D=B2=E5=8F=96=E5=96=AE=E8=B3=87=E6=96=99=E5=95=8F?= =?UTF-8?q?=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/HistoryController.cs | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index 7b535f9..718a374 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -1219,8 +1219,39 @@ namespace FrontendWebApi.ApiControllers var dataList = responseContentJsonResult["obj"]["list"]; if (dataList != null && dataList["obj"].HasValues) { - //讀取資料 - foreach (var obj in dataList["obj"]) + if (Convert.ToInt32(countObj["@val"].ToString()) > 1) + { + //讀取資料 + foreach (var obj in dataList["obj"]) + { + HistoryRawData historyRawData = new HistoryRawData(); + + //取得設備基本資訊 + var tempSplit = historyItem.Device_number_point.Split(":"); + var device_number = tempSplit[0]; + var point = tempSplit[1]; + var device_item_info = device_item_infos.Where(x => x.Device_number == device_number && x.Points == point).FirstOrDefault(); + + historyRawData.Building_name = device_item_info.Building_name; + historyRawData.Main_system_name = device_item_info.Main_system_name; + historyRawData.Sub_system_name = device_item_info.Sub_system_name; + historyRawData.Device_number = device_item_info.Device_number; + historyRawData.Device_name = device_item_info.Device_name; + historyRawData.Item_name = device_item_info.Item_name; + historyRawData.Points = device_item_info.Points; + historyRawData.Unit = device_item_info.Unit; + + //取得時間 + var abstime = obj["abstime"]["@val"].ToString(); + historyRawData.Timestamp = Convert.ToDateTime(abstime).ToString("yyyy-MM-dd HH:mm:ss"); + //取得資料 + string tag = device_item_info.Is_bool == "1" ? "bool" : "real"; + historyRawData.Value = obj[tag]["@val"].ToString(); + + historyRawDatas.Add(historyRawData); + } + } + else { HistoryRawData historyRawData = new HistoryRawData(); @@ -1240,11 +1271,11 @@ namespace FrontendWebApi.ApiControllers historyRawData.Unit = device_item_info.Unit; //取得時間 - var abstime = obj["abstime"]["@val"].ToString(); + var abstime = dataList["obj"]["abstime"]["@val"].ToString(); historyRawData.Timestamp = Convert.ToDateTime(abstime).ToString("yyyy-MM-dd HH:mm:ss"); //取得資料 string tag = device_item_info.Is_bool == "1" ? "bool" : "real"; - historyRawData.Value = obj[tag]["@val"].ToString(); + historyRawData.Value = dataList["obj"][tag]["@val"].ToString(); historyRawDatas.Add(historyRawData); }