diff --git a/Backend/Controllers/NiagaraDataSynchronizeController.cs b/Backend/Controllers/NiagaraDataSynchronizeController.cs index 1388483..cad41e1 100644 --- a/Backend/Controllers/NiagaraDataSynchronizeController.cs +++ b/Backend/Controllers/NiagaraDataSynchronizeController.cs @@ -120,6 +120,7 @@ namespace Backend.Controllers await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName(); await niagaraDataSynchronizeRepository.InsertBuildingMenu(); await niagaraDataSynchronizeRepository.InsertSubSystemFloor(); + await niagaraDataSynchronizeRepository.InsertFloor(); await this.DeviceDisasterAsync(); result = true; diff --git a/Backend/Services/Implement/webRequestService.cs b/Backend/Services/Implement/webRequestService.cs index 7219dcd..50cd254 100644 --- a/Backend/Services/Implement/webRequestService.cs +++ b/Backend/Services/Implement/webRequestService.cs @@ -4,23 +4,9 @@ using System.Linq; using System.Xml; using Newtonsoft.Json; using Repository.Models; -using Newtonsoft.Json.Linq; using System.IO; using System.Net; -using System.Text; using System.Xml.Linq; -using Repository.BackendRepository.Implement; -using Repository.BackendRepository; -using Ubiety.Dns.Core; -using System.Diagnostics; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using Repository.Models.CodeBeautify; -using NPOI.SS.Formula.Functions; -using Microsoft.AspNetCore.Localization; -using MySqlX.XDevAPI.Relational; -using Backend.Models; -using NPOI.OpenXmlFormats.Dml; namespace Backend.Services.Implement { @@ -151,6 +137,7 @@ namespace Backend.Services.Implement #region get control point data List conPoint = new List(); String cp_API_Url = bqlUrlString; + String building_tag = slot.Split("/")[2].Replace("|", "_").Trim(); //Ex: D2_, M_ HttpWebRequest cp_Postrequest = (HttpWebRequest)WebRequest.Create(cp_API_Url); cp_Postrequest.Method = "POST"; @@ -220,8 +207,14 @@ namespace Backend.Services.Implement XmlDocument xmlDoc2 = new XmlDocument(); xmlDoc2.LoadXml(responseString2); + // Create a namespace manager to handle the XML namespace + XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc2.NameTable); + string xmlns = xmlDoc2.DocumentElement.GetAttribute("xmlns") ?? "http://obix.org/ns/schema/1.0"; + namespaceManager.AddNamespace("obix", xmlns); - foreach (XmlNode node2 in xmlDoc2.DocumentElement.ChildNodes) + // Select all "ref" nodes using an XPath expression + XmlNodeList refNodes = xmlDoc2.SelectNodes($"//obix:ref[starts-with(@name, '{building_tag}')]", namespaceManager); + foreach (XmlNode node2 in refNodes) { string tagName = node2.Attributes["name"].InnerText; if (tagName.Split('_').Length == 9) @@ -241,8 +234,8 @@ namespace Backend.Services.Implement row.isHistory = true; result.Add(row); - - } else if (tagName.Split('_').Length == 6) + } + else if (tagName.Split('_').Length == 6) { //巨蛋 tag 5 段版本 ImpNiaItem row = new ImpNiaItem(); if (tagName.Split('_')[1] == "S") //for security system diff --git a/Backend/Views/BuildInfo/Index.cshtml b/Backend/Views/BuildInfo/Index.cshtml index a498f85..29306d2 100644 --- a/Backend/Views/BuildInfo/Index.cshtml +++ b/Backend/Views/BuildInfo/Index.cshtml @@ -762,11 +762,14 @@ return; } else { + $('#floor-modal').modal(); + $("#BuildName").html(selected_build_guid_top_name); $("#floor_name_modal").val(rel.data.full_name); - @*$("#map_file_preview_modal").attr("data-original", rel.data.mapUrl);*@ - - $('#floor-modal').modal(); + if (rel.data.mapUrl) + loadURLToInputFiled(rel.data.mapUrl, rel.data.initMapName + ".svg"); + else + $('#floor_map_file_modal')[0].value = ""; } }, 'json'); }); @@ -977,6 +980,27 @@ } //#endregion + function loadURLToInputFiled(url, filesName){ + getImgURL(url, (imgBlob)=>{ + // Load img blob to input + // WIP: UTF8 character error + let fileName = filesName + let file = new File([imgBlob], fileName,{type:"image/svg+xml", lastModified:new Date().getTime()}, 'utf-8'); + let container = new DataTransfer(); + container.items.add(file); + $('#floor_map_file_modal')[0].files = container.files; + }) + } + // xmlHTTP return blob respond + function getImgURL(url, callback){ + var xhr = new XMLHttpRequest(); + xhr.onload = function() { + callback(xhr.response); + }; + xhr.open('GET', url); + xhr.responseType = 'blob'; + xhr.send(); + } } \ No newline at end of file diff --git a/Backend/Views/BuildMenu/Index.cshtml b/Backend/Views/BuildMenu/Index.cshtml index c8ff911..07d0521 100644 --- a/Backend/Views/BuildMenu/Index.cshtml +++ b/Backend/Views/BuildMenu/Index.cshtml @@ -509,7 +509,7 @@ { "data": null, "render": function (data, type, row, meta){ - return ' '; + return ' '; } } ], diff --git a/Backend/Views/NiagaraDataSynchronize/Index.cshtml b/Backend/Views/NiagaraDataSynchronize/Index.cshtml index 7bd6a7d..25254ad 100644 --- a/Backend/Views/NiagaraDataSynchronize/Index.cshtml +++ b/Backend/Views/NiagaraDataSynchronize/Index.cshtml @@ -140,8 +140,9 @@ //#endregion function SynchronizeData() { - document.getElementById('loadDataText').innerText = "同步中..."; if (ds.length > 0) { + document.getElementById('loadDataText').innerText = "同步中..."; + showSpinner(); //比對資料,有差異的話,再同步到device等資料表 var url_synchronize_data = "/NiagaraDataSynchronize/CompareData/"; @@ -154,20 +155,25 @@ url: url_synchronize_data, data: JSON.stringify(ds), cache: false, - async: false, + async: true, contentType: "application/json; charset=UTF-8", dataType: 'json', success: function (rel) { if (rel.code != "0000") { + hideSpinner(); toast_error(rel.msg); document.getElementById('loadDataText').innerText = "比對資料出錯了!"; return; } + SyncDevItem(); //var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); //var dateTime = date + ' ' + time; //document.getElementById('loadDataText').innerText = "比對完成 \n" + dateTime; }, + error: function () { + hideSpinner(); + } }); } else { @@ -192,11 +198,12 @@ dataType: 'json', success: function (rel) { if (rel.code != "0000") { + hideSpinner(); toast_error(rel.msg); document.getElementById('loadDataText').innerText = "比對資料出錯了!"; return; } - + $.ajax({ method: "POST", url: url_synchronize_data_device_item, @@ -208,15 +215,20 @@ success: function (rel) { if (rel.code != "0000") { toast_error(rel.msg); + hideSpinner(); document.getElementById('loadDataText').innerText = "比對資料出錯了!"; return; } + hideSpinner(); console.log(rel); var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); var dateTime = date + ' ' + time; document.getElementById('loadDataText').innerText = "比對完成 \n" + dateTime; }, + error: function () { + hideSpinner(); + } }) var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); var dateTime = date + ' ' + time; diff --git a/Backend/Views/Shared/_Layout.cshtml b/Backend/Views/Shared/_Layout.cshtml index c5d27af..9587242 100644 --- a/Backend/Views/Shared/_Layout.cshtml +++ b/Backend/Views/Shared/_Layout.cshtml @@ -27,6 +27,11 @@ +
+
+ Loading... +
+
diff --git a/Backend/Views/UserInfo/_RoleAuth.cshtml b/Backend/Views/UserInfo/_RoleAuth.cshtml index 0416027..9c9b339 100644 --- a/Backend/Views/UserInfo/_RoleAuth.cshtml +++ b/Backend/Views/UserInfo/_RoleAuth.cshtml @@ -23,7 +23,7 @@ # 角色 功能類型 - 區域 + 棟別 功能名稱 功能細項名稱 建立時間 diff --git a/Backend/appsettings.Development.json b/Backend/appsettings.Development.json index c20498b..060577f 100644 --- a/Backend/appsettings.Development.json +++ b/Backend/appsettings.Development.json @@ -18,10 +18,10 @@ "Port": "js2LutKe+rdjzdxMPQUrvQ==", //"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 //"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp - //"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome + "Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome //"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel //"Database": "iuaY0h0+TWkir44/eZLDqw==", //tpe_dome_office - "Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut + //"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut //"Database": "2U+9jYGy0dCbMzLaguBXow==", //tpe_dome_mall "Root": "SzdxEgaJJ7tcTCrUl2zKsA==", "Password": "FVAPxztxpY4gJJKQ/se4bQ==" diff --git a/Backend/wwwroot/css/site.css b/Backend/wwwroot/css/site.css index dd26b5a..3319720 100644 --- a/Backend/wwwroot/css/site.css +++ b/Backend/wwwroot/css/site.css @@ -46,4 +46,35 @@ label.error { .t-gray { color:var(--bims-gray) !important; +} + +/* Absolute Center Spinner */ +.loading { + position: fixed; + z-index: 999; + display: block; + margin: auto; + top: 0; + left: 0; + bottom: 0; + right: 0; + width: 50px; + height: 50px; +} + +/* Transparent Overlay */ +.loading:before { + content: ''; + display: block; + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: radial-gradient(rgba(0, 0, 0, .5), rgba(0, 0, 0, .5)); + background: -webkit-radial-gradient(rgba(0, 0, 0, .5), rgba(0, 0, 0, .5)); +} + +.loading.hide { + display: none; } \ No newline at end of file diff --git a/Backend/wwwroot/js/site.js b/Backend/wwwroot/js/site.js index 0cccb43..51b8b64 100644 --- a/Backend/wwwroot/js/site.js +++ b/Backend/wwwroot/js/site.js @@ -222,3 +222,11 @@ function SaveSpinner(status) { //1:Spinner 0:還原儲存 $(document).ready(function () { }); + +function showSpinner() { + $("#spinner").removeClass("hide"); +} + +function hideSpinner() { + $("#spinner").addClass("hide"); +} \ No newline at end of file diff --git a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs index 79bc6db..9cdfa62 100644 --- a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs +++ b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs @@ -47,6 +47,7 @@ namespace BackendWorkerService.Quartz.Jobs public async Task Execute(IJobExecutionContext context) { Task_Detail task_Detail = new Task_Detail(loggers, backgroundServiceRepository); + string device_number = string.Empty; try { if(await task_Detail.GetNeedWorkTask("ArchiveElectricMeterDayJob", "All")) @@ -159,8 +160,8 @@ namespace BackendWorkerService.Quartz.Jobs List> waterArchiveDayRawDatas = new List>(); foreach (var deviceNumberPoint in electricDeviceNumberPoints) { - - archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); + device_number = deviceNumberPoint.FullDeviceNumberPoint; + archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/"); //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; archiveRequest.Headers.Add("Authorization", "Basic " + encoded); @@ -216,8 +217,8 @@ namespace BackendWorkerService.Quartz.Jobs } foreach (var deviceNumberPoint in waterDeviceNumberPoints) { - - archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); + device_number = deviceNumberPoint.FullDeviceNumberPoint; + archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/"); //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; archiveRequest.Headers.Add("Authorization", "Basic " + encoded); @@ -628,7 +629,8 @@ namespace BackendWorkerService.Quartz.Jobs List> waterArchiveWeekRawDatas = new List>(); foreach (var deviceNumberPoint in electricDeviceNumberPoints) { - archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); + device_number = deviceNumberPoint.FullDeviceNumberPoint; + archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; archiveRequest.Headers.Add("Authorization", "Basic " + encoded); @@ -685,7 +687,8 @@ namespace BackendWorkerService.Quartz.Jobs } foreach (var deviceNumberPoint in waterDeviceNumberPoints) { - archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); + device_number = deviceNumberPoint.FullDeviceNumberPoint; + archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; archiveRequest.Headers.Add("Authorization", "Basic " + encoded); @@ -993,7 +996,8 @@ namespace BackendWorkerService.Quartz.Jobs List> waterArchiveMonthRawDatas = new List>(); foreach (var deviceNumberPoint in electricDeviceNumberPoints) { - archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); + device_number = deviceNumberPoint.FullDeviceNumberPoint; + archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; archiveRequest.Headers.Add("Authorization", "Basic " + encoded); @@ -1049,7 +1053,8 @@ namespace BackendWorkerService.Quartz.Jobs } foreach (var deviceNumberPoint in waterDeviceNumberPoints) { - archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); + device_number = deviceNumberPoint.FullDeviceNumberPoint; + archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); archiveRequest.Method = "POST"; archiveRequest.Headers.Add("Authorization", "Basic " + encoded); @@ -1337,8 +1342,6 @@ namespace BackendWorkerService.Quartz.Jobs catch(Exception ex) { await task_Detail.WorkFail("ArchiveElectricMeterDayJob", "Compensate", ex.ToString()); - logger.LogError("【ArchiveElectricMeterDayJob】【補償機制】【任務失敗】"); - logger.LogError("【ArchiveElectricMeterDayJob】【補償機制】【任務失敗】[Exception]:{0}", ex.ToString()); } } #endregion 補償機制 @@ -1350,35 +1353,105 @@ namespace BackendWorkerService.Quartz.Jobs { await task_Detail.WorkFail("ArchiveElectricMeterDayJob", "All", exception.ToString()); logger.LogError("【ArchiveElectricMeterDayJob】【任務失敗】"); - logger.LogError("【ArchiveElectricMeterDayJob】【任務失敗】[Exception]:{0}", exception.ToString()); + logger.LogError("【ArchiveElectricMeterDayJob】【任務失敗】[Exception]:{0}, {1}", exception.ToString(), "device_number = " + device_number); } } private List> ArrangeRawData(DeviceNumberPoint deviceNumberPoint, JObject jsonResult) { List> arrangeRawDatas = new List>(); - var histories = jsonResult["obj"]["list"]; - var rawdateCount = Convert.ToInt32(jsonResult["obj"]["int"]["@val"].ToString()); - - if(rawdateCount == 0) + try { - return null; - } + var histories = jsonResult["obj"]["list"]; + var rawdateCount = Convert.ToInt32(jsonResult["obj"]["int"]["@val"].ToString()); - if (histories != null && histories.HasValues) - { - if (rawdateCount > 1) - { //多筆資料 - foreach (var history in histories) - { + if (rawdateCount == 0) + { + return null; + } + + if (histories != null && histories.HasValues) + { + if (rawdateCount > 1) + { //多筆資料 + foreach (var history in histories) + { + Dictionary arrangeRawData = new Dictionary(); + arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber); + arrangeRawData.Add("@point", deviceNumberPoint.Point); + + //時間 + if (history["abstime"] != null && history["abstime"].HasValues) + { + foreach (var abstime in history["abstime"]) + { + var name = abstime["@name"].ToString(); + switch (name) + { + case "start": + var startTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); + arrangeRawData.Add("@start_timestamp", startTimstamp); + break; + case "end": + var endTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); + arrangeRawData.Add("@end_timestamp", endTimstamp); + break; + } + } + } + + //區間內資料筆數 + if (history["int"] != null && history["int"].HasValues) + { + var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString()); + arrangeRawData.Add("@count_rawdata", count); + } + + //整合數值(最大、最小、平均、總和) + if (history["real"] != null && history["real"].HasValues) + { + foreach (var real in history["real"]) + { + var name = real["@name"].ToString(); + switch (name) + { + case "min": + var min = Convert.ToDecimal(real["@val"].ToString()); + arrangeRawData.Add("@min_rawdata", min); + break; + case "max": + var max = Convert.ToDecimal(real["@val"].ToString()); + arrangeRawData.Add("@max_rawdata", max); + break; + case "avg": + var avg = Convert.ToDecimal(real["@val"].ToString()); + arrangeRawData.Add("@avg_rawdata", avg); + break; + case "sum": + var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); + arrangeRawData.Add("@sum_rawdata", sum); + break; + } + } + } + arrangeRawData.Add("@is_complete", 1); + arrangeRawData.Add("@repeat_times", 0); + arrangeRawData.Add("@fail_reason", null); + arrangeRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + + arrangeRawDatas.Add(arrangeRawData); + } + } + else + { //單筆資料 Dictionary arrangeRawData = new Dictionary(); arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber); arrangeRawData.Add("@point", deviceNumberPoint.Point); //時間 - if (history["abstime"] != null && history["abstime"].HasValues) + if (histories["obj"]["abstime"] != null && histories["obj"]["abstime"].HasValues) { - foreach (var abstime in history["abstime"]) + foreach (var abstime in histories["obj"]["abstime"]) { var name = abstime["@name"].ToString(); switch (name) @@ -1396,16 +1469,16 @@ namespace BackendWorkerService.Quartz.Jobs } //區間內資料筆數 - if (history["int"] != null && history["int"].HasValues) + if (histories["obj"]["int"] != null && histories["obj"]["int"].HasValues) { var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString()); arrangeRawData.Add("@count_rawdata", count); } //整合數值(最大、最小、平均、總和) - if (history["real"] != null && history["real"].HasValues) + if (histories["obj"]["real"] != null && histories["obj"]["real"].HasValues) { - foreach (var real in history["real"]) + foreach (var real in histories["obj"]["real"]) { var name = real["@name"].ToString(); switch (name) @@ -1437,76 +1510,13 @@ namespace BackendWorkerService.Quartz.Jobs arrangeRawDatas.Add(arrangeRawData); } } - else - { //單筆資料 - Dictionary arrangeRawData = new Dictionary(); - arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber); - arrangeRawData.Add("@point", deviceNumberPoint.Point); - //時間 - if (histories["obj"]["abstime"] != null && histories["obj"]["abstime"].HasValues) - { - foreach (var abstime in histories["obj"]["abstime"]) - { - var name = abstime["@name"].ToString(); - switch (name) - { - case "start": - var startTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); - arrangeRawData.Add("@start_timestamp", startTimstamp); - break; - case "end": - var endTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); - arrangeRawData.Add("@end_timestamp", endTimstamp); - break; - } - } - } - - //區間內資料筆數 - if (histories["obj"]["int"] != null && histories["obj"]["int"].HasValues) - { - var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString()); - arrangeRawData.Add("@count_rawdata", count); - } - - //整合數值(最大、最小、平均、總和) - if (histories["obj"]["real"] != null && histories["obj"]["real"].HasValues) - { - foreach (var real in histories["obj"]["real"]) - { - var name = real["@name"].ToString(); - switch (name) - { - case "min": - var min = Convert.ToDecimal(real["@val"].ToString()); - arrangeRawData.Add("@min_rawdata", min); - break; - case "max": - var max = Convert.ToDecimal(real["@val"].ToString()); - arrangeRawData.Add("@max_rawdata", max); - break; - case "avg": - var avg = Convert.ToDecimal(real["@val"].ToString()); - arrangeRawData.Add("@avg_rawdata", avg); - break; - case "sum": - var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); - arrangeRawData.Add("@sum_rawdata", sum); - break; - } - } - } - arrangeRawData.Add("@is_complete", 1); - arrangeRawData.Add("@repeat_times", 0); - arrangeRawData.Add("@fail_reason", null); - arrangeRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); - - arrangeRawDatas.Add(arrangeRawData); - } + return arrangeRawDatas; + } + catch (Exception ex) + { + return arrangeRawDatas; } - - return arrangeRawDatas; } } } diff --git a/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs b/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs index a574ce1..d02515b 100644 --- a/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs +++ b/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs @@ -786,6 +786,7 @@ namespace BackendWorkerService.Services.Implement } catch (Exception exception) { + throw exception; } @@ -795,28 +796,98 @@ namespace BackendWorkerService.Services.Implement private List> ArrangeRawData(DeviceNumberPoint deviceNumberPoint, JObject jsonResult) { List> arrangeRawDatas = new List>(); - var histories = jsonResult["obj"]["list"]; - var rawdateCount = Convert.ToInt32(jsonResult["obj"]["int"]["@val"].ToString()); - - if (rawdateCount == 0) + try { - return null; - } + var histories = jsonResult["obj"]["list"]; + var rawdateCount = Convert.ToInt32(jsonResult["obj"]["int"]["@val"].ToString()); - if (histories != null && histories.HasValues) - { - if (rawdateCount > 1) - { //多筆資料 - foreach (var history in histories) - { + if (rawdateCount == 0) + { + return null; + } + + if (histories != null && histories.HasValues) + { + if (rawdateCount > 1) + { //多筆資料 + foreach (var history in histories) + { + Dictionary arrangeRawData = new Dictionary(); + arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber); + arrangeRawData.Add("@point", deviceNumberPoint.Point); + + //時間 + if (history["abstime"] != null && history["abstime"].HasValues) + { + foreach (var abstime in history["abstime"]) + { + var name = abstime["@name"].ToString(); + switch (name) + { + case "start": + var startTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); + arrangeRawData.Add("@start_timestamp", startTimstamp); + break; + case "end": + var endTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); + arrangeRawData.Add("@end_timestamp", endTimstamp); + break; + } + } + } + + //區間內資料筆數 + if (history["int"] != null && history["int"].HasValues) + { + var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString()); + arrangeRawData.Add("@count_rawdata", count); + } + + //整合數值(最大、最小、平均、總和) + if (history["real"] != null && history["real"].HasValues) + { + foreach (var real in history["real"]) + { + var name = real["@name"].ToString(); + switch (name) + { + case "min": + var min = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); + arrangeRawData.Add("@min_rawdata", min); + break; + case "max": + var max = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); + arrangeRawData.Add("@max_rawdata", max); + break; + case "avg": + var avg = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); + arrangeRawData.Add("@avg_rawdata", avg); + break; + case "sum": + var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); + arrangeRawData.Add("@sum_rawdata", sum); + break; + } + } + } + arrangeRawData.Add("@is_complete", 1); + arrangeRawData.Add("@repeat_times", 0); + arrangeRawData.Add("@fail_reason", null); + arrangeRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + + arrangeRawDatas.Add(arrangeRawData); + } + } + else + { //單筆資料 Dictionary arrangeRawData = new Dictionary(); arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber); arrangeRawData.Add("@point", deviceNumberPoint.Point); //時間 - if (history["abstime"] != null && history["abstime"].HasValues) + if (histories["obj"]["abstime"] != null && histories["obj"]["abstime"].HasValues) { - foreach (var abstime in history["abstime"]) + foreach (var abstime in histories["obj"]["abstime"]) { var name = abstime["@name"].ToString(); switch (name) @@ -834,30 +905,30 @@ namespace BackendWorkerService.Services.Implement } //區間內資料筆數 - if (history["int"] != null && history["int"].HasValues) + if (histories["obj"]["int"] != null && histories["obj"]["int"].HasValues) { var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString()); arrangeRawData.Add("@count_rawdata", count); } //整合數值(最大、最小、平均、總和) - if (history["real"] != null && history["real"].HasValues) + if (histories["obj"]["real"] != null && histories["obj"]["real"].HasValues) { - foreach (var real in history["real"]) + foreach (var real in histories["obj"]["real"]) { var name = real["@name"].ToString(); switch (name) { case "min": - var min = Convert.ToDecimal(real["@val"].ToString()); + var min = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@min_rawdata", min); break; case "max": - var max = Convert.ToDecimal(real["@val"].ToString()); + var max = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@max_rawdata", max); break; case "avg": - var avg = Convert.ToDecimal(real["@val"].ToString()); + var avg = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@avg_rawdata", avg); break; case "sum": @@ -867,6 +938,7 @@ namespace BackendWorkerService.Services.Implement } } } + arrangeRawData.Add("@is_complete", 1); arrangeRawData.Add("@repeat_times", 0); arrangeRawData.Add("@fail_reason", null); @@ -875,77 +947,13 @@ namespace BackendWorkerService.Services.Implement arrangeRawDatas.Add(arrangeRawData); } } - else - { //單筆資料 - Dictionary arrangeRawData = new Dictionary(); - arrangeRawData.Add("@device_number", deviceNumberPoint.DeviceNumber); - arrangeRawData.Add("@point", deviceNumberPoint.Point); - //時間 - if (histories["obj"]["abstime"] != null && histories["obj"]["abstime"].HasValues) - { - foreach (var abstime in histories["obj"]["abstime"]) - { - var name = abstime["@name"].ToString(); - switch (name) - { - case "start": - var startTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); - arrangeRawData.Add("@start_timestamp", startTimstamp); - break; - case "end": - var endTimstamp = Convert.ToDateTime(abstime["@val"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); - arrangeRawData.Add("@end_timestamp", endTimstamp); - break; - } - } - } - - //區間內資料筆數 - if (histories["obj"]["int"] != null && histories["obj"]["int"].HasValues) - { - var count = Convert.ToInt32(histories["obj"]["int"]["@val"].ToString()); - arrangeRawData.Add("@count_rawdata", count); - } - - //整合數值(最大、最小、平均、總和) - if (histories["obj"]["real"] != null && histories["obj"]["real"].HasValues) - { - foreach (var real in histories["obj"]["real"]) - { - var name = real["@name"].ToString(); - switch (name) - { - case "min": - var min = Convert.ToDecimal(real["@val"].ToString()); - arrangeRawData.Add("@min_rawdata", min); - break; - case "max": - var max = Convert.ToDecimal(real["@val"].ToString()); - arrangeRawData.Add("@max_rawdata", max); - break; - case "avg": - var avg = Convert.ToDecimal(real["@val"].ToString()); - arrangeRawData.Add("@avg_rawdata", avg); - break; - case "sum": - var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); - arrangeRawData.Add("@sum_rawdata", sum); - break; - } - } - } - - arrangeRawData.Add("@is_complete", 1); - arrangeRawData.Add("@repeat_times", 0); - arrangeRawData.Add("@fail_reason", null); - arrangeRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); - - arrangeRawDatas.Add(arrangeRawData); - } + return arrangeRawDatas; + } + catch (Exception ex) + { + return arrangeRawDatas; } - - return arrangeRawDatas; } } } diff --git a/Frontend/_dashboard.html b/Frontend/_dashboard.html index ae097f7..6399eed 100644 --- a/Frontend/_dashboard.html +++ b/Frontend/_dashboard.html @@ -655,7 +655,7 @@ pointColor: color.success._500, pointBackgroundColor: color.main1, data: todayData?.data.map((x) => x.sum), - order: 1, + order: 2, }, { id: "yesterday", @@ -667,7 +667,7 @@ pointColor: color.info._100, pointBackgroundColor: color.info._100, data: yesData?.data.map((x) => x.sum), - order: 2, + order: 1, }, ], }; @@ -743,7 +743,7 @@ pointColor: color.success._500, pointBackgroundColor: color.success._500, data: curWeekData.map((x) => x.sum), - order: 1, + order: 2, }, { id: "yesterday", @@ -755,7 +755,7 @@ pointColor: color.info._100, pointBackgroundColor: color.info._100, data: prevWeekData.map((x) => x.sum), - order: 2, + order: 1, }, ], }; diff --git a/Frontend/_historyData.html b/Frontend/_historyData.html index a8e0325..09e1404 100644 --- a/Frontend/_historyData.html +++ b/Frontend/_historyData.html @@ -70,6 +70,7 @@ \ No newline at end of file diff --git a/Frontend/_operation.html b/Frontend/_operation.html index 809a260..e080a32 100644 --- a/Frontend/_operation.html +++ b/Frontend/_operation.html @@ -8,13 +8,22 @@
- +
- - + +
@@ -60,7 +69,7 @@ 新增 - 匯出 + 匯出
@@ -76,7 +85,8 @@ -