[後端] 修改jsonobject 獲取單資料問題

This commit is contained in:
dev02 2024-03-04 17:44:13 +08:00
parent 45c03969ec
commit 0fe5ad831c

View File

@ -1219,8 +1219,39 @@ namespace FrontendWebApi.ApiControllers
var dataList = responseContentJsonResult["obj"]["list"]; var dataList = responseContentJsonResult["obj"]["list"];
if (dataList != null && dataList["obj"].HasValues) if (dataList != null && dataList["obj"].HasValues)
{ {
//讀取資料 if (Convert.ToInt32(countObj["@val"].ToString()) > 1)
foreach (var obj in dataList["obj"]) {
//讀取資料
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(); HistoryRawData historyRawData = new HistoryRawData();
@ -1240,11 +1271,11 @@ namespace FrontendWebApi.ApiControllers
historyRawData.Unit = device_item_info.Unit; 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"); historyRawData.Timestamp = Convert.ToDateTime(abstime).ToString("yyyy-MM-dd HH:mm:ss");
//取得資料 //取得資料
string tag = device_item_info.Is_bool == "1" ? "bool" : "real"; 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); historyRawDatas.Add(historyRawData);
} }