[後台] 修改排程問題
This commit is contained in:
parent
b110151c8e
commit
cacab7f20e
@ -127,7 +127,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
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.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));
|
||||
#endregion 取得obix 設定
|
||||
|
||||
@ -160,8 +160,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
foreach (var deviceNumberPoint in electricDeviceNumberPoints)
|
||||
{
|
||||
|
||||
archiveRequest = (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/");
|
||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest.Method = "POST";
|
||||
archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveRequest.PreAuthenticate = true;
|
||||
@ -176,7 +176,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
||||
archiveResponse.Dispose();
|
||||
archiveResponse.Close();
|
||||
|
||||
|
||||
xmlDocument.LoadXml(archiveResponseContent);
|
||||
archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||
archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
|
||||
@ -217,12 +217,12 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
foreach (var deviceNumberPoint in waterDeviceNumberPoints)
|
||||
{
|
||||
|
||||
archiveRequest = (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/");
|
||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest.Method = "POST";
|
||||
archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveRequest.PreAuthenticate = true;
|
||||
|
||||
|
||||
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||
using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||
@ -628,12 +628,12 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
List<Dictionary<string, object>> waterArchiveWeekRawDatas = new List<Dictionary<string, object>>();
|
||||
foreach (var deviceNumberPoint in electricDeviceNumberPoints)
|
||||
{
|
||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest.Method = "POST";
|
||||
archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveRequest.PreAuthenticate = true;
|
||||
|
||||
|
||||
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||
using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||
@ -685,12 +685,12 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
}
|
||||
foreach (var deviceNumberPoint in waterDeviceNumberPoints)
|
||||
{
|
||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest.Method = "POST";
|
||||
archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveRequest.PreAuthenticate = true;
|
||||
|
||||
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||
using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||
{
|
||||
@ -993,18 +993,18 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
List<Dictionary<string, object>> waterArchiveMonthRawDatas = new List<Dictionary<string, object>>();
|
||||
foreach (var deviceNumberPoint in electricDeviceNumberPoints)
|
||||
{
|
||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest.Method = "POST";
|
||||
archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveRequest.PreAuthenticate = true;
|
||||
|
||||
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||
using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(byteArray, 0, byteArray.Length);
|
||||
}
|
||||
|
||||
|
||||
archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
|
||||
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
||||
archiveResponse.Dispose();
|
||||
@ -1049,12 +1049,12 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
}
|
||||
foreach (var deviceNumberPoint in waterDeviceNumberPoints)
|
||||
{
|
||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveRequest.Method = "POST";
|
||||
archiveRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveRequest.PreAuthenticate = true;
|
||||
|
||||
|
||||
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||
using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||
|
@ -16,6 +16,7 @@ using Repository.Helper;
|
||||
using Repository.BackendRepository.Interface;
|
||||
using Repository.BackendRepository.Implement;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
|
||||
namespace BackendWorkerService.Services.Implement
|
||||
{
|
||||
@ -39,6 +40,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
bool result = false;
|
||||
int repeatTimes = 0;
|
||||
string targetTable = string.Empty;
|
||||
string sql_error_day = string.Empty;
|
||||
|
||||
EDFunction ed = new EDFunction();
|
||||
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.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();
|
||||
|
||||
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));
|
||||
#endregion 取得obix 設定
|
||||
|
||||
//取得錯誤的設備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
|
||||
var MYsql_update_format = @"
|
||||
@ -113,7 +115,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
WHERE ROW_COUNT() = 0;";
|
||||
//新增/修改sql format
|
||||
var sql_update_format = @"BEGIN TRANSACTION;
|
||||
|
||||
|
||||
UPDATE {0} SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = @min_rawdata,
|
||||
@ -187,8 +189,8 @@ namespace BackendWorkerService.Services.Implement
|
||||
// <reltime name='interval' val = 'PT1H' />
|
||||
// </obj>";
|
||||
|
||||
// HttpWebRequest archiveHourRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{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}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
// //HttpWebRequest archiveHourRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
// archiveHourRequest.Method = "POST";
|
||||
// archiveHourRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
// archiveHourRequest.PreAuthenticate = true;
|
||||
@ -248,96 +250,110 @@ namespace BackendWorkerService.Services.Implement
|
||||
#endregion 時歸檔補償
|
||||
|
||||
#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";
|
||||
var 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)
|
||||
targetTable = await backgroundServiceRepository.GetOneAsync<string>($@"
|
||||
select table_name
|
||||
from information_schema.`TABLES`
|
||||
where TABLE_NAME like 'archive_electric_meter_day%' and TABLE_SCHEMA = '{schema.Split('/')[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();
|
||||
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())
|
||||
foreach (var error_day in electric_error_days)
|
||||
{
|
||||
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 archiveDayResponseContent = new StreamReader(archiveDayResponse.GetResponseStream()).ReadToEnd();
|
||||
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>";
|
||||
|
||||
xmlDocument.LoadXml(archiveDayResponseContent);
|
||||
string archiveDayJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||
JObject archiveDayJsonResult = (JObject)JsonConvert.DeserializeObject(archiveDayJson);
|
||||
HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveDayRequest.Method = "POST";
|
||||
archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveDayRequest.PreAuthenticate = true;
|
||||
|
||||
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)
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||
using (Stream reqStream = archiveDayRequest.GetRequestStream())
|
||||
{
|
||||
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";
|
||||
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)
|
||||
targetTable = await backgroundServiceRepository.GetOneAsync<string>($@"
|
||||
select table_name
|
||||
from information_schema.`TABLES`
|
||||
where TABLE_NAME like 'archive_water_meter_day%' and TABLE_SCHEMA = '{schema.Split('/')[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)
|
||||
{
|
||||
@ -348,15 +364,14 @@ namespace BackendWorkerService.Services.Implement
|
||||
|
||||
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/");
|
||||
HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveDayRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveDayRequest.Method = "POST";
|
||||
archiveDayRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveDayRequest.PreAuthenticate = true;
|
||||
@ -416,6 +431,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveDayRawDatas);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion 天歸檔補償
|
||||
|
||||
#region 週歸檔補償
|
||||
@ -442,8 +458,8 @@ namespace BackendWorkerService.Services.Implement
|
||||
<reltime name='interval' val = 'PT7D' />
|
||||
</obj>";
|
||||
|
||||
HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{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}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveWeekRequest.Method = "POST";
|
||||
archiveWeekRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveWeekRequest.PreAuthenticate = true;
|
||||
@ -526,8 +542,8 @@ namespace BackendWorkerService.Services.Implement
|
||||
<reltime name='interval' val = 'PT7D' />
|
||||
</obj>";
|
||||
|
||||
HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{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}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveWeekRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveWeekRequest.Method = "POST";
|
||||
archiveWeekRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveWeekRequest.PreAuthenticate = true;
|
||||
@ -616,8 +632,8 @@ namespace BackendWorkerService.Services.Implement
|
||||
<reltime name='interval' val = 'PT{dayInMonth}D' />
|
||||
</obj>";
|
||||
|
||||
HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{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}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveMonthRequest.Method = "POST";
|
||||
archiveMonthRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveMonthRequest.PreAuthenticate = true;
|
||||
@ -674,11 +690,11 @@ namespace BackendWorkerService.Services.Implement
|
||||
{
|
||||
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);
|
||||
var water_error_months = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_month, new { RepeatTimes = repeatTimes });
|
||||
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' />
|
||||
</obj>";
|
||||
|
||||
HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/FIC_Center/{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}/{deviceNumberPoint.FullDeviceNumberPoint}/~historyRollup/");
|
||||
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/H_E1_B1F_MVCB_MVCBH_V1/~historyRollup/");
|
||||
archiveMonthRequest.Method = "POST";
|
||||
archiveMonthRequest.Headers.Add("Authorization", "Basic " + encoded);
|
||||
archiveMonthRequest.PreAuthenticate = true;
|
||||
@ -761,7 +777,7 @@ namespace BackendWorkerService.Services.Implement
|
||||
{
|
||||
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, waterArchiveMonthRawDatas);
|
||||
}
|
||||
await backgroundServiceRepository.ExecuteSql(MYsql_update_format, waterArchiveMonthRawDatas);
|
||||
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, waterArchiveMonthRawDatas);
|
||||
}
|
||||
}
|
||||
#endregion 月歸檔補償
|
||||
|
Loading…
Reference in New Issue
Block a user