[BGService][WebAPI]燈控排程修正設備split後開頭數字需轉換問題
This commit is contained in:
parent
e9189fe047
commit
0060be9c4d
@ -25,6 +25,8 @@ using Microsoft.Extensions.Hosting;
|
|||||||
using Repository.FrontendRepository.Implement;
|
using Repository.FrontendRepository.Implement;
|
||||||
using iTextSharp.text;
|
using iTextSharp.text;
|
||||||
using NPOI.SS.Formula.Functions;
|
using NPOI.SS.Formula.Functions;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Repository.Models;
|
||||||
|
|
||||||
namespace BackendWorkerService.Quartz.Jobs
|
namespace BackendWorkerService.Quartz.Jobs
|
||||||
{
|
{
|
||||||
@ -54,7 +56,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await task_Detail.InsertWorkTime("LightScheduleJob", "light_schedule");
|
await task_Detail.InsertWorkTime("LightScheduleJob", "light_schedule");
|
||||||
#region 參考
|
|
||||||
var TimeNow = DateTime.Now.ToString("dddd HH:mm");
|
var TimeNow = DateTime.Now.ToString("dddd HH:mm");
|
||||||
var schedule = await backendRepository.GetAllAsync<Schedule>("light_schedule","deleted = 0 and status = 1");
|
var schedule = await backendRepository.GetAllAsync<Schedule>("light_schedule","deleted = 0 and status = 1");
|
||||||
string date = DateTime.Now.ToString("yyyy-MM-dd");
|
string date = DateTime.Now.ToString("yyyy-MM-dd");
|
||||||
@ -127,7 +129,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
logger.LogInformation($"【LightScheduleJob】【燈控排程關閉成功】排程名稱 :{oneSchedule.full_name}");
|
logger.LogInformation($"【LightScheduleJob】【燈控排程關閉成功】排程名稱 :{oneSchedule.full_name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
|
|
||||||
await task_Detail.InsertWorkTime_End("LightScheduleJob", "light_schedule");
|
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();
|
string pass = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
|
||||||
foreach (var deviceNum in deviceNumList)
|
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";
|
var html = $"{url}obix/config/Arena/" + $"{d[0]}/{d[1]}/{d[2]}/{d[3]}/{deviceNum}/SSC/set";
|
||||||
string authInfo = account + ":" + pass;
|
string authInfo = account + ":" + pass;
|
||||||
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
|
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
|
||||||
|
@ -6,6 +6,7 @@ using Newtonsoft.Json;
|
|||||||
using Repository.BackendRepository.Implement;
|
using Repository.BackendRepository.Implement;
|
||||||
using Repository.BackendRepository.Interface;
|
using Repository.BackendRepository.Interface;
|
||||||
using Repository.FrontendRepository.Interface;
|
using Repository.FrontendRepository.Interface;
|
||||||
|
using Serilog.Core;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -340,7 +341,8 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
string pass = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
|
string pass = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
|
||||||
foreach (var deviceNum in deviceNumList)
|
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";
|
var html = $"{url}obix/config/Arena/" + $"{d[0]}/{d[1]}/{d[2]}/{d[3]}/{deviceNum}/SSC/set";
|
||||||
string authInfo = account + ":" + pass;
|
string authInfo = account + ":" + pass;
|
||||||
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
|
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
|
||||||
@ -360,6 +362,10 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
{
|
{
|
||||||
strResponse = sr.ReadToEnd();
|
strResponse = sr.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
if (strResponse.Contains("<err"))
|
||||||
|
{
|
||||||
|
Logger.LogWarning($"【LightScheduleJob 】【set niagara light value fail】[排程 名稱]:{oneSchedule.full_name},[設備 名稱]:{deviceNum}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
apiResult.Msg = "執行成功";
|
apiResult.Msg = "執行成功";
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
|
@ -7,6 +7,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Repository.Models
|
namespace Repository.Models
|
||||||
@ -263,4 +264,26 @@ namespace Repository.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 轉換Niagara tag符號
|
||||||
|
/// </summary>
|
||||||
|
public class TagChangeFunction
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 拆解tagName後,若開頭為數字則做轉換
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user