From c480e9ef3d5e1a0597e56fcadca92fec09b8f3c4 Mon Sep 17 00:00:00 2001 From: dev02 Date: Mon, 17 Oct 2022 17:45:27 +0800 Subject: [PATCH 01/14] fix sql --- Backend/Controllers/BuildMenuController.cs | 2 +- Backend/Controllers/DeviceManageController.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Backend/Controllers/BuildMenuController.cs b/Backend/Controllers/BuildMenuController.cs index ff1db9e..22bdc87 100644 --- a/Backend/Controllers/BuildMenuController.cs +++ b/Backend/Controllers/BuildMenuController.cs @@ -29,7 +29,7 @@ namespace Backend.Controllers try { - var sqlString = @$"select building_guid as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0 ORDER BY A.priority ASC, A.created_at DESC"; + var sqlString = @$"select building_guid as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0 ORDER BY a.priority ASC, a.created_at DESC"; KeyValue = await backendRepository.GetAllAsync(sqlString); apiResult.Code = "0000"; diff --git a/Backend/Controllers/DeviceManageController.cs b/Backend/Controllers/DeviceManageController.cs index 701cdbf..00c8da0 100644 --- a/Backend/Controllers/DeviceManageController.cs +++ b/Backend/Controllers/DeviceManageController.cs @@ -179,7 +179,7 @@ namespace Backend.Controllers dk.device_close_flashing, dk.device_error_flashing, (SELECT - STRING_AGG( ISNULL(system_key, ' '), ',') + GROUP_CONCAT( IFNULL(system_key, ' '), ',') FROM device_disaster dd JOIN variable v ON v.deleted = 0 AND v.system_type = 'disaster' AND v.system_value = dd.device_system_value WHERE dd.device_guid = d.device_guid From d4f0add911b4222ca480297e9f13c907ef8d24b2 Mon Sep 17 00:00:00 2001 From: dev02 Date: Tue, 18 Oct 2022 18:22:36 +0800 Subject: [PATCH 02/14] =?UTF-8?q?[=E5=BE=8C=E5=8F=B0]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=8D=B2=E5=8F=96table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/DeviceManageController.cs | 61 +++++++++---------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/Backend/Controllers/DeviceManageController.cs b/Backend/Controllers/DeviceManageController.cs index 00c8da0..4325c9a 100644 --- a/Backend/Controllers/DeviceManageController.cs +++ b/Backend/Controllers/DeviceManageController.cs @@ -805,7 +805,7 @@ namespace Backend.Controllers try { - var rawDatas = await backendRepository.GetAllAsync("device_import_ckeck_temp", "is_correct = 1 ORDER BY device_building_tag, device_system_tag, device_floor_tag, device_name_tag"); + var rawDatas = await backendRepository.GetAllAsync("import_niagara_tag", null, null, "device_building_tag, device_system_tag, device_floor_tag, device_name_tag"); var rawDatas_Group_Building_tag = rawDatas.GroupBy(x => x.Device_building_tag).ToList(); List tempFilters = new List(); @@ -871,37 +871,34 @@ namespace Backend.Controllers try { - string sql = @"SELECT - di.device_building_tag, - di.device_system_tag, - di.device_floor_tag, - di.device_name_tag, - di.device_serial_tag, - di.device_number, - di.device_system_category_layer3, - STRING_AGG( ISNULL(v.system_value, ' '), ',') AS Device_disasters, - STRING_AGG( ISNULL(v.system_key, ' '), ',') AS Device_disaster_type_text - FROM - (SELECT - * - FROM device_import_ckeck_temp di - WHERE device_building_tag = @Device_building_tag - AND device_system_tag = @Device_system_tag - AND device_floor_tag = @Device_floor_tag - AND device_name_tag = @Device_name_tag - AND is_correct = 1 - AND device_number NOT IN (SELECT d.device_number FROM device d WHERE d.deleted = 0) - ) di - CROSS APPLY STRING_SPLIT(di.device_disaster, ',') dd - LEFT JOIN variable v ON v.system_type = 'disaster' AND v.system_value = dd.value - GROUP BY di.device_building_tag, - di.device_system_tag, - di.device_floor_tag, - di.device_name_tag, - di.device_serial_tag, - di.device_number, - di.device_system_category_layer3"; - + string sql = @"SELECT + di.device_building_tag, + di.device_system_tag, + di.device_floor_tag, + di.device_last_name_tag as device_name_tag, + di.device_serial_tag, + 0 as device_disaster, + di.niagara_tags as device_number + FROM + ( + SELECT + * + FROM + import_niagara_tag intag + WHERE + device_building_tag = @Device_building_tag + AND device_system_tag = @Device_system_tag + AND device_floor_tag = @Device_floor_tag + AND device_name_tag = @Device_name_tag + AND convert(intag.niagara_tags, nchar) NOT IN ( SELECT convert(d.device_number, nchar) FROM device d WHERE d.deleted = 0 ) + ) di + GROUP BY + di.device_building_tag, + di.device_system_tag, + di.device_floor_tag, + di.device_last_name_tag, + di.device_serial_tag, + di.niagara_tags"; var deviceImports = await backendRepository.GetAllAsync(sql, post); From 240dc6ec25d032f98cf7d87a498768d02a26459b Mon Sep 17 00:00:00 2001 From: dev01 Date: Wed, 19 Oct 2022 09:41:03 +0800 Subject: [PATCH 03/14] =?UTF-8?q?[=E5=8D=80=E5=9F=9F=E9=81=B8=E5=96=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86]=20=E5=B7=A6=E5=8F=B3=E9=82=8A=E9=A0=90?= =?UTF-8?q?=E8=A8=AD=E9=A0=81=E9=9D=A2=E7=A8=8B=E5=BA=8F=E5=BB=BA=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Views/BuildMenu/Index.cshtml | 407 ++++++++++++++++++--------- Backend/wwwroot/css/site.css | 9 + 2 files changed, 286 insertions(+), 130 deletions(-) diff --git a/Backend/Views/BuildMenu/Index.cshtml b/Backend/Views/BuildMenu/Index.cshtml index 3fabb76..9aee64f 100644 --- a/Backend/Views/BuildMenu/Index.cshtml +++ b/Backend/Views/BuildMenu/Index.cshtml @@ -131,103 +131,246 @@ -
- -
-
- - -
-
- - -
- -
-
-
-
- - -
-
-
- - -
-
- - @*
+ +
+ +
+ +
+ +
- -
- -
+ +
+ + +
+
+ + +
+
+
+
+
+ + +
+
+
+ + +
+
+ + +
+
+ + @*
+
+ + +
+
+ + +
*@ -
-
@@ -147,6 +153,13 @@
+
+
+ + +
+
+
From 73510f6c96b1d579c8a8b837000ada92ac829f94 Mon Sep 17 00:00:00 2001 From: wanli Date: Thu, 20 Oct 2022 17:37:54 +0800 Subject: [PATCH 07/14] =?UTF-8?q?App:=20niagara=E8=88=87device=E5=92=8Cdev?= =?UTF-8?q?ice=5Fitem=E5=81=9A=E5=B0=8D=E6=AF=94=EF=BC=8C=E8=8B=A5?= =?UTF-8?q?=E6=9C=89=E5=B7=AE=E7=95=B0=EF=BC=8C=E5=89=87=E6=9B=B4=E6=96=B0?= =?UTF-8?q?device=E5=92=8Cdevice=5Fitem=20building=5Fmenu=E5=92=8Csub=5Fsy?= =?UTF-8?q?stem=5Ffloor=E5=90=8C=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- z01_WinAPP/Service/procCompare.cs | 338 ++++++++++++++++++------------ z01_WinAPP/fmCheckTagName.cs | 2 +- 2 files changed, 208 insertions(+), 132 deletions(-) diff --git a/z01_WinAPP/Service/procCompare.cs b/z01_WinAPP/Service/procCompare.cs index 6b309fd..3d5045e 100644 --- a/z01_WinAPP/Service/procCompare.cs +++ b/z01_WinAPP/Service/procCompare.cs @@ -26,43 +26,34 @@ namespace tpDomeWinAPP.Service private readonly IBackendRepository backendRepository; - public bool InsertNiagaraTagList(List dt, string building ) + public bool ToInsertNiagaraTagList(List dt, string building ) { bool result = false; //tag + InsertNiagaraTagList(dt, building); + insertItemFromNiagara(dt, building); + deviceComparison(); + deviceItemComparison(); + insertBuildingMenu(); + insertSubSystemFloor(); + return result; + } + + protected void InsertNiagaraTagList(List dt, string building) + { var ds2 = dt.GroupBy(x => new { tag_name2 = x.tag_name - }).Select( x => new device_value2 { + }).Select(x => new device_value2 + { tag_name = x.Key.tag_name2 }); using (MySqlConnection conn = new MySqlConnection(Connection1)) { - //CONCAT('{baseURL}', '{deviceKindFilePath}', dk.device_image) AS device_image_url, conn.Open(); #region 不存在就 Create table - //string ss = @"IF (not EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'import_niagara_tag')) - // BEGIN - - // CREATE TABLE [dbo].[import_niagara_tag]( - // [id] [int] IDENTITY(1,1) NOT NULL, - // [db_tags] [varchar](50) NULL, - // [niagara_tags] [varchar](50) NULL, - // [building] [varchar](10) NULL, - // [system_code1] [varchar](10) NULL, - // [floor] [varchar](10) NULL, - // [system_code2] [varchar](10) NULL, - // [device_serial] [varchar](10) NULL, - // [atDateTime] [smalldatetime] NULL, - // CONSTRAINT [PK_import_niagara_tag] PRIMARY KEY CLUSTERED - // ( - // [id] ASC - // )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, @@ -81,7 +72,6 @@ namespace tpDomeWinAPP.Service ) 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 @@ -104,19 +94,6 @@ 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 { @@ -130,18 +107,16 @@ namespace tpDomeWinAPP.Service { throw ex; } - insertItemFromNiagara(dt, conn, building); - deviceComparison(); - deviceItemComparison(); } - - return result; } - protected void insertItemFromNiagara(List dt, MySqlConnection conn, string building) + protected void insertItemFromNiagara(List dt, string building) { - #region create table - string ss = @"CREATE TABLE IF NOT EXISTS `import_niagara_item` ( + using (MySqlConnection conn = new MySqlConnection(Connection1)) + { + conn.Open(); + #region create table + string ss = @"CREATE TABLE IF NOT EXISTS `import_niagara_item` ( `id` int(11) NOT NULL AUTO_INCREMENT, `device_area_tag` varchar(50) DEFAULT NULL, `device_building_tag` varchar(50) DEFAULT NULL, @@ -151,89 +126,81 @@ namespace tpDomeWinAPP.Service `check_status` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) ) 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()); - #endregion - - List dt_item = new List(); - - foreach (var row in dt) - { - if (string.IsNullOrEmpty(row.tag_name)) continue; - string[] arrTag = row.tag_name.Split('_'); - - #region for item - device_item8 row_item = new device_item8(); - row_item.tag_name = row.tag_name; - row_item.device_area_tag = arrTag[0]; - row_item.device_building_tag = arrTag[1]; - row_item.device_system_tag = arrTag[2]; - row_item.device_name_tag = arrTag[3]; - row_item.device_floor_tag = arrTag[4]; - row_item.device_master_tag = arrTag[5]; - row_item.device_last_name_tag = arrTag[6]; - row_item.device_serial_tag = arrTag[7]; - row_item.point_name = row.point_name; - dt_item.Add(row_item); + conn.Execute(ss.ToString()); + ss = "delete from import_niagara_item where device_building_tag = '" + building + "'"; + conn.Execute(ss.ToString()); #endregion - } - //device_item - var ds2_item = dt_item.GroupBy(x => new - { - device_area_tag2 = x.device_area_tag, - device_building_tag2 = x.device_building_tag, - device_system_tag2 = x.device_system_tag, - device_name_tag2 = x.device_name_tag, - point_name2 = x.point_name - }).Select(x => new device_item8 - { - device_area_tag = x.Key.device_area_tag2, - device_building_tag = x.Key.device_building_tag2, - device_system_tag = x.Key.device_system_tag2, - device_name_tag = x.Key.device_name_tag2, - point_name = x.Key.point_name2 - }); + List dt_item = new List(); - StringBuilder sb = new StringBuilder(); - foreach (var row2 in ds2_item) - { - sb.Append($@" insert import_niagara_item(device_area_tag, device_building_tag, device_system_tag, device_name_tag, device_point_name) - values('" + - row2.device_area_tag + "', '" + - row2.device_building_tag + "', '" + - row2.device_system_tag + "', '" + - 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 - { - if (sb.Length > 0) + foreach (var row in dt) { - conn.Execute(sb.ToString()); - sb.Clear(); + if (string.IsNullOrEmpty(row.tag_name)) continue; + string[] arrTag = row.tag_name.Split('_'); + + #region for item + device_item8 row_item = new device_item8(); + row_item.tag_name = row.tag_name; + row_item.device_area_tag = arrTag[0]; + row_item.device_building_tag = arrTag[1]; + row_item.device_system_tag = arrTag[2]; + row_item.device_name_tag = arrTag[3]; + row_item.device_floor_tag = arrTag[4]; + row_item.device_master_tag = arrTag[5]; + row_item.device_last_name_tag = arrTag[6]; + row_item.device_serial_tag = arrTag[7]; + row_item.point_name = row.point_name; + dt_item.Add(row_item); + #endregion + } + + //device_item + var ds2_item = dt_item.GroupBy(x => new + { + device_area_tag2 = x.device_area_tag, + device_building_tag2 = x.device_building_tag, + device_system_tag2 = x.device_system_tag, + device_name_tag2 = x.device_name_tag, + point_name2 = x.point_name + }).Select(x => new device_item8 + { + device_area_tag = x.Key.device_area_tag2, + device_building_tag = x.Key.device_building_tag2, + device_system_tag = x.Key.device_system_tag2, + device_name_tag = x.Key.device_name_tag2, + point_name = x.Key.point_name2 + }); + + StringBuilder sb = new StringBuilder(); + foreach (var row2 in ds2_item) + { + sb.Append($@" insert import_niagara_item(device_area_tag, device_building_tag, device_system_tag, device_name_tag, device_point_name) + values('" + + row2.device_area_tag + "', '" + + row2.device_building_tag + "', '" + + row2.device_system_tag + "', '" + + row2.device_name_tag + "', '" + + row2.point_name + "'" + + ");"); + } + try + { + if (sb.Length > 0) + { + conn.Execute(sb.ToString()); + sb.Clear(); + } + } + catch (Exception ex) + { + throw ex; } - } - catch (Exception ex) - { - throw ex; } } + /// + /// 比對device和import_Niagara_tag,並更新至device(資料表) + /// public void deviceComparison() { using (MySqlConnection conn = new MySqlConnection(Connection1)) @@ -258,8 +225,8 @@ namespace tpDomeWinAPP.Service 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 + "', '" + // + values(uuid(), 0, 1, 0, 1, '" + + data.device_area_tag + "', '" + data.device_building_tag + "', '" + data.device_system_tag + "', '" + data.device_name_tag + "', '" + @@ -268,7 +235,7 @@ namespace tpDomeWinAPP.Service data.device_master_tag + "', '" + data.device_last_name_tag + "', '" + data.device_serial_tag + "', '" + - data.niagara_tags + "', '" + //device_number + data.niagara_tags + "', '" + data.device_system_tag + "', now(), now() );"); } if(sb.Length > 0) @@ -288,6 +255,9 @@ namespace tpDomeWinAPP.Service } } + /// + /// 比對device_item和import_Niagara_item,並更新至device_item(資料表) + /// public void deviceItemComparison() { using (MySqlConnection conn = new MySqlConnection(Connection1)) @@ -299,8 +269,7 @@ namespace tpDomeWinAPP.Service 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 + ON 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(); @@ -319,14 +288,12 @@ namespace tpDomeWinAPP.Service { 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) + sb.Append($@"insert device_item(deleted, points, is_show, is_show_riserDiagram, is_controll, is_bool, is_link, + 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());"); @@ -340,11 +307,120 @@ namespace tpDomeWinAPP.Service //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 + 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 = 0 WHERE m.device_point_name IS NULL"); conn.Execute(sb.ToString()); + } + } + + public void insertBuildingMenu() + { + using (MySqlConnection conn = new MySqlConnection(Connection1)) + { + conn.Open(); + List result; + StringBuilder sb = new StringBuilder(); + #region comparison building_menu and import_niagara_tag + sb.Append($@" select a.* from ( + select device_building_tag, device_system_tag, device_name_tag + from import_niagara_tag + group by device_building_tag, device_system_tag, device_name_tag + ) AS a + LEFT JOIN building_menu b + ON a.device_building_tag = b.device_building_tag and a.device_system_tag = b.device_system_tag and a.device_name_tag = b.sub_system_tag + WHERE b.device_building_tag IS NULL"); + result = conn.Query(sb.ToString()).ToList(); + #endregion + sb.Clear(); + + if (result.Count > 0) + { + foreach (var data in result) { + #region insert building_menu + sb.Append(@"insert building_menu(building_tag, main_system_tag, sub_system_tag, device_building_tag, device_system_tag, + is_link, created_by, created_at, updated_by, updated_at) + VALUES ('" + data.device_building_tag + "', '" + + data.device_system_tag + "', '" + + data.device_name_tag + "', '" + + data.device_building_tag + "', '" + + data.device_system_tag + "', " + + "1, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now(), 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now() );"); + #endregion + } + if (sb.Length > 0) + { + conn.Execute(sb.ToString()); + sb.Clear(); + } + } + //building_menu有,import_niagara_tag沒有,is_link 更新成 0 + sb.Append($@" SET SQL_SAFE_UPDATES = 0; + UPDATE building_menu b LEFT JOIN ( + select device_building_tag, device_system_tag, device_name_tag + from import_niagara_tag + group by device_building_tag, device_system_tag, device_name_tag + ) AS a ON b.device_building_tag = a.device_building_tag + and a.device_system_tag = b.device_system_tag and a.device_name_tag = b.sub_system_tag + SET b.is_link = 0 + WHERE b.device_building_tag IS NULL"); + conn.Execute(sb.ToString()); + } + } + + public void insertSubSystemFloor() + { + using (MySqlConnection conn = new MySqlConnection(Connection1)) + { + conn.Open(); + List result; + StringBuilder sb = new StringBuilder(); + #region comparison sub_system_floor and import_niagara_tag + sb.Append($@" select a.* from ( + select device_building_tag, device_system_tag, device_name_tag, device_floor_tag + from import_niagara_tag + group by device_building_tag, device_system_tag, device_name_tag, device_floor_tag + ) AS a + LEFT JOIN sub_system_floor b + ON a.device_building_tag = b.building_tag and a.device_system_tag = b.main_system_tag and a.device_name_tag = b.sub_system_tag and a.device_floor_tag = b.floor_tag + WHERE b.building_tag IS NULL"); + result = conn.Query(sb.ToString()).ToList(); + #endregion + sb.Clear(); + + + if(result.Count > 0) + { + foreach(var data in result) + { + #region insert building_menu + sb.Append(@"insert sub_system_floor(building_tag, main_system_tag, sub_system_tag, floor_tag, + is_link, created_by, created_at, updated_by, updated_at) + VALUES ('" + + data.device_building_tag + "', '" + + data.device_system_tag + "', '" + + data.device_name_tag + "', '" + + data.device_floor_tag + "', " + + "1, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now(), 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now());"); + #endregion + } + if (sb.Length > 0) + { + conn.Execute(sb.ToString()); + sb.Clear(); + } + } + //building_menu有,import_niagara_tag沒有,is_link 更新成 0 + sb.Append($@" SET SQL_SAFE_UPDATES = 0; + UPDATE sub_system_floor b LEFT JOIN ( + select device_building_tag, device_system_tag, device_name_tag, device_floor_tag + from import_niagara_tag + group by device_building_tag, device_system_tag, device_name_tag, device_floor_tag + ) AS a ON b.building_tag = a.device_building_tag + and b.main_system_tag = a.device_system_tag and b.sub_system_tag = a.device_name_tag and b.floor_tag = a.device_floor_tag + SET b.is_link = 0 + WHERE b.building_tag IS NULL"); + conn.Execute(sb.ToString()); } } diff --git a/z01_WinAPP/fmCheckTagName.cs b/z01_WinAPP/fmCheckTagName.cs index 959440e..4691256 100644 --- a/z01_WinAPP/fmCheckTagName.cs +++ b/z01_WinAPP/fmCheckTagName.cs @@ -141,7 +141,7 @@ namespace tpDomeWinAPP if (ds != null && ds.Count > 0) { - svcCompare.InsertNiagaraTagList(ds, building); + svcCompare.ToInsertNiagaraTagList(ds, building); lbMsg2.Text = "Done!" + Environment.NewLine + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } else From abf63105ef75f83c9748fb204503ecd76c16d719 Mon Sep 17 00:00:00 2001 From: dev02 Date: Thu, 20 Oct 2022 23:27:00 +0800 Subject: [PATCH 08/14] =?UTF-8?q?[=E5=BE=8C=E5=8F=B0]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=8D=80=E5=9F=9F=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/BuildInfoController.cs | 229 +++++++++--------- Backend/Models/BuildModel.cs | 2 + Backend/Views/BuildInfo/Index.cshtml | 44 +++- Backend/Views/BuildInfo/_BuildInfo.cshtml | 4 + .../be95566e-860e-48cb-af54-9f98218663b9.svg | 5 + 5 files changed, 167 insertions(+), 117 deletions(-) create mode 100644 Backend/wwwroot/upload/floor_map/be95566e-860e-48cb-af54-9f98218663b9.svg diff --git a/Backend/Controllers/BuildInfoController.cs b/Backend/Controllers/BuildInfoController.cs index ac19472..f4e4265 100644 --- a/Backend/Controllers/BuildInfoController.cs +++ b/Backend/Controllers/BuildInfoController.cs @@ -19,6 +19,8 @@ namespace Backend.Controllers { private readonly IBackendRepository backendRepository; private string mapFileSaveAsPath = ""; + private string main_system_name = "device_system_category_layer2"; + private string sub_system_name = "device_system_category_layer1"; public BuildInfoController(IBackendRepository backendRepository) { @@ -44,7 +46,7 @@ namespace Backend.Controllers try { - var sqlString = @$"SELECT A.priority, A.building_guid, A.full_name, A.ip_address, A.ip_port, (SELECT COUNT(*) FROM floor f WHERE f.deleted = 0 AND f.building_guid = A.building_guid) AS 'floorNum', A.created_at + var sqlString = @$"SELECT A.priority, A.building_tag, A.full_name, A.ip_address, A.ip_port, (SELECT COUNT(*) FROM floor f WHERE f.deleted = 0 AND f.building_tag = A.building_tag) AS 'floorNum', A.created_at FROM building A WHERE A.deleted = 0 ORDER BY A.priority ASC, A.created_at DESC"; @@ -78,8 +80,8 @@ namespace Backend.Controllers //判斷監控主機IP是否重複 var judgeIPAddressRepeat = true; - var sWhere = $@"deleted = 0 AND ip_address = @ip_address AND ip_port = @ip_port AND building_guid != @building_guid"; - var buildInfos = await backendRepository.GetAllAsync("building", sWhere, new { ip_address = post.Ip_address, ip_port = post.Ip_port, building_guid = post.Building_guid }); + var sWhere = $@"deleted = 0 AND ip_address = @ip_address AND ip_port = @ip_port AND building_tag != @building_tag"; + var buildInfos = await backendRepository.GetAllAsync("building", sWhere, new { ip_address = post.Ip_address, ip_port = post.Ip_port, building_tag = post.building_tag }); if (buildInfos.Count == 0) { judgeIPAddressRepeat = false; @@ -87,46 +89,92 @@ namespace Backend.Controllers if (!judgeIPAddressRepeat) { + //Check for duplicate building tag + sWhere = $@"deleted = 0 AND building_tag = @Building_tag"; + buildInfos = await backendRepository.GetAllAsync("building", sWhere, new { building_tag = post.building_tag }); + + if (buildInfos.Count > 0) + { + apiResult.Code = "0002"; + apiResult.Msg = "區域代號不可重複"; + return apiResult; + } + //新增 - if (post.Building_guid == "0") + //抓取當前的Priority + var current_priority = await backendRepository.GetCurrentPriority("building"); + + Dictionary building = new Dictionary(); + building = new Dictionary() { - //產生一組GUID - var guid = Guid.NewGuid(); //大樓GUID + { "@building_tag", post.building_tag}, + { "@full_name", post.Full_name}, + { "@ip_address", post.Ip_address}, + { "@ip_port", post.Ip_port}, + { "@priority", current_priority + 1}, + { "@created_by", myUserInfo.Userinfo_guid} + }; + await backendRepository.AddOneByCustomTable(building, "building"); - //抓取當前的Priority - var current_priority = await backendRepository.GetCurrentPriority("building"); + apiResult.Code = "0000"; + apiResult.Msg = "新增成功"; + } + else + { + apiResult.Code = "0001"; + apiResult.Msg = "監控主機IP不可重複"; + } - Dictionary building = new Dictionary(); - building = new Dictionary() - { - { "@building_guid", guid}, - { "@full_name", post.Full_name}, - { "@ip_address", post.Ip_address}, - { "@ip_port", post.Ip_port}, - { "@priority", current_priority + 1}, - { "@created_by", myUserInfo.Userinfo_guid} - }; - await backendRepository.AddOneByCustomTable(building, "building"); + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + string json = System.Text.Json.JsonSerializer.Serialize(post); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } - apiResult.Code = "0000"; - apiResult.Msg = "新增成功"; - } - else //修改 + return apiResult; + } + + /// + /// 新增 / 修改 區域基本資料 + /// + /// + /// + [HttpPost] + public async Task> EditBuildInfo(BuildInfo post) + { + ApiResult apiResult = new ApiResult(); + + try + { + //判斷監控主機IP是否重複 + var judgeIPAddressRepeat = true; + + var sWhere = $@"deleted = 0 AND ip_address = @ip_address AND ip_port = @ip_port AND building_tag != @building_tag"; + var buildInfos = await backendRepository.GetAllAsync("building", sWhere, new { ip_address = post.Ip_address, ip_port = post.Ip_port, building_tag = post.building_tag }); + if (buildInfos.Count == 0) + { + judgeIPAddressRepeat = false; + } + + if (!judgeIPAddressRepeat) + { + Dictionary building = new Dictionary(); + building = new Dictionary() { - Dictionary building = new Dictionary(); - building = new Dictionary() - { - { "@full_name", post.Full_name}, - { "@ip_address", post.Ip_address}, - { "@ip_port", post.Ip_port}, - { "@updated_by", myUserInfo.Userinfo_guid}, - { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} - }; - await backendRepository.UpdateOneByCustomTable(building, "building", "building_guid='" + post.Building_guid + "'"); + { "@full_name", post.Full_name}, + { "@ip_address", post.Ip_address}, + { "@ip_port", post.Ip_port}, + { "@updated_by", myUserInfo.Userinfo_guid}, + { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} + }; + await backendRepository.UpdateOneByCustomTable(building, "building", "building_tag='" + post.building_tag + "'"); - apiResult.Code = "0000"; - apiResult.Msg = "修改成功"; - } + apiResult.Code = "0000"; + apiResult.Msg = "修改成功"; } else { @@ -148,14 +196,14 @@ namespace Backend.Controllers } [HttpPost] - public async Task> DeleteOneBuild(string guid) + public async Task> DeleteOneBuild(string tag) { var apiResult = new ApiResult(); try { - string sWhere = @$"deleted = @Deleted AND building_guid = @Guid"; + string sWhere = @$"deleted = @Deleted AND building_tag = @Tag"; - object param = new { Deleted = 0, Guid = guid }; + object param = new { Deleted = 0, Tag = tag }; var buildInfo = await backendRepository.GetOneAsync("building", sWhere, param); @@ -167,8 +215,8 @@ namespace Backend.Controllers } //檢查是否有未刪除的區域選單 - var sbuildMenuWhere = $@"building_guid = @Guid"; - var buildMenus = await backendRepository.GetAllAsync("building_menu", sbuildMenuWhere, new { Guid = guid }); + var sbuildMenuWhere = $@"building_tag = @Tag"; + var buildMenus = await backendRepository.GetAllAsync("building_menu", sbuildMenuWhere, new { Tag = tag }); if (buildMenus.Count > 0) { @@ -178,8 +226,8 @@ namespace Backend.Controllers } //檢查底下是否有未刪除的樓層 - var sfloorWhere = $@"deleted = 0 AND building_guid = @Guid"; - var floors = await backendRepository.GetAllAsync("floor", sfloorWhere, new { Guid = guid }); + var sfloorWhere = $@"deleted = 0 AND building_tag = @tag"; + var floors = await backendRepository.GetAllAsync("floor", sfloorWhere, new { Tag = tag }); if (floors.Count > 0) { @@ -189,7 +237,7 @@ namespace Backend.Controllers return apiResult; } - await backendRepository.DeleteOne(guid, "building", "building_guid"); + await backendRepository.DeleteOne(tag, "building", "building_tag"); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -199,7 +247,7 @@ namespace Backend.Controllers { apiResult.Code = "9999"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - Logger.LogError("【" + controllerName + "/" + actionName + "】" + "building_guid=" + guid); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "building_tag=" + tag); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } return apiResult; @@ -223,7 +271,7 @@ namespace Backend.Controllers Dictionary building_priority_dic = new Dictionary(); building_priority_dic = new Dictionary() { - { "building_guid", building_priority.Building_guid}, + { "building_tag", building_priority.Building_tag}, { "@priority", building_priority.Priority}, { "@updated_by", myUserInfo.Userinfo_guid}, { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} @@ -232,14 +280,9 @@ namespace Backend.Controllers building_priorities.Add(building_priority_dic); } - var sql = $@"UPDATE building SET priority = @priority, updated_by = @updated_by, updated_at=@updated_at WHERE building_guid = @building_guid"; + var sql = $@"UPDATE building SET priority = @priority, updated_by = @updated_by, updated_at=@updated_at WHERE building_tag = @building_tag"; await backendRepository.ExecuteSql(sql, building_priorities); - - #region 新增至派送資料表 - await backendRepository.ManualInsertBackgroundServiceTask("", "", "building", "update_list", building_priorities); - #endregion - } apiResult.Code = "0000"; @@ -261,7 +304,7 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task>> BuildFloorList(string BuildGuid) + public async Task>> BuildFloorList(string build_tag) { ApiResult> apiResult = new ApiResult>(); List buildInfo = new List(); @@ -271,9 +314,9 @@ namespace Backend.Controllers var sqlString = @$"SELECT A.floor_guid, A.full_name, InitMapName + '.svg' AS 'initMapName', A.priority, A.created_at FROM floor A WHERE deleted = @deleted - AND A.building_guid = @building_guid + AND A.building_tag = @building_tag ORDER BY A.priority ASC"; - buildInfo = await backendRepository.GetAllAsync(sqlString, new { deleted = 0, building_guid = BuildGuid }); + buildInfo = await backendRepository.GetAllAsync(sqlString, new { deleted = 0, building_tag = build_tag }); apiResult.Code = "0000"; apiResult.Data = buildInfo; @@ -348,13 +391,13 @@ namespace Backend.Controllers var floor_map_guid = Guid.NewGuid(); //抓取當前的Priority - var current_priority = await backendRepository.GetCurrentPriority("floor", "deleted = 0 AND building_guid = '" + post.Building_guid + "'"); + var current_priority = await backendRepository.GetCurrentPriority("floor", "deleted = 0 AND building_tag = '" + post.Building_tag + "'"); Dictionary floor = new Dictionary(); floor = new Dictionary() { { "@floor_guid", guid}, - { "@building_guid", post.Building_guid}, + { "@building_tag", post.Building_tag}, { "@full_name", post.Full_name}, { "@InitMapName", post.InitMapName}, { "@floor_map_name", floor_map_guid}, @@ -374,27 +417,7 @@ namespace Backend.Controllers { post.MapFile.CopyTo(stream); } - } - - #region 新增至派送資料表 - List fileInfos = new List(); - if (post.MapFile != null) - { - var split = post.MapFile.FileName.Split("."); - var fileName = floor_map_guid + "." + split[split.Length - 1]; - - var fullPath = Path.Combine(mapFileSaveAsPath, fileName); - - Repository.Models.FileInfo fileInfo = new Repository.Models.FileInfo(); - fileInfo.Folder = "floor_map"; - fileInfo.OriginalFileName = null; - fileInfo.FileName = fileName; - fileInfo.File = fullPath; - - fileInfos.Add(fileInfo); - await backendRepository.ManualInsertFileBackgroundServiceTask("", post.Building_guid, "floor", fileInfos); - } - #endregion + } apiResult.Code = "0000"; apiResult.Msg = "新增成功"; @@ -436,26 +459,6 @@ namespace Backend.Controllers } } - #region 新增至派送資料表 - List fileInfos = new List(); - if (post.MapFile != null) - { - var split = post.MapFile.FileName.Split("."); - var fileName = floor_map_guid + "." + split[split.Length - 1]; - - var fullPath = Path.Combine(mapFileSaveAsPath, fileName); - - Repository.Models.FileInfo fileInfo = new Repository.Models.FileInfo(); - fileInfo.Folder = "floor_map"; - fileInfo.OriginalFileName = buildFloor.Floor_map_name + ".svg"; - fileInfo.FileName = fileName; - fileInfo.File = fullPath; - - fileInfos.Add(fileInfo); - } - await backendRepository.ManualInsertFileBackgroundServiceTask("", post.Building_guid, "floor", fileInfos); - #endregion - apiResult.Code = "0000"; apiResult.Msg = "修改成功"; } @@ -502,10 +505,6 @@ namespace Backend.Controllers var sql = $@"UPDATE floor SET priority = @priority, updated_by = @updated_by, updated_at=@updated_at WHERE floor_guid = @floor_guid"; await backendRepository.ExecuteSql(sql, floor_priorities); - - #region 新增至派送資料表 - await backendRepository.ManualInsertBackgroundServiceTask("", "", "floor", "update_list", floor_priorities); - #endregion } apiResult.Code = "0000"; @@ -547,20 +546,20 @@ namespace Backend.Controllers //判斷區域選單是否還有使用該樓層 var sub_system_where = $@"SELECT - CONCAT(b.full_name, ' - ', ms.full_name, ' - ', ss.full_name) - FROM ( - SELECT - ssf.building_guid, - ssf.main_system_guid, - ssf.sub_system_guid - FROM sub_system_floor ssf - WHERE ssf.deleted = 0 AND floor_guid = @Guid - ) ssf - LEFT JOIN building b ON ssf.building_guid = b.building_guid AND b.deleted = 0 - LEFT JOIN main_system ms ON ssf.main_system_guid = ms.main_system_guid AND ms.deleted = 0 - LEFT JOIN sub_system ss ON ssf.sub_system_guid = ss.sub_system_guid AND ss.deleted = 0"; + CONCAT(b.full_name, ' - ', v1.system_key, ' - ', v2.system_key) + FROM ( + SELECT + ssf.building_tag, + ssf.main_system_tag, + ssf.sub_system_tag + FROM sub_system_floor ssf + WHERE ssf.deleted = 0 AND ssf.floor_tag = @floor_tag + ) ssf + LEFT JOIN building b ON ssf.building_tag = b.building_tag AND b.deleted = 0 + LEFT JOIN variable v1 ON ssf.main_system_tag = v1.system_value AND v1.system_type = @main_system_type AND v1.deleted = 0 + LEFT JOIN variable v2 ON ssf.sub_system_tag = v2.system_value AND v2.system_type = @sub_system_type AND v2.deleted = 0"; - var sub_system_floors = await backendRepository.GetAllAsync(sub_system_where, new { Guid = guid }); + var sub_system_floors = await backendRepository.GetAllAsync(sub_system_where, new { floor_tag = buildFloor.Full_name, main_system_type = main_system_name, sub_system_type = sub_system_name }); if (sub_system_floors.Count > 0) { apiResult.Code = "9997"; diff --git a/Backend/Models/BuildModel.cs b/Backend/Models/BuildModel.cs index 25e47bd..ab59ef2 100644 --- a/Backend/Models/BuildModel.cs +++ b/Backend/Models/BuildModel.cs @@ -23,6 +23,7 @@ namespace Backend.Models { public string Floor_guid { get; set; } //樓層GUID public string Building_guid { get; set; } //區域GUID + public string Building_tag { get; set; } //區域GUID public string Full_name { get; set; } //建築名稱 public string InitMapName { get; set; } //使用者命名平面圖檔檔名 public string MapUrl { get; set; } //使用者命名平面圖檔檔名 @@ -43,6 +44,7 @@ namespace Backend.Models public class BuildInfoPriority { public string Building_guid { get; set; } //區域GUID + public string Building_tag { get; set; } //區域TAG public int Priority { get; set; } } diff --git a/Backend/Views/BuildInfo/Index.cshtml b/Backend/Views/BuildInfo/Index.cshtml index 956fd36..9e49dfb 100644 --- a/Backend/Views/BuildInfo/Index.cshtml +++ b/Backend/Views/BuildInfo/Index.cshtml @@ -163,6 +163,9 @@ selected_build_guid = $(this).parents('tr').attr('data-guid'); $('#build-modal .modal-title').html("區域基本資料 - 修改"); + $('#build_name_tag').val(selected_build_guid); + $('#build_name_tag').prop('disabled', true); + $("#save-building-btn").attr("onClick", "EditBuild()"); $('#build_name_modal').val($(this).parents('tr')[0].children[1].innerText); $('#ip_address_modal').val($(this).parents('tr')[0].children[2].innerText); $('#ip_port_modal').val($(this).parents('tr')[0].children[3].innerText); @@ -187,7 +190,7 @@ if (result.value) { var url = "/BuildInfo/DeleteOneBuild/"; var send_data = { - guid: selected_build_guid + tag: selected_build_guid } $.post(url, send_data, function (rel) { if (rel.code == "9999") { @@ -218,7 +221,9 @@ function AddBuild() { selected_build_guid = "0"; BuildInfoValidate.resetForm(); + $("#save-building-btn").attr("onClick", "SaveBuild()"); $("#build-modal .modal-title").html("區域基本資料 - 新增"); + $('#build_name_tag').prop('disabled', false); $("#build-form").trigger("reset"); $("#build-modal").modal(); @@ -252,6 +257,41 @@ if ($("#build-form").valid()) { $("#save-building-btn").html('').attr("disabled", true); var url = "/BuildInfo/SaveBuildInfo"; + var send_data = { + building_tag: $('#build_name_tag').val(), + Full_name: $('#build_name_modal').val(), + Ip_address: $('#ip_address_modal').val(), + Ip_port: $('#ip_port_modal').val() + } + + $.post(url, send_data, function (rel) { + $("#save-building-btn").html('確定').attr("disabled", false); + if (rel.code != "0000") { + if (rel.code == "9999") { + toast_error(rel.msg); + } + else { + toast_warning(rel.msg); + } + return; + } + else { + toast_ok(rel.msg); + buildInfoTable.ajax.reload(null, false); + $('#build-modal').modal('hide'); + return; + } + }, 'json') + .fail(function (xhr, status, error) { + $("#save-building-btn").html('確定').attr("disabled", false); + }); + } + } + + function EditBuild() { + if ($("#build-form").valid()) { + $("#save-building-btn").html('').attr("disabled", true); + var url = "/BuildInfo/EditBuildInfo"; var send_data = { building_tag: selected_build_guid, Full_name: $('#build_name_modal').val(), @@ -342,7 +382,7 @@ "url": "/BuildInfo/BuildFloorList", "type": "POST", "data": function (d) { - d.BuildGuid = selected_build_guid_top; + d.build_tag = selected_build_guid_top; }, "dataSrc": function (rel) { if (rel.code == "9999") { diff --git a/Backend/Views/BuildInfo/_BuildInfo.cshtml b/Backend/Views/BuildInfo/_BuildInfo.cshtml index c0d2dc3..fe932af 100644 --- a/Backend/Views/BuildInfo/_BuildInfo.cshtml +++ b/Backend/Views/BuildInfo/_BuildInfo.cshtml @@ -40,6 +40,10 @@