From e309b167a5a913f21109e7cf11492bfb3727e16d Mon Sep 17 00:00:00 2001 From: GiteaAdmin Date: Tue, 28 Mar 2023 13:48:30 +0800 Subject: [PATCH] =?UTF-8?q?niagara=20import=20=E7=85=A7=E6=98=8E=20node=20?= =?UTF-8?q?=20=E8=99=95=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/DeviceImportController.cs | 26 +- .../NiagaraDataSynchronizeController.cs | 17 +- .../Services/Implement/webRequestService.cs | 18 +- Backend/appsettings.Development.json | 4 +- Backend/wwwroot/forgeDemo.html | 4 +- .../3393c0f5-e6e6-4aaa-9641-6e1de001f1c0.svg | 1751 ++++++++ .../4fca9c23-c868-46c6-b976-8e1b339534a5.svg | 2008 +++++++++ .../85299a47-29db-4e98-9e2f-9f07f05791ca.svg | 3662 ----------------- .../ApiControllers/DeviceManageController.cs | 16 +- .../ApiControllers/UserController.cs | 4 +- FrontendWebApi/Models/Build.cs | 1 + .../NiagaraDataSynchronizeRepository.cs | 168 +- .../INiagaraDataSynchronizeRepository.cs | 10 +- 13 files changed, 3951 insertions(+), 3738 deletions(-) create mode 100644 Backend/wwwroot/upload/floor_map/3393c0f5-e6e6-4aaa-9641-6e1de001f1c0.svg create mode 100644 Backend/wwwroot/upload/floor_map/4fca9c23-c868-46c6-b976-8e1b339534a5.svg delete mode 100644 Backend/wwwroot/upload/floor_map/85299a47-29db-4e98-9e2f-9f07f05791ca.svg diff --git a/Backend/Controllers/DeviceImportController.cs b/Backend/Controllers/DeviceImportController.cs index 446185b..6cbfcb9 100644 --- a/Backend/Controllers/DeviceImportController.cs +++ b/Backend/Controllers/DeviceImportController.cs @@ -763,7 +763,12 @@ namespace Backend.Controllers if (post.Count > 0) { //清空device_node資料表 - await backendRepository.TruncateTable("device_node"); + //await backendRepository.TruncateTable("device_node"); + + //清空 3D 坐標 + await backendRepository.ExecuteSql("update device set device_coordinate_3d = '';"); + await backendRepository.ExecuteSql("update device_node set device_node_coordinate_3d = '';"); + //await backendRepository.UpdateOneByCustomTable(deviceForLight, "device", $@" device_guid = '{device_guid}'"); int node_priority = 1; @@ -780,12 +785,12 @@ namespace Backend.Controllers continue; } - if (device_guid.ToString() != device_guid_record) + if (device_guid.ToString() != device_guid_record && !string.IsNullOrEmpty(idfc.node.device_coordinate_3d)) // 如果跟前一筆不同,才需要 update device.forge_dbid 與坐標 { device_guid_record = device_guid.ToString(); node_priority = 1; Dictionary deviceForLight = new Dictionary(); - deviceForLight.Add("@device_coordinate_3d", idfc.device_coordinate_3d); + deviceForLight.Add("@device_coordinate_3d", idfc.node.device_coordinate_3d); deviceForLight.Add("@forge_dbid", idfc.forge_dbid); deviceForLight.Add("@room_name", idfc.room_name); deviceForLight.Add("@updated_at", DateTime.Now); @@ -793,18 +798,19 @@ namespace Backend.Controllers } Dictionary device = new Dictionary(); - device.Add("@device_node_guid", Guid.NewGuid()); - device.Add("@deleted", 0); - device.Add("@device_guid", device_guid); + // device.Add("@device_node_guid", Guid.NewGuid()); + //device.Add("@deleted", 0); + device.Add("@device_guid", device_guid); // 父層由 forge 提供 device.Add("@device_node_coordinate_3d", (idfc.node == null) ? idfc.device_coordinate_3d: idfc.node.device_coordinate_3d); device.Add("@forge_dbid", (idfc.node == null) ? idfc.forge_dbid: idfc.node.forge_dbid); - device.Add("@device_number", (idfc.node == null) ? idfc.device_number : idfc.node.device_number); + //device.Add("@device_number", (idfc.node == null) ? idfc.device_number : idfc.node.device_number); device.Add("@priority", node_priority); - device.Add("@created_by", myUserInfo.Userinfo_guid); - device.Add("@created_at", DateTime.Now); + //device.Add("@created_by", myUserInfo.Userinfo_guid); + //device.Add("@created_at", DateTime.Now); node_priority++; - await backendRepository.AddOneByCustomTableReturnId(device, "device_node", false); + await backendRepository.UpdateOneByCustomTable(device, "device_node", $@" device_number = '{idfc.node.device_number}'"); + // await backendRepository.AddOneByCustomTableReturnId(device, "device_node", false); } else { diff --git a/Backend/Controllers/NiagaraDataSynchronizeController.cs b/Backend/Controllers/NiagaraDataSynchronizeController.cs index 1933a14..9441523 100644 --- a/Backend/Controllers/NiagaraDataSynchronizeController.cs +++ b/Backend/Controllers/NiagaraDataSynchronizeController.cs @@ -79,10 +79,11 @@ namespace Backend.Controllers ApiResult apiResult = new ApiResult(); try - { + { var building = ds.FirstOrDefault().building; - await niagaraDataSynchronizeRepository.InsertNiagaraTagList(ds, building); - await niagaraDataSynchronizeRepository.DeviceComparison(); + string LightSwitchLevel = await niagaraDataSynchronizeRepository.getLightSwitchLevel(); //獲取照明開關 是否在 device or device_node + await niagaraDataSynchronizeRepository.InsertNiagaraTagList(ds, building); // 匯入 MySQL table: import_niagara_tag + await niagaraDataSynchronizeRepository.DeviceComparison(LightSwitchLevel); await niagaraDataSynchronizeRepository.CheckDiffFullNameAndCover(); await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName(); await niagaraDataSynchronizeRepository.InsertBuildingMenu(); @@ -144,11 +145,11 @@ namespace Backend.Controllers try { var building = ds.FirstOrDefault().device_building_tag; - await niagaraDataSynchronizeRepository.InsertItemFromNiagara(ds, building); - await niagaraDataSynchronizeRepository.DeviceItemComparison(); - await niagaraDataSynchronizeRepository.CheckItemDiffFullNameAndCover(); - await niagaraDataSynchronizeRepository.ItemCheckFullNameEmptyReplaceByDeviceName(); - await niagaraDataSynchronizeRepository.CheckItemIsShowHistory(); + await niagaraDataSynchronizeRepository.InsertItemFromNiagara(ds, building); // insert 暫存table import_niagara_item + await niagaraDataSynchronizeRepository.DeviceItemComparison(); //insert device_item + await niagaraDataSynchronizeRepository.CheckItemDiffFullNameAndCover(); // update device_item.fullname + await niagaraDataSynchronizeRepository.ItemCheckFullNameEmptyReplaceByDeviceName(); // 檢查device_item內FullName為空的值,以points取代 + await niagaraDataSynchronizeRepository.CheckItemIsShowHistory(); result = true; apiResult.Code = "0000"; diff --git a/Backend/Services/Implement/webRequestService.cs b/Backend/Services/Implement/webRequestService.cs index 4cbf093..c4f3b0e 100644 --- a/Backend/Services/Implement/webRequestService.cs +++ b/Backend/Services/Implement/webRequestService.cs @@ -105,6 +105,13 @@ namespace Backend.Services.Implement return result; } + /// + /// 獲取 niagara history 中的點位 + /// + /// + /// + /// + /// public List obixHisQuery(string bqlUrlString, string urlString, string slot) { String username = "obixUser"; @@ -202,7 +209,16 @@ namespace Backend.Services.Implement } else if (tagName.Split('_').Length == 6) { //巨蛋 tag 5 段版本 - + ImpNiaItem row = new ImpNiaItem(); + row.device_building_tag = tagName.Split('_')[0]; + row.device_system_tag = tagName.Split('_')[1]; + //row.device_floor_tag = tagName.Split('_')[4]; + row.device_name_tag = tagName.Split('_')[3]; + row.device_point_name = tagName.Split('_')[8]; + row.parent_path = stationName; + + //full_name 其實是點位名稱 point_name + row.full_name = conPoint.Where(x => x.name == tagName).Select(x => x.displayName).FirstOrDefault(); } } } diff --git a/Backend/appsettings.Development.json b/Backend/appsettings.Development.json index 24e445c..d879b34 100644 --- a/Backend/appsettings.Development.json +++ b/Backend/appsettings.Development.json @@ -16,8 +16,8 @@ "MySqlDBConfig": { "Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201 "Port": "js2LutKe+rdjzdxMPQUrvQ==", - "Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 - //"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp + //"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 + "Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp "Root": "SzdxEgaJJ7tcTCrUl2zKsA==", "Password": "FVAPxztxpY4gJJKQ/se4bQ==" } diff --git a/Backend/wwwroot/forgeDemo.html b/Backend/wwwroot/forgeDemo.html index acb4db5..d4d0cd9 100644 --- a/Backend/wwwroot/forgeDemo.html +++ b/Backend/wwwroot/forgeDemo.html @@ -276,9 +276,9 @@ //launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dmVnb29nemNhdmNia2l0aHl2bHJzdnJjdGg2dHR3eWgtMjAyMzAyX2libXMvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU2JUE4JUExJUU1JUJDJThGK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8lRTklOUIlQkIlRTYlQTIlQUYlRTclQjQlQjAlRTclQUYlODAlRTclODklODhfMDIyNC5ud2Q") // 0303 - launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dmVnb29nemNhdmNia2l0aHl2bHJzdnJjdGg2dHR3eWgtMjAyMzAyX2libXMvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU2JUE4JUExJUU1JUJDJThGK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8lRTklOUIlQkIlRTYlQTIlQUYlRTclQjQlQjAlRTclQUYlODAlRTclODklODhfMDMwMy5ud2Q") + //launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dmVnb29nemNhdmNia2l0aHl2bHJzdnJjdGg2dHR3eWgtMjAyMzAyX2libXMvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU2JUE4JUExJUU1JUJDJThGK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8lRTklOUIlQkIlRTYlQTIlQUYlRTclQjQlQjAlRTclQUYlODAlRTclODklODhfMDMwMy5ud2Q") // 0221 WSP - //launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dmVnb29nemNhdmNia2l0aHl2bHJzdnJjdGg2dHR3eWgtMjAyMzAyX2libXMvQmFucWlhbyUyMFRhaXBlaSUyME1haW4lMjBPZmZpY2UtQUxMXzAyMjEubndk") + launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dmVnb29nemNhdmNia2l0aHl2bHJzdnJjdGg2dHR3eWgtMjAyMzAyX2libXMvQmFucWlhbyUyMFRhaXBlaSUyME1haW4lMjBPZmZpY2UtQUxMXzAyMjEubndk") }); function move1Floor() { diff --git a/Backend/wwwroot/upload/floor_map/3393c0f5-e6e6-4aaa-9641-6e1de001f1c0.svg b/Backend/wwwroot/upload/floor_map/3393c0f5-e6e6-4aaa-9641-6e1de001f1c0.svg new file mode 100644 index 0000000..ae90309 --- /dev/null +++ b/Backend/wwwroot/upload/floor_map/3393c0f5-e6e6-4aaa-9641-6e1de001f1c0.svg @@ -0,0 +1,1751 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Backend/wwwroot/upload/floor_map/4fca9c23-c868-46c6-b976-8e1b339534a5.svg b/Backend/wwwroot/upload/floor_map/4fca9c23-c868-46c6-b976-8e1b339534a5.svg new file mode 100644 index 0000000..f419c47 --- /dev/null +++ b/Backend/wwwroot/upload/floor_map/4fca9c23-c868-46c6-b976-8e1b339534a5.svg @@ -0,0 +1,2008 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Backend/wwwroot/upload/floor_map/85299a47-29db-4e98-9e2f-9f07f05791ca.svg b/Backend/wwwroot/upload/floor_map/85299a47-29db-4e98-9e2f-9f07f05791ca.svg deleted file mode 100644 index 4d6ccdd..0000000 --- a/Backend/wwwroot/upload/floor_map/85299a47-29db-4e98-9e2f-9f07f05791ca.svg +++ /dev/null @@ -1,3662 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/FrontendWebApi/ApiControllers/DeviceManageController.cs b/FrontendWebApi/ApiControllers/DeviceManageController.cs index e6d41fc..9ea8cdb 100644 --- a/FrontendWebApi/ApiControllers/DeviceManageController.cs +++ b/FrontendWebApi/ApiControllers/DeviceManageController.cs @@ -263,7 +263,7 @@ namespace FrontendWebApi.ApiControllers ApiResult> apiResult = new ApiResult>(); //是否顯示DeviceNode - string sqlStringqueryModuleLightNodeDisplay = $"SELECT system_value FROM variable WHERE system_type = 'module' AND system_key = 'displaynode'"; + string sqlStringqueryModuleLightNodeDisplay = $"SELECT system_value FROM variable WHERE system_type = 'module_light_switch' AND system_key = 'displaynode'"; string displayNode = await backendRepository.GetOneAsync(sqlStringqueryModuleLightNodeDisplay); if (string.IsNullOrEmpty(fd.sub_system_tag)) { @@ -310,6 +310,8 @@ namespace FrontendWebApi.ApiControllers dn.device_guid, dn.full_name AS Device_node_full_name, dn.device_node_coordinate, + dn.device_node_coordinate_3d, + dn.device_number, dn.priority, dn.forge_dbid FROM device_node dn @@ -768,12 +770,12 @@ namespace FrontendWebApi.ApiControllers dn.full_name AS Device_node_full_name, dn.device_node_coordinate, dn.device_node_coordinate_3d, + dn.device_number, dn.priority, dn.forge_dbid FROM device_node dn WHERE dn.deleted = 0 AND dn.device_guid = @device_guid ORDER BY dn.priority ASC"; - d.Device_nodes = await backendRepository.GetAllAsync(sql_node, new { device_guid = d.device_guid }); } @@ -927,10 +929,12 @@ namespace FrontendWebApi.ApiControllers try { - var sqlString = $@" SELECT * FROM floor WHERE - priority = (SELECT MIN(priority) FROM floor WHERE priority > (SELECT priority FROM floor WHERE floor_guid = @floor_guid) - AND building_tag = (SELECT building_tag FROM floor WHERE floor_guid = @floor_guid)) - AND building_tag = (SELECT building_tag FROM floor WHERE floor_guid = @floor_guid)"; + //var sqlString = $@" SELECT * FROM floor WHERE + // priority = (SELECT MIN(priority) FROM floor WHERE priority > (SELECT priority FROM floor WHERE floor_guid = @floor_guid) + // AND building_tag = (SELECT building_tag FROM floor WHERE floor_guid = @floor_guid)) + // AND building_tag = (SELECT building_tag FROM floor WHERE floor_guid = @floor_guid)"; + + var sqlString = $@" SELECT * FROM floor WHERE floor_guid = @floor_guid;"; var param = new { @floor_guid = f.floor_guid }; var fr = await backendRepository.GetOneAsync(sqlString, param); diff --git a/FrontendWebApi/ApiControllers/UserController.cs b/FrontendWebApi/ApiControllers/UserController.cs index 859faea..16b3b60 100644 --- a/FrontendWebApi/ApiControllers/UserController.cs +++ b/FrontendWebApi/ApiControllers/UserController.cs @@ -863,6 +863,7 @@ namespace FrontendWebApi.ApiControllers try { + // User 權限可見的系統 var dbsub = await frontendRepository.GetAllAsync( @$"select distinct v1.system_key main_name, v1.system_value main_system_tag, v2.system_key sub_name, v2.system_value sub_system_tag, v1.system_priority, v2.system_priority, d.device_number, d.full_name as device_full_name, d.device_serial_tag, b.AuthCode @@ -871,9 +872,10 @@ namespace FrontendWebApi.ApiControllers join userinfo c on c.role_guid = a.role_guid join variable v2 on b.ShowView = v2.id and v2.system_type = @sub_system_type join variable v1 on v1.id = v2.system_parent_id and v1.system_type = @main_system_type - join device d on v1.system_value = d.device_system_tag and v2.system_value = d.device_name_tag and d.deleted = 0 + left join device d on v1.system_value = d.device_system_tag and v2.system_value = d.device_name_tag and d.deleted = 0 where c.account = @account order by v1.system_priority, v2.system_priority", new { @account = myUser.account, @sub_system_type = sub_system_type, @main_system_type = main_system_type }); + // User var dbbuilding = await frontendRepository.GetAllAsync( @$"select distinct d.building_guid,d.full_name,d.priority from role_auth a join auth_page b on a.AuthCode = b.AuthCode diff --git a/FrontendWebApi/Models/Build.cs b/FrontendWebApi/Models/Build.cs index d642125..3e87117 100644 --- a/FrontendWebApi/Models/Build.cs +++ b/FrontendWebApi/Models/Build.cs @@ -207,6 +207,7 @@ namespace FrontendWebApi.Models public string Device_node_full_name { get; set; } public string Device_node_coordinate { get; set; } public string Device_node_coordinate_3D { get; set; } + public string Device_number { get; set; } public int Priority { get; set; } public int forge_dbid { get; set; } } diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index a95c456..58e35b3 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -24,7 +24,7 @@ namespace Repository.BackendRepository.Implement /// 更新import_niagara_tag資料表 /// /// - /// + /// /// public async Task InsertNiagaraTagList(List ds, string building) { @@ -64,30 +64,31 @@ namespace Repository.BackendRepository.Implement { tag_name = x.Key.tag_name2, displayName = x.Key.displayName2 - }); - + }); + StringBuilder sb = new StringBuilder(); foreach (var row in ds2) { if (string.IsNullOrEmpty(row.tag_name)) continue; - string[] arrTag = row.tag_name.Split('_'); - + string[] arrTag = row.tag_name.Split('_'); + + if (arrTag.Length == 8) { sb.Append($@" insert into import_niagara_tag(niagara_tags, device_area_tag, device_building_tag, device_system_tag, device_name_tag, device_floor_tag, device_master_tag, device_last_name_tag, device_serial_tag, device_full_name, atDateTime) values('" + - row.tag_name + "', '" + - arrTag[0] + "', '" + - arrTag[1] + "', '" + - arrTag[2] + "', '" + - arrTag[3] + "', '" + - arrTag[4] + "', '" + - arrTag[5] + "', '" + - arrTag[6] + "', '" + - arrTag[7] + "', '" + - row.displayName + "', " + - "now());"); + row.tag_name + "', '" + //niagara_tags + arrTag[0] + "', '" + //device_area_tag + arrTag[1] + "', '" + //device_building_tag + arrTag[2] + "', '" + //device_system_tag + arrTag[3] + "', '" + //device_name_tag + arrTag[4] + "', '" + //device_floor_tag + arrTag[5] + "', '" + //device_master_tag + arrTag[6] + "', '" + //device_last_name_tag + arrTag[7] + "', '" + //device_serial_tag + row.displayName + "', " + //device_full_name + "now());"); //atDateTime } } if (sb.Length > 0) @@ -107,12 +108,29 @@ namespace Repository.BackendRepository.Implement } } } + + /// + /// 獲取照明開關 是否在 device_node 層 + /// + /// + public async Task getLightSwitchLevel() + { + using (IDbConnection conn = GetDbConnection()) + { + conn.Open(); + var sql = "select system_value from variable where system_type = 'module_light_switch' "; + var module_light_switch = conn.QueryAsync(sql).Result.FirstOrDefault(); + conn.Close(); + return module_light_switch; + } + } /// /// 更新import_niagara_tag資料表 /// /// /// + /// public async Task InsertItemFromNiagara(List ds, string building) { @@ -179,7 +197,7 @@ namespace Repository.BackendRepository.Implement /// 比對 device /// /// - public async Task DeviceComparison() + public async Task DeviceComparison(string LightSwitchLevel) { using (IDbConnection conn = GetDbConnection()) { @@ -199,6 +217,7 @@ namespace Repository.BackendRepository.Implement result = (await conn.QueryAsync(sb.ToString())).ToList(); sb.Clear(); + #region device, device_kind 新增 //新增至device, is_link = 1 if (result.Count > 0) { @@ -216,21 +235,29 @@ namespace Repository.BackendRepository.Implement foreach (var data in result) { - 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() );"); + //開關控制在個別燈具(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() );"); + } } foreach (var data in result2) @@ -251,20 +278,71 @@ namespace Repository.BackendRepository.Implement if (sb.Length > 0) { - await conn.ExecuteAsync(sb.ToString()); - await conn.ExecuteAsync(sb2.ToString()); + await conn.ExecuteAsync(sb.ToString()); + await conn.ExecuteAsync(sb2.ToString()); + sb.Clear(); sb2.Clear(); } } + #endregion - //device有,niagara沒有,is_link 更新成 0 - sb.Append($@" SET SQL_SAFE_UPDATES = 0; + #region device_node 新增 + sb.Append($@" SELECT m.* FROM import_niagara_tag m + LEFT JOIN device_node d ON m.niagara_tags = d.device_number + WHERE d.device_number IS NULL"); + result = (await conn.QueryAsync(sb.ToString())).ToList(); + sb.Clear(); + + if (result.Count > 0) + { + 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 + }); + + 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 + 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());"); + } + } + + if (sb.Length > 0) + { + await conn.ExecuteAsync(sb.ToString()); + sb.Clear(); + } + } + #endregion + + //device有,niagara沒有,is_link 更新成 0 + sb.Append($@" SET SQL_SAFE_UPDATES = 0; UPDATE device d LEFT JOIN import_niagara_tag m ON d.device_number = m.niagara_tags SET d.is_link = 0 - WHERE m.niagara_tags IS NULL"); + WHERE m.niagara_tags IS NULL;"); await conn.ExecuteAsync(sb.ToString()); + // device_node 有, niagara沒有, is_link 更新成 0 + sb.Append($@" SET SQL_SAFE_UPDATES = 0; + UPDATE device_node d LEFT JOIN import_niagara_tag m ON d.device_number = m.niagara_tags + SET d.is_link = 0 + WHERE m.niagara_tags IS NULL;"); + await conn.ExecuteAsync(sb.ToString()); } catch (Exception exception) { @@ -628,13 +706,13 @@ 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 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) @@ -650,7 +728,7 @@ namespace Repository.BackendRepository.Implement } /// - /// 先將device_ite的is_show_history全部關掉 + /// 先將device_item 的is_show_history全部關掉 /// 根據niagara輸入資料來決定要開哪些點 /// /// diff --git a/Repository/BackendRepository/Interface/INiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Interface/INiagaraDataSynchronizeRepository.cs index e9bdf44..c88f28d 100644 --- a/Repository/BackendRepository/Interface/INiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Interface/INiagaraDataSynchronizeRepository.cs @@ -13,6 +13,14 @@ namespace Repository.BackendRepository.Interface /// /// Task InsertNiagaraTagList(List ds, string building); + + + /// + /// 獲取照明開關 是否在 device_node 層 + /// + /// + Task getLightSwitchLevel(); + /// /// 同步N4至資料表 import_niagara_item /// @@ -24,7 +32,7 @@ namespace Repository.BackendRepository.Interface /// 比對 device /// /// - Task DeviceComparison(); + Task DeviceComparison(string LightSwitchLevel); /// ///檢查Device與import_niagara_tag 的Full_Name是否相同 不同則Full_Name從import_niagara_tag 覆蓋至device ///