From 4c956e3a4a0ddac536f57d6906db6246885279b8 Mon Sep 17 00:00:00 2001 From: dev02 Date: Wed, 26 Apr 2023 17:43:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9obix=20history?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NiagaraDataSynchronizeController.cs | 4 +- .../Services/Implement/webRequestService.cs | 76 +++++++++++++++++-- .../NiagaraDataSynchronizeRepository.cs | 13 ++-- Repository/Models/BackgroundServiceTask.cs | 3 + 4 files changed, 82 insertions(+), 14 deletions(-) diff --git a/Backend/Controllers/NiagaraDataSynchronizeController.cs b/Backend/Controllers/NiagaraDataSynchronizeController.cs index 55968ce..a8d1c0b 100644 --- a/Backend/Controllers/NiagaraDataSynchronizeController.cs +++ b/Backend/Controllers/NiagaraDataSynchronizeController.cs @@ -53,6 +53,8 @@ namespace Backend.Controllers obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault() + "obix/config/Program/ObixQuery/query/"; obixApiConfig.UrlSlot =variableObix.Where(x => x.Name == "url_slot").Select(x => x.Value).FirstOrDefault(); obixApiConfig.TagQuantity = variableObix.Where(x => x.Name == "tag_quantity").Select(x => x.Value).FirstOrDefault(); + obixApiConfig.UserName = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault(); + obixApiConfig.Password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault(); List ds; @@ -61,7 +63,7 @@ namespace Backend.Controllers string bql = obixApiConfig.UrlSlot + "bql:select " + top100 + " * from baja:Folder "; //ds = svc.obixQuery("http://192.168.0.136:8080/obix/config/Arena/Program/ObixQuery/query/", bql); //ds = svc.obixQuery("http://localhost:8080/obix/config/Program/ObixQuery/query/", bql); - ds = svc.obixQuery(obixApiConfig.ApiBase, bql, obixApiConfig.TagQuantity);//三菱 + ds = svc.obixQuery(obixApiConfig.ApiBase, bql, obixApiConfig.TagQuantity, obixApiConfig.UserName, obixApiConfig.Password);//三菱 apiResult.Code = "0000"; apiResult.Data = ds; diff --git a/Backend/Services/Implement/webRequestService.cs b/Backend/Services/Implement/webRequestService.cs index cc37d16..83a741d 100644 --- a/Backend/Services/Implement/webRequestService.cs +++ b/Backend/Services/Implement/webRequestService.cs @@ -17,18 +17,23 @@ 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; namespace Backend.Services.Implement { public class webRequestService { - public List obixQuery(string urlString, string bql, string tag_quantity) + public List obixQuery(string urlString, string bql, string tag_quantity, string acc, string pass) { List result = new List(); - String username = "obixUser"; - String password = "Admin123456"; + //String username = "obixUser"; + //String password = "Admin123456"; //String username = "stanGG"; //String password = "St12345678"; + String username = acc; + String password = pass; String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); String API_Url = urlString; @@ -141,7 +146,7 @@ namespace Backend.Services.Implement String username = acc; String password = pass; String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); - + String oneStationName = null; #region get control point data List conPoint = new List(); String cp_API_Url = bqlUrlString; @@ -176,6 +181,7 @@ namespace Backend.Services.Implement row.name = s1[0].Replace('/', '_').Remove(s1[0].Length - 1, 1).Remove(0, 1); row.displayName = displayName; + row.isHistory = false; conPoint.Add(row); } @@ -199,7 +205,8 @@ namespace Backend.Services.Implement //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 stationName = node.Attributes["name"].InnerText; // WSP_Supervisor + var stationName = node.Attributes["name"].InnerText; // WSP_Supervisor + oneStationName = oneStationName ?? stationName; String API_Url2 = urlString + "/" + stationName; // http://192.168.0.136:8081/obix/histories/WSP_Supervisor HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2); @@ -228,6 +235,9 @@ namespace Backend.Services.Implement //full_name 其實是點位名稱 point_name row.full_name = conPoint.Where(x => x.name == tagName).Select(x => x.displayName).FirstOrDefault(); + if (conPoint.Where(x => x.name == tagName).FirstOrDefault() != null) + conPoint.Where(x => x.name == tagName).FirstOrDefault().isHistory = true; + row.isHistory = true; result.Add(row); @@ -239,7 +249,7 @@ namespace Backend.Services.Implement row.device_building_tag = tagName.Split('_')[0]; row.device_system_tag = tagName.Split('_')[1]; row.device_floor_tag = tagName.Split('_')[2]; - row.device_name_tag = tagName.Split('_')[3].Substring(1); + row.device_name_tag = tagName.Split('_')[3]; row.device_point_name = tagName.Split('_')[5]; } else //for normal @@ -253,13 +263,63 @@ namespace Backend.Services.Implement row.parent_path = stationName; //full_name 其實是點位名稱 point_name - row.full_name = conPoint.Where(x => x.name == tagName).Select(x => x.displayName).FirstOrDefault(); + row.full_name = conPoint.Where(x => x.name.Contains(tagName) && !x.isHistory).Select(x => x.displayName).FirstOrDefault(); + if (conPoint.Where(x => x.name.Contains(tagName) && !x.isHistory).FirstOrDefault() != null) + conPoint.Where(x => x.name.Contains(tagName) && !x.isHistory).FirstOrDefault().isHistory = true; + row.isHistory = true; result.Add(row); } } } - #endregion + var newConPoint = conPoint.Where(x => !x.isHistory).ToArray(); + foreach(var n in newConPoint) + { + if (n.name.Split('_').Length == 9) + { + result.Add(new ImpNiaItem + { + device_area_tag = n.name.Split('_')[0], + device_building_tag = n.name.Split('_')[1], + device_system_tag = n.name.Split('_')[2], + device_name_tag = n.name.Split('_')[3], + device_point_name = n.name.Split('_')[8], + full_name = n.displayName, + parent_path = oneStationName, + isHistory = n.isHistory + }); + } + else if (n.name.Split('_').Length == 11) //Arena_D2_CWB_L110_CAP_D2_CWB_L110_CAP_MET1_ER + { + if (n.name.Split('_')[6] == "S" || n.name.Split('_')[6] == "CWB") //for security system and CWB system + { + result.Add(new ImpNiaItem { + device_building_tag = n.name.Split('_')[5], + device_system_tag = n.name.Split('_')[6], + device_floor_tag = n.name.Split('_')[7], + device_name_tag = n.name.Split('_')[8], + device_point_name = n.name.Split('_')[10], + full_name = n.displayName, + parent_path = oneStationName, + isHistory = n.isHistory + }); + } + else //for normal + { + result.Add(new ImpNiaItem + { + device_building_tag = n.name.Split('_')[5], + //device_system_tag = n.name.Split('_')[1], + device_floor_tag = n.name.Split('_')[7], + device_name_tag = n.name.Split('_')[6], + device_point_name = n.name.Split('_')[10], + full_name = n.displayName, + parent_path = oneStationName, + isHistory = n.isHistory + }); + } + } + } return result; } diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index ee35579..18c1d86 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -201,7 +201,7 @@ namespace Repository.BackendRepository.Implement #region 放入import_niagara_item資料表 foreach (var row in ds) { - sb.Append($@" insert import_niagara_item(device_area_tag, device_building_tag, device_system_tag, device_name_tag, device_point_name, parent_path, full_name) + sb.Append($@" insert import_niagara_item(device_area_tag, device_building_tag, device_system_tag, device_name_tag, device_point_name, parent_path, full_name, is_history) values('"+ row.device_area_tag + "', '" + row.device_building_tag + "', '" + @@ -209,7 +209,8 @@ namespace Repository.BackendRepository.Implement row.device_name_tag + "', '" + row.device_point_name + "', '" + row.parent_path + "', '" + - row.full_name + "'" + + row.full_name + "'," + + row.isHistory + ");"); } @@ -440,12 +441,14 @@ namespace Repository.BackendRepository.Implement { isBool = 1; } - sb.Append($@"insert device_item(deleted, points, is_show, is_show_riserDiagram, is_controll, is_bool, is_link, is_show_history, + sb.Append($@"insert device_item(deleted, points, is_show, is_show_riserDiagram, is_controll, is_bool, is_show_history, is_link, device_system_tag, device_name_tag, full_name, parent_path, created_at, updated_at) VALUES (0, '" + data.device_point_name + "', 1, 0, " + isControll + "," + - isBool + ", 1, 1, '" + + isBool + "," + + data.is_history + + ", 1, '" + data.device_system_tag + "', '" + data.device_name_tag + "', '" + data.full_name + "', '" + @@ -474,7 +477,7 @@ namespace Repository.BackendRepository.Implement UPDATE device_item d LEFT JOIN import_niagara_item m ON d.device_system_tag = m.device_system_tag and d.device_name_tag = m.device_name_tag and d.points = m.device_point_name SET d.is_link = case when device_point_name is null then 0 else 1 end , - d.is_show_history = case when device_point_name is null then 0 else 1 end"); + d.is_show_history = case when device_point_name is null = 0 then 0 else 1 end"); await conn.ExecuteAsync(sb.ToString()); } diff --git a/Repository/Models/BackgroundServiceTask.cs b/Repository/Models/BackgroundServiceTask.cs index de511ae..7ccafa3 100644 --- a/Repository/Models/BackgroundServiceTask.cs +++ b/Repository/Models/BackgroundServiceTask.cs @@ -95,6 +95,7 @@ namespace Repository.Models public string device_point_name { get; set; } public string full_name { get; set; } public string parent_path { get; set; } + public bool is_history { get; set; } } public class building_menu @@ -121,11 +122,13 @@ namespace Repository.Models public string parent_path { get; set; } public string check_status { get; set; } public string full_name { get; set; } + public bool isHistory { get; set; } } public class control_point { public string name { get; set; } public string displayName { get; set; } + public bool isHistory { get; set; } } }