修改obix history

This commit is contained in:
dev02 2023-04-26 17:43:55 +08:00
parent 605f3f8f87
commit 4c956e3a4a
4 changed files with 82 additions and 14 deletions

View File

@ -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.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.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.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<Device_value> ds; List<Device_value> ds;
@ -61,7 +63,7 @@ namespace Backend.Controllers
string bql = obixApiConfig.UrlSlot + "bql:select " + top100 + " * from baja:Folder "; 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://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("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.Code = "0000";
apiResult.Data = ds; apiResult.Data = ds;

View File

@ -17,18 +17,23 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Repository.Models.CodeBeautify; using Repository.Models.CodeBeautify;
using NPOI.SS.Formula.Functions; using NPOI.SS.Formula.Functions;
using Microsoft.AspNetCore.Localization;
using MySqlX.XDevAPI.Relational;
using Backend.Models;
namespace Backend.Services.Implement namespace Backend.Services.Implement
{ {
public class webRequestService public class webRequestService
{ {
public List<Device_value> obixQuery(string urlString, string bql, string tag_quantity) public List<Device_value> obixQuery(string urlString, string bql, string tag_quantity, string acc, string pass)
{ {
List<Device_value> result = new List<Device_value>(); List<Device_value> result = new List<Device_value>();
String username = "obixUser"; //String username = "obixUser";
String password = "Admin123456"; //String password = "Admin123456";
//String username = "stanGG"; //String username = "stanGG";
//String password = "St12345678"; //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 encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
String API_Url = urlString; String API_Url = urlString;
@ -141,7 +146,7 @@ namespace Backend.Services.Implement
String username = acc; String username = acc;
String password = pass; String password = pass;
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
String oneStationName = null;
#region get control point data #region get control point data
List<control_point> conPoint = new List<control_point>(); List<control_point> conPoint = new List<control_point>();
String cp_API_Url = bqlUrlString; 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.name = s1[0].Replace('/', '_').Remove(s1[0].Length - 1, 1).Remove(0, 1);
row.displayName = displayName; row.displayName = displayName;
row.isHistory = false;
conPoint.Add(row); 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 //ref https://stackoverflow.com/questions/642293/how-do-i-read-and-parse-an-xml-file-in-c
foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) 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 String API_Url2 = urlString + "/" + stationName; // http://192.168.0.136:8081/obix/histories/WSP_Supervisor
HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2); HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2);
@ -228,6 +235,9 @@ namespace Backend.Services.Implement
//full_name 其實是點位名稱 point_name //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 == 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); result.Add(row);
@ -239,7 +249,7 @@ namespace Backend.Services.Implement
row.device_building_tag = tagName.Split('_')[0]; row.device_building_tag = tagName.Split('_')[0];
row.device_system_tag = tagName.Split('_')[1]; row.device_system_tag = tagName.Split('_')[1];
row.device_floor_tag = tagName.Split('_')[2]; 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]; row.device_point_name = tagName.Split('_')[5];
} }
else //for normal else //for normal
@ -253,13 +263,63 @@ namespace Backend.Services.Implement
row.parent_path = stationName; row.parent_path = stationName;
//full_name 其實是點位名稱 point_name //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); result.Add(row);
} }
} }
} }
#endregion #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; return result;
} }

View File

@ -201,7 +201,7 @@ namespace Repository.BackendRepository.Implement
#region import_niagara_item資料表 #region import_niagara_item資料表
foreach (var row in ds) 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('"+ values('"+
row.device_area_tag + "', '" + row.device_area_tag + "', '" +
row.device_building_tag + "', '" + row.device_building_tag + "', '" +
@ -209,7 +209,8 @@ namespace Repository.BackendRepository.Implement
row.device_name_tag + "', '" + row.device_name_tag + "', '" +
row.device_point_name + "', '" + row.device_point_name + "', '" +
row.parent_path + "', '" + row.parent_path + "', '" +
row.full_name + "'" + row.full_name + "'," +
row.isHistory +
");"); ");");
} }
@ -440,12 +441,14 @@ namespace Repository.BackendRepository.Implement
{ {
isBool = 1; 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) device_system_tag, device_name_tag, full_name, parent_path, created_at, updated_at)
VALUES (0, '" + VALUES (0, '" +
data.device_point_name + "', 1, 0, " + data.device_point_name + "', 1, 0, " +
isControll + "," + isControll + "," +
isBool + ", 1, 1, '" + isBool + "," +
data.is_history +
", 1, '" +
data.device_system_tag + "', '" + data.device_system_tag + "', '" +
data.device_name_tag + "', '" + data.device_name_tag + "', '" +
data.full_name + "', '" + data.full_name + "', '" +
@ -474,7 +477,7 @@ namespace Repository.BackendRepository.Implement
UPDATE device_item d LEFT JOIN import_niagara_item m 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 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 , 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()); await conn.ExecuteAsync(sb.ToString());
} }

View File

@ -95,6 +95,7 @@ namespace Repository.Models
public string device_point_name { get; set; } public string device_point_name { get; set; }
public string full_name { get; set; } public string full_name { get; set; }
public string parent_path { get; set; } public string parent_path { get; set; }
public bool is_history { get; set; }
} }
public class building_menu public class building_menu
@ -121,11 +122,13 @@ namespace Repository.Models
public string parent_path { get; set; } public string parent_path { get; set; }
public string check_status { get; set; } public string check_status { get; set; }
public string full_name { get; set; } public string full_name { get; set; }
public bool isHistory { get; set; }
} }
public class control_point public class control_point
{ {
public string name { get; set; } public string name { get; set; }
public string displayName { get; set; } public string displayName { get; set; }
public bool isHistory { get; set; }
} }
} }