From 7ab418c7b1839b454abbe6134b5deafe390e4e71 Mon Sep 17 00:00:00 2001 From: dev02 Date: Thu, 14 Sep 2023 17:30:26 +0800 Subject: [PATCH 1/4] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9device=20item=20=E7=8D=B2?= =?UTF-8?q?=E5=8F=96=E8=B3=87=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implement/webRequestService.cs | 25 +- .../NiagaraDataSynchronizeRepository.cs | 322 ++++++++++-------- 2 files changed, 183 insertions(+), 164 deletions(-) diff --git a/Backend/Services/Implement/webRequestService.cs b/Backend/Services/Implement/webRequestService.cs index 9e1996f..2386ec1 100644 --- a/Backend/Services/Implement/webRequestService.cs +++ b/Backend/Services/Implement/webRequestService.cs @@ -235,24 +235,23 @@ namespace Backend.Services.Implement result.Add(row); } - else if (tagName.Split('_').Length == 6) + else if (tagName.Split('_').Length == 7) { //巨蛋 tag 5 段版本 ImpNiaItem row = new ImpNiaItem(); - if (tagName.Split('_')[1] == "S") //for security system + if (tagName.Split('_')[2] == "S" || tagName.Split('_')[2] == "B" || tagName.Split('_')[2] == "CWB") //for security system and parking system { - 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]; - row.device_point_name = tagName.Split('_')[5]; + row.device_building_tag = tagName.Split('_')[1]; + row.device_system_tag = tagName.Split('_')[2]; + row.device_floor_tag = tagName.Split('_')[3]; + row.device_name_tag = tagName.Split('_')[4]; + row.device_point_name = tagName.Split('_')[6]; } else //for normal { - 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('_')[1]; - row.device_point_name = tagName.Split('_')[5]; + row.device_building_tag = tagName.Split('_')[1]; + row.device_floor_tag = tagName.Split('_')[3]; + row.device_name_tag = tagName.Split('_')[2]; + row.device_point_name = tagName.Split('_')[6]; } row.parent_path = stationName; @@ -288,7 +287,7 @@ namespace Backend.Services.Implement } else if (n.name.Split('/').Length == 7) // Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/Summery { - if (n.name.Split('/')[3] == "S" || n.name.Split('/')[3] == "CWB") //for security system and CWB system + if (n.name.Split('/')[2] == "S" || n.name.Split('/')[2] == "B" || n.name.Split('/')[2] == "CWB") //for security system and CWB system { result.Add(new ImpNiaItem { device_building_tag = n.name.Split('/')[1], diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index e554cc8..b30d49e 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -283,7 +283,7 @@ namespace Repository.BackendRepository.Implement sb.Append($@" update import_niagara_item a join dic_system b on a.device_name_tag COLLATE utf8mb4_0900_ai_ci = b.s2_code COLLATE utf8mb4_0900_ai_ci set device_system_tag = b.s1_code - where (device_system_tag <> 'S' and device_system_tag <> 'CWB');"); + where (device_system_tag <> 'S' and device_system_tag <> 'CWB' and device_system_tag <> 'B');"); } sb.Append($@" update import_niagara_item set full_name = device_point_name where full_name = '' or full_name is null;"); @@ -315,200 +315,220 @@ namespace Repository.BackendRepository.Implement using (IDbConnection conn = GetDbConnection()) { conn.Open(); - using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled)) - try + try + { + List result; + StringBuilder sb = new StringBuilder(); + StringBuilder sb2 = new StringBuilder(); + sb.Append($@"SELECT m.* + FROM import_niagara_tag m + WHERE NOT EXISTS ( + SELECT 1 + FROM device d + WHERE m.niagara_tags = d.device_number + );"); + result = (await conn.QueryAsync(sb.ToString())).ToList(); + + sb.Clear(); + #region device, device_kind 新增 + //新增至device, is_link = 1 + if (result.Count > 0) { - List result; - StringBuilder sb = new StringBuilder(); - StringBuilder sb2 = new StringBuilder(); - sb.Append($@"SELECT m.* - FROM import_niagara_tag m - WHERE NOT EXISTS ( - SELECT 1 - FROM device d - WHERE m.niagara_tags = d.device_number - );"); - result = (await conn.QueryAsync(sb.ToString())).ToList(); - - sb.Clear(); - #region device, device_kind 新增 - //新增至device, is_link = 1 - if (result.Count > 0) + var result2 = result.GroupBy(x => new { - var result2 = result.GroupBy(x => new - { - device_building_tag2 = x.device_building_tag, - device_system_tag2 = x.device_system_tag, - device_name_tag2 = x.device_name_tag - }).Select(x => new Device_item8 - { - device_building_tag = x.Key.device_building_tag2, - device_system_tag = x.Key.device_system_tag2, - device_name_tag = x.Key.device_name_tag2 - }); + device_building_tag2 = x.device_building_tag, + device_system_tag2 = x.device_system_tag, + device_name_tag2 = x.device_name_tag + }).Select(x => new Device_item8 + { + device_building_tag = x.Key.device_building_tag2, + device_system_tag = x.Key.device_system_tag2, + device_name_tag = x.Key.device_name_tag2 + }); - int count = 0; - foreach (var data in result) + int count = 0; + foreach (var data in result) + { + //開關控制在個別燈具(device_node層) and 小類為二線式照明系統 and tag第八段開頭不是 G + if (LightSwitchLevel == "node" && data.device_name_tag == "L1" && data.device_serial_tag.Substring(0, 1) != "G") { - //開關控制在個別燈具(device_node層) and 小類為二線式照明系統 and tag第八段開頭不是 G - if (LightSwitchLevel == "node" && data.device_name_tag == "L1" && data.device_serial_tag.Substring(0, 1) != "G") + // 燈具新增 device_node + continue; + } + else { + sb.Append($@" insert device(device_guid, deleted, status, priority, is_link, device_area_tag, + device_building_tag, device_system_tag, device_name_tag, full_name, device_floor_tag, device_master, + device_last_name, device_serial_tag, device_number, device_system_category_layer3, visible, created_at, updated_at) + values(uuid(), 0, 1, 0, 1, '" + + data.device_area_tag + "', '" + + data.device_building_tag + "', '" + + data.device_system_tag + "', '" + + data.device_name_tag + "', '" + + data.device_full_name + "', '" + + data.device_floor_tag + "', '" + + data.device_master_tag + "', '" + + data.device_last_name_tag + "', '" + + data.device_serial_tag + "', '" + + data.niagara_tags + "', '" + + data.device_system_tag + "', 1, now(), now() );"); + count += 1; + if (count >= 100) { - // 燈具新增 device_node - continue; - } - else { - sb.Append($@" insert device(device_guid, deleted, status, priority, is_link, device_area_tag, - device_building_tag, device_system_tag, device_name_tag, full_name, device_floor_tag, device_master, - device_last_name, device_serial_tag, device_number, device_system_category_layer3, visible, created_at, updated_at) - values(uuid(), 0, 1, 0, 1, '" + - data.device_area_tag + "', '" + - data.device_building_tag + "', '" + - data.device_system_tag + "', '" + - data.device_name_tag + "', '" + - data.device_full_name + "', '" + - data.device_floor_tag + "', '" + - data.device_master_tag + "', '" + - data.device_last_name_tag + "', '" + - data.device_serial_tag + "', '" + - data.niagara_tags + "', '" + - data.device_system_tag + "', 1, now(), now() );"); - count += 1; - if (count >= 100) + using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled)) { await conn.ExecuteAsync(sb.ToString()); - sb.Clear(); - count = 0; } - } - } + sb.Clear(); + count = 0; + } + } + } - count = 0; - foreach (var data in result2) + count = 0; + foreach (var data in result2) + { + var sqlString = new StringBuilder(); + sqlString.Append("select * from device_kind where device_building_tag = '" + data.device_building_tag + "' and device_system_tag = '" + data.device_system_tag + "' and device_name_tag = '" + data.device_name_tag + "'"); + var dk = (await conn.QueryAsync(sqlString.ToString())).ToList(); + + if (dk.Count == 0) { - var sqlString = new StringBuilder(); - sqlString.Append("select * from device_kind where device_building_tag = '" + data.device_building_tag + "' and device_system_tag = '" + data.device_system_tag + "' and device_name_tag = '" + data.device_name_tag + "'"); - var dk = (await conn.QueryAsync(sqlString.ToString())).ToList(); - - if (dk.Count == 0) + sb2.Append($@"INSERT device_kind (device_kind_guid, device_building_tag, device_system_tag, device_name_tag, + device_normal_flashing, device_close_flashing, device_error_flashing, device_error_independent, + created_by, created_at) + VALUES (uuid(), '" + data.device_building_tag + "', '" + data.device_system_tag + "', '" + data.device_name_tag + + "', 0, 0, 1, 0, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now());"); + count += 1; + if (count >= 100) { - sb2.Append($@"INSERT device_kind (device_kind_guid, device_building_tag, device_system_tag, device_name_tag, - device_normal_flashing, device_close_flashing, device_error_flashing, device_error_independent, - created_by, created_at) - VALUES (uuid(), '" + data.device_building_tag + "', '" + data.device_system_tag + "', '" + data.device_name_tag + - "', 0, 0, 1, 0, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now());"); - count += 1; - if (count >= 100) + using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled)) { await conn.ExecuteAsync(sb2.ToString()); - sb2.Clear(); - count = 0; } + sb2.Clear(); + count = 0; } } + } - if (sb.Length > 0) + if (sb.Length > 0) + { + using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled)) { await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb2.ToString()); - - sb.Clear(); - sb2.Clear(); } + + sb.Clear(); + sb2.Clear(); } - #endregion + } + #endregion - #region device_node 新增 - sb.Append($@" SELECT m.* - FROM import_niagara_tag m - WHERE NOT EXISTS ( - SELECT 1 - FROM device_node d - WHERE m.niagara_tags COLLATE utf8mb4_0900_ai_ci = d.device_number COLLATE utf8mb4_0900_ai_ci - );"); - result = (await conn.QueryAsync(sb.ToString())).ToList(); - sb.Clear(); + #region device_node 新增 + sb.Append($@" SELECT m.* + FROM import_niagara_tag m + WHERE NOT EXISTS ( + SELECT 1 + FROM device_node d + WHERE m.niagara_tags COLLATE utf8mb4_0900_ai_ci = d.device_number COLLATE utf8mb4_0900_ai_ci + );"); + result = (await conn.QueryAsync(sb.ToString())).ToList(); + sb.Clear(); - if (result.Count > 0) + if (result.Count > 0) + { + var result2 = result.GroupBy(x => new { - var result2 = result.GroupBy(x => new - { - device_building_tag2 = x.device_building_tag, - device_system_tag2 = x.device_system_tag, - device_name_tag2 = x.device_name_tag - }).Select(x => new Device_item8 - { - device_building_tag = x.Key.device_building_tag2, - device_system_tag = x.Key.device_system_tag2, - device_name_tag = x.Key.device_name_tag2 - }); + device_building_tag2 = x.device_building_tag, + device_system_tag2 = x.device_system_tag, + device_name_tag2 = x.device_name_tag + }).Select(x => new Device_item8 + { + device_building_tag = x.Key.device_building_tag2, + device_system_tag = x.Key.device_system_tag2, + device_name_tag = x.Key.device_name_tag2 + }); - int count = 0; - foreach (var data in result) + int count = 0; + foreach (var data in result) + { + //開關控制在個別燈具(device_node層) and 小類為二線式照明系統 and tag第八段開頭不是 G + if (LightSwitchLevel == "node" && data.device_name_tag == "L1" && data.device_serial_tag.Substring(0, 1) != "G") { - //開關控制在個別燈具(device_node層) and 小類為二線式照明系統 and tag第八段開頭不是 G - if (LightSwitchLevel == "node" && data.device_name_tag == "L1" && data.device_serial_tag.Substring(0, 1) != "G") + // 燈具新增 device_node + sb.Append($@"INSERT INTO device_node(device_node_guid, deleted, device_guid, device_number, full_name, created_by, created_at, updated_at) + VALUES (uuid(), 0, '' " + //device_guid 父層需要 forge 那邊提供 + ",'" + data.niagara_tags + // device_number + "', '" + data.device_full_name + //full_name + "','B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now(), now());"); + count += 1; + if (count >= 100) { - // 燈具新增 device_node - sb.Append($@"INSERT INTO device_node(device_node_guid, deleted, device_guid, device_number, full_name, created_by, created_at, updated_at) - VALUES (uuid(), 0, '' " + //device_guid 父層需要 forge 那邊提供 - ",'" + data.niagara_tags + // device_number - "', '" + data.device_full_name + //full_name - "','B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now(), now());"); - count += 1; - if (count >= 100) + using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled)) { await conn.ExecuteAsync(sb.ToString()); - sb.Clear(); - count = 0; } + sb.Clear(); + count = 0; } } + } - if (sb.Length > 0) + if (sb.Length > 0) + { + using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled)) { await conn.ExecuteAsync(sb.ToString()); - sb.Clear(); } + sb.Clear(); } - #endregion + } + #endregion - //device有,niagara沒有,is_link 更新成 0 - sb.Append($@" SET SQL_SAFE_UPDATES = 0; - UPDATE device d + //device有,niagara沒有,is_link 更新成 0 + sb.Append($@" SET SQL_SAFE_UPDATES = 0; + UPDATE device d + left JOIN ( + SELECT niagara_tags + FROM import_niagara_tag + LIMIT 100000 + ) i ON d.device_number = i.niagara_tags + SET d.is_link = 0 + WHERE d.is_link = 1 and i.niagara_tags is null;"); + using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled)) + { + await conn.ExecuteAsync(sb.ToString()); + } + + sb.Clear(); + + // device_node 有, niagara沒有, is_link 更新成 0 + sb.Append($@" SET SQL_SAFE_UPDATES = 0; + UPDATE device_node dn left JOIN ( - SELECT niagara_tags - FROM import_niagara_tag - LIMIT 100000 - ) i ON d.device_number = i.niagara_tags - SET d.is_link = 0 - WHERE d.is_link = 1 and i.niagara_tags is null;"); - await conn.ExecuteAsync(sb.ToString()); + SELECT niagara_tags + FROM import_niagara_tag + LIMIT 100000 + ) i ON dn.device_number COLLATE utf8mb4_0900_ai_ci = i.niagara_tags COLLATE utf8mb4_0900_ai_ci + SET dn.is_link = 0 + WHERE dn.is_link = 1 and i.niagara_tags is null;"); - sb.Clear(); - - // device_node 有, niagara沒有, is_link 更新成 0 - sb.Append($@" SET SQL_SAFE_UPDATES = 0; - UPDATE device_node dn - left JOIN ( - SELECT niagara_tags - FROM import_niagara_tag - LIMIT 100000 - ) i ON dn.device_number COLLATE utf8mb4_0900_ai_ci = i.niagara_tags COLLATE utf8mb4_0900_ai_ci - SET dn.is_link = 0 - WHERE dn.is_link = 1 and i.niagara_tags is null;"); + using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled)) + { await conn.ExecuteAsync(sb.ToString()); } - catch (Exception exception) - { - //throw exception; - throw; - } - finally - { - conn.Close(); - } - { } + catch (Exception exception) + { + //throw exception; + throw; + } + finally + { + conn.Close(); + } + } } From 80be5b1fa202f365a431f1552e2802862445975c Mon Sep 17 00:00:00 2001 From: dev02 Date: Mon, 18 Sep 2023 13:00:24 +0800 Subject: [PATCH 2/4] =?UTF-8?q?[=E5=BE=8C=E5=8F=B0]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=BB=9E=E4=BD=8D=E5=90=8C=E6=AD=A5=E5=85=A8=E6=A3=9F=E5=95=8F?= =?UTF-8?q?=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/SystemCategoryController.cs | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/Backend/Controllers/SystemCategoryController.cs b/Backend/Controllers/SystemCategoryController.cs index 0030edd..1c3bac6 100644 --- a/Backend/Controllers/SystemCategoryController.cs +++ b/Backend/Controllers/SystemCategoryController.cs @@ -557,21 +557,33 @@ namespace Backend.Controllers } else { - Dictionary Device_itemDic = new Dictionary() - { - { "@full_name", device_Item.full_name}, - { "@points", device_Item.points}, - { "@unit", device_Item.unit}, - { "@is_show", device_Item.is_show}, - { "@is_show_riserDiagram", device_Item.is_show_riserDiagram}, - { "@is_controll", device_Item.is_controll}, - { "@is_bool", device_Item.is_bool}, - { "@is_show_history", device_Item.is_show_history}, - { "@updated_by", myUserInfo.Userinfo_guid}, - { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, - }; + var sql = $@"SELECT di.id FROM device_item di + WHERE di.deleted = 0 AND device_system_tag = @device_system_tag and device_name_tag = @device_name_tag and points = @points"; - await backendRepository.UpdateOneByCustomTable(Device_itemDic, "device_item", "id='" + device_Item.id + "'"); + var deviceItemId = await backendRepository.GetAllAsync(sql, + new { points = device_Item.points, device_system_tag = main_tag, device_name_tag = sub_tag }); + + if (deviceItemId.Count() > 0) + { + foreach (var id in deviceItemId) + { + Dictionary Device_itemDic = new Dictionary() + { + { "@full_name", device_Item.full_name}, + { "@points", device_Item.points}, + { "@unit", device_Item.unit}, + { "@is_show", device_Item.is_show}, + { "@is_show_riserDiagram", device_Item.is_show_riserDiagram}, + { "@is_controll", device_Item.is_controll}, + { "@is_bool", device_Item.is_bool}, + { "@is_show_history", device_Item.is_show_history}, + { "@updated_by", myUserInfo.Userinfo_guid}, + { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + }; + + await backendRepository.UpdateOneByCustomTable(Device_itemDic, "device_item", "id='" + id + "'"); + } + } apiResult.Code = "0000"; apiResult.Msg = "修改成功"; @@ -652,7 +664,7 @@ namespace Backend.Controllers { string sWhere = @$"deleted = @Deleted AND id = @id"; - object param = new { Deleted = 0, id = id}; + object param = new { Deleted = 0, id = id }; var device_Item = await backendRepository.GetOneAsync("device_item", sWhere, param); @@ -663,7 +675,9 @@ namespace Backend.Controllers return apiResult; } - await backendRepository.DeleteOne(id.ToString(), "device_item", "id"); + string sql = $@"update device_item set deleted = 1 where device_system_tag = '{device_Item.device_system_tag}' and device_name_tag = '{device_Item.device_name_tag}' and deleted = 0 + and points = '{device_Item.points}'"; + await backendRepository.ExecuteSql(sql); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; From d02642ae271b76bfbbf5b6bbbaf5174583b1e477 Mon Sep 17 00:00:00 2001 From: dev02 Date: Tue, 19 Sep 2023 10:18:43 +0800 Subject: [PATCH 3/4] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9de?= =?UTF-8?q?vice=5Fitem=20history=20show=20=E5=95=8F=E9=A1=8C=20[=E5=89=8D?= =?UTF-8?q?=E7=AB=AF]=20=E4=BF=AE=E6=94=B9=E5=89=8D=E7=AB=AFapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/BuildController.cs | 2 +- .../NiagaraDataSynchronizeRepository.cs | 60 ++++++++++++++----- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/FrontendWebApi/ApiControllers/BuildController.cs b/FrontendWebApi/ApiControllers/BuildController.cs index d7dcebd..8f8fa12 100644 --- a/FrontendWebApi/ApiControllers/BuildController.cs +++ b/FrontendWebApi/ApiControllers/BuildController.cs @@ -585,7 +585,7 @@ namespace FrontendWebApi.ApiControllers left join floor f on d.device_floor_tag = f.full_name and f.deleted = 0 {disasterjoinsql} LEFT JOIN building_menu bm ON d.device_building_tag = bm.building_tag AND d.device_system_tag = bm.main_system_tag AND d.device_name_tag = bm.sub_system_tag - where d.deleted = 0 and d.device_building_tag = '{post.building_tag}' {sWhere} + where d.deleted = 0 and d.is_link = 1 and d.device_building_tag = '{post.building_tag}' {sWhere} order by d.priority ASC, left(device_serial_tag, LENGTH(device_serial_tag) - 1) ASC"; var devicelist = await backendRepository.GetAllAsync(sql); diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index b30d49e..1cf2fc5 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -486,6 +486,22 @@ namespace Repository.BackendRepository.Implement } #endregion + //device有,niagara有,is_link 更新成 1 + sb.Append($@" SET SQL_SAFE_UPDATES = 0; + UPDATE device d + JOIN ( + SELECT niagara_tags + FROM import_niagara_tag + LIMIT 100000 + ) i ON d.device_number = i.niagara_tags + SET d.is_link = 1"); + using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled)) + { + await conn.ExecuteAsync(sb.ToString()); + } + + sb.Clear(); + //device有,niagara沒有,is_link 更新成 0 sb.Append($@" SET SQL_SAFE_UPDATES = 0; UPDATE device d @@ -976,27 +992,43 @@ namespace Repository.BackendRepository.Implement using (IDbConnection conn = GetDbConnection()) { conn.Open(); - using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) + try { - try + StringBuilder sb = new StringBuilder(); + //先全部關閉 + sb.Append("update device_item set is_show_history=0;"); + using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { - StringBuilder sb = new StringBuilder(); - //先全部關閉 - //sb.Append("update device_item set is_show_history=0;"); - sb.Append("update device_item set is_show_history = 0 " + - "WHERE(device_system_tag, device_name_tag, points, full_name, is_show_history) NOT IN " + - "(select distinct device_system_tag, device_name_tag, device_point_name, full_name, is_history From import_niagara_item where is_history = 1);"); await conn.ExecuteAsync(sb.ToString()); } - catch (Exception exception) + + sb.Clear(); + + sb.Append($@"SET SQL_SAFE_UPDATES = 0; + update device_item di + JOIN ( + select distinct device_system_tag, device_name_tag, device_point_name, full_name, device_building_tag from import_niagara_item where is_history = 1 limit 100000 + ) niagara + ON di.device_system_tag = niagara.device_system_tag + AND di.device_name_tag = niagara.device_name_tag + AND di.points = niagara.device_point_name + AND di.full_name = niagara.full_name + AND di.device_building_tag = niagara.device_building_tag + set di.is_show_history = 1"); + using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { - throw exception; - } - finally - { - conn.Close(); + await conn.ExecuteAsync(sb.ToString()); } } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + } } From 05f708224a493444d724d8f70d3f23c656aeb648 Mon Sep 17 00:00:00 2001 From: dev02 Date: Tue, 19 Sep 2023 19:14:51 +0800 Subject: [PATCH 4/4] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=B3=87=E6=96=99=E9=A1=AF=E7=A4=BA=E4=BA=BA=E6=B5=81=E8=A8=88?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/BuildMenuController.cs | 11 +++++++++++ Backend/Controllers/UserInfoController.cs | 19 ++++++++++++++++++- Backend/Models/UserInfo.cs | 1 + Backend/appsettings.Development.json | 4 ++-- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Backend/Controllers/BuildMenuController.cs b/Backend/Controllers/BuildMenuController.cs index b7c7d35..fd9fd32 100644 --- a/Backend/Controllers/BuildMenuController.cs +++ b/Backend/Controllers/BuildMenuController.cs @@ -389,6 +389,17 @@ namespace Backend.Controllers ORDER BY bm.priority, mv.system_priority ASC, sv.system_priority ASC, sv.created_at DESC ", new { building_tag = post.building_tag, MainList = post.MainList, main_system_type = main_system_type, sub_system_type = sub_system_type }); + if (buildMenuTables.Any()) + { + var data = buildMenuTables.Where(x => x.main_system_tag == "S" && x.sub_system_tag.Contains("CA")).ToList(); + foreach (var d in data) + { + if (d.sub_system_tag.Length == 3 && !(d.building_tag[0] == d.sub_system_tag[0])) + { + buildMenuTables.Remove(d); + } + } + } apiResult.Code = "0000"; apiResult.Data = buildMenuTables; } diff --git a/Backend/Controllers/UserInfoController.cs b/Backend/Controllers/UserInfoController.cs index c574434..47d6a6a 100644 --- a/Backend/Controllers/UserInfoController.cs +++ b/Backend/Controllers/UserInfoController.cs @@ -520,7 +520,7 @@ namespace Backend.Controllers { buildingGuid = $" AND ap.building_tag = '{post.SelectedBuild}'"; } - var sqlString = @$" SELECT ap.AuthCode, ap.MainName, ap.SubName FROM auth_page ap + var sqlString = @$" SELECT ap.AuthCode, ap.MainName, ap.SubName, ap.ShowView FROM auth_page ap WHERE ap.AuthType='{post.SelectedAuthType}' {buildingGuid} AND ap.AuthCode NOT IN ( @@ -531,6 +531,23 @@ namespace Backend.Controllers AND ap.AuthType='{post.SelectedAuthType}' )"; authPage = await backendRepository.GetAllAsync(sqlString); + + if (authPage.Any()) + { + var sub_system = await backendRepository.GetAllAsync($@"select * from variable where system_type = 'device_system_category_layer3' and system_value LIKE '%CA' + and LENGTH(system_value) = 3 and system_value != '{post.SelectedBuild[0]}CA'"); + if (sub_system.Any()) + { + foreach (var d in sub_system) + { + var ap = authPage.Where(x => x.ShowView.Equals(d.id.ToString())).FirstOrDefault(); + if (authPage != null) + { + authPage.Remove(ap); + } + } + } + } } apiResult.Code = "0000"; apiResult.Data = authPage; diff --git a/Backend/Models/UserInfo.cs b/Backend/Models/UserInfo.cs index 298f868..933aa81 100644 --- a/Backend/Models/UserInfo.cs +++ b/Backend/Models/UserInfo.cs @@ -121,6 +121,7 @@ namespace Backend.Models public string AuthCode { get; set; } public string MainName { get; set; } public string SubName { get; set; } + public string ShowView { get; set; } } public class PostSaveRoleAuth diff --git a/Backend/appsettings.Development.json b/Backend/appsettings.Development.json index 12cfb8b..2c7281e 100644 --- a/Backend/appsettings.Development.json +++ b/Backend/appsettings.Development.json @@ -22,9 +22,9 @@ //"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel //"Database": "iuaY0h0+TWkir44/eZLDqw==", //tpe_dome_office //"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut - //"Database": "+5RAiFLJVU+LRyDxF1K/pcLZaoZa4k/thZqF6xKoCag=", //dome_online_0821 + "Database": "+5RAiFLJVU+LRyDxF1K/pcLZaoZa4k/thZqF6xKoCag=", //dome_online_0821 //"Database": "2U+9jYGy0dCbMzLaguBXow==", //tpe_dome_mall - "Database": "FbHCCU4CapG9UryANXC1W+iMe403Bd82RnA7bCNVbL0=", //ibms_dome_cinema, + //"Database": "FbHCCU4CapG9UryANXC1W+iMe403Bd82RnA7bCNVbL0=", //ibms_dome_cinema, "Root": "SzdxEgaJJ7tcTCrUl2zKsA==", "Password": "FVAPxztxpY4gJJKQ/se4bQ==" },