From b86a6ff42f676bd7a38d5a3b7a38c9c16c8622cd Mon Sep 17 00:00:00 2001 From: "jay.chang" Date: Wed, 25 Dec 2024 16:26:44 +0800 Subject: [PATCH] =?UTF-8?q?[WebApi]=E6=AD=B7=E5=8F=B2=E8=B3=87=E6=96=992?= =?UTF-8?q?=E8=AA=BF=E6=95=B4=E6=88=90=E9=9A=A8=E6=A3=9F=E5=88=A5=E8=AE=8A?= =?UTF-8?q?=E5=8B=95=20[Backend]=E5=90=8C=E6=AD=A5=E9=82=8F=E8=BC=AF?= =?UTF-8?q?=E8=AA=BF=E6=95=B4=20[BGService]=E6=AD=B8=E6=AA=94=E8=AA=BF?= =?UTF-8?q?=E6=95=B4=E9=81=8E=E6=BF=BE=E9=A0=85=E5=8F=8A=E6=96=B0=E8=A8=AD?= =?UTF-8?q?=E5=82=99=E9=A0=90=E8=A8=AD=E6=9C=80=E5=BE=8C=E6=AD=B8=E6=AA=94?= =?UTF-8?q?=E6=97=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/BuildInfoController.cs | 6 ++-- .../NiagaraDataSynchronizeController.cs | 2 ++ Backend/Models/Device.cs | 4 +-- .../Quartz/Jobs/ArchiveElectricMeterDayJob.cs | 10 +++--- .../ApiControllers/HistoryController.cs | 2 +- .../NiagaraDataSynchronizeRepository.cs | 31 ++++++++++--------- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Backend/Controllers/BuildInfoController.cs b/Backend/Controllers/BuildInfoController.cs index 71176cd..cbae018 100644 --- a/Backend/Controllers/BuildInfoController.cs +++ b/Backend/Controllers/BuildInfoController.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Repository.BackendRepository.Interface; - +using Repository.Extension; using System; using System.Collections.Generic; using System.Diagnostics; @@ -52,6 +52,7 @@ namespace Backend.Controllers WHERE A.deleted = 0 ORDER BY A.priority ASC, A.created_at DESC"; buildInfo = await backendRepository.GetAllAsync(sqlString); + buildInfo.ForEach(x => x.building_tag = x.building_tag.ConvertNormal()); // 字串轉換 apiResult.Code = "0000"; apiResult.Data = buildInfo; @@ -75,7 +76,7 @@ namespace Backend.Controllers public async Task> SaveBuildInfo([FromForm] BuildInfo post) { ApiResult apiResult = new ApiResult(); - + post.building_tag = post.building_tag.ConvertN4(); // 字串轉換 try { //判斷監控主機IP是否重複 @@ -317,6 +318,7 @@ namespace Backend.Controllers public async Task> DeleteOneBuild(string tag) { var apiResult = new ApiResult(); + tag = tag.ConvertN4(); try { string sWhere = @$"deleted = @Deleted AND building_tag = @Tag"; diff --git a/Backend/Controllers/NiagaraDataSynchronizeController.cs b/Backend/Controllers/NiagaraDataSynchronizeController.cs index ed2451c..9571f3d 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 Repository.Extension; namespace Backend.Controllers { @@ -170,6 +171,7 @@ namespace Backend.Controllers // } var buildings = backendRepository.GetAllAsync("select building_tag from building where deleted = 0").Result; + ds.ForEach(x => x.device_building_tag = x.device_building_tag.ConvertN4()); apiResult.Code = "0000"; apiResult.Data = ds.Where(x => buildings.Contains(x.device_building_tag)).ToList(); } diff --git a/Backend/Models/Device.cs b/Backend/Models/Device.cs index f13c69e..9d63981 100644 --- a/Backend/Models/Device.cs +++ b/Backend/Models/Device.cs @@ -85,7 +85,7 @@ namespace Backend.Models /// /// 前次成功日期;下次重新歸檔日期 /// - public System.DateTime archive_lastDate { get; set; } + public System.DateTime? archive_lastDate { get; set; } /// /// 前次執行日期 @@ -279,7 +279,7 @@ namespace Backend.Models /// /// 前次成功日期;下次重新歸檔日期 /// - public System.DateTime archive_lastDate { get; set; } + public System.DateTime archive_lastDate { get; set; } /// /// 前次執行日期 diff --git a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs index 4084dd4..988f726 100644 --- a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs +++ b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs @@ -81,8 +81,8 @@ namespace BackendWorkerService.Quartz.Jobs JObject archiveJsonResult = new JObject(); #endregion #region 找出所有電錶設備 與前次成功日期 - var sWhere_E4 = @$"device_name_tag = '{electricMeterGuid}' and deleted = 0 "; - var sWhere_W1 = @$"device_name_tag = '{waterMeterGuid}' and deleted = 0 "; + var sWhere_E4 = @$"device_name_tag = '{electricMeterGuid}' and deleted = 0 and is_link = 1"; + var sWhere_W1 = @$"device_name_tag = '{waterMeterGuid}' and deleted = 0 and is_link = 1"; var electricMeters = await backgroundServiceRepository.GetAllAsync("device", sWhere_E4); var waterMeters = await backgroundServiceRepository.GetAllAsync("device", sWhere_W1); @@ -94,7 +94,7 @@ namespace BackendWorkerService.Quartz.Jobs #endregion 找出所有電錶設備 #region 找出所有電錶系統的點位 - var sPointWhere = "is_needArchive = 1 and deleted = 0 AND device_name_tag = @sub_system_guid"; + var sPointWhere = "is_needArchive = 1 and deleted = 0 and is_link = 1 AND device_name_tag = @sub_system_guid"; var electricPoints = await backgroundServiceRepository.GetAllAsync("device_item", sPointWhere, new { sub_system_guid = electricMeterGuid }); var waterPoints = await backgroundServiceRepository.GetAllAsync("device_item", sPointWhere, new { sub_system_guid = waterMeterGuid }); #endregion 找出所有電錶系統的點位 @@ -115,7 +115,7 @@ namespace BackendWorkerService.Quartz.Jobs deviceNumberPoint.DeviceNumber = electricMeter.Device_number; deviceNumberPoint.Point = point.points; deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", electricMeter.Device_number, point.points); - deviceNumberPoint.archive_lastDate = electricMeter.archive_lastDate; + deviceNumberPoint.archive_lastDate = electricMeter.archive_lastDate ?? DateTime.Now.AddDays(-1); electricDeviceNumberPoints.Add(deviceNumberPoint); } } @@ -133,7 +133,7 @@ namespace BackendWorkerService.Quartz.Jobs deviceNumberPoint.DeviceNumber = waterMeter.Device_number; deviceNumberPoint.Point = point.points; deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", waterMeter.Device_number, point.points); - deviceNumberPoint.archive_lastDate = waterMeter.archive_lastDate; + deviceNumberPoint.archive_lastDate = waterMeter.archive_lastDate ?? DateTime.Now.AddDays(-1); waterDeviceNumberPoints.Add(deviceNumberPoint); } } diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index fdc4c0c..5cb92e2 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -1129,7 +1129,7 @@ namespace FrontendWebApi.ApiControllers from (SELECT * FROM device d WHERE {wheres_str}) a - join building b on b.building_tag = a.device_building_tag + join building b on b.building_tag = a.device_building_tag and b.deleted = 0 join variable v1 on v1.system_value = a.device_system_tag and v1.deleted = 0 and v1.system_type = 'device_system_category_layer2' join variable v2 on v2.system_value = a.device_name_tag and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3' order by b.priority,v1.system_priority,v2.system_priority,a.priority,a.device_serial_tag"; diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index b740160..8fd1fc6 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -655,18 +655,10 @@ SET FOREIGN_KEY_CHECKS = 1;"; and d.device_name_tag = m.device_name_tag and d.points = m.device_point_name and d.full_name = m.full_name - SET d.is_link = case when device_point_name is null then 0 else 1 end; + and m.device_building_tag collate utf8mb4_0900_ai_ci = d.device_building_tag + SET d.is_link = case when device_point_name is null then 0 else 1 end, + d.parent_path = m.parent_path; - 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 - and d.full_name = m.full_name - and d.is_show_history = m.is_history - SET d.is_show_history = case when device_point_name is null then 0 else 1 end - where (m.is_history = 1 or d.is_show_history); "); await conn.ExecuteAsync(sb.ToString()); @@ -984,9 +976,20 @@ SET FOREIGN_KEY_CHECKS = 1;"; StringBuilder sb = new StringBuilder(); //先全部關閉 //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);"); + sb.Append(@"UPDATE device_item d + SET is_show_history = CASE + WHEN EXISTS ( + SELECT 1 + FROM import_niagara_item m + WHERE 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.full_name = d.full_name + AND m.is_history = 1 + ) THEN 1 + ELSE 0 + END; + "); await conn.ExecuteAsync(sb.ToString()); } catch (Exception exception)