From fb1d03c994db2da9d6c81e77db151e9f9ae4c182 Mon Sep 17 00:00:00 2001 From: dev02 Date: Fri, 8 Sep 2023 18:48:13 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9device?= =?UTF-8?q?=5Fitem=E7=8D=B2=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implement/webRequestService.cs | 22 +++---- .../NiagaraDataSynchronizeRepository.cs | 66 ++++++++++++------- 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/Backend/Services/Implement/webRequestService.cs b/Backend/Services/Implement/webRequestService.cs index b37b1cb..68bbe28 100644 --- a/Backend/Services/Implement/webRequestService.cs +++ b/Backend/Services/Implement/webRequestService.cs @@ -286,16 +286,16 @@ namespace Backend.Services.Implement isHistory = n.isHistory }); } - else if (n.name.Split('/').Length == 11) //Arena_D2_CWB_L110_CAP_D2_CWB_L110_CAP_MET1_ER + else if (n.name.Split('/').Length == 7) // Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/Summery { - if (n.name.Split('/')[6] == "S" || n.name.Split('/')[6] == "CWB") //for security system and CWB system + if (n.name.Split('/')[3] == "S" || n.name.Split('/')[3] == "CWB") //for security system and CWB system { result.Add(new ImpNiaItem { - device_building_tag = n.name.Split('/')[5], - device_system_tag = n.name.Split('/')[6], - device_floor_tag = n.name.Split('/')[7], - device_name_tag = n.name.Split('/')[8], - device_point_name = n.name.Split('/')[10], + device_building_tag = n.name.Split('/')[1], + device_system_tag = n.name.Split('/')[2], + device_floor_tag = n.name.Split('/')[3], + device_name_tag = n.name.Split('/')[4], + device_point_name = n.name.Split('/')[6], full_name = n.displayName, parent_path = oneStationName, isHistory = n.isHistory @@ -305,11 +305,11 @@ namespace Backend.Services.Implement { result.Add(new ImpNiaItem { - device_building_tag = n.name.Split('/')[5], + device_building_tag = n.name.Split('/')[1], //device_system_tag = n.name.Split('/')[1], - device_floor_tag = n.name.Split('/')[7], - device_name_tag = n.name.Split('/')[6], - device_point_name = n.name.Split('/')[10], + device_floor_tag = n.name.Split('/')[3], + device_name_tag = n.name.Split('/')[2], + device_point_name = n.name.Split('/')[6], full_name = n.displayName, parent_path = oneStationName, isHistory = n.isHistory diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index da787f3..98942f8 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -565,28 +565,39 @@ namespace Repository.BackendRepository.Implement //本次有匯入的 isLink 改為 1, 沒有的 isLink = 0 sb.Append($@" SET SQL_SAFE_UPDATES = 0; - update - device_item d - LEFT JOIN import_niagara_item m - 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 - and d.full_name = m.full_name - SET d.is_link = case when device_point_name is null then 0 else 1 end; - - update - device_item d - LEFT JOIN import_niagara_item m + UPDATE device_item d + LEFT JOIN ( + SELECT device_system_tag, device_name_tag, device_point_name, full_name + FROM import_niagara_item + LIMIT 100000 -- Specify your desired limit here + ) m 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 - and d.full_name = m.full_name - and d.is_show_history = m.is_history - SET d.is_show_history = case when device_point_name is null then 0 else 1 end - where (m.is_history = 1 or d.is_show_history); + AND d.device_name_tag = m.device_name_tag + AND d.points = m.device_point_name + AND d.full_name = m.full_name + SET d.is_link = CASE WHEN m.device_point_name IS NULL THEN 0 ELSE 1 END; + "); await conn.ExecuteAsync(sb.ToString()); + + sb.Clear(); + sb.Append($@" SET SQL_SAFE_UPDATES = 0; + UPDATE device_item d + LEFT JOIN ( + SELECT m.device_system_tag, m.device_name_tag, m.device_point_name, m.full_name + FROM import_niagara_item m + WHERE (m.is_history = 1) + LIMIT 100000 -- Specify your desired limit here + ) AS subquery + ON d.device_system_tag = subquery.device_system_tag + AND d.device_name_tag = subquery.device_name_tag + AND d.points = subquery.device_point_name + AND d.full_name = subquery.full_name + SET d.is_show_history = CASE WHEN subquery.device_point_name IS NULL THEN 0 ELSE 1 END + WHERE (d.is_show_history);"); + + await conn.ExecuteAsync(sb.ToString()); } catch (Exception exception) { @@ -876,13 +887,18 @@ namespace Repository.BackendRepository.Implement 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;"); + sb.Append($@"UPDATE device_item d + INNER JOIN ( + SELECT m.device_system_tag, m.device_name_tag, m.device_point_name, m.full_name + FROM import_niagara_item m + join device_item d + LIMIT 100000 -- Specify your desired limit here + ) AS subquery + ON d.device_system_tag = subquery.device_system_tag + AND d.device_name_tag = subquery.device_name_tag + AND d.points = subquery.device_point_name + SET d.full_name = subquery.full_name + WHERE d.full_name <> subquery.full_name"); await conn.ExecuteAsync(sb.ToString()); } catch (Exception exception)