資料表:

device和import_niagara_tag比對,並更新/新增資料至device。
device_item和import_niagara_item比對,
並更新/新增資料至device_item。
This commit is contained in:
wanli 2022-10-20 11:32:38 +08:00
parent 16e07b3df3
commit 9744ea469e
4 changed files with 178 additions and 18 deletions

View File

@ -74,26 +74,37 @@ namespace tpDomeWinAPP.Models
public string Device_guid { get; set; } public string Device_guid { get; set; }
public byte Deleted { get; set; } public byte Deleted { get; set; }
public byte Status { get; set; } public byte Status { get; set; }
public string Building_guid { get; set; } public int Priority { get; set; }
public string Building_full_name { get; set; } public int Is_link { get; set; }
public string Main_system_guid { get; set; } //public string Building_guid { get; set; }
public string Main_system_full_name { get; set; } //public string Building_full_name { get; set; }
public string Sub_system_guid { get; set; } //public string Main_system_guid { get; set; }
public string Sub_system_full_name { get; set; } //public string Main_system_full_name { get; set; }
public string Floor_guid { get; set; } //public string Sub_system_guid { get; set; }
public string Floor_full_name { 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_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_number { get; set; } //設備編號
public string Device_model { 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_system_category_layer3 { get; set; }
public string Device_image { get; set; } //public string Device_image { get; set; }
public string Device_image_url { get; set; } //public string Device_image_url { get; set; }
public string Device_close_color { get; set; } //public string Device_close_color { get; set; }
public string Device_normal_color { get; set; } //public string Device_normal_color { get; set; }
public string Device_error_color { get; set; } //public string Device_error_color { get; set; }
public string Device_flashing { get; set; } //public string Device_flashing { get; set; }
public string Device_ip { get; set; } public string Device_ip { get; set; }
public string Device_port { get; set; } public string Device_port { get; set; }
public List<DeviceDisaster> Device_disasters { get; set; } //防災類型 public List<DeviceDisaster> Device_disasters { get; set; } //防災類型

View File

@ -18,6 +18,7 @@ namespace tpDomeWinAPP.Models
public string device_last_name_tag { get; set; } public string device_last_name_tag { get; set; }
public string device_serial_tag { get; set; } public string device_serial_tag { get; set; }
public string atDateTime { get; set; } public string atDateTime { get; set; }
public int is_used { get; set; }
} }
public class NiagaraTagsForItem public class NiagaraTagsForItem
@ -26,5 +27,6 @@ namespace tpDomeWinAPP.Models
public string device_building_tag { get; set; } public string device_building_tag { get; set; }
public string device_system_tag { get; set; } public string device_system_tag { get; set; }
public string device_name_tag { get; set; } public string device_name_tag { get; set; }
public string device_point_name { get; set; }
} }
} }

View File

@ -13,6 +13,7 @@ using System.Linq;
using NPOI.SS.Formula.Functions; using NPOI.SS.Formula.Functions;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using MySqlX.XDevAPI.Relational; using MySqlX.XDevAPI.Relational;
using static NPOI.HSSF.Util.HSSFColor;
namespace tpDomeWinAPP.Service 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] // )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]; // ) ON [PRIMARY];
// END" ; // END" ;
string ss = @" CREATE TABLE IF NOT EXISTS `import_niagara_tag` ( string ss = @" CREATE TABLE IF NOT EXISTS `import_niagara_tag` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`db_tags` varchar(50) DEFAULT NULL, `db_tags` varchar(50) DEFAULT NULL,
@ -76,9 +78,10 @@ namespace tpDomeWinAPP.Service
`atDateTime` datetime(1) DEFAULT NULL, `atDateTime` datetime(1) DEFAULT NULL,
`is_used` smallint(1) DEFAULT 0, `is_used` smallint(1) DEFAULT 0,
PRIMARY KEY (`id`) 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()); conn.Execute(ss.ToString());
ss = "delete from import_niagara_tag where device_building_tag = '" + building + "'"; 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()); conn.Execute(ss.ToString());
#endregion #endregion
@ -101,6 +104,19 @@ namespace tpDomeWinAPP.Service
arrTag[6] + "', '" + arrTag[6] + "', '" +
arrTag[7] + "', " + arrTag[7] + "', " +
"now());"); "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 try
{ {
@ -115,6 +131,8 @@ namespace tpDomeWinAPP.Service
throw ex; throw ex;
} }
insertItemFromNiagara(dt, conn, building); insertItemFromNiagara(dt, conn, building);
deviceComparison();
deviceItemComparison();
} }
return result; return result;
@ -132,7 +150,7 @@ namespace tpDomeWinAPP.Service
`device_point_name` varchar(50) DEFAULT NULL, `device_point_name` varchar(50) DEFAULT NULL,
`check_status` varchar(50) DEFAULT NULL, `check_status` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`) 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()); conn.Execute(ss.ToString());
ss = "delete from import_niagara_item where device_building_tag = '" + building + "'"; ss = "delete from import_niagara_item where device_building_tag = '" + building + "'";
conn.Execute(ss.ToString()); conn.Execute(ss.ToString());
@ -189,6 +207,18 @@ namespace tpDomeWinAPP.Service
row2.device_name_tag + "', '" + row2.device_name_tag + "', '" +
row2.point_name + "'" + 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 try
{ {
@ -204,6 +234,121 @@ namespace tpDomeWinAPP.Service
} }
} }
public void deviceComparison()
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
List<NiagaraTags> 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<NiagaraTags>(sb.ToString()).ToList<NiagaraTags>();
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<NiagaraTagsForItem> 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<NiagaraTagsForItem>(sb.ToString()).ToList<NiagaraTagsForItem>();
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<device_value2> dt, string building) public bool InsertDbTagList(List<device_value2> dt, string building)
{ {
bool result = false; bool result = false;

View File

@ -169,6 +169,8 @@ namespace tpDomeWinAPP
string bql = url_slot + "bql:select " + top100 + " * from control:ControlPoint "; 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://60.251.164.125: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);
dataGridView1.DataSource = ds; dataGridView1.DataSource = ds;
dataGridView1.Columns[0].Visible = false; dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[1].Width = 400; dataGridView1.Columns[1].Width = 400;