From da2c265dd01cf137bbfb4346ada7418f50d0d14a Mon Sep 17 00:00:00 2001 From: "LAPTOP-6U09CO6D\\User" Date: Wed, 8 Feb 2023 15:17:03 +0800 Subject: [PATCH] =?UTF-8?q?feature:=E6=AF=8F=E6=AC=A1=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=99=82device=20.deviceItem=E5=88=A4=E6=96=B7=E8=88=87?= =?UTF-8?q?=E4=BE=86=E6=BA=90niagara=E7=9A=84full=5Fname=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E5=89=87=E8=A6=86=E8=93=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NiagaraDataSynchronizeController.cs | 2 + .../NiagaraDataSynchronizeRepository.cs | 75 +++++++++++++++++++ .../INiagaraDataSynchronizeRepository.cs | 12 +++ 3 files changed, 89 insertions(+) diff --git a/Backend/Controllers/NiagaraDataSynchronizeController.cs b/Backend/Controllers/NiagaraDataSynchronizeController.cs index 77e2cdb..b1f5206 100644 --- a/Backend/Controllers/NiagaraDataSynchronizeController.cs +++ b/Backend/Controllers/NiagaraDataSynchronizeController.cs @@ -82,6 +82,7 @@ namespace Backend.Controllers var building = ds.FirstOrDefault().building; await niagaraDataSynchronizeRepository.InsertNiagaraTagList(ds, building); await niagaraDataSynchronizeRepository.DeviceComparison(); + await niagaraDataSynchronizeRepository.CheckDiffFullNameAndCover(); await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName(); await niagaraDataSynchronizeRepository.InsertBuildingMenu(); await niagaraDataSynchronizeRepository.InsertSubSystemFloor(); @@ -146,6 +147,7 @@ namespace Backend.Controllers var building = ds.FirstOrDefault().device_building_tag; await niagaraDataSynchronizeRepository.InsertItemFromNiagara(ds, building); await niagaraDataSynchronizeRepository.DeviceItemComparison(); + await niagaraDataSynchronizeRepository.CheckItemDiffFullNameAndCover(); await niagaraDataSynchronizeRepository.ItemCheckFullNameEmptyReplaceByDeviceName(); result = true; diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index 116ec37..dddc9da 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -512,6 +512,8 @@ namespace Repository.BackendRepository.Implement /// public async Task CheckFullNameEmptyReplaceByDeviceName() { + + using (IDbConnection conn = GetDbConnection()) { conn.Open(); @@ -542,6 +544,8 @@ namespace Repository.BackendRepository.Implement /// public async Task ItemCheckFullNameEmptyReplaceByDeviceName() { + + //檢查是否有空值 using (IDbConnection conn = GetDbConnection()) { conn.Open(); @@ -565,5 +569,76 @@ namespace Repository.BackendRepository.Implement } } + + /// + /// 檢查device的full_name與niagara device_full_name不同者 覆蓋 + /// + /// + public async Task CheckDiffFullNameAndCover() + { + using (IDbConnection conn = GetDbConnection()) + { + conn.Open(); + using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) + { + try + { + StringBuilder sb = new StringBuilder(); + sb.Append("update device d inner JOIN import_niagara_tag m ON m.niagara_tags = d.device_number " + + "set d.full_name=m.device_full_name " + + "where m.device_full_name<>d.full_name;"); + await conn.ExecuteAsync(sb.ToString()); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + } + + } + } + + + /// + /// 比對 device_item full_name 與 import_niagara_item full_name是否相同 + /// 不同則覆蓋 + /// + /// + public async Task CheckItemDiffFullNameAndCover() + { + //檢查 + using (IDbConnection conn = GetDbConnection()) + { + conn.Open(); + using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) + { + try + { + StringBuilder sb = new StringBuilder(); + sb.Append("update device_item d " + + "inner JOIN import_niagara_item m 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 " + + "set d.full_name=m.full_name " + + "where d.full_name<>m.full_name;"); + await conn.ExecuteAsync(sb.ToString()); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + } + + } + } } } diff --git a/Repository/BackendRepository/Interface/INiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Interface/INiagaraDataSynchronizeRepository.cs index f079975..5629b9c 100644 --- a/Repository/BackendRepository/Interface/INiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Interface/INiagaraDataSynchronizeRepository.cs @@ -25,6 +25,12 @@ namespace Repository.BackendRepository.Interface /// /// Task DeviceComparison(); + /// + ///檢查Device與import_niagara_tag 的Full_Name是否相同 不同則Full_Name從import_niagara_tag 覆蓋至device + /// + /// + Task CheckDiffFullNameAndCover(); + /// /// 比對 device的FullName,若為空則以DeviceName取代 @@ -36,6 +42,12 @@ namespace Repository.BackendRepository.Interface /// /// Task DeviceItemComparison(); + /// + /// 比對 device_item full_name 與 import_niagara_item是否相同 + /// 不同則覆蓋 + /// + /// + Task CheckItemDiffFullNameAndCover(); Task ItemCheckFullNameEmptyReplaceByDeviceName(); ///