From d02642ae271b76bfbbf5b6bbbaf5174583b1e477 Mon Sep 17 00:00:00 2001 From: dev02 Date: Tue, 19 Sep 2023 10:18:43 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9device?= =?UTF-8?q?=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(); + } + } }