From 4ec1f0f5bd438f5116c415426dc89923f09ce611 Mon Sep 17 00:00:00 2001 From: dev02 Date: Thu, 27 Apr 2023 14:43:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9niagara=20=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NiagaraDataSynchronizeRepository.cs | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index 18c1d86..cd34f0f 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -196,6 +196,27 @@ namespace Repository.BackendRepository.Implement sql = "delete from import_niagara_item where device_building_tag = '" + building + "'"; await conn.ExecuteAsync(sql); #endregion + ds = ds.GroupBy(x => new { + device_area_tag = x.device_area_tag, + device_building_tag = x.device_building_tag, + device_system_tag = x.device_system_tag, + device_name_tag = x.device_name_tag, + device_point_name = x.device_point_name, + full_name = x.full_name, + parent_path = x.parent_path, + isHistory = x.isHistory + }) + .Select(x => new ImpNiaItem + { + device_area_tag = x.Key.device_area_tag, + device_building_tag = x.Key.device_building_tag, + device_system_tag = x.Key.device_system_tag, + device_name_tag = x.Key.device_name_tag, + device_point_name = x.Key.device_point_name, + full_name = x.Key.full_name, + parent_path = x.Key.parent_path, + isHistory = x.Key.isHistory + }).ToList(); StringBuilder sb = new StringBuilder(); #region 放入import_niagara_item資料表 @@ -424,9 +445,9 @@ namespace Repository.BackendRepository.Implement 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 = (await conn.QueryAsync(sb.ToString())).ToList(); - + sb.Clear(); -# region 新增至device, is_link = 1 + # region 新增至device, is_link = 1 if (result.Count > 0) { foreach (var data in result) @@ -475,9 +496,11 @@ 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 + 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_link = case when device_point_name is null then 0 else 1 end , - d.is_show_history = case when device_point_name is null = 0 then 0 else 1 end"); + d.is_show_history = case when device_point_name is null then 0 else 1 end + where m.is_history = 1 + "); await conn.ExecuteAsync(sb.ToString()); } @@ -793,10 +816,10 @@ namespace Repository.BackendRepository.Implement { StringBuilder sb = new StringBuilder(); //先全部關閉 - sb.Append("update device_item set is_show_history=0;"); - sb.Append("update device_item set is_show_history = 1 " + - "WHERE(device_system_tag, device_name_tag, points) IN " + - "(select distinct device_system_tag, device_name_tag, device_point_name From import_niagara_item);"); + //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)