diff --git a/Backend/Controllers/NiagaraDataSynchronizeController.cs b/Backend/Controllers/NiagaraDataSynchronizeController.cs index f85cca4..c30ef88 100644 --- a/Backend/Controllers/NiagaraDataSynchronizeController.cs +++ b/Backend/Controllers/NiagaraDataSynchronizeController.cs @@ -13,6 +13,7 @@ using Microsoft.Extensions.DependencyInjection; using NPOI.SS.Formula.Functions; using Repository.Helper; using Microsoft.AspNetCore.Routing.Matching; +using Newtonsoft.Json; namespace Backend.Controllers { @@ -192,7 +193,7 @@ namespace Backend.Controllers public async Task> DevIteComData([FromBody] List ds) { bool result = false; - + var oldDs = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(ds)); ApiResult apiResult = new ApiResult(); try { @@ -200,14 +201,7 @@ namespace Backend.Controllers { //string ss = ds.Where(x => x.tag_name != "").FirstOrDefault().tag_name; //var building = ss.Split("_")[0]; - var building = ds.GroupBy(x => x.device_building_tag).Select(x => x.Key).ToList(); - 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(); - #region 歷史資料處理 ds.Clear(); var isDome = await backendRepository.GetOneAsync("select system_value from variable where deleted = 0 and system_type = 'project_name';"); @@ -229,6 +223,12 @@ namespace Backend.Controllers await niagaraDataSynchronizeRepository.RecoverSysTag("import_niagara_item_history"); // recover missing deivce_system_tag #endregion + await niagaraDataSynchronizeRepository.InsertItemFromNiagara(oldDs, 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 0fbf0db..bcf182d 100644 --- a/Backend/Services/Implement/webRequestService.cs +++ b/Backend/Services/Implement/webRequestService.cs @@ -176,103 +176,106 @@ namespace Backend.Services.Implement } #endregion - #region main program List result = new List(); - String API_Url = urlString; + #region main program (deleted) + //String API_Url = urlString; - HttpWebRequest Postrequest = (HttpWebRequest)WebRequest.Create(API_Url); - Postrequest.Method = "GET"; - Postrequest.Headers.Add("Authorization", "Basic " + encoded); - Postrequest.PreAuthenticate = true; - Postrequest.Timeout = System.Threading.Timeout.Infinite; + //HttpWebRequest Postrequest = (HttpWebRequest)WebRequest.Create(API_Url); + //Postrequest.Method = "GET"; + //Postrequest.Headers.Add("Authorization", "Basic " + encoded); + //Postrequest.PreAuthenticate = true; + //Postrequest.Timeout = System.Threading.Timeout.Infinite; - HttpWebResponse response = (HttpWebResponse)Postrequest.GetResponse(); - var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); + //HttpWebResponse response = (HttpWebResponse)Postrequest.GetResponse(); + //var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); - XmlDocument xmlDoc = new XmlDocument(); - xmlDoc.LoadXml(responseString); + //XmlDocument xmlDoc = new XmlDocument(); + //xmlDoc.LoadXml(responseString); - //ref https://stackoverflow.com/questions/642293/how-do-i-read-and-parse-an-xml-file-in-c - foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) - { - var stationName = node.Attributes["name"].InnerText; // WSP_Supervisor - oneStationName = oneStationName ?? stationName; - String API_Url2 = urlString + "/" + stationName; // http://192.168.0.136:8081/obix/histories/WSP_Supervisor + ////ref https://stackoverflow.com/questions/642293/how-do-i-read-and-parse-an-xml-file-in-c + //foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) + //{ + // var stationName = node.Attributes["name"].InnerText; // WSP_Supervisor + // if (stationName.Split("_").Length > 1 && stationName.Split("_")[1] == building_tag.Split("_")[0]) + // { + // oneStationName = oneStationName ?? stationName; + // String API_Url2 = urlString + "/" + stationName; // http://192.168.0.136:8081/obix/histories/WSP_Supervisor - HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2); - Postrequest2.Method = "GET"; - Postrequest2.Headers.Add("Authorization", "Basic " + encoded); - Postrequest2.PreAuthenticate = true; - Postrequest2.Timeout = System.Threading.Timeout.Infinite; + // HttpWebRequest Postrequest2 = (HttpWebRequest)WebRequest.Create(API_Url2); + // Postrequest2.Method = "GET"; + // Postrequest2.Headers.Add("Authorization", "Basic " + encoded); + // Postrequest2.PreAuthenticate = true; + // Postrequest2.Timeout = System.Threading.Timeout.Infinite; - HttpWebResponse response2 = (HttpWebResponse)Postrequest2.GetResponse(); - var responseString2 = new StreamReader(response2.GetResponseStream()).ReadToEnd(); + // HttpWebResponse response2 = (HttpWebResponse)Postrequest2.GetResponse(); + // var responseString2 = new StreamReader(response2.GetResponseStream()).ReadToEnd(); - XmlDocument xmlDoc2 = new XmlDocument(); - xmlDoc2.LoadXml(responseString2); - // Create a namespace manager to handle the XML namespace - XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc2.NameTable); - string xmlns = xmlDoc2.DocumentElement.GetAttribute("xmlns") ?? "http://obix.org/ns/schema/1.0"; - namespaceManager.AddNamespace("obix", xmlns); + // XmlDocument xmlDoc2 = new XmlDocument(); + // xmlDoc2.LoadXml(responseString2); + // // Create a namespace manager to handle the XML namespace + // XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc2.NameTable); + // string xmlns = xmlDoc2.DocumentElement.GetAttribute("xmlns") ?? "http://obix.org/ns/schema/1.0"; + // namespaceManager.AddNamespace("obix", xmlns); - // Select all "ref" nodes using an XPath expression - XmlNodeList refNodes = xmlDoc2.SelectNodes($"//obix:ref[starts-with(@name, '{AreaTag ?? building_tag}')]", namespaceManager); - foreach (XmlNode node2 in refNodes) - { - string tagName = node2.Attributes["name"].InnerText; - if (tagName.Split('_').Length == 9) - { - ImpNiaItem row = new ImpNiaItem(); - row.device_area_tag = tagName.Split('_')[0]; - row.device_building_tag = tagName.Split('_')[1]; - row.device_system_tag = tagName.Split('_')[2]; - row.device_name_tag = tagName.Split('_')[3]; - row.device_point_name = tagName.Split('_')[8]; - row.parent_path = stationName; + // // Select all "ref" nodes using an XPath expression + // XmlNodeList refNodes = xmlDoc2.SelectNodes($"//obix:ref[starts-with(@name, '{AreaTag ?? building_tag}')]", namespaceManager); + // foreach (XmlNode node2 in refNodes) + // { + // string tagName = node2.Attributes["name"].InnerText; + // if (tagName.Split('_').Length == 9) + // { + // ImpNiaItem row = new ImpNiaItem(); + // row.device_area_tag = tagName.Split('_')[0]; + // row.device_building_tag = tagName.Split('_')[1]; + // row.device_system_tag = tagName.Split('_')[2]; + // 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.Replace('_', '/') && !x.isHistory).Select(x => x.displayName).FirstOrDefault(); - if (conPoint.Where(x => x.name == tagName.Replace('_', '/') && !x.isHistory).FirstOrDefault() != null) - conPoint.Where(x => x.name == tagName.Replace('_', '/') && !x.isHistory).FirstOrDefault().isHistory = true; - row.isHistory = true; + // //full_name 其實是點位名稱 point_name + // row.full_name = conPoint.Where(x => x.name == tagName.Replace('_', '/') && !x.isHistory).Select(x => x.displayName).FirstOrDefault(); + // if (conPoint.Where(x => x.name == tagName.Replace('_', '/') && !x.isHistory).FirstOrDefault() != null) + // conPoint.Where(x => x.name == tagName.Replace('_', '/') && !x.isHistory).FirstOrDefault().isHistory = true; + // row.isHistory = true; - result.Add(row); - } - else if (tagName.Split('_').Length == 6) - { //巨蛋 tag 5 段版本 - ImpNiaItem row = new ImpNiaItem(); - if (tagName.Split('_')[1] == "S" || tagName.Split('_')[1] == "B" || tagName.Split('_')[1] == "CWB") //for security system and parking 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]; - row.device_point_name = tagName.Split('_')[5]; - } - else //for normal - { - row.device_building_tag = tagName.Split('_')[0]; - row.device_floor_tag = tagName.Split('_')[2]; - row.device_name_tag = tagName.Split('_')[1]; - row.device_point_name = tagName.Split('_')[5]; - } + // result.Add(row); + // } + // else if (tagName.Split('_').Length == 6) + // { //巨蛋 tag 5 段版本 + // ImpNiaItem row = new ImpNiaItem(); + // if (tagName.Split('_')[1] == "S" || tagName.Split('_')[1] == "B" || tagName.Split('_')[1] == "CWB") //for security system and parking 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]; + // row.device_point_name = tagName.Split('_')[5]; + // } + // else //for normal + // { + // row.device_building_tag = tagName.Split('_')[0]; + // 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 - var deviceNumber = tagName.Substring(0, tagName.LastIndexOf(tagName.Split("_")[5]) - 1); - var point = tagName.Split("_")[5]; - conPoint = conPoint.Where(x => x.name.Split("/").Length > 6).ToList(); - row.full_name = conPoint.Where(x => x.name.Split("/")[5] == deviceNumber && x.name.Split("/")[6] == point && !x.isHistory).Select(x => x.displayName).FirstOrDefault(); - if (conPoint.Where(x => x.name.Split("/")[5] == deviceNumber && x.name.Split("/")[6] == point && !x.isHistory).FirstOrDefault() != null) - conPoint.Where(x => x.name.Split("/")[5] == deviceNumber && x.name.Split("/")[6] == point && !x.isHistory).FirstOrDefault().isHistory = true; - row.isHistory = true; - result.Add(row); - } - } - } + // row.parent_path = stationName; + // //full_name 其實是點位名稱 point_name + // var deviceNumber = tagName.Substring(0, tagName.LastIndexOf(tagName.Split("_")[5]) - 1); + // var point = tagName.Split("_")[5]; + // conPoint = conPoint.Where(x => x.name.Split("/").Length > 6).ToList(); + // row.full_name = conPoint.Where(x => x.name.Split("/")[5] == deviceNumber && x.name.Split("/")[6] == point && !x.isHistory).Select(x => x.displayName).FirstOrDefault(); + // if (conPoint.Where(x => x.name.Split("/")[5] == deviceNumber && x.name.Split("/")[6] == point && !x.isHistory).FirstOrDefault() != null) + // conPoint.Where(x => x.name.Split("/")[5] == deviceNumber && x.name.Split("/")[6] == point && !x.isHistory).FirstOrDefault().isHistory = true; + // row.isHistory = true; + // result.Add(row); + // } + // } + // } + //} #endregion - var newConPoint = conPoint.Where(x => !x.isHistory).ToArray(); - foreach(var n in newConPoint) + + foreach(var n in conPoint) { if (n.name.Split('/').Length == 9) { @@ -283,9 +286,7 @@ namespace Backend.Services.Implement device_system_tag = n.name.Split('/')[2], device_name_tag = n.name.Split('/')[3], device_point_name = n.name.Split('/')[8], - full_name = n.displayName, - parent_path = oneStationName, - isHistory = n.isHistory + full_name = n.displayName }); } else if (n.name.Split('/').Length == 7) // Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/Summery @@ -298,9 +299,7 @@ namespace Backend.Services.Implement 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 + full_name = n.displayName }); } else //for normal @@ -312,9 +311,7 @@ namespace Backend.Services.Implement 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 + full_name = n.displayName }); } } diff --git a/BackendWorkerService/Program.cs b/BackendWorkerService/Program.cs index e293df7..bb7f330 100644 --- a/BackendWorkerService/Program.cs +++ b/BackendWorkerService/Program.cs @@ -121,19 +121,19 @@ namespace BackendWorkerService //); //#endregion - //#region ޲z(]wC 5 @) - //services.AddSingleton(); - //services.AddSingleton( - //new JobSchedule(jobType: typeof(ParkingJob), cronExpression: configuration.GetValue("BackgroundServiceCron:ParkingJob")) - //); - //#endregion + #region ޲z(]wC 5 @) + services.AddSingleton(); + services.AddSingleton( + new JobSchedule(jobType: typeof(ParkingJob), cronExpression: configuration.GetValue("BackgroundServiceCron:ParkingJob")) + ); + #endregion - //#region qk(]wC p @) - //services.AddSingleton(); - //services.AddSingleton( - //new JobSchedule(jobType: typeof(ArchiveElectricMeterHourJob), cronExpression: configuration.GetValue("BackgroundServiceCron:ArchiveElectricMeterHourJob")) - //); - //#endregion + #region qk(]wC p @) + services.AddSingleton(); + services.AddSingleton( + new JobSchedule(jobType: typeof(ArchiveElectricMeterHourJob), cronExpression: configuration.GetValue("BackgroundServiceCron:ArchiveElectricMeterHourJob")) + ); + #endregion #region qk(]wC @) services.AddSingleton(); @@ -143,10 +143,10 @@ namespace BackendWorkerService #endregion #region wɨoHAPI - services.AddSingleton(); - services.AddSingleton( - new JobSchedule(jobType: typeof(Quartz.Jobs.WeatherAPIJob), cronExpression: configuration.GetValue("BackgroundServiceCron:WeatherAPIJob")) - ); + //services.AddSingleton(); + //services.AddSingleton( + //new JobSchedule(jobType: typeof(Quartz.Jobs.WeatherAPIJob), cronExpression: configuration.GetValue("BackgroundServiceCron:WeatherAPIJob")) + //); #endregion }).ConfigureLogging((hostContext, logFactory) => { diff --git a/BackendWorkerService/Quartz/Jobs/ParkingJob.cs b/BackendWorkerService/Quartz/Jobs/ParkingJob.cs index 4391508..4424da6 100644 --- a/BackendWorkerService/Quartz/Jobs/ParkingJob.cs +++ b/BackendWorkerService/Quartz/Jobs/ParkingJob.cs @@ -69,6 +69,8 @@ namespace BackendWorkerService.Quartz.Jobs spaceRequest.Method = "GET"; //request.Headers.Add("Authorization", "Basic " + encoded); spaceRequest.PreAuthenticate = true; + spaceRequest.Timeout = System.Threading.Timeout.Infinite; + spaceRequest.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; //Stopwatch stopWatch = new Stopwatch(); //stopWatch.Start(); @@ -116,6 +118,7 @@ namespace BackendWorkerService.Quartz.Jobs request.Method = "POST"; request.Headers.Add("Authorization", "Basic " + encoded); request.PreAuthenticate = true; + request.Timeout = System.Threading.Timeout.Infinite; var real = $@""; byte[] realByteArray = Encoding.UTF8.GetBytes(real); @@ -123,7 +126,6 @@ namespace BackendWorkerService.Quartz.Jobs { reqStream.Write(realByteArray, 0, realByteArray.Length); } - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); var responseContent = new StreamReader(response.GetResponseStream()).ReadToEnd(); @@ -180,7 +182,7 @@ namespace BackendWorkerService.Quartz.Jobs #endregion #region 取得設備資訊 - if (await task_Detail.GetNeedWorkTask("ParkingJob", "Device")) + if (await task_Detail.GetNeedWorkTask("ParkingJob", "Device")) { try { @@ -191,6 +193,7 @@ namespace BackendWorkerService.Quartz.Jobs equipmentRequest.Method = "GET"; //request.Headers.Add("Authorization", "Basic " + encoded); equipmentRequest.PreAuthenticate = true; + equipmentRequest.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; HttpWebResponse equipmentResponse = (HttpWebResponse)equipmentRequest.GetResponse(); var equipmentResponseContent = new StreamReader(equipmentResponse.GetResponseStream()).ReadToEnd(); diff --git a/BackendWorkerService/appsettings.Development.json b/BackendWorkerService/appsettings.Development.json index b4569f6..e822289 100644 --- a/BackendWorkerService/appsettings.Development.json +++ b/BackendWorkerService/appsettings.Development.json @@ -12,7 +12,7 @@ "MessageNotificationJob": "0 0 2 * * ?", "DataDeliveryJob": "0 0 2 * * ?", "RegularUpdateDBTableJob": "0 0 2 * * ?", - "ParkingJob": "0 0 2 * * ?", + "ParkingJob": "0/5 * * * * ?", "ArchiveElectricMeterHourJob": "0 0 2 * * ?", "ArchiveElectricMeterDayJob": "0/5 * * * * ?", "WeatherAPIJob": "0 0 2 * * ?" @@ -25,7 +25,8 @@ //"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp //"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome //"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel - "Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut + //"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut + "Database": "+5RAiFLJVU+LRyDxF1K/pcLZaoZa4k/thZqF6xKoCag=", //dome_online_0821 "Root": "SzdxEgaJJ7tcTCrUl2zKsA==", "Password": "FVAPxztxpY4gJJKQ/se4bQ==" }, diff --git a/BackendWorkerService/appsettings.json b/BackendWorkerService/appsettings.json index b4569f6..8c853d2 100644 --- a/BackendWorkerService/appsettings.json +++ b/BackendWorkerService/appsettings.json @@ -25,7 +25,8 @@ //"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp //"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome //"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel - "Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut + //"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut + "Database": "+5RAiFLJVU+LRyDxF1K/pcLZaoZa4k/thZqF6xKoCag=", //dome_online_0821 "Root": "SzdxEgaJJ7tcTCrUl2zKsA==", "Password": "FVAPxztxpY4gJJKQ/se4bQ==" }, diff --git a/FrontendWebApi/ApiControllers/BuildController.cs b/FrontendWebApi/ApiControllers/BuildController.cs index 8f8fa12..ddf30b2 100644 --- a/FrontendWebApi/ApiControllers/BuildController.cs +++ b/FrontendWebApi/ApiControllers/BuildController.cs @@ -200,7 +200,7 @@ namespace FrontendWebApi.ApiControllers order by b.priority, v1.system_priority, me.priority, v2.system_priority, v2.created_at DESC", new { Account = account }); var floorsql = await backendRepository.GetAllAsync(@" - select * from (select * from sub_system_floor ssf where ssf.deleted = 0 and ssf.status = 0) a + select * from (select * from sub_system_floor ssf where ssf.deleted = 0 and ssf.status = 0 and ssf.is_link = 1) a left join floor on floor.full_name = a.floor_tag order by floor.priority;"); var common = await backendRepository.GetAllAsync($@"select ap.building_tag Name,ap.ShowView Value from auth_page ap @@ -329,7 +329,7 @@ namespace FrontendWebApi.ApiControllers List Floors = new List(); var floorsql = await backendRepository.GetAllAsync($@" - select * from (select * from sub_system_floor ssf where ssf.deleted = 0 and ssf.status = 0 and ssf.building_tag = '{get.building_tag}' and ssf.main_system_tag = '{get.main_system_tag}' and ssf.sub_system_tag = '{get.sub_system_tag}') a + select * from (select * from sub_system_floor ssf where ssf.deleted = 0 and ssf.status = 0 and ssf.building_tag = '{get.building_tag}' and ssf.main_system_tag = '{get.main_system_tag}' and ssf.sub_system_tag = '{get.sub_system_tag}' and ssf.is_link = 1) a left join floor on floor.full_name = a.floor_tag and a.building_tag = floor.building_tag where floor.deleted = 0 order by floor.priority"); diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index 8a80b3f..b01f79f 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -343,9 +343,12 @@ 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 and d.visible = 1 and d.is_link = 1 - join device_item di on d.device_system_tag=di.device_system_tag and d.device_name_tag=di.device_name_tag - and di.is_link = 1 and di.is_show_history = 1 + join ( + select distinct device_system_tag, device_name_tag, device_serial_tag, device_number, full_name from device d where d.deleted = 0 and d.visible = 1 and d.is_link = 1 limit 1000000 + ) d on v1.system_value = d.device_system_tag and v2.system_value = d.device_name_tag + join ( + select distinct device_system_tag, device_name_tag, is_show_history from device_item where deleted = 0 and is_link = 1 and is_show_history = 1 + ) di on d.device_system_tag=di.device_system_tag and d.device_name_tag=di.device_name_tag 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 }); var dbbuilding = await frontendRepository.GetAllAsync( diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index 18fb7b1..4ce81fc 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -242,9 +242,7 @@ namespace Repository.BackendRepository.Implement 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 + full_name = x.full_name }) .Select(x => new ImpNiaItem { @@ -253,9 +251,7 @@ namespace Repository.BackendRepository.Implement 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 + full_name = x.Key.full_name }).ToList(); StringBuilder sb = new StringBuilder(); @@ -269,9 +265,9 @@ namespace Repository.BackendRepository.Implement row.device_system_tag + "', '" + row.device_name_tag + "', '" + row.device_point_name + "', '" + - row.parent_path + "', '" + + "" + "', '" + row.full_name + "'," + - row.isHistory + + "0" + ");"); } @@ -292,6 +288,34 @@ namespace Repository.BackendRepository.Implement await conn.ExecuteAsync(sb.ToString()); } sb.Clear(); + + sb.Append($@"SET SQL_SAFE_UPDATES = 0; + update import_niagara_item ini + join ( + select device_building_tag, device_system_tag, device_name_tag, device_point_name + from import_niagara_item_history + group by device_building_tag, device_system_tag, device_name_tag, device_point_name + ) as inih on ini.device_building_tag = inih.device_building_tag and ini.device_system_tag = inih.device_system_tag and ini.device_name_tag = inih.device_name_tag + and ini.device_point_name = inih.device_point_name + set ini.is_history = 1"); + + using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) + { + await conn.ExecuteAsync(sb.ToString()); + } + sb.Clear(); + + sb.Append($@"SET SQL_SAFE_UPDATES = 0; + update import_niagara_item ini + join ( + select distinct device_building_tag, parent_path from import_niagara_item_history + ) inih on ini.device_building_tag = inih.device_building_tag + set ini.parent_path = inih.parent_path"); + + using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) + { + await conn.ExecuteAsync(sb.ToString()); + } } #endregion } @@ -565,7 +589,7 @@ namespace Repository.BackendRepository.Implement FROM import_niagara_item m LEFT JOIN device_item d 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 and m.device_building_tag collate utf8mb4_0900_ai_ci = d.device_building_tag - WHERE d.points IS NULL;"); + WHERE d.points IS NULL and d.deleted = 0;"); result = (await conn.QueryAsync(sb.ToString())).ToList(); sb.Clear(); @@ -623,13 +647,14 @@ namespace Repository.BackendRepository.Implement sb.Append($@" SET SQL_SAFE_UPDATES = 0; UPDATE device_item d LEFT JOIN ( - SELECT device_system_tag, device_name_tag, device_point_name, full_name + SELECT device_system_tag, device_name_tag, device_point_name, full_name, device_building_tag 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.device_building_tag = m.device_building_tag SET d.is_link = CASE WHEN m.device_point_name IS NULL THEN 0 ELSE 1 END;"); using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) @@ -641,7 +666,7 @@ namespace Repository.BackendRepository.Implement 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 + SELECT m.device_system_tag, m.device_name_tag, m.device_point_name, m.full_name, device_building_tag FROM import_niagara_item m WHERE (m.is_history = 1) LIMIT 100000 -- Specify your desired limit here @@ -649,7 +674,8 @@ namespace Repository.BackendRepository.Implement 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.is_show_history = CASE WHEN subquery.device_point_name IS NULL THEN 0 ELSE 1 END"); + AND d.device_building_tag = subquery.device_building_tag + SET d.is_show_history = CASE WHEN subquery.device_point_name IS NULL THEN 0 ELSE 1 END;"); using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { @@ -738,6 +764,22 @@ namespace Repository.BackendRepository.Implement { await conn.ExecuteAsync(sb.ToString()); } + + sb.Clear(); + sb.Append($@"SET SQL_SAFE_UPDATES = 0; + UPDATE building_menu b LEFT JOIN ( + select device_building_tag, device_system_tag, device_name_tag + from import_niagara_tag + group by device_building_tag, device_system_tag, device_name_tag + ) AS a ON b.building_tag COLLATE utf8mb4_0900_ai_ci = a.device_building_tag COLLATE utf8mb4_0900_ai_ci + and a.device_system_tag COLLATE utf8mb4_0900_ai_ci = b.main_system_tag COLLATE utf8mb4_0900_ai_ci and a.device_name_tag COLLATE utf8mb4_0900_ai_ci = b.sub_system_tag COLLATE utf8mb4_0900_ai_ci + SET b.is_link = 1 + WHERE a.device_building_tag IS NOT NULL and b.is_link < 2"); + + using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) + { + await conn.ExecuteAsync(sb.ToString()); + } } catch (Exception exception) { @@ -814,7 +856,26 @@ namespace Repository.BackendRepository.Implement and b.sub_system_tag COLLATE utf8mb4_0900_ai_ci = a.device_name_tag COLLATE utf8mb4_0900_ai_ci and b.floor_tag COLLATE utf8mb4_0900_ai_ci = a.device_floor_tag COLLATE utf8mb4_0900_ai_ci SET b.is_link = 0 - WHERE b.building_tag IS NULL"); + WHERE a.device_building_tag IS NULL"); + + using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) + { + await conn.ExecuteAsync(sb.ToString()); + } + + sb.Clear(); + + sb.Append($@" SET SQL_SAFE_UPDATES = 0; + UPDATE sub_system_floor b LEFT JOIN ( + select device_building_tag, device_system_tag, device_name_tag, device_floor_tag + from import_niagara_tag + group by device_building_tag, device_system_tag, device_name_tag, device_floor_tag + ) AS a ON b.building_tag COLLATE utf8mb4_0900_ai_ci = a.device_building_tag COLLATE utf8mb4_0900_ai_ci + and b.main_system_tag COLLATE utf8mb4_0900_ai_ci = a.device_system_tag COLLATE utf8mb4_0900_ai_ci + and b.sub_system_tag COLLATE utf8mb4_0900_ai_ci = a.device_name_tag COLLATE utf8mb4_0900_ai_ci + and b.floor_tag COLLATE utf8mb4_0900_ai_ci = a.device_floor_tag COLLATE utf8mb4_0900_ai_ci + SET b.is_link = 1 + WHERE a.device_building_tag IS NOT NULL"); using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) {