diff --git a/BackendWorkerService/Quartz/Jobs/LightScheduleJob .cs b/BackendWorkerService/Quartz/Jobs/LightScheduleJob .cs index 6866f2b..9c3ffa0 100644 --- a/BackendWorkerService/Quartz/Jobs/LightScheduleJob .cs +++ b/BackendWorkerService/Quartz/Jobs/LightScheduleJob .cs @@ -25,6 +25,8 @@ using Microsoft.Extensions.Hosting; using Repository.FrontendRepository.Implement; using iTextSharp.text; using NPOI.SS.Formula.Functions; +using System.Text.RegularExpressions; +using Repository.Models; namespace BackendWorkerService.Quartz.Jobs { @@ -54,7 +56,7 @@ namespace BackendWorkerService.Quartz.Jobs try { await task_Detail.InsertWorkTime("LightScheduleJob", "light_schedule"); - #region 參考 + var TimeNow = DateTime.Now.ToString("dddd HH:mm"); var schedule = await backendRepository.GetAllAsync("light_schedule","deleted = 0 and status = 1"); string date = DateTime.Now.ToString("yyyy-MM-dd"); @@ -127,7 +129,7 @@ namespace BackendWorkerService.Quartz.Jobs logger.LogInformation($"【LightScheduleJob】【燈控排程關閉成功】排程名稱 :{oneSchedule.full_name}"); } } - #endregion + await task_Detail.InsertWorkTime_End("LightScheduleJob", "light_schedule"); } @@ -157,7 +159,8 @@ namespace BackendWorkerService.Quartz.Jobs string pass = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault(); foreach (var deviceNum in deviceNumList) { - var d = deviceNum.Split("_"); + TagChangeFunction tagChange = new TagChangeFunction(); + var d = tagChange.AddStringIfStartsWithDigit(deviceNum, "$3"); var html = $"{url}obix/config/Arena/" + $"{d[0]}/{d[1]}/{d[2]}/{d[3]}/{deviceNum}/SSC/set"; string authInfo = account + ":" + pass; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); diff --git a/FrontendWebApi/ApiControllers/LightScheduleController.cs b/FrontendWebApi/ApiControllers/LightScheduleController.cs index a43657a..5f2357e 100644 --- a/FrontendWebApi/ApiControllers/LightScheduleController.cs +++ b/FrontendWebApi/ApiControllers/LightScheduleController.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json; using Repository.BackendRepository.Implement; using Repository.BackendRepository.Interface; using Repository.FrontendRepository.Interface; +using Serilog.Core; using System; using System.Collections.Generic; using System.IO; @@ -340,7 +341,8 @@ namespace FrontendWebApi.ApiControllers string pass = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault(); foreach (var deviceNum in deviceNumList) { - var d = deviceNum.Split("_"); + Repository.Models.TagChangeFunction tagChange = new Repository.Models.TagChangeFunction(); + var d = tagChange.AddStringIfStartsWithDigit(deviceNum, "$3"); var html = $"{url}obix/config/Arena/" + $"{d[0]}/{d[1]}/{d[2]}/{d[3]}/{deviceNum}/SSC/set"; string authInfo = account + ":" + pass; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); @@ -360,6 +362,10 @@ namespace FrontendWebApi.ApiControllers { strResponse = sr.ReadToEnd(); } + if (strResponse.Contains(" + /// 轉換Niagara tag符號 + /// + public class TagChangeFunction + { + /// + /// 拆解tagName後,若開頭為數字則做轉換 + /// + public string[] AddStringIfStartsWithDigit(string deviceNumber, string appendString) + { + Regex regex = new Regex(@"^\d"); + string[] parts = deviceNumber.Split("_"); + for (int i = 0; i < parts.Length; i++) + { + if (regex.IsMatch(parts[i])) + { + parts[i] = appendString + parts[i]; + } + } + return parts; + } + } }