[BackendWorkService]新增日歸檔的最後歸檔日期判斷,月歸檔會從最後歸檔日期開始補做的邏輯
This commit is contained in:
parent
e91066df9c
commit
30aa417f78
@ -82,6 +82,7 @@ namespace Backend.Models
|
|||||||
public List<DeviceDisaster> Device_disasters { get; set; } //防災類型
|
public List<DeviceDisaster> Device_disasters { get; set; } //防災類型
|
||||||
public List<DeviceNode> Device_nodes { get; set; } //設備子節點
|
public List<DeviceNode> Device_nodes { get; set; } //設備子節點
|
||||||
|
|
||||||
|
public System.DateTime created_at { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 前次成功日期;下次重新歸檔日期
|
/// 前次成功日期;下次重新歸檔日期
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -277,6 +278,8 @@ namespace Backend.Models
|
|||||||
public string Point { get; set; }
|
public string Point { get; set; }
|
||||||
public string FullDeviceNumberPoint { get; set; }
|
public string FullDeviceNumberPoint { get; set; }
|
||||||
public System.DateTime archive_lastDate { get; set; }
|
public System.DateTime archive_lastDate { get; set; }
|
||||||
|
|
||||||
|
public System.DateTime created_at { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ImportDevForCoo
|
public class ImportDevForCoo
|
||||||
|
@ -99,6 +99,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
deviceNumberPoint.Point = point.points;
|
deviceNumberPoint.Point = point.points;
|
||||||
deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", electricMeter.Device_number, point.points);
|
deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", electricMeter.Device_number, point.points);
|
||||||
deviceNumberPoint.archive_lastDate = electricMeter.archive_lastDate;
|
deviceNumberPoint.archive_lastDate = electricMeter.archive_lastDate;
|
||||||
|
deviceNumberPoint.created_at = electricMeter.created_at;
|
||||||
electricDeviceNumberPoints.Add(deviceNumberPoint);
|
electricDeviceNumberPoints.Add(deviceNumberPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +118,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
deviceNumberPoint.Point = point.points;
|
deviceNumberPoint.Point = point.points;
|
||||||
deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", waterMeter.Device_number, point.points);
|
deviceNumberPoint.FullDeviceNumberPoint = string.Format("{0}_{1}", waterMeter.Device_number, point.points);
|
||||||
deviceNumberPoint.archive_lastDate = waterMeter.archive_lastDate;
|
deviceNumberPoint.archive_lastDate = waterMeter.archive_lastDate;
|
||||||
|
deviceNumberPoint.created_at = waterMeter.created_at;
|
||||||
waterDeviceNumberPoints.Add(deviceNumberPoint);
|
waterDeviceNumberPoints.Add(deviceNumberPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,6 +169,10 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
{
|
{
|
||||||
var startDay = deviceNumberPoint.archive_lastDate.ToString("yyyy-MM-dd");
|
var startDay = deviceNumberPoint.archive_lastDate.ToString("yyyy-MM-dd");
|
||||||
var endDay = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
var endDay = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
||||||
|
if (startDay == "0001-01-01") // 假設archive_lastDate為null
|
||||||
|
{
|
||||||
|
startDay = deviceNumberPoint.created_at.ToString("yyyy-MM-dd");
|
||||||
|
}
|
||||||
foreach (DateTime day in EachDay(startDay, endDay))
|
foreach (DateTime day in EachDay(startDay, endDay))
|
||||||
{
|
{
|
||||||
var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); // 巨蛋用此時間抓到的實際是T00:15:00的資料
|
var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); // 巨蛋用此時間抓到的實際是T00:15:00的資料
|
||||||
@ -252,6 +257,10 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
{
|
{
|
||||||
var startDay = deviceNumberPoint.archive_lastDate.ToString("yyyy-MM-dd");
|
var startDay = deviceNumberPoint.archive_lastDate.ToString("yyyy-MM-dd");
|
||||||
var endDay = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
var endDay = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
||||||
|
if (startDay == "0001-01-01") // 假設archive_lastDate為null
|
||||||
|
{
|
||||||
|
startDay = deviceNumberPoint.created_at.ToString("yyyy-MM-dd");
|
||||||
|
}
|
||||||
foreach (DateTime day in EachDay(startDay, endDay))
|
foreach (DateTime day in EachDay(startDay, endDay))
|
||||||
{
|
{
|
||||||
var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); // 巨蛋用此時間抓到的實際是T00:15:00的資料
|
var sDay = string.Format("{0}T00:00:00.000+08:00", day.ToString("yyyy-MM-dd").Replace(" ", "T")); // 巨蛋用此時間抓到的實際是T00:15:00的資料
|
||||||
@ -1101,27 +1110,10 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Month", "水電表月任務開始");
|
await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Month", "水電表月任務開始");
|
||||||
var preDay = now.AddDays(-1); //取得前一天
|
|
||||||
|
|
||||||
var dayInMonth = DateTime.DaysInMonth(preDay.Year, preDay.Month);
|
string startTimestamp = "";
|
||||||
var FirstDay = new DateTime(preDay.Year, preDay.Month, 1);
|
string endTimestamp = "";
|
||||||
//var LastDay = now.AddMonths(1).AddDays(-now.AddMonths(1).Day); // 這是抓到該月最後一天
|
string historyQueryFilter = "";
|
||||||
var LastDay = now;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//var startTimestamp = string.Format("{0}T23:59:59.000+08:00", FirstDay.AddDays(-1).ToString("yyyy-MM-dd")); // 巨蛋要這樣抓數據才是對的
|
|
||||||
var startTimestamp = string.Format("{0}T00:00:00.000+08:00", FirstDay.ToString("yyyy-MM-dd"));
|
|
||||||
|
|
||||||
//var endTimestamp = string.Format("{0}T23:59:59.000+08:00", LastDay.ToString("yyyy-MM-dd"));
|
|
||||||
var endTimestamp = string.Format("{0}T00:15:00.000+08:00", LastDay.ToString("yyyy-MM-dd")); // 240131 jay for dome
|
|
||||||
|
|
||||||
|
|
||||||
var historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
|
||||||
<abstime name='start' val='{startTimestamp}' />
|
|
||||||
<abstime name='end' val='{endTimestamp}' />
|
|
||||||
<reltime name='interval' val = 'PT{dayInMonth+1}D' />
|
|
||||||
</obj>";
|
|
||||||
|
|
||||||
//Stopwatch stopWatch = new Stopwatch();
|
//Stopwatch stopWatch = new Stopwatch();
|
||||||
//stopWatch.Start();
|
//stopWatch.Start();
|
||||||
@ -1131,138 +1123,229 @@ 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)
|
||||||
{
|
{
|
||||||
device_number = deviceNumberPoint.FullDeviceNumberPoint;
|
var startDay = deviceNumberPoint.archive_lastDate.ToString("yyyy-MM-dd");
|
||||||
if (tagQuantity.Equals("5"))
|
|
||||||
station = await backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history
|
var endDay = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
||||||
|
|
||||||
|
foreach (DateTime day in EachMonth(startDay, endDay))
|
||||||
|
{
|
||||||
|
if (day.ToString("yyyy-MM") == System.DateTime.Now.AddDays(-1).ToString("yyyy-MM"))
|
||||||
|
{
|
||||||
|
var preDay = now.AddDays(-1); //取得前一天
|
||||||
|
|
||||||
|
var dayInMonth = DateTime.DaysInMonth(preDay.Year, preDay.Month);
|
||||||
|
var FirstDay = new DateTime(preDay.Year, preDay.Month, 1);
|
||||||
|
//var LastDay = now.AddMonths(1).AddDays(-now.AddMonths(1).Day); // 這是抓到該月最後一天
|
||||||
|
var LastDay = now;
|
||||||
|
|
||||||
|
//var startTimestamp = string.Format("{0}T23:59:59.000+08:00", FirstDay.AddDays(-1).ToString("yyyy-MM-dd")); // 巨蛋要這樣抓數據才是對的
|
||||||
|
startTimestamp = string.Format("{0}T00:00:00.000+08:00", FirstDay.ToString("yyyy-MM-dd"));
|
||||||
|
|
||||||
|
//var endTimestamp = string.Format("{0}T23:59:59.000+08:00", LastDay.ToString("yyyy-MM-dd"));
|
||||||
|
endTimestamp = string.Format("{0}T00:15:00.000+08:00", LastDay.ToString("yyyy-MM-dd")); // 240131 jay for dome
|
||||||
|
|
||||||
|
|
||||||
|
historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
||||||
|
<abstime name='start' val='{startTimestamp}' />
|
||||||
|
<abstime name='end' val='{endTimestamp}' />
|
||||||
|
<reltime name='interval' val = 'PT{dayInMonth + 1}D' />
|
||||||
|
</obj>";
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var dayInMonth = DateTime.DaysInMonth(day.Year, day.Month);
|
||||||
|
var FirstDay = new DateTime(day.Year, day.Month, 1);
|
||||||
|
var LastDay = new DateTime(day.Year, day.Month, dayInMonth);
|
||||||
|
|
||||||
|
startTimestamp = string.Format("{0}T00:00:00.000+08:00", FirstDay.ToString("yyyy-MM-dd"));
|
||||||
|
|
||||||
|
endTimestamp = string.Format("{0}T00:15:00.000+08:00", LastDay.ToString("yyyy-MM-dd"));
|
||||||
|
historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
||||||
|
<abstime name='start' val='{startTimestamp}' />
|
||||||
|
<abstime name='end' val='{endTimestamp}' />
|
||||||
|
<reltime name='interval' val = 'PT{dayInMonth + 1}D' />
|
||||||
|
</obj>";
|
||||||
|
}
|
||||||
|
|
||||||
|
device_number = deviceNumberPoint.FullDeviceNumberPoint;
|
||||||
|
if (tagQuantity.Equals("5"))
|
||||||
|
station = await backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history
|
||||||
where device_building_tag = '{device_number.Split("_")[0]}' and device_floor_tag = '{device_number.Split("_")[2]}'
|
where device_building_tag = '{device_number.Split("_")[0]}' and device_floor_tag = '{device_number.Split("_")[2]}'
|
||||||
and device_name_tag = '{device_number.Split("_")[1]}' and device_point_name = '{device_number.Split("_")[5]}'");
|
and device_name_tag = '{device_number.Split("_")[1]}' and device_point_name = '{device_number.Split("_")[5]}'");
|
||||||
else
|
else
|
||||||
station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history
|
station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history
|
||||||
where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and
|
where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and
|
||||||
device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}'
|
device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}'
|
||||||
and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}'
|
and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}'
|
||||||
and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
|
and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
|
||||||
and device_point_name = '{device_number.Split("_")[8]}'").Result;
|
and device_point_name = '{device_number.Split("_")[8]}'").Result;
|
||||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
|
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
|
||||||
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/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;
|
||||||
|
|
||||||
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||||
using (Stream reqStream = archiveRequest.GetRequestStream())
|
using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||||
{
|
|
||||||
reqStream.Write(byteArray, 0, byteArray.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
|
|
||||||
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
|
||||||
archiveResponse.Dispose();
|
|
||||||
archiveResponse.Close();
|
|
||||||
|
|
||||||
xmlDocument.LoadXml(archiveResponseContent);
|
|
||||||
archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
|
||||||
archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
|
|
||||||
|
|
||||||
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤
|
|
||||||
{
|
|
||||||
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】");
|
|
||||||
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveMonthJsonResult);
|
|
||||||
|
|
||||||
Dictionary<string, object> archiveMonthRawData = new Dictionary<string, object>();
|
|
||||||
archiveMonthRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
|
||||||
archiveMonthRawData.Add("@point", deviceNumberPoint.Point);
|
|
||||||
archiveMonthRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
|
|
||||||
archiveMonthRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
|
|
||||||
archiveMonthRawData.Add("@is_complete", 0);
|
|
||||||
archiveMonthRawData.Add("@repeat_times", 0);
|
|
||||||
archiveMonthRawData.Add("@fail_reason", archiveJson);
|
|
||||||
|
|
||||||
archiveMonthRawData.Add("@count_rawdata", 0);
|
|
||||||
archiveMonthRawData.Add("@min_rawdata", 0);
|
|
||||||
archiveMonthRawData.Add("@max_rawdata", 0);
|
|
||||||
archiveMonthRawData.Add("@avg_rawdata", 0);
|
|
||||||
archiveMonthRawData.Add("@sum_rawdata", 0);
|
|
||||||
archiveMonthRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
||||||
|
|
||||||
electricArchiveMonthRawDatas.Add(archiveMonthRawData);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
|
||||||
{
|
|
||||||
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult);
|
|
||||||
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
|
||||||
{
|
{
|
||||||
electricArchiveMonthRawDatas.AddRange(ArrangeRawDatas);
|
reqStream.Write(byteArray, 0, byteArray.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
|
||||||
|
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
||||||
|
archiveResponse.Dispose();
|
||||||
|
archiveResponse.Close();
|
||||||
|
|
||||||
|
xmlDocument.LoadXml(archiveResponseContent);
|
||||||
|
archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||||
|
archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
|
||||||
|
|
||||||
|
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤
|
||||||
|
{
|
||||||
|
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】");
|
||||||
|
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveMonthJsonResult);
|
||||||
|
|
||||||
|
Dictionary<string, object> archiveMonthRawData = new Dictionary<string, object>();
|
||||||
|
archiveMonthRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
||||||
|
archiveMonthRawData.Add("@point", deviceNumberPoint.Point);
|
||||||
|
archiveMonthRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
|
||||||
|
archiveMonthRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
|
||||||
|
archiveMonthRawData.Add("@is_complete", 0);
|
||||||
|
archiveMonthRawData.Add("@repeat_times", 0);
|
||||||
|
archiveMonthRawData.Add("@fail_reason", archiveJson);
|
||||||
|
|
||||||
|
archiveMonthRawData.Add("@count_rawdata", 0);
|
||||||
|
archiveMonthRawData.Add("@min_rawdata", 0);
|
||||||
|
archiveMonthRawData.Add("@max_rawdata", 0);
|
||||||
|
archiveMonthRawData.Add("@avg_rawdata", 0);
|
||||||
|
archiveMonthRawData.Add("@sum_rawdata", 0);
|
||||||
|
archiveMonthRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
|
||||||
|
electricArchiveMonthRawDatas.Add(archiveMonthRawData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
||||||
|
{
|
||||||
|
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult);
|
||||||
|
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
||||||
|
{
|
||||||
|
electricArchiveMonthRawDatas.AddRange(ArrangeRawDatas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (var deviceNumberPoint in waterDeviceNumberPoints)
|
foreach (var deviceNumberPoint in waterDeviceNumberPoints)
|
||||||
{
|
{
|
||||||
device_number = deviceNumberPoint.FullDeviceNumberPoint;
|
var startDay = deviceNumberPoint.archive_lastDate.ToString("yyyy-MM-dd");
|
||||||
if (tagQuantity.Equals("5"))
|
|
||||||
station = await backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history
|
var endDay = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
||||||
|
|
||||||
|
foreach (DateTime day in EachMonth(startDay, endDay))
|
||||||
|
{
|
||||||
|
if (day.ToString("yyyy-MM") == System.DateTime.Now.AddDays(-1).ToString("yyyy-MM"))
|
||||||
|
{
|
||||||
|
var preDay = now.AddDays(-1); //取得前一天
|
||||||
|
|
||||||
|
var dayInMonth = DateTime.DaysInMonth(preDay.Year, preDay.Month);
|
||||||
|
var FirstDay = new DateTime(preDay.Year, preDay.Month, 1);
|
||||||
|
//var LastDay = now.AddMonths(1).AddDays(-now.AddMonths(1).Day); // 這是抓到該月最後一天
|
||||||
|
var LastDay = now;
|
||||||
|
|
||||||
|
//var startTimestamp = string.Format("{0}T23:59:59.000+08:00", FirstDay.AddDays(-1).ToString("yyyy-MM-dd")); // 巨蛋要這樣抓數據才是對的
|
||||||
|
startTimestamp = string.Format("{0}T00:00:00.000+08:00", FirstDay.ToString("yyyy-MM-dd"));
|
||||||
|
|
||||||
|
//var endTimestamp = string.Format("{0}T23:59:59.000+08:00", LastDay.ToString("yyyy-MM-dd"));
|
||||||
|
endTimestamp = string.Format("{0}T00:15:00.000+08:00", LastDay.ToString("yyyy-MM-dd")); // 240131 jay for dome
|
||||||
|
|
||||||
|
|
||||||
|
historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
||||||
|
<abstime name='start' val='{startTimestamp}' />
|
||||||
|
<abstime name='end' val='{endTimestamp}' />
|
||||||
|
<reltime name='interval' val = 'PT{dayInMonth + 1}D' />
|
||||||
|
</obj>";
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var dayInMonth = DateTime.DaysInMonth(day.Year, day.Month);
|
||||||
|
var FirstDay = new DateTime(day.Year, day.Month, 1);
|
||||||
|
var LastDay = new DateTime(day.Year, day.Month, dayInMonth);
|
||||||
|
|
||||||
|
startTimestamp = string.Format("{0}T00:00:00.000+08:00", FirstDay.ToString("yyyy-MM-dd"));
|
||||||
|
|
||||||
|
endTimestamp = string.Format("{0}T00:15:00.000+08:00", LastDay.ToString("yyyy-MM-dd"));
|
||||||
|
historyQueryFilter = $@"<obj is='obix: HistoryFilter'>
|
||||||
|
<abstime name='start' val='{startTimestamp}' />
|
||||||
|
<abstime name='end' val='{endTimestamp}' />
|
||||||
|
<reltime name='interval' val = 'PT{dayInMonth + 1}D' />
|
||||||
|
</obj>";
|
||||||
|
}
|
||||||
|
device_number = deviceNumberPoint.FullDeviceNumberPoint;
|
||||||
|
if (tagQuantity.Equals("5"))
|
||||||
|
station = await backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history
|
||||||
where device_building_tag = '{device_number.Split("_")[0]}' and device_floor_tag = '{device_number.Split("_")[2]}'
|
where device_building_tag = '{device_number.Split("_")[0]}' and device_floor_tag = '{device_number.Split("_")[2]}'
|
||||||
and device_name_tag = '{device_number.Split("_")[1]}' and device_point_name = '{device_number.Split("_")[5]}'");
|
and device_name_tag = '{device_number.Split("_")[1]}' and device_point_name = '{device_number.Split("_")[5]}'");
|
||||||
else
|
else
|
||||||
station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history
|
station = backgroundServiceRepository.GetOneAsync<string>($@"select parent_path from import_niagara_item_history
|
||||||
where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and
|
where device_building_tag = '{device_number.Split("_")[1].Replace("$3", "")}' and
|
||||||
device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}'
|
device_system_tag = '{device_number.Split("_")[2]}' and device_name_tag = '{device_number.Split("_")[3]}'
|
||||||
and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}'
|
and device_floor_tag = '{device_number.Split("_")[4]}' and device_master_tag = '{device_number.Split("_")[5]}'
|
||||||
and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
|
and device_last_name_tag = '{device_number.Split("_")[6]}' and device_serial_tag = '{device_number.Split("_")[7]}'
|
||||||
and device_point_name = '{device_number.Split("_")[8]}'").Result;
|
and device_point_name = '{device_number.Split("_")[8]}'").Result;
|
||||||
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
|
archiveRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/{deviceNumberPoint.FullDeviceNumberPoint.Replace("$3", "")}/~historyRollup/");
|
||||||
//HttpWebRequest archiveMonthRequest = (HttpWebRequest)WebRequest.Create($"{obixApiConfig.ApiBase}obix/histories/{station}/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;
|
||||||
|
|
||||||
|
|
||||||
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
byte[] byteArray = Encoding.UTF8.GetBytes(historyQueryFilter);
|
||||||
using (Stream reqStream = archiveRequest.GetRequestStream())
|
using (Stream reqStream = archiveRequest.GetRequestStream())
|
||||||
{
|
|
||||||
reqStream.Write(byteArray, 0, byteArray.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
|
|
||||||
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
|
||||||
archiveResponse.Dispose();
|
|
||||||
archiveResponse.Close();
|
|
||||||
|
|
||||||
xmlDocument.LoadXml(archiveResponseContent);
|
|
||||||
archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
|
||||||
archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
|
|
||||||
|
|
||||||
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤
|
|
||||||
{
|
|
||||||
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】");
|
|
||||||
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveMonthJsonResult);
|
|
||||||
|
|
||||||
Dictionary<string, object> archiveMonthRawData = new Dictionary<string, object>();
|
|
||||||
archiveMonthRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
|
||||||
archiveMonthRawData.Add("@point", deviceNumberPoint.Point);
|
|
||||||
archiveMonthRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
|
|
||||||
archiveMonthRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
|
|
||||||
archiveMonthRawData.Add("@is_complete", 0);
|
|
||||||
archiveMonthRawData.Add("@repeat_times", 0);
|
|
||||||
archiveMonthRawData.Add("@fail_reason", archiveJson);
|
|
||||||
|
|
||||||
archiveMonthRawData.Add("@count_rawdata", 0);
|
|
||||||
archiveMonthRawData.Add("@min_rawdata", 0);
|
|
||||||
archiveMonthRawData.Add("@max_rawdata", 0);
|
|
||||||
archiveMonthRawData.Add("@avg_rawdata", 0);
|
|
||||||
archiveMonthRawData.Add("@sum_rawdata", 0);
|
|
||||||
archiveMonthRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
||||||
|
|
||||||
waterArchiveMonthRawDatas.Add(archiveMonthRawData);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
|
||||||
{
|
|
||||||
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult);
|
|
||||||
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
|
||||||
{
|
{
|
||||||
waterArchiveMonthRawDatas.AddRange(ArrangeRawDatas);
|
reqStream.Write(byteArray, 0, byteArray.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
archiveResponse = (HttpWebResponse)archiveRequest.GetResponse();
|
||||||
|
archiveResponseContent = new StreamReader(archiveResponse.GetResponseStream()).ReadToEnd();
|
||||||
|
archiveResponse.Dispose();
|
||||||
|
archiveResponse.Close();
|
||||||
|
|
||||||
|
xmlDocument.LoadXml(archiveResponseContent);
|
||||||
|
archiveJson = JsonConvert.SerializeXmlNode(xmlDocument);
|
||||||
|
archiveJsonResult = (JObject)JsonConvert.DeserializeObject(archiveJson);
|
||||||
|
|
||||||
|
if (archiveJsonResult.ContainsKey("err")) //抓取錯誤
|
||||||
|
{
|
||||||
|
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】");
|
||||||
|
//logger.LogError("【ArchiveElectricMeterDayJob】【月歸檔】【取得資料失敗】[錯誤內容]:{0}", archiveMonthJsonResult);
|
||||||
|
|
||||||
|
Dictionary<string, object> archiveMonthRawData = new Dictionary<string, object>();
|
||||||
|
archiveMonthRawData.Add("@device_number", deviceNumberPoint.DeviceNumber);
|
||||||
|
archiveMonthRawData.Add("@point", deviceNumberPoint.Point);
|
||||||
|
archiveMonthRawData.Add("@start_timestamp", startTimestamp.Replace("T", " ").Substring(0, 19));
|
||||||
|
archiveMonthRawData.Add("@end_timestamp", endTimestamp.Replace("T", " ").Substring(0, 19));
|
||||||
|
archiveMonthRawData.Add("@is_complete", 0);
|
||||||
|
archiveMonthRawData.Add("@repeat_times", 0);
|
||||||
|
archiveMonthRawData.Add("@fail_reason", archiveJson);
|
||||||
|
|
||||||
|
archiveMonthRawData.Add("@count_rawdata", 0);
|
||||||
|
archiveMonthRawData.Add("@min_rawdata", 0);
|
||||||
|
archiveMonthRawData.Add("@max_rawdata", 0);
|
||||||
|
archiveMonthRawData.Add("@avg_rawdata", 0);
|
||||||
|
archiveMonthRawData.Add("@sum_rawdata", 0);
|
||||||
|
archiveMonthRawData.Add("@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
|
||||||
|
waterArchiveMonthRawDatas.Add(archiveMonthRawData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (archiveJsonResult.ContainsKey("obj")) //表示可以讀取到內容
|
||||||
|
{
|
||||||
|
var ArrangeRawDatas = ArrangeRawData(deviceNumberPoint, archiveJsonResult);
|
||||||
|
if (ArrangeRawDatas != null && ArrangeRawDatas.Count() > 0)
|
||||||
|
{
|
||||||
|
waterArchiveMonthRawDatas.AddRange(ArrangeRawDatas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1663,7 +1746,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
|||||||
{
|
{
|
||||||
var strtday = DateTime.Parse(from);
|
var strtday = DateTime.Parse(from);
|
||||||
var endday = DateTime.Parse(thru);
|
var endday = DateTime.Parse(thru);
|
||||||
for (var _month = strtday.Date; _month.Month <= endday.Month; _month = _month.AddDays(1))
|
for (var _month = strtday.Date; _month.Month <= endday.Month; _month = _month.AddMonths(1))
|
||||||
yield return _month;
|
yield return _month;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user