From 0060be9c4d54a2014d36fe73e33d2674c5295480 Mon Sep 17 00:00:00 2001 From: "jay.chang" Date: Wed, 8 May 2024 13:09:19 +0800 Subject: [PATCH] =?UTF-8?q?[BGService][WebAPI]=E7=87=88=E6=8E=A7=E6=8E=92?= =?UTF-8?q?=E7=A8=8B=E4=BF=AE=E6=AD=A3=E8=A8=AD=E5=82=99split=E5=BE=8C?= =?UTF-8?q?=E9=96=8B=E9=A0=AD=E6=95=B8=E5=AD=97=E9=9C=80=E8=BD=89=E6=8F=9B?= =?UTF-8?q?=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Quartz/Jobs/LightScheduleJob .cs | 9 +++++--- .../ApiControllers/LightScheduleController.cs | 8 ++++++- Repository/Models/Share.cs | 23 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) 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; + } + } }