[後台] 修改排程問題

This commit is contained in:
dev02 2023-06-08 09:55:44 +08:00
parent b110151c8e
commit cacab7f20e
2 changed files with 132 additions and 116 deletions

View File

@ -127,7 +127,7 @@ namespace BackendWorkerService.Quartz.Jobs
obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault(); obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault();
obixApiConfig.UserName = ed.AESDecrypt(variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault()); obixApiConfig.UserName = ed.AESDecrypt(variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault());
obixApiConfig.Password = ed.AESDecrypt(variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault()); obixApiConfig.Password = ed.AESDecrypt(variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault());
var station = await backgroundServiceRepository.GetOneAsync<string>($@"select system_value from variable where system_type = 'obixStatus' and deleted = 0");
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(obixApiConfig.UserName + ":" + obixApiConfig.Password)); String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(obixApiConfig.UserName + ":" + obixApiConfig.Password));
#endregion obix #endregion obix
@ -160,8 +160,8 @@ namespace BackendWorkerService.Quartz.Jobs
foreach (var deviceNumberPoint in electricDeviceNumberPoints) foreach (var deviceNumberPoint in electricDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveRequest.PreAuthenticate = true;
@ -217,8 +217,8 @@ namespace BackendWorkerService.Quartz.Jobs
foreach (var deviceNumberPoint in waterDeviceNumberPoints) foreach (var deviceNumberPoint in waterDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveRequest.PreAuthenticate = true;
@ -628,8 +628,8 @@ namespace BackendWorkerService.Quartz.Jobs
List<Dictionary<string, object>> waterArchiveWeekRawDatas = new List<Dictionary<string, object>>(); List<Dictionary<string, object>> waterArchiveWeekRawDatas = new List<Dictionary<string, object>>();
foreach (var deviceNumberPoint in electricDeviceNumberPoints) foreach (var deviceNumberPoint in electricDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveRequest.PreAuthenticate = true;
@ -685,8 +685,8 @@ namespace BackendWorkerService.Quartz.Jobs
} }
foreach (var deviceNumberPoint in waterDeviceNumberPoints) foreach (var deviceNumberPoint in waterDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveRequest.PreAuthenticate = true;
@ -993,8 +993,8 @@ namespace BackendWorkerService.Quartz.Jobs
List<Dictionary<string, object>> waterArchiveMonthRawDatas = new List<Dictionary<string, object>>(); List<Dictionary<string, object>> waterArchiveMonthRawDatas = new List<Dictionary<string, object>>();
foreach (var deviceNumberPoint in electricDeviceNumberPoints) foreach (var deviceNumberPoint in electricDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveRequest.PreAuthenticate = true;
@ -1049,8 +1049,8 @@ namespace BackendWorkerService.Quartz.Jobs
} }
foreach (var deviceNumberPoint in waterDeviceNumberPoints) foreach (var deviceNumberPoint in waterDeviceNumberPoints)
{ {
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveRequest.Method = "POST"; archiveRequest.Method = "POST";
archiveRequest.Headers.Add("Authorization", "Basic " + encoded); archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveRequest.PreAuthenticate = true; archiveRequest.PreAuthenticate = true;

View File

@ -16,6 +16,7 @@ using Repository.Helper;
using Repository.BackendRepository.Interface; using Repository.BackendRepository.Interface;
using Repository.BackendRepository.Implement; using Repository.BackendRepository.Implement;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Infrastructure;
namespace BackendWorkerService.Services.Implement namespace BackendWorkerService.Services.Implement
{ {
@ -39,6 +40,7 @@ namespace BackendWorkerService.Services.Implement
bool result = false; bool result = false;
int repeatTimes = 0; int repeatTimes = 0;
string targetTable = string.Empty; string targetTable = string.Empty;
string sql_error_day = string.Empty;
EDFunction ed = new EDFunction(); EDFunction ed = new EDFunction();
XmlDocument xmlDocument = new XmlDocument(); XmlDocument xmlDocument = new XmlDocument();
@ -61,12 +63,12 @@ namespace BackendWorkerService.Services.Implement
obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault(); obixApiConfig.ApiBase = variableObix.Where(x => x.Name == "ApiBase").Select(x => x.Value).FirstOrDefault();
obixApiConfig.UserName = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault(); obixApiConfig.UserName = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
obixApiConfig.Password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault(); obixApiConfig.Password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
var station = await backgroundServiceRepository.GetOneAsync<string>($@"select system_value from variable where system_type = 'obixStatus' and deleted = 0");
encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(obixApiConfig.UserName + ":" + obixApiConfig.Password)); encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(obixApiConfig.UserName + ":" + obixApiConfig.Password));
#endregion obix #endregion obix
//取得錯誤的設備sql format //取得錯誤的設備sql format
var sql_error_format = @"SELECT * FROM {0} WHERE is_complete = 0 AND repeat_times < @RepeatTimes"; var sql_error_format = @"SELECT * FROM {0} WHERE is_complete = 0 AND repeat_times < @RepeatTimes AND (point = 'KWH' or point = 'RCV')";
//MY 新增/修改sql format //MY 新增/修改sql format
var MYsql_update_format = @" var MYsql_update_format = @"
@ -187,8 +189,8 @@ namespace BackendWorkerService.Services.Implement
// <reltime name='interval' val = 'PT1H' /> // <reltime name='interval' val = 'PT1H' />
// </obj>"; // </obj>";
// HttpWebRequest archiveHourRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); // HttpWebRequest archiveHourRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
// //HttpWebRequest archiveHourRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); // //HttpWebRequest archiveHourRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
// archiveHourRequest.Method = "POST"; // archiveHourRequest.Method = "POST";
// archiveHourRequest.Headers.Add("Authorization", "Basic " + encoded); // archiveHourRequest.Headers.Add("Authorization", "Basic " + encoded);
// archiveHourRequest.PreAuthenticate = true; // archiveHourRequest.PreAuthenticate = true;
@ -248,96 +250,110 @@ namespace BackendWorkerService.Services.Implement
#endregion #endregion
#region #region
string schema = await backgroundServiceRepository.GetOneAsync<string>(@"
select system_value from variable where system_type = 'project_name' and deleted = 0");
//取得所有須補償的設備資訊 //取得所有須補償的設備資訊
targetTable = "archive_electric_meter_day"; targetTable = await backgroundServiceRepository.GetOneAsync<string>($@"
var sql_error_day = string.Format(sql_error_format, targetTable); select table_name
var electric_error_days = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_day, new { RepeatTimes = repeatTimes }); from information_schema.`TABLES`
List<Dictionary<string, object>> electricArchiveDayRawDatas = new List<Dictionary<string, object>>(); where TABLE_NAME like 'archive_electric_meter_day%' and TABLE_SCHEMA = '{schema.Split('/')[0]}'
if (electric_error_days.Count() > 0) order by TABLE_NAME desc limit 1 ");
if (!string.IsNullOrEmpty(targetTable))
{ {
foreach (var error_day in electric_error_days) sql_error_day = string.Format(sql_error_format, targetTable);
var electric_error_days = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_day, new { RepeatTimes = repeatTimes });
List<Dictionary<string, object>> electricArchiveDayRawDatas = new List<Dictionary<string, object>>();
if (electric_error_days.Count() > 0)
{ {
DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint(); foreach (var error_day in electric_error_days)
deviceNumberPoint.DeviceNumber = error_day.Device_number;
deviceNumberPoint.Point = error_day.Point;
deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_day.Device_number, error_day.Point);
var startTimestamp = string.Format("{0}+08:00", error_day.Start_timestamp.Replace(" ", "T"));
var endTimestamp = string.Format("{0}+08:00", error_day.End_timestamp.Replace(" ", "T"));
var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
<abstime name='start' val='{startTimestamp}' />
<abstime name='end' val='{endTimestamp}' />
<reltime name='interval' val = 'PT1D' />
</obj>";
HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveDayRequest.Method = "POST";
archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveDayRequest.PreAuthenticate = true;
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
using (Stream reqStream = archiveDayRequest.GetRequestStream())
{ {
reqStream.Write(byteArray, 0, byteArray.Length); DeviceNumberPoint deviceNumberPoint = new DeviceNumberPoint();
} deviceNumberPoint.DeviceNumber = error_day.Device_number;
deviceNumberPoint.Point = error_day.Point;
deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", error_day.Device_number, error_day.Point);
HttpWebResponse archiveDayResponse = (HttpWebResponse)archiveDayRequest.GetResponse(); var startTimestamp = string.Format("{0}+08:00", error_day.Start_timestamp.Replace(" ", "T"));
var archiveDayResponseContent = new StreamReader(archiveDayResponse.GetResponseStream()).ReadToEnd(); var endTimestamp = string.Format("{0}+08:00", error_day.End_timestamp.Replace(" ", "T"));
var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
<abstime name='start' val='{startTimestamp}' />
<abstime name='end' val='{endTimestamp}' />
<reltime name='interval' val = 'PT1D' />
</obj>";
xmlDocument.LoadXml(archiveDayResponseContent); HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
string archiveDayJson = JsonConvert.SerializeXmlNode(xmlDocument); //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
JObject archiveDayJsonResult = (JObject)JsonConvert.DeserializeObject(archiveDayJson); archiveDayRequest.Method = "POST";
archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveDayRequest.PreAuthenticate = true;
if (archiveDayJsonResult.ContainsKey("err")) //抓取錯誤 byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
{ using (Stream reqStream = archiveDayRequest.GetRequestStream())
Dictionary<string, object> archiveDayRawData = new Dictionary<string, object>();
archiveDayRawData.Add("@device_number", error_day.Device_number);
archiveDayRawData.Add("@point", error_day.Point);
archiveDayRawData.Add("@start_timestamp", DateTime.Parse(error_day.Start_timestamp, System.Globalization.CultureInfo.CurrentCulture));
archiveDayRawData.Add("@end_timestamp", DateTime.Parse(error_day.End_timestamp, System.Globalization.CultureInfo.CurrentCulture));
archiveDayRawData.Add("@is_complete", 0);
archiveDayRawData.Add("@repeat_times", ++error_day.Repeat_times);
archiveDayRawData.Add("@fail_reason", archiveDayJson);
archiveDayRawData.Add("@count_rawdata", 0);
archiveDayRawData.Add("@min_rawdata", 0);
archiveDayRawData.Add("@max_rawdata", 0);
archiveDayRawData.Add("@avg_rawdata", 0);
archiveDayRawData.Add("@sum_rawdata", 0);
archiveDayRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
electricArchiveDayRawDatas.Add(archiveDayRawData);
}
if (archiveDayJsonResult.ContainsKey("obj")) //表示可以讀取到內容
{
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveDayJsonResult);
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
{ {
electricArchiveDayRawDatas.AddRange(ArrangeRawDatas); reqStream.Write(byteArray, 0, byteArray.Length);
}
HttpWebResponse archiveDayResponse = (HttpWebResponse)archiveDayRequest.GetResponse();
var archiveDayResponseContent = new StreamReader(archiveDayResponse.GetResponseStream()).ReadToEnd();
xmlDocument.LoadXml(archiveDayResponseContent);
string archiveDayJson = JsonConvert.SerializeXmlNode(xmlDocument);
JObject archiveDayJsonResult = (JObject)JsonConvert.DeserializeObject(archiveDayJson);
if (archiveDayJsonResult.ContainsKey("err")) //抓取錯誤
{
Dictionary<string, object> archiveDayRawData = new Dictionary<string, object>();
archiveDayRawData.Add("@device_number", error_day.Device_number);
archiveDayRawData.Add("@point", error_day.Point);
archiveDayRawData.Add("@start_timestamp", DateTime.Parse(error_day.Start_timestamp, System.Globalization.CultureInfo.CurrentCulture));
archiveDayRawData.Add("@end_timestamp", DateTime.Parse(error_day.End_timestamp, System.Globalization.CultureInfo.CurrentCulture));
archiveDayRawData.Add("@is_complete", 0);
archiveDayRawData.Add("@repeat_times", ++error_day.Repeat_times);
archiveDayRawData.Add("@fail_reason", archiveDayJson);
archiveDayRawData.Add("@count_rawdata", 0);
archiveDayRawData.Add("@min_rawdata", 0);
archiveDayRawData.Add("@max_rawdata", 0);
archiveDayRawData.Add("@avg_rawdata", 0);
archiveDayRawData.Add("@sum_rawdata", 0);
archiveDayRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
electricArchiveDayRawDatas.Add(archiveDayRawData);
}
if (archiveDayJsonResult.ContainsKey("obj")) //表示可以讀取到內容
{
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveDayJsonResult);
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
{
electricArchiveDayRawDatas.AddRange(ArrangeRawDatas);
}
}
}
if (electricArchiveDayRawDatas.Count() > 0)
{
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
var sql_error_update = string.Format(sql_update_format, targetTable);
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, electricArchiveDayRawDatas);
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
{
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveDayRawDatas);
} }
} }
} }
if (electricArchiveDayRawDatas.Count() > 0)
{
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
var sql_error_update = string.Format(sql_update_format, targetTable);
if (!string.IsNullOrEmpty(saveToMSDB) && saveToMSDB == "1")
{
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveDayRawDatas);
}
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, electricArchiveDayRawDatas);
}
} }
targetTable = "archive_water_meter_day"; targetTable = await backgroundServiceRepository.GetOneAsync<string>($@"
sql_error_day = string.Format(sql_error_format, targetTable); select table_name
var water_error_days = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_day, new { RepeatTimes = repeatTimes }); from information_schema.`TABLES`
List<Dictionary<string, object>> waterArchiveDayRawDatas = new List<Dictionary<string, object>>(); where TABLE_NAME like 'archive_water_meter_day%' and TABLE_SCHEMA = '{schema.Split('/')[0]}'
if (water_error_days.Count() > 0) order by TABLE_NAME desc limit 1 ");
if (!string.IsNullOrEmpty(targetTable))
{
sql_error_day = string.Format(sql_error_format, targetTable);
var water_error_days = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_day, new { RepeatTimes = repeatTimes });
List<Dictionary<string, object>> waterArchiveDayRawDatas = new List<Dictionary<string, object>>();
if (water_error_days.Count() > 0)
{ {
foreach (var error_day in water_error_days) foreach (var error_day in water_error_days)
{ {
@ -348,15 +364,14 @@ namespace BackendWorkerService.Services.Implement
var startTimestamp = string.Format("{0}+08:00", error_day.Start_timestamp.Replace(" ", "T")); var startTimestamp = string.Format("{0}+08:00", error_day.Start_timestamp.Replace(" ", "T"));
var endTimestamp = string.Format("{0}+08:00", error_day.End_timestamp.Replace(" ", "T")); var endTimestamp = string.Format("{0}+08:00", error_day.End_timestamp.Replace(" ", "T"));
var historyQueryFilter = $@"<obj is='obix: HistoryFilter'> var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
<abstime name='start' val='{startTimestamp}' /> <abstime name='start' val='{startTimestamp}' />
<abstime name='end' val='{endTimestamp}' /> <abstime name='end' val='{endTimestamp}' />
<reltime name='interval' val = 'PT1D' /> <reltime name='interval' val = 'PT1D' />
</obj>"; </obj>";
HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveDayRequest.Method = "POST"; archiveDayRequest.Method = "POST";
archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded); archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveDayRequest.PreAuthenticate = true; archiveDayRequest.PreAuthenticate = true;
@ -416,6 +431,7 @@ namespace BackendWorkerService.Services.Implement
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveDayRawDatas); await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveDayRawDatas);
} }
} }
}
#endregion #endregion
#region #region
@ -442,8 +458,8 @@ namespace BackendWorkerService.Services.Implement
<reltime name='interval' val = 'PT7D' /> <reltime name='interval' val = 'PT7D' />
</obj>"; </obj>";
HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveWeekRequest.Method = "POST"; archiveWeekRequest.Method = "POST";
archiveWeekRequest.Headers.Add("Authorization", "Basic " + encoded); archiveWeekRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveWeekRequest.PreAuthenticate = true; archiveWeekRequest.PreAuthenticate = true;
@ -526,8 +542,8 @@ namespace BackendWorkerService.Services.Implement
<reltime name='interval' val = 'PT7D' /> <reltime name='interval' val = 'PT7D' />
</obj>"; </obj>";
HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveWeekRequest.Method = "POST"; archiveWeekRequest.Method = "POST";
archiveWeekRequest.Headers.Add("Authorization", "Basic " + encoded); archiveWeekRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveWeekRequest.PreAuthenticate = true; archiveWeekRequest.PreAuthenticate = true;
@ -616,8 +632,8 @@ namespace BackendWorkerService.Services.Implement
<reltime name='interval' val = 'PT{dayInMonth}D' /> <reltime name='interval' val = 'PT{dayInMonth}D' />
</obj>"; </obj>";
HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveMonthRequest.Method = "POST"; archiveMonthRequest.Method = "POST";
archiveMonthRequest.Headers.Add("Authorization", "Basic " + encoded); archiveMonthRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveMonthRequest.PreAuthenticate = true; archiveMonthRequest.PreAuthenticate = true;
@ -674,11 +690,11 @@ namespace BackendWorkerService.Services.Implement
{ {
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveMonthRawDatas); await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, electricArchiveMonthRawDatas);
} }
await backgroundServiceRepository.ExecuteSql(MYsql_update_format, electricArchiveMonthRawDatas); await backgroundServiceRepository.ExecuteSql(Mysql_error_update, electricArchiveMonthRawDatas);
} }
} }
targetTable = "archive_electric_meter_month"; targetTable = "archive_water_meter_month";
sql_error_month = string.Format(sql_error_format, targetTable); sql_error_month = string.Format(sql_error_format, targetTable);
var water_error_months = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_month, new { RepeatTimes = repeatTimes }); var water_error_months = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_month, new { RepeatTimes = repeatTimes });
List<Dictionary<string, object>> waterArchiveMonthRawDatas = new List<Dictionary<string, object>>(); List<Dictionary<string, object>> waterArchiveMonthRawDatas = new List<Dictionary<string, object>>();
@ -703,8 +719,8 @@ namespace BackendWorkerService.Services.Implement
<reltime name='interval' val = 'PT{dayInMonth}D' /> <reltime name='interval' val = 'PT{dayInMonth}D' />
</obj>"; </obj>";
HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/"); HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/"); //HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
archiveMonthRequest.Method = "POST"; archiveMonthRequest.Method = "POST";
archiveMonthRequest.Headers.Add("Authorization", "Basic " + encoded); archiveMonthRequest.Headers.Add("Authorization", "Basic " + encoded);
archiveMonthRequest.PreAuthenticate = true; archiveMonthRequest.PreAuthenticate = true;
@ -761,7 +777,7 @@ namespace BackendWorkerService.Services.Implement
{ {
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveMonthRawDatas); await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveMonthRawDatas);
} }
await backgroundServiceRepository.ExecuteSql(MYsql_update_format, waterArchiveMonthRawDatas); await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveMonthRawDatas);
} }
} }
#endregion #endregion