From 9744ea469e75eecd020e2dfb8f150fb06fc1b972 Mon Sep 17 00:00:00 2001 From: wanli Date: Thu, 20 Oct 2022 11:32:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B3=87=E6=96=99=E8=A1=A8:=20device=E5=92=8Ci?= =?UTF-8?q?mport=5Fniagara=5Ftag=E6=AF=94=E5=B0=8D=EF=BC=8C=E4=B8=A6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0/=E6=96=B0=E5=A2=9E=E8=B3=87=E6=96=99?= =?UTF-8?q?=E8=87=B3device=E3=80=82=20device=5Fitem=E5=92=8Cimport=5Fniaga?= =?UTF-8?q?ra=5Fitem=E6=AF=94=E5=B0=8D=EF=BC=8C=20=E4=B8=A6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0/=E6=96=B0=E5=A2=9E=E8=B3=87=E6=96=99=E8=87=B3device?= =?UTF-8?q?=5Fitem=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- z01_WinAPP/Models/Device.cs | 43 +++++---- z01_WinAPP/Models/NiagaraTags.cs | 2 + z01_WinAPP/Service/procCompare.cs | 149 +++++++++++++++++++++++++++++- z01_WinAPP/fmCheckTagName.cs | 2 + 4 files changed, 178 insertions(+), 18 deletions(-) diff --git a/z01_WinAPP/Models/Device.cs b/z01_WinAPP/Models/Device.cs index 53f1c24..2428074 100644 --- a/z01_WinAPP/Models/Device.cs +++ b/z01_WinAPP/Models/Device.cs @@ -74,26 +74,37 @@ namespace tpDomeWinAPP.Models public string Device_guid { get; set; } public byte Deleted { get; set; } public byte Status { get; set; } - public string Building_guid { get; set; } - public string Building_full_name { get; set; } - public string Main_system_guid { get; set; } - public string Main_system_full_name { get; set; } - public string Sub_system_guid { get; set; } - public string Sub_system_full_name { get; set; } - public string Floor_guid { get; set; } - public string Floor_full_name { get; set; } + public int Priority { get; set; } + public int Is_link { get; set; } + //public string Building_guid { get; set; } + //public string Building_full_name { get; set; } + //public string Main_system_guid { get; set; } + //public string Main_system_full_name { get; set; } + //public string Sub_system_guid { get; set; } + //public string Sub_system_full_name { get; set; } + //public string Floor_guid { get; set; } + //public string Floor_full_name { get; set; } public string Device_coordinate { get; set; } - public string Device_full_name { get; set; } + public string Full_name { get; set; } + + public string Device_area_tag { get; set; } + public string Device_building_tag { get; set; } + public string Device_system_tag { get; set; } + public string Device_name_tag { get; set; } + public string Device_floor_tag { get; set; } + public string Device_master { get; set; } + public string Device_last_name { get; set; } + public string Device_serial_tag { get; set; } public string Device_number { get; set; } //設備編號 public string Device_model { get; set; } //設備型號 - public string Device_disaster_type_text { get; set; } + //public string Device_disaster_type_text { get; set; } public string Device_system_category_layer3 { get; set; } - public string Device_image { get; set; } - public string Device_image_url { get; set; } - public string Device_close_color { get; set; } - public string Device_normal_color { get; set; } - public string Device_error_color { get; set; } - public string Device_flashing { get; set; } + //public string Device_image { get; set; } + //public string Device_image_url { get; set; } + //public string Device_close_color { get; set; } + //public string Device_normal_color { get; set; } + //public string Device_error_color { get; set; } + //public string Device_flashing { get; set; } public string Device_ip { get; set; } public string Device_port { get; set; } public List Device_disasters { get; set; } //防災類型 diff --git a/z01_WinAPP/Models/NiagaraTags.cs b/z01_WinAPP/Models/NiagaraTags.cs index c3de9f2..d39c03d 100644 --- a/z01_WinAPP/Models/NiagaraTags.cs +++ b/z01_WinAPP/Models/NiagaraTags.cs @@ -18,6 +18,7 @@ namespace tpDomeWinAPP.Models public string device_last_name_tag { get; set; } public string device_serial_tag { get; set; } public string atDateTime { get; set; } + public int is_used { get; set; } } public class NiagaraTagsForItem @@ -26,5 +27,6 @@ namespace tpDomeWinAPP.Models public string device_building_tag { get; set; } public string device_system_tag { get; set; } public string device_name_tag { get; set; } + public string device_point_name { get; set; } } } diff --git a/z01_WinAPP/Service/procCompare.cs b/z01_WinAPP/Service/procCompare.cs index 6237d00..6b309fd 100644 --- a/z01_WinAPP/Service/procCompare.cs +++ b/z01_WinAPP/Service/procCompare.cs @@ -13,6 +13,7 @@ using System.Linq; using NPOI.SS.Formula.Functions; using Microsoft.Extensions.Primitives; using MySqlX.XDevAPI.Relational; +using static NPOI.HSSF.Util.HSSFColor; namespace tpDomeWinAPP.Service { @@ -61,6 +62,7 @@ namespace tpDomeWinAPP.Service // )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] // ) ON [PRIMARY]; // END" ; + string ss = @" CREATE TABLE IF NOT EXISTS `import_niagara_tag` ( `id` int(11) NOT NULL AUTO_INCREMENT, `db_tags` varchar(50) DEFAULT NULL, @@ -76,9 +78,10 @@ namespace tpDomeWinAPP.Service `atDateTime` datetime(1) DEFAULT NULL, `is_used` smallint(1) DEFAULT 0, PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;"; + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"; conn.Execute(ss.ToString()); ss = "delete from import_niagara_tag where device_building_tag = '" + building + "'"; + //string ss = "delete from device where device_building_tag = '" + building + "'"; conn.Execute(ss.ToString()); #endregion @@ -101,6 +104,19 @@ namespace tpDomeWinAPP.Service arrTag[6] + "', '" + arrTag[7] + "', " + "now());"); + + //sb.Append($@" insert device(device_number, device_guid, deleted, status, priority, device_system_category_layer3, device_area_tag, device_building_tag, device_system_tag, + // device_name_tag, device_floor_tag, device_master, device_last_name, device_serial_tag, created_at, updated_at) values('" + + // row.tag_name + "', uuid(), 0, 1, 0, '" + + // arrTag[0] + "', '" + + // arrTag[1] + "', '" + + // arrTag[2] + "', '" + + // arrTag[3] + "', '" + + // arrTag[4] + "', '" + + // arrTag[5] + "', '" + + // arrTag[6] + "', '" + + // arrTag[7] + "', " + + // "now(), now());"); } try { @@ -115,6 +131,8 @@ namespace tpDomeWinAPP.Service throw ex; } insertItemFromNiagara(dt, conn, building); + deviceComparison(); + deviceItemComparison(); } return result; @@ -132,7 +150,7 @@ namespace tpDomeWinAPP.Service `device_point_name` varchar(50) DEFAULT NULL, `check_status` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) - ) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;"; + ) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"; conn.Execute(ss.ToString()); ss = "delete from import_niagara_item where device_building_tag = '" + building + "'"; conn.Execute(ss.ToString()); @@ -189,6 +207,18 @@ namespace tpDomeWinAPP.Service row2.device_name_tag + "', '" + row2.point_name + "'" + ");"); + //var isControll = 0; + //var isBool = 0; + //if(row2.point_name == "ER" || row2.point_name == "AL" || row2.point_name == "ST") + //{ + // isControll = 1; + //} + //if(row2.point_name == "ER" || row2.point_name == "ST") + //{ + // isBool = 1; + //} + //sb.Append($@" insert device_item(deleted, points, is_show, is_show_riserDiagram, is_controll, is_bool, created_at, updated_at) + // values('0, " + row2.point_name + "', 1, 0," + isControll + "," + isBool + ", now(), now();"); } try { @@ -204,6 +234,121 @@ namespace tpDomeWinAPP.Service } } + public void deviceComparison() + { + using (MySqlConnection conn = new MySqlConnection(Connection1)) + { + List result; + + conn.Open(); + StringBuilder sb = new StringBuilder(); + sb.Append($@" SELECT m.* + FROM import_niagara_tag m + LEFT JOIN device d + ON m.niagara_tags = d.device_number + WHERE d.device_number IS NULL"); + result = conn.Query(sb.ToString()).ToList(); + + sb.Clear(); + //新增至device, is_link = 1 + if (result.Count > 0) + { + foreach (var data in result) + { + sb.Append($@" insert device(device_guid, deleted, status, priority, is_link, device_area_tag, + device_building_tag, device_system_tag, device_name_tag, device_floor_tag, device_master, + device_last_name, device_serial_tag, device_number, device_system_category_layer3, created_at, updated_at) + values(uuid(), 0, 1, 0, 1, '" + //device_guid + data.device_area_tag + "', '" + // + data.device_building_tag + "', '" + + data.device_system_tag + "', '" + + data.device_name_tag + "', '" + + + data.device_floor_tag + "', '" + + data.device_master_tag + "', '" + + data.device_last_name_tag + "', '" + + data.device_serial_tag + "', '" + + data.niagara_tags + "', '" + //device_number + data.device_system_tag + "', now(), now() );"); + } + if(sb.Length > 0) + { + conn.Execute(sb.ToString()); + sb.Clear(); + } + } + + //device有,niagara沒有,is_link 更新成 0 + sb.Append($@" SET SQL_SAFE_UPDATES = 0; + UPDATE device d LEFT JOIN import_niagara_tag m ON d.device_number = m.niagara_tags + SET d.is_link = 0 + WHERE m.niagara_tags IS NULL"); + conn.Execute(sb.ToString()); + + } + } + + public void deviceItemComparison() + { + using (MySqlConnection conn = new MySqlConnection(Connection1)) + { + List result; + + conn.Open(); + StringBuilder sb = new StringBuilder(); + sb.Append($@" SELECT m.* + FROM import_niagara_item m + LEFT JOIN device_item d + ON m.device_area_tag = d.device_area_tag and m.device_building_tag = d.device_building_tag + and m.device_system_tag = d.device_system_tag and m.device_name_tag = d.device_name_tag and m.device_point_name = d.points + WHERE d.points IS NULL"); + result = conn.Query(sb.ToString()).ToList(); + sb.Clear(); + //新增至device, is_link = 1 + if (result.Count > 0) + { + foreach (var data in result) + { + var isControll = 0; + var isBool = 0; + if (data.device_point_name == "ER" || data.device_point_name == "AL" || data.device_point_name == "ST") + { + isControll = 1; + } + if (data.device_point_name == "ER" || data.device_point_name == "ST") + { + isBool = 1; + } + sb.Append($@"insert device_item(deleted, points, is_show, is_show_riserDiagram, is_controll, is_bool, is_link, device_area_tag, + device_building_tag, device_system_tag, device_name_tag, created_at, updated_at) + VALUES (0, '" + + data.device_point_name + "', 1, 0, " + + isControll + "," + + isBool + ", 1, '" + + data.device_area_tag + "', '" + + data.device_building_tag + "', '" + + data.device_system_tag + "', '" + + data.device_name_tag + "', " + + "now(), now());"); + } + if (sb.Length > 0) + { + conn.Execute(sb.ToString()); + sb.Clear(); + } + } + //device有,niagara沒有,is_link 更新成 0 + sb.Append($@" SET SQL_SAFE_UPDATES = 0; + UPDATE device_item d LEFT JOIN import_niagara_item m + ON d.device_area_tag = m.device_area_tag and d.device_building_tag = m.device_building_tag + and 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 = 0 + WHERE m.device_point_name IS NULL"); + conn.Execute(sb.ToString()); + + } + } + public bool InsertDbTagList(List dt, string building) { bool result = false; diff --git a/z01_WinAPP/fmCheckTagName.cs b/z01_WinAPP/fmCheckTagName.cs index 509fe6a..959440e 100644 --- a/z01_WinAPP/fmCheckTagName.cs +++ b/z01_WinAPP/fmCheckTagName.cs @@ -169,6 +169,8 @@ namespace tpDomeWinAPP string bql = url_slot + "bql:select " + top100 + " * from control:ControlPoint "; //ds = svc.obixQuery("http://60.251.164.125:8080/obix/config/Arena/Program/ObixQuery/query/", bql);//原本的 ds = svc.obixQuery("http://localhost:8080/obix/config/Program/ObixQuery/query/", bql); + + dataGridView1.DataSource = ds; dataGridView1.Columns[0].Visible = false; dataGridView1.Columns[1].Width = 400;