From 917696275baa3cbdb5b36af47a0c78fb0abed16b Mon Sep 17 00:00:00 2001 From: dev02 Date: Fri, 21 Apr 2023 17:40:18 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9niagar?= =?UTF-8?q?a=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NiagaraDataSynchronizeController.cs | 11 +++--- Backend/Controllers/VariableController.cs | 23 +++++++++++++ .../Services/Implement/webRequestService.cs | 31 ++++++++++++----- .../Views/NiagaraDataSynchronize/Index.cshtml | 34 ++++++++++++++++--- Backend/appsettings.Development.json | 6 +++- Backend/appsettings.json | 6 +++- .../NiagaraDataSynchronizeRepository.cs | 14 ++++++-- Repository/Helper/BackEndConfigHelper.cs | 11 +++++- Repository/Models/BackEndConfig.cs | 2 ++ 9 files changed, 114 insertions(+), 24 deletions(-) diff --git a/Backend/Controllers/NiagaraDataSynchronizeController.cs b/Backend/Controllers/NiagaraDataSynchronizeController.cs index f33735a..af030d6 100644 --- a/Backend/Controllers/NiagaraDataSynchronizeController.cs +++ b/Backend/Controllers/NiagaraDataSynchronizeController.cs @@ -85,8 +85,9 @@ namespace Backend.Controllers { string ss = ds.Where(x => x.tag_name != "").FirstOrDefault().tag_name; var building = ss.Split("_")[0]; + var newDs = ds.Where(x => x.building == building).ToList(); string LightSwitchLevel = await niagaraDataSynchronizeRepository.getLightSwitchLevel(); //獲取照明開關 是否在 device or device_node - await niagaraDataSynchronizeRepository.InsertNiagaraTagList(ds, building, tag_quantity); // 匯入 MySQL table: import_niagara_tag + await niagaraDataSynchronizeRepository.InsertNiagaraTagList(newDs, building, tag_quantity); // 匯入 MySQL table: import_niagara_tag await niagaraDataSynchronizeRepository.DeviceComparison(LightSwitchLevel); await niagaraDataSynchronizeRepository.CheckDiffFullNameAndCover(); await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName(); @@ -111,7 +112,7 @@ namespace Backend.Controllers /// /// [HttpPost] - public Task>> RawDataDevItemList() + public Task>> RawDataDevItemList([FromBody] Device_value building) { ApiResult> apiResult = new ApiResult>(); @@ -121,10 +122,10 @@ namespace Backend.Controllers string url_slot = backEndConfig.GetUrlSlot(); webRequestService svc = new webRequestService(); - ds = svc.obixHisQuery(backEndConfig.GetobixHisBqlQuery(), backEndConfig.GetobixHisUrlQuery(), url_slot);//三菱 - + ds = svc.obixHisQuery(backEndConfig.GetobixHisBqlQuery(), backEndConfig.GetobixHisUrlQuery(), url_slot, backEndConfig.Getobixtag_acc(), backEndConfig.Getobixtag_pass());//三菱 + apiResult.Code = "0000"; - apiResult.Data = ds; + apiResult.Data = ds.Where(x => x.device_building_tag == building.building).ToList(); ; } catch (Exception exception) { diff --git a/Backend/Controllers/VariableController.cs b/Backend/Controllers/VariableController.cs index ccaee2a..a79ecbf 100644 --- a/Backend/Controllers/VariableController.cs +++ b/Backend/Controllers/VariableController.cs @@ -241,5 +241,28 @@ namespace Backend.Controllers return apiResult; } + + [HttpPost] + public async Task> ProjectName() + { + ApiResult apiResult = new ApiResult(); + + try + { + var variable = await backendRepository.GetOneAsync("select * from variable where deleted = 0 and system_type = 'project_name';"); + + apiResult.Data = variable; + apiResult.Code = "0000"; + apiResult.Msg = "成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } } } diff --git a/Backend/Services/Implement/webRequestService.cs b/Backend/Services/Implement/webRequestService.cs index 208940b..6114897 100644 --- a/Backend/Services/Implement/webRequestService.cs +++ b/Backend/Services/Implement/webRequestService.cs @@ -132,12 +132,14 @@ namespace Backend.Services.Implement /// /// /// - public List obixHisQuery(string bqlUrlString, string urlString, string slot) + public List obixHisQuery(string bqlUrlString, string urlString, string slot, string acc, string pass) { //String username = "obixUser"; //String password = "Admin123456"; - String username = "stanGG"; - String password = "St12345678"; + //String username = "stanGG"; + //String password = "St12345678"; + String username = acc; + String password = pass; String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); #region get control point data @@ -232,13 +234,24 @@ 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('_')[5]; - row.parent_path = stationName; + if (tagName.Split('_')[1] == "S") //for security system + { + row.device_building_tag = tagName.Split('_')[0]; + row.device_system_tag = tagName.Split('_')[1]; + row.device_floor_tag = tagName.Split('_')[2]; + row.device_name_tag = tagName.Split('_')[3].Substring(1); + row.device_point_name = tagName.Split('_')[5]; + } + else //for normal + { + row.device_building_tag = tagName.Split('_')[0]; + //row.device_system_tag = tagName.Split('_')[1]; + row.device_floor_tag = tagName.Split('_')[2]; + row.device_name_tag = tagName.Split('_')[1]; + row.device_point_name = tagName.Split('_')[5]; + } + row.parent_path = stationName; //full_name 其實是點位名稱 point_name row.full_name = conPoint.Where(x => x.name == tagName).Select(x => x.displayName).FirstOrDefault(); result.Add(row); diff --git a/Backend/Views/NiagaraDataSynchronize/Index.cshtml b/Backend/Views/NiagaraDataSynchronize/Index.cshtml index cdc5dd0..7bd6a7d 100644 --- a/Backend/Views/NiagaraDataSynchronize/Index.cshtml +++ b/Backend/Views/NiagaraDataSynchronize/Index.cshtml @@ -21,7 +21,7 @@
- +
@*
@@ -85,9 +85,9 @@ $(function () { ds = null; - building = "B1"; document.getElementById("Building_B").checked = true; + projectName(); rawDataImportTable = $("#niagara_data_table").DataTable({ "columns": [ { @@ -133,7 +133,7 @@ document.getElementById('loadDataText').innerText = "Loading..."; buildingId = document.querySelector('input[name="Building"]:checked').value; if (buildingId == "B") { - building = "B1"; + //building = "B1"; rawDataImportTable.ajax.reload(); } } @@ -180,10 +180,16 @@ //比對資料,有差異的話,再同步到device等資料表 var url_synchronize_data = "/NiagaraDataSynchronize/RawDataDevItemList/"; var url_synchronize_data_device_item = "/NiagaraDataSynchronize/DevIteComData/"; - + let object = {}; + object.building = building; $.ajax({ method: "POST", url: url_synchronize_data, + cache: false, + async: false, + contentType: "application/json; charset=UTF-8", + data: JSON.stringify(object), + dataType: 'json', success: function (rel) { if (rel.code != "0000") { toast_error(rel.msg); @@ -218,5 +224,25 @@ }, }); } + + function projectName() + { + $.post("/Variable/ProjectName", null, function (rel) { + building = "B1"; + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + if (rel.data != null) { + building = rel.data.system_value.split('/')[1]; + $(`label[for='Building_B']`).html(rel.data.system_key + building); + } + else + { + $(`label[for='Building_B']`).html('三菱B1'); + } + }, 'json'); + } } \ No newline at end of file diff --git a/Backend/appsettings.Development.json b/Backend/appsettings.Development.json index 380f7c4..d9b4695 100644 --- a/Backend/appsettings.Development.json +++ b/Backend/appsettings.Development.json @@ -56,13 +56,17 @@ //"ObixQuery": "7C/j7U8PmDqMxpb7f6gMpHFicuOA83OZeuWHBFdi/xpfEIklxyQ/wP75bEKwrdh+fXXgjmpc9cLX9GqbBC7eGw==", //三菱 //"ObixHisBqlQuery": "7C/j7U8PmDqMxpb7f6gMpHFicuOA83OZeuWHBFdi/xpfEIklxyQ/wP75bEKwrdh+fXXgjmpc9cLX9GqbBC7eGw==", //三菱 //"ObixHisUrlQuery": "7C/j7U8PmDqMxpb7f6gMpD06cJcRzpVx0+IAssROlE4MlzSDPojSI17+XkQIL9Eu" //三菱 + //"Account": "UnUq+XFB1pEDdz8OId/kaA==", //三菱 + //"Password": "CQC+JFF11YW+axvka4WOKQ==", //三菱 "UrlSlot": "e1dUH6340WkFoHPJYq7IYQ==", // 巨蛋棟 D2 //"UrlSlot": "f9cDBTw5PCfbDTOt4Kwbew==", // 旅館棟 slot:/Arena/H| "ObixQuery": "7C/j7U8PmDqMxpb7f6gMpIDkLYyNwmXoqhx+N1G+fqQxEETrRbFLZfC7Sud5yX24CphfLlSUbfjft7gcP6v+gw==", //巨蛋 http://192.168.0.136:8082/obix/config/Program/ObixQuery/query/ "ObixHisBqlQuery": "7C/j7U8PmDqMxpb7f6gMpIDkLYyNwmXoqhx+N1G+fqQxEETrRbFLZfC7Sud5yX24CphfLlSUbfjft7gcP6v+gw==", // 巨蛋 http://192.168.0.136:8082/obix/config/Program/ObixQuery/query/ "ObixHisUrlQuery": "7C/j7U8PmDqMxpb7f6gMpEVUZrrjJT0WiTUBn0FzipXfBFsxYAX3plIWBcJ+oZzW", //巨蛋 http://192.168.0.136:8081/obix/histories - "tag_quantity": "AeqCvTnIRIpvQcjBfwi+qg==" + "tag_quantity": "AeqCvTnIRIpvQcjBfwi+qg==", + "Account": "FMiVG4sIeDFmAUc/8Hn/kw==", //巨蛋 + "Password": "4+ussQ8rHohjPWpNvoujJQ==" //巨蛋 } } } diff --git a/Backend/appsettings.json b/Backend/appsettings.json index 0c7670b..c0ce7a5 100644 --- a/Backend/appsettings.json +++ b/Backend/appsettings.json @@ -44,12 +44,16 @@ //"ObixHisBqlQuery": "7C/j7U8PmDqMxpb7f6gMpHFicuOA83OZeuWHBFdi/xpfEIklxyQ/wP75bEKwrdh+fXXgjmpc9cLX9GqbBC7eGw==", //三菱 //"ObixHisUrlQuery": "7C/j7U8PmDqMxpb7f6gMpD06cJcRzpVx0+IAssROlE4MlzSDPojSI17+XkQIL9Eu" //三菱 //"tag_quantity": "fFA0lNwg5d/4ZNzWrPbVzw==" 8段 + //"Account": "UnUq+XFB1pEDdz8OId/kaA==", //三菱 + //"Password": "CQC+JFF11YW+axvka4WOKQ==", //三菱 "UrlSlot": "e1dUH6340WkFoHPJYq7IYQ==", // 巨蛋棟 D2 "ObixQuery": "7C/j7U8PmDqMxpb7f6gMpIDkLYyNwmXoqhx+N1G+fqQxEETrRbFLZfC7Sud5yX24CphfLlSUbfjft7gcP6v+gw==", //巨蛋 http://192.168.0.136:8082/obix/config/Program/ObixQuery/query/ "ObixHisBqlQuery": "7C/j7U8PmDqMxpb7f6gMpIDkLYyNwmXoqhx+N1G+fqQxEETrRbFLZfC7Sud5yX24CphfLlSUbfjft7gcP6v+gw==", // 巨蛋 http://192.168.0.136:8082/obix/config/Program/ObixQuery/query/ "ObixHisUrlQuery": "7C/j7U8PmDqMxpb7f6gMpEVUZrrjJT0WiTUBn0FzipXfBFsxYAX3plIWBcJ+oZzW", //巨蛋 http://192.168.0.136:8081/obix/histories - "tag_quantity": "AeqCvTnIRIpvQcjBfwi+qg==" // 5段 + "tag_quantity": "AeqCvTnIRIpvQcjBfwi+qg==", // 5段 + "Account": "FMiVG4sIeDFmAUc/8Hn/kw==", //巨蛋 + "Password": "4+ussQ8rHohjPWpNvoujJQ==" //巨蛋 } } } diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index 8429f7f..7019331 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -212,9 +212,17 @@ namespace Repository.BackendRepository.Implement row.full_name + "'" + ");"); } - + + var isDome = await GetOneAsync("select system_value from variable where deleted = 0 and system_type = 'project_name';"); if (sb.Length > 0) { + if (isDome == "ibms_dome_dome/D2") + { + sb.Append($@" update import_niagara_item a join dic_system b + on a.device_name_tag COLLATE utf8mb4_general_ci = b.s2_code + set device_system_tag = b.s1_code + where device_system_tag <> 'S'"); + } await conn.ExecuteAsync(sb.ToString()); sb.Clear(); } @@ -439,8 +447,8 @@ namespace Repository.BackendRepository.Implement isControll + "," + isBool + ", 1, 1, '" + data.device_system_tag + "', '" + - data.device_name_tag + "', " + - data.full_name + "', " + + data.device_name_tag + "', '" + + data.full_name + "', '" + data.parent_path + "', " + "now(), now());"); } diff --git a/Repository/Helper/BackEndConfigHelper.cs b/Repository/Helper/BackEndConfigHelper.cs index cd65f2e..e64fb8b 100644 --- a/Repository/Helper/BackEndConfigHelper.cs +++ b/Repository/Helper/BackEndConfigHelper.cs @@ -26,6 +26,8 @@ namespace Repository.Helper /// /// string Getobixtag_quantity(); + string Getobixtag_acc(); + string Getobixtag_pass(); } @@ -60,7 +62,14 @@ namespace Repository.Helper { return ed.AESDecrypt(_NiagaraDataSyncConfig.tag_quantity); } - + public string Getobixtag_acc() + { + return ed.AESDecrypt(_NiagaraDataSyncConfig.Account); + } + public string Getobixtag_pass() + { + return ed.AESDecrypt(_NiagaraDataSyncConfig.Password); + } } } diff --git a/Repository/Models/BackEndConfig.cs b/Repository/Models/BackEndConfig.cs index b579342..19ee9f1 100644 --- a/Repository/Models/BackEndConfig.cs +++ b/Repository/Models/BackEndConfig.cs @@ -16,6 +16,8 @@ /// tag 段數 /// public string tag_quantity { get; set; } + public string Account { get; set; } + public string Password { get; set; } }