From e3700b63b81ae072cdf37c856b23071a8f8392d7 Mon Sep 17 00:00:00 2001 From: GiteaAdmin Date: Tue, 7 Mar 2023 15:02:29 +0800 Subject: [PATCH] =?UTF-8?q?debug=20=E5=BE=8C=E5=8F=B0=E5=90=8C=E6=AD=A5=20?= =?UTF-8?q?niagara=20=E8=B3=87=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/DeviceImportController.cs | 7 +- .../Services/Implement/webRequestService.cs | 124 +- .../85299a47-29db-4e98-9e2f-9f07f05791ca.svg | 3662 +++++++++++++++++ Repository/Models/obixHistory.cs | 167 + Repository/Models/quickType.cs | 23 +- 5 files changed, 3957 insertions(+), 26 deletions(-) create mode 100644 Backend/wwwroot/upload/floor_map/85299a47-29db-4e98-9e2f-9f07f05791ca.svg create mode 100644 Repository/Models/obixHistory.cs diff --git a/Backend/Controllers/DeviceImportController.cs b/Backend/Controllers/DeviceImportController.cs index 5e534a4..446185b 100644 --- a/Backend/Controllers/DeviceImportController.cs +++ b/Backend/Controllers/DeviceImportController.cs @@ -820,11 +820,10 @@ namespace Backend.Controllers //更新device資料表 room_dbid 欄位 string sql = @" SET SQL_SAFE_UPDATES = 0; - UPDATE - device AS de, + UPDATE device AS de, ( - select f.room_id, f.room_name from forge_room f - join device d ON f.room_name = d.room_name + select f.room_id, f.room_name from forge_room f + join device d ON f.room_name = d.room_name ) AS re SET de.room_dbid = re.room_id WHERE de.room_name = re.room_name;"; diff --git a/Backend/Services/Implement/webRequestService.cs b/Backend/Services/Implement/webRequestService.cs index ca135aa..4cbf093 100644 --- a/Backend/Services/Implement/webRequestService.cs +++ b/Backend/Services/Implement/webRequestService.cs @@ -15,6 +15,8 @@ using Ubiety.Dns.Core; using System.Diagnostics; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using Repository.Models.CodeBeautify; +using NPOI.SS.Formula.Functions; namespace Backend.Services.Implement { @@ -163,12 +165,11 @@ namespace Backend.Services.Implement XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(responseString); - string jsonText = JsonConvert.SerializeXmlNode(xmlDoc); - var data = Welcome.FromJson(jsonText); - - foreach (var item in data.Obj.Ref) + //ref https://stackoverflow.com/questions/642293/how-do-i-read-and-parse-an-xml-file-in-c + foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) { - String API_Url2 = urlString + "/" + item.Name; + string stationName = node.Attributes["name"].InnerText; // WSP_Supervisor + String API_Url2 = urlString + "/" + stationName; // http://192.168.0.136:8081/obix/histories/WSP_Supervisor HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2); Postrequest2.Method = "GET"; @@ -181,32 +182,117 @@ namespace Backend.Services.Implement XmlDocument xmlDoc2 = new XmlDocument(); xmlDoc2.LoadXml(responseString2); - string jsonText2 = JsonConvert.SerializeXmlNode(xmlDoc2); - var data2 = Welcome.FromJson(jsonText2); - - foreach (var item2 in data2.Obj.Ref) + foreach (XmlNode node2 in xmlDoc2.DocumentElement.ChildNodes) { - if (item2.Name.Split('_').Length == 9) + string tagName = node2.Attributes["name"].InnerText; + if (tagName.Split('_').Length == 9) { ImpNiaItem row = new ImpNiaItem(); - row.device_area_tag = item2.Name.Split('_')[0]; - row.device_building_tag = item2.Name.Split('_')[1]; - row.device_system_tag = item2.Name.Split('_')[2]; - row.device_name_tag = item2.Name.Split('_')[3]; - row.device_point_name = item2.Name.Split('_')[8]; - row.parent_path = item.Name; - + row.device_area_tag = tagName.Split('_')[0]; + row.device_building_tag = tagName.Split('_')[1]; + row.device_system_tag = tagName.Split('_')[2]; + row.device_name_tag = tagName.Split('_')[3]; + row.device_point_name = tagName.Split('_')[8]; + row.parent_path = stationName; + //full_name 其實是點位名稱 point_name - row.full_name = conPoint.Where(x => x.name == item2.Name).Select(x => x.displayName).FirstOrDefault(); + row.full_name = conPoint.Where(x => x.name == tagName).Select(x => x.displayName).FirstOrDefault(); result.Add(row); + + } else if (tagName.Split('_').Length == 6) + { //巨蛋 tag 5 段版本 + } - } + } } + #endregion return result; } + //private static void getRefData(string urlString, string encoded, List conPoint, List result, Welcome data ) //obixHistory data + //{ + // foreach (var item in data.Obj.Ref) + // { + // //var item = data.Obj.Ref; + // String API_Url2 = urlString + "/" + item.Name; + + // HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2); + // Postrequest2.Method = "GET"; + // Postrequest2.Headers.Add("Authorization", "Basic " + encoded); + // Postrequest2.PreAuthenticate = true; + + // HttpWebResponse response2 = (HttpWebResponse)Postrequest2.GetResponse(); + // var responseString2 = new StreamReader(response2.GetResponseStream()).ReadToEnd(); + + // XmlDocument xmlDoc2 = new XmlDocument(); + // xmlDoc2.LoadXml(responseString2); + + // string jsonText2 = JsonConvert.SerializeXmlNode(xmlDoc2); + // var data2 = Welcome.FromJson(jsonText2); + + // foreach (var item2 in data2.Obj.Ref) + // { + // if (item2.Name.Split('_').Length == 9) + // { + // ImpNiaItem row = new ImpNiaItem(); + // row.device_area_tag = item2.Name.Split('_')[0]; + // row.device_building_tag = item2.Name.Split('_')[1]; + // row.device_system_tag = item2.Name.Split('_')[2]; + // row.device_name_tag = item2.Name.Split('_')[3]; + // row.device_point_name = item2.Name.Split('_')[8]; + // row.parent_path = item.Name; + + // //full_name 其實是點位名稱 point_name + // row.full_name = conPoint.Where(x => x.name == item2.Name).Select(x => x.displayName).FirstOrDefault(); + + // result.Add(row); + // } + // } + // } + //} + + //private static void getRefData(string urlString, string encoded, List conPoint, List result, Welcome4 data) + //{ + // foreach (var item in data.Obj.Ref) + // { + // String API_Url2 = urlString + "/" + item.Name; + + // HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2); + // Postrequest2.Method = "GET"; + // Postrequest2.Headers.Add("Authorization", "Basic " + encoded); + // Postrequest2.PreAuthenticate = true; + + // HttpWebResponse response2 = (HttpWebResponse)Postrequest2.GetResponse(); + // var responseString2 = new StreamReader(response2.GetResponseStream()).ReadToEnd(); + + // XmlDocument xmlDoc2 = new XmlDocument(); + // xmlDoc2.LoadXml(responseString2); + + // string jsonText2 = JsonConvert.SerializeXmlNode(xmlDoc2); + // var data2 = Welcome.FromJson(jsonText2); + + // foreach (var item2 in data2.Obj.Ref) + // { + // if (item2.Name.Split('_').Length == 9) + // { + // ImpNiaItem row = new ImpNiaItem(); + // row.device_area_tag = item2.Name.Split('_')[0]; + // row.device_building_tag = item2.Name.Split('_')[1]; + // row.device_system_tag = item2.Name.Split('_')[2]; + // row.device_name_tag = item2.Name.Split('_')[3]; + // row.device_point_name = item2.Name.Split('_')[8]; + // row.parent_path = item.Name; + + // //full_name 其實是點位名稱 point_name + // row.full_name = conPoint.Where(x => x.name == item2.Name).Select(x => x.displayName).FirstOrDefault(); + + // result.Add(row); + // } + // } + // } + //} //public void getObix() //{ diff --git a/Backend/wwwroot/upload/floor_map/85299a47-29db-4e98-9e2f-9f07f05791ca.svg b/Backend/wwwroot/upload/floor_map/85299a47-29db-4e98-9e2f-9f07f05791ca.svg new file mode 100644 index 0000000..4d6ccdd --- /dev/null +++ b/Backend/wwwroot/upload/floor_map/85299a47-29db-4e98-9e2f-9f07f05791ca.svg @@ -0,0 +1,3662 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Repository/Models/obixHistory.cs b/Repository/Models/obixHistory.cs new file mode 100644 index 0000000..582972c --- /dev/null +++ b/Repository/Models/obixHistory.cs @@ -0,0 +1,167 @@ +using Newtonsoft.Json.Converters; +using Newtonsoft.Json; +using System.Globalization; +using System; +using System.Collections.Generic; + + +namespace Repository.Models.CodeBeautify +{ + //public class obixHistory + //{ + //} + public partial class obixHistory + { + [JsonProperty("obj")] + public Objs Obj { get; set; } + } + + public class Objs + { + [JsonProperty("ref")] + public Refs Ref { get; set; } + + [JsonProperty("_xmlns")] + public Uri Xmlns { get; set; } + + [JsonProperty("_xmlns:xsi")] + public Uri XmlnsXsi { get; set; } + + [JsonProperty("_href")] + public Uri Href { get; set; } + + [JsonProperty("_display")] + public string Display { get; set; } + + [JsonProperty("_icon")] + public string Icon { get; set; } + + [JsonProperty("_xsi:schemaLocation")] + public Uri XsiSchemaLocation { get; set; } + } + + public class Refs + { + [JsonProperty("_name")] + public string Name { get; set; } + + [JsonProperty("_href")] + public string Href { get; set; } + + [JsonProperty("_display")] + public string Display { get; set; } + + [JsonProperty("_icon")] + public string Icon { get; set; } + } + + public partial class obixHistory + { + public static obixHistory FromJson(string json) => JsonConvert.DeserializeObject(json, CodeBeautify.Converter.Settings); + } + + public static class Serialize + { + public static string ToJson(this obixHistory self) => JsonConvert.SerializeObject(self, CodeBeautify.Converter.Settings); + } + + internal static class Converter + { + public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings + { + MetadataPropertyHandling = MetadataPropertyHandling.Ignore, + DateParseHandling = DateParseHandling.None, + Converters = + { + new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } + }, + }; + } +} + + +// +// +// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do: +// +// using CodeBeautify; +// +// var welcome4 = Welcome4.FromJson(jsonString); + +//namespace CodeBeautify +//{ +// using System; +// using System.Collections.Generic; + +// using System.Globalization; +// using Newtonsoft.Json; +// using Newtonsoft.Json.Converters; + +// public partial class Welcome4 +// { +// [JsonProperty("obj")] +// public Obj Obj { get; set; } +// } + +// public partial class Obj +// { +// [JsonProperty("ref")] +// public Ref Ref { get; set; } + +// [JsonProperty("_xmlns")] +// public Uri Xmlns { get; set; } + +// [JsonProperty("_xmlns:xsi")] +// public Uri XmlnsXsi { get; set; } + +// [JsonProperty("_href")] +// public Uri Href { get; set; } + +// [JsonProperty("_display")] +// public string Display { get; set; } + +// [JsonProperty("_icon")] +// public string Icon { get; set; } + +// [JsonProperty("_xsi:schemaLocation")] +// public Uri XsiSchemaLocation { get; set; } +// } + +// public partial class Ref +// { +// [JsonProperty("_name")] +// public string Name { get; set; } + +// [JsonProperty("_href")] +// public string Href { get; set; } + +// [JsonProperty("_display")] +// public string Display { get; set; } + +// [JsonProperty("_icon")] +// public string Icon { get; set; } +// } + +// public partial class Welcome4 +// { +// public static Welcome4 FromJson(string json) => JsonConvert.DeserializeObject(json, CodeBeautify.Converter.Settings); +// } + +// public static class Serialize +// { +// public static string ToJson(this Welcome4 self) => JsonConvert.SerializeObject(self, CodeBeautify.Converter.Settings); +// } + +// internal static class Converter +// { +// public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings +// { +// MetadataPropertyHandling = MetadataPropertyHandling.Ignore, +// DateParseHandling = DateParseHandling.None, +// Converters = +// { +// new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } +// }, +// }; +// } +//} diff --git a/Repository/Models/quickType.cs b/Repository/Models/quickType.cs index 9e573e8..13eb593 100644 --- a/Repository/Models/quickType.cs +++ b/Repository/Models/quickType.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; @@ -19,6 +20,11 @@ namespace Repository.Models public partial class Obj { + [JsonProperty("@href")] + public string? href { get; set; } + [JsonProperty("@icon")] + public string? icon { get; set; } + [JsonProperty("@display")] public string Display { get; set; } @@ -36,6 +42,7 @@ namespace Repository.Models [JsonProperty("ref")] public Str[] Ref { get; set; } + //public Ref Ref { get; set; } } public partial class Str @@ -48,15 +55,25 @@ namespace Repository.Models [JsonProperty("@href")] public string Href { get; set; } + [JsonProperty("@display")] + public string display { get; set; } + [JsonProperty("@_icon")] + public string _icon { get; set; } } - public partial class Ref + public class Ref { - [JsonProperty("@name")] + [JsonProperty("_name")] public string Name { get; set; } - [JsonProperty("@href")] + [JsonProperty("_href")] public string Href { get; set; } + + [JsonProperty("_display")] + public string Display { get; set; } + + [JsonProperty("_icon")] + public string Icon { get; set; } } public partial class Xml