From 4d38c0d73d06fd3baa1c7f3da630c9f39c0e61dc Mon Sep 17 00:00:00 2001 From: dev02 Date: Sat, 31 Dec 2022 16:49:47 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=8C=E5=8F=B0?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E8=A8=AD=E5=82=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/MybaseController.cs | 3 +- .../NiagaraDataSynchronizeController.cs | 6 ++- .../Views/NiagaraDataSynchronize/Index.cshtml | 37 ++++++++++++------- .../NiagaraDataSynchronizeRepository.cs | 24 +++++++----- Repository/Models/BackgroundServiceTask.cs | 7 ++++ 5 files changed, 51 insertions(+), 26 deletions(-) diff --git a/Backend/Controllers/MybaseController.cs b/Backend/Controllers/MybaseController.cs index 4cb7fb4..6db4590 100644 --- a/Backend/Controllers/MybaseController.cs +++ b/Backend/Controllers/MybaseController.cs @@ -95,7 +95,8 @@ namespace Backend.Controllers { "@created_by", myUserInfo.Userinfo_guid} }; - backendRepository.InsertOperatorLog(operatorLog, "operation_back_log"); + if (actionName != "CompareData" && controllerName != "NiagaraDataSynchronize") //skip the log + backendRepository.InsertOperatorLog(operatorLog, "operation_back_log"); //operatorLogRepository.Add(operatorLog, properties); #endregion diff --git a/Backend/Controllers/NiagaraDataSynchronizeController.cs b/Backend/Controllers/NiagaraDataSynchronizeController.cs index 8209ed9..692f525 100644 --- a/Backend/Controllers/NiagaraDataSynchronizeController.cs +++ b/Backend/Controllers/NiagaraDataSynchronizeController.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using Backend.Services; using Backend.Services.Implement; using Repository.Models; +using System.Linq; namespace Backend.Controllers { @@ -69,13 +70,14 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task> CompareData(List ds, string building) + public async Task> CompareData([FromBody] List ds) { bool result = false; + ApiResult apiResult = new ApiResult(); try { - + var building = ds.FirstOrDefault().building; await niagaraDataSynchronizeRepository.InsertNiagaraTagList(ds, building); await niagaraDataSynchronizeRepository.InsertItemFromNiagara(ds, building); await niagaraDataSynchronizeRepository.DeviceComparison(); diff --git a/Backend/Views/NiagaraDataSynchronize/Index.cshtml b/Backend/Views/NiagaraDataSynchronize/Index.cshtml index ac25e57..75ccf70 100644 --- a/Backend/Views/NiagaraDataSynchronize/Index.cshtml +++ b/Backend/Views/NiagaraDataSynchronize/Index.cshtml @@ -144,20 +144,29 @@ //比對資料,有差異的話,再同步到device等資料表 var url_synchronize_data = "/NiagaraDataSynchronize/CompareData/"; - var send_data = { - ds: ds, - building: building - } - $.post(url_synchronize_data, send_data, function (rel) { - if (rel.code != "0000") { - toast_error(rel.msg); - document.getElementById('loadDataText').innerText = "比對資料出錯了!"; - return; - } - var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); - var dateTime = date + ' ' + time; - document.getElementById('loadDataText').innerText = "比對完成 \n" + dateTime; - }, 'json'); + $.each(ds, function (i, v) { + v.building = building; + }) + + $.ajax({ + method: "POST", + url: url_synchronize_data, + data: JSON.stringify(ds), + cache: false, + async: false, + contentType: "application/json; charset=UTF-8", + dataType: 'json', + success: function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + document.getElementById('loadDataText').innerText = "比對資料出錯了!"; + return; + } + var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); + var dateTime = date + ' ' + time; + document.getElementById('loadDataText').innerText = "比對完成 \n" + dateTime; + }, + }); } else { document.getElementById('loadDataText').innerText = "查無資料 無法比對!"; diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index 18e2e45..9522f55 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using System.Transactions; using Repository.Models; - namespace Repository.BackendRepository.Implement { public class NiagaraDataSynchronizeRepository : BackendRepository, INiagaraDataSynchronizeRepository @@ -389,15 +388,22 @@ namespace Repository.BackendRepository.Implement { foreach (var data in result) { + StringBuilder sqlString = new StringBuilder(); + sqlString.Append(@"select * from building_menu where building_tag = '" + data.device_building_tag + "' and main_system_tag = '" + data.device_system_tag + "' and sub_system_tag = '" + data.device_name_tag + "'"); + var bm = (await conn.QueryAsync(sqlString.ToString())).ToList(); + #region insert building_menu - sb.Append(@"insert building_menu(building_tag, main_system_tag, sub_system_tag, device_building_tag, device_system_tag, - is_link, created_by, created_at, updated_by, updated_at) - VALUES ('" + data.device_building_tag + "', '" + - data.device_system_tag + "', '" + - data.device_name_tag + "', '" + - data.device_building_tag + "', '" + - data.device_system_tag + "', " + - "1, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now(), 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now() );"); + if (bm.Count == 0) + { + sb.Append(@"insert building_menu(building_tag, main_system_tag, sub_system_tag, device_building_tag, device_system_tag, + is_link, created_by, created_at, updated_by, updated_at) + VALUES ('" + data.device_building_tag + "', '" + + data.device_system_tag + "', '" + + data.device_name_tag + "', '" + + data.device_building_tag + "', '" + + data.device_system_tag + "', " + + "1, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now(), 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now() );"); + } #endregion } if (sb.Length > 0) diff --git a/Repository/Models/BackgroundServiceTask.cs b/Repository/Models/BackgroundServiceTask.cs index fafd4d4..d81f8d6 100644 --- a/Repository/Models/BackgroundServiceTask.cs +++ b/Repository/Models/BackgroundServiceTask.cs @@ -47,6 +47,7 @@ namespace Repository.Models public string value { get; set; } public string tag_name { get; set; } public string point_name { get; set; } + public string building { get; set; } } public class Device_item8 @@ -93,4 +94,10 @@ namespace Repository.Models public string device_point_name { get; set; } } + public class building_menu + { + public string building_tag { get; set; } + public string device_system_tag { get; set; } + public string device_name_tag { get; set; } + } } From 4d29bb220c7ae3ba7ea36b52f3ec6afba21e7952 Mon Sep 17 00:00:00 2001 From: wanli Date: Sat, 31 Dec 2022 16:51:31 +0800 Subject: [PATCH 2/4] =?UTF-8?q?[App]=20N4=E5=90=8C=E6=AD=A5=EF=BC=8Cdevice?= =?UTF-8?q?=5Fkind=E5=8A=A0=E4=B8=8Agroup=20by?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- z01_WinAPP/App.config | 2 +- z01_WinAPP/Service/procCompare.cs | 77 ++++++++++++++++++++----------- z01_WinAPP/fmCheckTagName.cs | 6 +-- 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/z01_WinAPP/App.config b/z01_WinAPP/App.config index 499124a..0d579f1 100644 --- a/z01_WinAPP/App.config +++ b/z01_WinAPP/App.config @@ -9,7 +9,7 @@ connectionString="Data Source=192.168.0.201:33306;Initial Catalog=bims_mitsubishi;Persist Security Info=True;User ID=bims;Password=mjmdev_BIMS2022" providerName="MySql.Data.MySqlClient" />--> - + \ No newline at end of file diff --git a/z01_WinAPP/Service/procCompare.cs b/z01_WinAPP/Service/procCompare.cs index d61efd2..59f9843 100644 --- a/z01_WinAPP/Service/procCompare.cs +++ b/z01_WinAPP/Service/procCompare.cs @@ -81,19 +81,22 @@ namespace tpDomeWinAPP.Service { if (string.IsNullOrEmpty(row.tag_name)) continue; string[] arrTag = row.tag_name.Split('_'); + if (arrTag.Length == 8) + { - sb.Append($@" insert import_niagara_tag(niagara_tags, device_area_tag, device_building_tag, device_system_tag, + sb.Append($@" insert 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, atDateTime) values('" + - row.tag_name + "', '" + - arrTag[0] + "', '" + - arrTag[1] + "', '" + - arrTag[2] + "', '" + - arrTag[3] + "', '" + - arrTag[4] + "', '" + - arrTag[5] + "', '" + - arrTag[6] + "', '" + - arrTag[7] + "', " + - "now());"); + row.tag_name + "', '" + + arrTag[0] + "', '" + + arrTag[1] + "', '" + + arrTag[2] + "', '" + + arrTag[3] + "', '" + + arrTag[4] + "', '" + + arrTag[5] + "', '" + + arrTag[6] + "', '" + + arrTag[7] + "', " + + "now());"); + } } try { @@ -137,21 +140,23 @@ namespace tpDomeWinAPP.Service { if (string.IsNullOrEmpty(row.tag_name)) continue; string[] arrTag = row.tag_name.Split('_'); - - #region for item - device_item8 row_item = new device_item8(); - row_item.tag_name = row.tag_name; - row_item.device_area_tag = arrTag[0]; - row_item.device_building_tag = arrTag[1]; - row_item.device_system_tag = arrTag[2]; - row_item.device_name_tag = arrTag[3]; - row_item.device_floor_tag = arrTag[4]; - row_item.device_master_tag = arrTag[5]; - row_item.device_last_name_tag = arrTag[6]; - row_item.device_serial_tag = arrTag[7]; - row_item.point_name = row.point_name; - dt_item.Add(row_item); - #endregion + if (arrTag.Length == 8) + { + #region for item + device_item8 row_item = new device_item8(); + row_item.tag_name = row.tag_name; + row_item.device_area_tag = arrTag[0]; + row_item.device_building_tag = arrTag[1]; + row_item.device_system_tag = arrTag[2]; + row_item.device_name_tag = arrTag[3]; + row_item.device_floor_tag = arrTag[4]; + row_item.device_master_tag = arrTag[5]; + row_item.device_last_name_tag = arrTag[6]; + row_item.device_serial_tag = arrTag[7]; + row_item.point_name = row.point_name; + dt_item.Add(row_item); + #endregion + } } //device_item @@ -221,6 +226,18 @@ namespace tpDomeWinAPP.Service //新增至device, is_link = 1 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) { sb.Append($@" insert device(device_guid, deleted, status, priority, is_link, device_area_tag, @@ -238,14 +255,18 @@ namespace tpDomeWinAPP.Service data.device_serial_tag + "', '" + data.niagara_tags + "', '" + data.device_system_tag + "', now(), now() );"); + } + foreach (var data in result2) + { sb2.Append($@"INSERT device_kind (device_kind_guid, device_building_tag, device_system_tag, device_name_tag, device_normal_flashing, device_close_flashing, device_error_flashing, device_error_independent, created_by, created_at) - VALUES (uuid(), '" + data.device_building_tag + "', '" + data.device_system_tag + "', '" + data.device_name_tag + + VALUES (uuid(), '" + data.device_building_tag + "', '" + data.device_system_tag + "', '" + data.device_name_tag + "', 0, 0, 1, 0, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now());"); } - if(sb.Length > 0) + + if (sb.Length > 0) { conn.Execute(sb.ToString()); conn.Execute(sb2.ToString()); diff --git a/z01_WinAPP/fmCheckTagName.cs b/z01_WinAPP/fmCheckTagName.cs index 0f9778d..18b31b8 100644 --- a/z01_WinAPP/fmCheckTagName.cs +++ b/z01_WinAPP/fmCheckTagName.cs @@ -167,10 +167,10 @@ namespace tpDomeWinAPP { webRequestSvc svc = new webRequestSvc(); string url_slot2 = "slot:/NTPC/B1|";//wsp - string bql = url_slot2 + "bql:select " + top100 + " * from control:ControlPoint ";//三菱: url_slot; wsp: url_slot2 + string bql = url_slot + "bql:select " + top100 + " * from control:ControlPoint ";//三菱: url_slot; wsp: url_slot2 //ds = svc.obixQuery("http://60.251.164.125:8080/obix/config/Arena/Program/ObixQuery/query/", bql); - //ds = svc.obixQuery("http://192.168.0.136:8080/obix/config/Program/ObixQuery/query/", bql);//三菱 - ds = svc.obixQuery("http://192.168.0.136:8081/obix/config/Program/ObixQuery/query/", bql);//wsp + ds = svc.obixQuery("http://192.168.0.136:8080/obix/config/Program/ObixQuery/query/", bql);//三菱 + //ds = svc.obixQuery("http://192.168.0.136:8081/obix/config/Program/ObixQuery/query/", bql);//wsp //ds = svc.obixQuery("http://localhost:8080/obix/config/Program/ObixQuery/query/", bql); dataGridView1.DataSource = ds; dataGridView1.Columns[0].Visible = false; From 125696a5d35a05d3ac3dbdc2132029c2261d80c6 Mon Sep 17 00:00:00 2001 From: wanli Date: Sat, 31 Dec 2022 16:59:19 +0800 Subject: [PATCH 3/4] =?UTF-8?q?[Backend]=20N4=E5=90=8C=E6=AD=A5:=20device?= =?UTF-8?q?=5Fkind=E9=87=8D=E8=A4=87=E5=95=8F=E9=A1=8C=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NiagaraDataSynchronizeRepository.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index 9522f55..6db5b2e 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -229,6 +229,18 @@ namespace Repository.BackendRepository.Implement //新增至device, is_link = 1 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) { sb.Append($@" insert device(device_guid, deleted, status, priority, is_link, device_area_tag, @@ -246,7 +258,9 @@ namespace Repository.BackendRepository.Implement data.device_serial_tag + "', '" + data.niagara_tags + "', '" + data.device_system_tag + "', now(), now() );"); - + } + foreach (var data in result) + { sb2.Append($@"INSERT device_kind (device_kind_guid, device_building_tag, device_system_tag, device_name_tag, device_normal_flashing, device_close_flashing, device_error_flashing, device_error_independent, created_by, created_at) From 811a1fd4652a998e6385cefcd3d910a16aecddfb Mon Sep 17 00:00:00 2001 From: dev02 Date: Sat, 31 Dec 2022 17:03:17 +0800 Subject: [PATCH 4/4] fix problem of use result --- .../Implement/NiagaraDataSynchronizeRepository.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index 6db5b2e..804cc30 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -259,7 +259,8 @@ namespace Repository.BackendRepository.Implement data.niagara_tags + "', '" + data.device_system_tag + "', now(), now() );"); } - foreach (var data in result) + + foreach (var data in result2) { sb2.Append($@"INSERT device_kind (device_kind_guid, device_building_tag, device_system_tag, device_name_tag, device_normal_flashing, device_close_flashing, device_error_flashing, device_error_independent, @@ -267,6 +268,7 @@ namespace Repository.BackendRepository.Implement VALUES (uuid(), '" + data.device_building_tag + "', '" + data.device_system_tag + "', '" + data.device_name_tag + "', 0, 0, 1, 0, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now());"); } + if (sb.Length > 0) { await conn.ExecuteAsync(sb.ToString());