修改排成程序
This commit is contained in:
parent
3f45fe7c2c
commit
665f9a69f8
@ -83,6 +83,7 @@ namespace BackendWorkerService
|
||||
#region Repository ª`¤J
|
||||
services.AddTransient<IBackendRepository, BackendRepository>();
|
||||
services.AddTransient<IBackgroundServiceRepository, BackgroundServiceRepository>();
|
||||
services.AddTransient<IBackgroundServiceMsSqlRepository, BackgroundServiceMsSqlRepository>();
|
||||
services.AddTransient<IFrontendRepository, FrontendRepository>();
|
||||
services.AddTransient<IBaseRepository, BaseRepository>();
|
||||
#endregion Repository ª`¤J
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Backend.Models;
|
||||
using BackendWorkerService.Services.Implement;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
@ -25,6 +26,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
{
|
||||
private readonly ILogger<ArchiveElectricMeterDayJob> logger;
|
||||
private readonly IBackgroundServiceRepository backgroundServiceRepository;
|
||||
private readonly IBackgroundServiceMsSqlRepository backgroundServiceMsSqlRepository;
|
||||
protected readonly IDatabaseHelper _databaseHelper;
|
||||
private readonly ILogger<Task_Detail> loggers;
|
||||
|
||||
@ -32,10 +34,12 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
public ArchiveElectricMeterDayJob(
|
||||
ILogger<ArchiveElectricMeterDayJob> logger,
|
||||
IBackgroundServiceRepository backgroundServiceRepository,
|
||||
IBackgroundServiceMsSqlRepository backgroundServiceMySqlRepository,
|
||||
IDatabaseHelper databaseHelper, ILogger<Task_Detail> loggers, IBackendRepository backendRepository)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.backgroundServiceRepository = backgroundServiceRepository;
|
||||
this.backgroundServiceMsSqlRepository = backgroundServiceMySqlRepository;
|
||||
this._databaseHelper = databaseHelper;
|
||||
this.loggers = loggers;
|
||||
}
|
||||
@ -57,12 +61,12 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
var electricMeterGuid = variableArchive.Where(x => x.Name == "ElectricMeterGuid").Select(x => x.Value).FirstOrDefault();
|
||||
|
||||
#region 找出所有電錶設備
|
||||
var sWhere = "deleted = 0 AND sub_system_guid = @sub_system_guid";
|
||||
var sWhere = "deleted = 0 AND device_name_tag = @sub_system_guid";
|
||||
var electricMeters = await backgroundServiceRepository.GetAllAsync<Device>("device", sWhere, new { sub_system_guid = electricMeterGuid });
|
||||
#endregion 找出所有電錶設備
|
||||
|
||||
#region 找出所有電錶系統的點位
|
||||
var sPointWhere = "deleted = 0 AND sub_system_guid = @sub_system_guid";
|
||||
var sPointWhere = "deleted = 0 AND device_name_tag = @sub_system_guid";
|
||||
var points = await backgroundServiceRepository.GetAllAsync<Device_item>("device_item", sPointWhere, new { sub_system_guid = electricMeterGuid });
|
||||
#endregion 找出所有電錶系統的點位
|
||||
|
||||
@ -180,7 +184,51 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
|
||||
if (archiveDayRawDatas.Count() > 0)
|
||||
{
|
||||
var sql = $@"BEGIN TRANSACTION;
|
||||
var sql = $@"
|
||||
UPDATE archive_electric_meter_day SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = @min_rawdata,
|
||||
max_rawdata = @max_rawdata,
|
||||
avg_rawdata = @avg_rawdata,
|
||||
sum_rawdata = @sum_rawdata,
|
||||
is_complete = @is_complete,
|
||||
repeat_times = @repeat_times,
|
||||
fail_reason = @fail_reason,
|
||||
updated_at = @updated_at
|
||||
WHERE device_number = @device_number
|
||||
AND point = @point
|
||||
AND start_timestamp = @start_timestamp;
|
||||
|
||||
|
||||
INSERT INTO archive_electric_meter_day (
|
||||
device_number,
|
||||
point,
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
count_rawdata,
|
||||
min_rawdata,
|
||||
max_rawdata,
|
||||
avg_rawdata,
|
||||
sum_rawdata,
|
||||
is_complete,
|
||||
repeat_times,
|
||||
fail_reason)
|
||||
SELECT
|
||||
@device_number,
|
||||
@point,
|
||||
@start_timestamp,
|
||||
@end_timestamp,
|
||||
@count_rawdata,
|
||||
@min_rawdata,
|
||||
@max_rawdata,
|
||||
@avg_rawdata,
|
||||
@sum_rawdata,
|
||||
@is_complete,
|
||||
@repeat_times,
|
||||
@fail_reason
|
||||
WHERE ROW_COUNT() = 0;";
|
||||
|
||||
var mySql = $@"BEGIN TRANSACTION;
|
||||
|
||||
UPDATE archive_electric_meter_day SET
|
||||
count_rawdata = @count_rawdata,
|
||||
@ -228,7 +276,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
|
||||
COMMIT TRANSACTION;";
|
||||
await backgroundServiceRepository.ExecuteSql(sql, archiveDayRawDatas);
|
||||
|
||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, archiveDayRawDatas);
|
||||
}
|
||||
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Day", "任務完成");
|
||||
}
|
||||
@ -324,7 +372,53 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
|
||||
if (archiveWeekRawDatas.Count() > 0)
|
||||
{
|
||||
var sql = $@"BEGIN TRANSACTION;
|
||||
var sql = $@"
|
||||
|
||||
UPDATE archive_electric_meter_week SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = @min_rawdata,
|
||||
max_rawdata = @max_rawdata,
|
||||
avg_rawdata = @avg_rawdata,
|
||||
sum_rawdata = @sum_rawdata,
|
||||
is_complete = @is_complete,
|
||||
repeat_times = @repeat_times,
|
||||
fail_reason = @fail_reason,
|
||||
updated_at = @updated_at
|
||||
WHERE device_number = @device_number
|
||||
AND point = @point
|
||||
AND start_timestamp = @start_timestamp;
|
||||
|
||||
|
||||
INSERT INTO archive_electric_meter_week (
|
||||
device_number,
|
||||
point,
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
count_rawdata,
|
||||
min_rawdata,
|
||||
max_rawdata,
|
||||
avg_rawdata,
|
||||
sum_rawdata,
|
||||
is_complete,
|
||||
repeat_times,
|
||||
fail_reason)
|
||||
SELECT
|
||||
@device_number,
|
||||
@point,
|
||||
@start_timestamp,
|
||||
@end_timestamp,
|
||||
@count_rawdata,
|
||||
@min_rawdata,
|
||||
@max_rawdata,
|
||||
@avg_rawdata,
|
||||
@sum_rawdata,
|
||||
@is_complete,
|
||||
@repeat_times,
|
||||
@fail_reason
|
||||
WHERE ROW_COUNT() = 0;
|
||||
";
|
||||
|
||||
var mySql = $@"BEGIN TRANSACTION;
|
||||
|
||||
UPDATE archive_electric_meter_week SET
|
||||
count_rawdata = @count_rawdata,
|
||||
@ -372,6 +466,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
|
||||
COMMIT TRANSACTION;";
|
||||
await backgroundServiceRepository.ExecuteSql(sql, archiveWeekRawDatas);
|
||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, archiveWeekRawDatas);
|
||||
|
||||
}
|
||||
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Week", "任務完成");
|
||||
@ -470,7 +565,50 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
|
||||
if (archiveMonthRawDatas.Count() > 0)
|
||||
{
|
||||
var sql = $@"BEGIN TRANSACTION;
|
||||
var sql = $@"
|
||||
UPDATE archive_electric_meter_month SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = @min_rawdata,
|
||||
max_rawdata = @max_rawdata,
|
||||
avg_rawdata = @avg_rawdata,
|
||||
sum_rawdata = @sum_rawdata,
|
||||
is_complete = @is_complete,
|
||||
repeat_times = @repeat_times,
|
||||
fail_reason = @fail_reason,
|
||||
updated_at = @updated_at
|
||||
WHERE device_number = @device_number
|
||||
AND point = @point
|
||||
AND start_timestamp = @start_timestamp;
|
||||
|
||||
INSERT INTO archive_electric_meter_month (
|
||||
device_number,
|
||||
point,
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
count_rawdata,
|
||||
min_rawdata,
|
||||
max_rawdata,
|
||||
avg_rawdata,
|
||||
sum_rawdata,
|
||||
is_complete,
|
||||
repeat_times,
|
||||
fail_reason)
|
||||
SELECT
|
||||
@device_number,
|
||||
@point,
|
||||
@start_timestamp,
|
||||
@end_timestamp,
|
||||
@count_rawdata,
|
||||
@min_rawdata,
|
||||
@max_rawdata,
|
||||
@avg_rawdata,
|
||||
@sum_rawdata,
|
||||
@is_complete,
|
||||
@repeat_times,
|
||||
@fail_reason
|
||||
WHERE ROW_COUNT() = 0;";
|
||||
|
||||
var mySql = $@"BEGIN TRANSACTION;
|
||||
|
||||
UPDATE archive_electric_meter_month SET
|
||||
count_rawdata = @count_rawdata,
|
||||
@ -518,6 +656,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
|
||||
COMMIT TRANSACTION;";
|
||||
await backgroundServiceRepository.ExecuteSql(sql, archiveMonthRawDatas);
|
||||
await backgroundServiceMsSqlRepository.ExecuteSql(mySql, archiveMonthRawDatas);
|
||||
}
|
||||
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Month", "任務完成");
|
||||
}
|
||||
@ -537,8 +676,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
try
|
||||
{
|
||||
await task_Detail.InsertWorkTime("ArchiveElectricMeterDayJob", "Compensate", "任務開始");
|
||||
ProcEletricMeterService procEletricMeterService = new ProcEletricMeterService(_databaseHelper.GetMSSqlConnectionString());
|
||||
procEletricMeterService.ArchiveData();
|
||||
ProcEletricMeterService procEletricMeterService = new ProcEletricMeterService(backgroundServiceRepository, backgroundServiceMsSqlRepository);
|
||||
await procEletricMeterService.ArchiveData();
|
||||
await task_Detail.InsertWorkTime_End("ArchiveElectricMeterDayJob", "Compensate", "任務完成");
|
||||
}
|
||||
catch(Exception ex)
|
||||
|
@ -16,6 +16,7 @@ using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using System.Linq;
|
||||
using NCrontab;
|
||||
using BackendWorkerService.Services.Implement;
|
||||
|
||||
namespace BackendWorkerService.Quartz.Jobs
|
||||
{
|
||||
@ -232,8 +233,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
{ "@msgType", observation.Alert.MsgType},
|
||||
{ "@headline", observation.Alert.Info.Headline},
|
||||
{ "@areaDesc", area},
|
||||
{ "@onset", observation.Alert.Info.Onset},
|
||||
{ "@expires", observation.Alert.Info.Expires},
|
||||
{ "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{ "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{ "@created_by", "system"},
|
||||
{ "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
};
|
||||
@ -317,8 +318,8 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
{ "@areaDesc", area},
|
||||
{ "@urgency",observation.Alert.Info.Urgency},
|
||||
{ "@severity",observation.Alert.Info.Severity},
|
||||
{ "@onset", observation.Alert.Info.Onset},
|
||||
{ "@expires", observation.Alert.Info.Expires},
|
||||
{ "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{ "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{ "@created_by", "system"},
|
||||
{ "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
};
|
||||
@ -458,7 +459,7 @@ namespace BackendWorkerService.Quartz.Jobs
|
||||
weather_type,
|
||||
get_value
|
||||
FROM api_weateher
|
||||
where id in (select MAX(id) from api_weateher where start_time < GETDATE() group by weather_type)
|
||||
where id in (select MAX(id) from api_weateher where start_time < NOW() group by weather_type)
|
||||
order by start_time desc";
|
||||
var types = await backendRepository.GetAllAsync<ShowWeather>(sql);
|
||||
var T = types.Where(a => a.weather_type == "T").FirstOrDefault();
|
||||
|
@ -12,6 +12,10 @@ using System.Xml;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Repository.Helper;
|
||||
using Repository.BackendRepository.Interface;
|
||||
using Repository.BackendRepository.Implement;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BackendWorkerService.Services.Implement
|
||||
{
|
||||
@ -20,23 +24,17 @@ namespace BackendWorkerService.Services.Implement
|
||||
/// </summary>
|
||||
public class ProcEletricMeterService
|
||||
{
|
||||
string Connection1 = string.Empty;
|
||||
IDbConnection conn;
|
||||
private readonly IBackgroundServiceRepository backgroundServiceRepository;
|
||||
private readonly IBackgroundServiceMsSqlRepository backgroundServiceMsSqlRepository;
|
||||
|
||||
public ProcEletricMeterService(string Connection_parame = null)
|
||||
public ProcEletricMeterService(IBackgroundServiceRepository backgroundServiceRepository,
|
||||
IBackgroundServiceMsSqlRepository backgroundServiceMySqlRepository)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Connection_parame))
|
||||
{
|
||||
Connection1 = Connection_parame;
|
||||
conn = new SqlConnection(Connection_parame);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Connection1 = ConfigurationManager.ConnectionStrings["mySql"].ConnectionString;
|
||||
}
|
||||
this.backgroundServiceRepository = backgroundServiceRepository;
|
||||
this.backgroundServiceMsSqlRepository = backgroundServiceMySqlRepository;
|
||||
}
|
||||
|
||||
public bool ArchiveData()
|
||||
public async Task<bool> ArchiveData()
|
||||
{
|
||||
bool result = false;
|
||||
int repeatTimes = 0;
|
||||
@ -50,36 +48,68 @@ namespace BackendWorkerService.Services.Implement
|
||||
try
|
||||
{
|
||||
//取得可錯誤次數
|
||||
using (IDbConnection conn = new SqlConnection(Connection1))
|
||||
{
|
||||
var sqlArchive = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'archiveConfig'";
|
||||
|
||||
var variableArchive = conn.Query<KeyValue>(sqlArchive);
|
||||
var variableArchive = await backgroundServiceRepository.GetAllAsync<KeyValue>(sqlArchive);
|
||||
repeatTimes = Convert.ToInt32(variableArchive.Where(x => x.Name == "RepeatTimes").Select(x => x.Value).FirstOrDefault());
|
||||
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
#region 取得obix 設定
|
||||
using (IDbConnection conn = new SqlConnection(Connection1))
|
||||
{
|
||||
|
||||
var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'";
|
||||
|
||||
var variableObix = conn.Query<KeyValue>(sqlObix).ToList();
|
||||
var variableObix = await backgroundServiceRepository.GetAllAsync<KeyValue>(sqlObix);
|
||||
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());
|
||||
|
||||
encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(obixApiConfig.UserName + ":" + obixApiConfig.Password));
|
||||
|
||||
conn.Close();
|
||||
}
|
||||
#endregion 取得obix 設定
|
||||
|
||||
//取得錯誤的設備sql format
|
||||
var sql_error_format = @"SELECT * FROM {0} WHERE is_complete = 0 AND repeat_times < @RepeatTimes";
|
||||
|
||||
//MY 新增/修改sql format
|
||||
var MYsql_update_format = @"
|
||||
UPDATE {0} SET
|
||||
count_rawdata = @count_rawdata,
|
||||
min_rawdata = @min_rawdata,
|
||||
max_rawdata = @max_rawdata,
|
||||
avg_rawdata = @avg_rawdata,
|
||||
sum_rawdata = @sum_rawdata,
|
||||
is_complete = @is_complete,
|
||||
repeat_times = @repeat_times,
|
||||
fail_reason = @fail_reason,
|
||||
updated_at = @updated_at
|
||||
WHERE device_number = @device_number
|
||||
AND point = @point
|
||||
AND start_timestamp = @start_timestamp;
|
||||
|
||||
INSERT INTO {0} (
|
||||
device_number,
|
||||
point,
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
count_rawdata,
|
||||
min_rawdata,
|
||||
max_rawdata,
|
||||
avg_rawdata,
|
||||
sum_rawdata,
|
||||
is_complete,
|
||||
repeat_times,
|
||||
fail_reason)
|
||||
SELECT
|
||||
@device_number,
|
||||
@point,
|
||||
@start_timestamp,
|
||||
@end_timestamp,
|
||||
@count_rawdata,
|
||||
@min_rawdata,
|
||||
@max_rawdata,
|
||||
@avg_rawdata,
|
||||
@sum_rawdata,
|
||||
@is_complete,
|
||||
@repeat_times,
|
||||
@fail_reason
|
||||
WHERE ROW_COUNT() = 0;";
|
||||
//新增/修改sql format
|
||||
var sql_update_format = @"BEGIN TRANSACTION;
|
||||
|
||||
@ -217,12 +247,10 @@ namespace BackendWorkerService.Services.Implement
|
||||
#endregion 時歸檔補償
|
||||
|
||||
#region 天歸檔補償
|
||||
using (IDbConnection conn = new SqlConnection(Connection1))
|
||||
{
|
||||
//取得所有須補償的設備資訊
|
||||
targetTable = "archive_electric_meter_day";
|
||||
var sql_error_day = string.Format(sql_error_format, targetTable);
|
||||
var error_days = conn.Query<ArchiveElectricMeter>(sql_error_day, new { RepeatTimes = repeatTimes }).ToList();
|
||||
var error_days = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_day, new { RepeatTimes = repeatTimes });
|
||||
|
||||
List<Dictionary<string, object>> archiveDayRawDatas = new List<Dictionary<string, object>>();
|
||||
if (error_days.Count() > 0)
|
||||
@ -267,8 +295,8 @@ namespace BackendWorkerService.Services.Implement
|
||||
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", error_day.Start_timestamp);
|
||||
archiveDayRawData.Add("@end_timestamp", error_day.End_timestamp);
|
||||
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);
|
||||
@ -295,22 +323,19 @@ namespace BackendWorkerService.Services.Implement
|
||||
|
||||
if (archiveDayRawDatas.Count() > 0)
|
||||
{
|
||||
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
||||
var sql_error_update = string.Format(sql_update_format, targetTable);
|
||||
conn.Execute(sql_error_update, archiveDayRawDatas);
|
||||
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, archiveDayRawDatas);
|
||||
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, archiveDayRawDatas);
|
||||
}
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
}
|
||||
#endregion 天歸檔補償
|
||||
|
||||
#region 週歸檔補償
|
||||
using (IDbConnection conn = new SqlConnection(Connection1))
|
||||
{
|
||||
//取得所有須補償的設備資訊
|
||||
targetTable = "archive_electric_meter_week";
|
||||
var sql_error_week = string.Format(sql_error_format, targetTable);
|
||||
var error_weeks = conn.Query<ArchiveElectricMeter>(sql_error_week, new { RepeatTimes = repeatTimes }).ToList();
|
||||
var error_weeks = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_week, new { RepeatTimes = repeatTimes });
|
||||
|
||||
List<Dictionary<string, object>> archiveWeekRawDatas = new List<Dictionary<string, object>>();
|
||||
if (error_weeks.Count() > 0)
|
||||
@ -355,8 +380,8 @@ namespace BackendWorkerService.Services.Implement
|
||||
Dictionary<string, object> archiveWeekRawData = new Dictionary<string, object>();
|
||||
archiveWeekRawData.Add("@device_number", error_week.Device_number);
|
||||
archiveWeekRawData.Add("@point", error_week.Point);
|
||||
archiveWeekRawData.Add("@start_timestamp", error_week.Start_timestamp);
|
||||
archiveWeekRawData.Add("@end_timestamp", error_week.End_timestamp);
|
||||
archiveWeekRawData.Add("@start_timestamp", DateTime.Parse(error_week.Start_timestamp, System.Globalization.CultureInfo.CurrentCulture));
|
||||
archiveWeekRawData.Add("@end_timestamp", DateTime.Parse(error_week.End_timestamp, System.Globalization.CultureInfo.CurrentCulture));
|
||||
archiveWeekRawData.Add("@is_complete", 0);
|
||||
archiveWeekRawData.Add("@repeat_times", ++error_week.Repeat_times);
|
||||
archiveWeekRawData.Add("@fail_reason", archiveWeekJson);
|
||||
@ -383,22 +408,19 @@ namespace BackendWorkerService.Services.Implement
|
||||
|
||||
if (archiveWeekRawDatas.Count() > 0)
|
||||
{
|
||||
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
||||
var sql_error_update = string.Format(sql_update_format, targetTable);
|
||||
conn.Execute(sql_error_update, archiveWeekRawDatas);
|
||||
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, archiveWeekRawDatas);
|
||||
await backgroundServiceRepository.ExecuteSql(Mysql_error_update, archiveWeekRawDatas);
|
||||
}
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
}
|
||||
#endregion 週歸檔補償
|
||||
|
||||
#region 月歸檔補償
|
||||
using (IDbConnection conn = new SqlConnection(Connection1))
|
||||
{
|
||||
//取得所有須補償的設備資訊
|
||||
targetTable = "archive_electric_meter_month";
|
||||
var sql_error_month = string.Format(sql_error_format, targetTable);
|
||||
var error_months = conn.Query<ArchiveElectricMeter>(sql_error_month, new { RepeatTimes = repeatTimes }).ToList();
|
||||
var error_months = await backgroundServiceRepository.GetAllAsync<ArchiveElectricMeter>(sql_error_month, new { RepeatTimes = repeatTimes });
|
||||
|
||||
List<Dictionary<string, object>> archiveMonthRawDatas = new List<Dictionary<string, object>>();
|
||||
if (error_months.Count() > 0)
|
||||
@ -446,8 +468,8 @@ namespace BackendWorkerService.Services.Implement
|
||||
Dictionary<string, object> archiveMonthRawData = new Dictionary<string, object>();
|
||||
archiveMonthRawData.Add("@device_number", error_month.Device_number);
|
||||
archiveMonthRawData.Add("@point", error_month.Point);
|
||||
archiveMonthRawData.Add("@start_timestamp", error_month.Start_timestamp);
|
||||
archiveMonthRawData.Add("@end_timestamp", error_month.End_timestamp);
|
||||
archiveMonthRawData.Add("@start_timestamp", DateTime.Parse(error_month.Start_timestamp, System.Globalization.CultureInfo.CurrentCulture));
|
||||
archiveMonthRawData.Add("@end_timestamp", DateTime.Parse(error_month.End_timestamp, System.Globalization.CultureInfo.CurrentCulture));
|
||||
archiveMonthRawData.Add("@is_complete", 0);
|
||||
archiveMonthRawData.Add("@repeat_times", ++error_month.Repeat_times);
|
||||
archiveMonthRawData.Add("@fail_reason", archiveMonthJson);
|
||||
@ -474,13 +496,12 @@ namespace BackendWorkerService.Services.Implement
|
||||
|
||||
if (archiveMonthRawDatas.Count() > 0)
|
||||
{
|
||||
var Mysql_error_update = string.Format(MYsql_update_format, targetTable);
|
||||
var sql_error_update = string.Format(sql_update_format, targetTable);
|
||||
conn.Execute(sql_error_update, archiveMonthRawDatas);
|
||||
await backgroundServiceMsSqlRepository.ExecuteSql(sql_error_update, archiveMonthRawDatas);
|
||||
await backgroundServiceRepository.ExecuteSql(MYsql_update_format, archiveMonthRawDatas);
|
||||
}
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
}
|
||||
#endregion 月歸檔補償
|
||||
|
||||
result = true;
|
||||
|
@ -7,23 +7,40 @@
|
||||
}
|
||||
},
|
||||
"BackgroundServiceCron": {
|
||||
"ExecutionBackgroundServicePlanJob": "0 0 2 * * ?",
|
||||
"MessageNotificationJob": "0 0 2 * * ?",
|
||||
"DataDeliveryJob": "0 0 2 * * ?",
|
||||
"RegularUpdateDBTableJob": "0 0 2 * * ?",
|
||||
"ParkingJob": "0 0 2 * * ?",
|
||||
"ArchiveElectricMeterHourJob": "0 0 2 * * ?",
|
||||
"ArchiveElectricMeterDayJob": "0 0 2 * * ?",
|
||||
"ExecutionBackgroundServicePlanJob": "0 0 1 * * ?",
|
||||
"MessageNotificationJob": "0 0 1 * * ?",
|
||||
"DataDeliveryJob": "0 0 1 * * ?",
|
||||
"RegularUpdateDBTableJob": "0 0 1 * * ?",
|
||||
"ParkingJob": "0 0 1 * * ?",
|
||||
"ArchiveElectricMeterHourJob": "0 0 1 * * ?",
|
||||
"ArchiveElectricMeterDayJob": "0 0 1 * * ?",
|
||||
"WeatherAPIJob": "0/5 * * * * ?"
|
||||
},
|
||||
"DBConfig": {
|
||||
//"MySqlDBConfig": {
|
||||
// "Server": "TNi6aupYHPZT8ZU177KTKw==", //172.16.220.251
|
||||
// "Port": "mkF51jVbg40V5K5eTh2Ckw==",
|
||||
// "Database": "VvfWH/59gQguY2eA2xBCug==",
|
||||
// "Root": "IV8Ec1Ng2AWAnkBafXy2kg==",
|
||||
// "Password": "Jue6jMFRi11meN6xbdKwDA=="
|
||||
//},
|
||||
"MySqlDBConfig": {
|
||||
"Server": "TNi6aupYHPZT8ZU177KTKw==", //172.16.220.251
|
||||
"Port": "mkF51jVbg40V5K5eTh2Ckw==",
|
||||
"Database": "VvfWH/59gQguY2eA2xBCug==",
|
||||
"Root": "IV8Ec1Ng2AWAnkBafXy2kg==",
|
||||
"Password": "Jue6jMFRi11meN6xbdKwDA=="
|
||||
"Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201
|
||||
"Port": "js2LutKe+rdjzdxMPQUrvQ==",
|
||||
//"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
|
||||
//"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp
|
||||
"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome
|
||||
//"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel
|
||||
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
|
||||
"Password": "FVAPxztxpY4gJJKQ/se4bQ=="
|
||||
},
|
||||
"MSSqlDBConfig": {
|
||||
"Server": "bJm+UAtbeaTjDmp/A5ep2w==", //0.130
|
||||
"Port": "S5cUXKnKOacFtFy9+0dtpw==",
|
||||
"Database": "VvfWH/59gQguY2eA2xBCug==", //taipei_dome
|
||||
"Root": "sD8GZ9UPiIQGU6dU011/4A==",
|
||||
"Password": "0O24es2ZRF5uoJ4aU+YCdg=="
|
||||
}
|
||||
//"MSSqlDBConfig": { //greencloud.fic.com.tw,1433
|
||||
// "Server": "ueFp+VFb200lhh1Uctc97WH0/tX6tfXYU2v1oxCWuuM=",
|
||||
// "Port": "S5cUXKnKOacFtFy9+0dtpw==",
|
||||
@ -31,13 +48,13 @@
|
||||
// "Root": "+plVKQ+enAqt7BYV2uMQng==",
|
||||
// "Password": "0O24es2ZRF5uoJ4aU+YCdg=="
|
||||
//}
|
||||
"MSSqlDBConfig": {
|
||||
"Server": "zp3Nilx0PISEEC4caZWqCg==", //172.16.220.250
|
||||
"Port": "7puf4kd9qJ/q0fq2QASWeQ==",
|
||||
"Database": "VvfWH/59gQguY2eA2xBCug==",
|
||||
"Root": "sD8GZ9UPiIQGU6dU011/4A==",
|
||||
"Password": "Jue6jMFRi11meN6xbdKwDA=="
|
||||
}
|
||||
//"MSSqlDBConfig": {
|
||||
// "Server": "zp3Nilx0PISEEC4caZWqCg==", //172.16.220.250
|
||||
// "Port": "7puf4kd9qJ/q0fq2QASWeQ==",
|
||||
// "Database": "VvfWH/59gQguY2eA2xBCug==",
|
||||
// "Root": "sD8GZ9UPiIQGU6dU011/4A==",
|
||||
// "Password": "Jue6jMFRi11meN6xbdKwDA=="
|
||||
//}
|
||||
|
||||
},
|
||||
"SMTPConfig": {
|
||||
|
@ -14,13 +14,30 @@
|
||||
"RegularUpdateDBTableJob": "0 0 2 * * ?"
|
||||
},
|
||||
"DBConfig": {
|
||||
//"MySqlDBConfig": {
|
||||
// "Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201
|
||||
// "Port": "js2LutKe+rdjzdxMPQUrvQ==",
|
||||
// "Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
|
||||
// "Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
|
||||
// "Password": "FVAPxztxpY4gJJKQ/se4bQ=="
|
||||
//},
|
||||
"MySqlDBConfig": {
|
||||
"Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201
|
||||
"Port": "js2LutKe+rdjzdxMPQUrvQ==",
|
||||
"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
|
||||
//"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
|
||||
//"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp
|
||||
"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome
|
||||
//"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel
|
||||
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
|
||||
"Password": "FVAPxztxpY4gJJKQ/se4bQ=="
|
||||
},
|
||||
"MSSqlDBConfig": {
|
||||
"Server": "bJm+UAtbeaTjDmp/A5ep2w==", //0.130
|
||||
"Port": "S5cUXKnKOacFtFy9+0dtpw==",
|
||||
"Database": "VvfWH/59gQguY2eA2xBCug==", //taipei_dome
|
||||
"Root": "sD8GZ9UPiIQGU6dU011/4A==",
|
||||
"Password": "0O24es2ZRF5uoJ4aU+YCdg=="
|
||||
}
|
||||
//"MSSqlDBConfig": {
|
||||
// "Server": "avZg8PA8C9GVgYZBgEKzCg==",
|
||||
// "Port": "lJA0KPkG6RvFfTgWiXFyUw==",
|
||||
|
@ -0,0 +1,18 @@
|
||||
using Repository.BackendRepository.Interface;
|
||||
using Repository.Helper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Repository.BackendRepository.Implement
|
||||
{
|
||||
public class BackgroundServiceMsSqlRepository : BackendRepository, IBackgroundServiceMsSqlRepository
|
||||
{
|
||||
public BackgroundServiceMsSqlRepository(IDatabaseHelper databaseHelper) : base(databaseHelper)
|
||||
{
|
||||
UseDB = "MSSQL";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Repository.BackendRepository.Interface
|
||||
{
|
||||
public interface IBackgroundServiceMsSqlRepository : IBackendRepository
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user