log 增加筆數

This commit is contained in:
cesar liu 2022-04-06 15:33:30 +08:00
parent 3f34f8a052
commit cad8e37fbd
2 changed files with 20 additions and 14 deletions

View File

@ -17,14 +17,14 @@ namespace solarApp.Service
/// <param name="errMessage">異常資訊</param>
/// <param name="myCon">連線資訊</param>
/// <param name="cmd">command物件</param>
public void insert_log(string power_stationID, string action_name, double duration_sec, string src_table, string dest_table, string errMessage, MySqlConnection myCon , MySqlCommand cmd) {
public void insert_log(string power_stationID, string action_name, double duration_sec, string src_table, string dest_table, string procResult, string errMessage, string note, MySqlConnection myCon , MySqlCommand cmd) {
string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string procResult = (string.IsNullOrEmpty(errMessage)) ? "0" : "1";
string sql = @"INSERT INTO `solar_master`.`log_archive`(power_stationID, `action_name`, `action_time`, `duration_sec`, `src_table`, `dest_table`, `result`, `err_txt`)
//string procResult = (string.IsNullOrEmpty(errMessage)) ? "0" : "1";
string sql = @"INSERT INTO `solar_master`.`log_archive`(power_stationID, `action_name`, `action_time`, `duration_sec`, `src_table`, `dest_table`, `result`, `err_txt`, `note`)
VALUES ("+ power_stationID + ", '" + action_name + "', '" + nowTime + "', " + duration_sec + ", '" + // action_time, duration_sec
src_table + "', '"+ dest_table + "', b'"+ procResult + "', '" + // src_table, dest_table, result
errMessage + "');"; // err_txt
errMessage + "', '"+ note +"');"; // err_txt
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}

View File

@ -209,6 +209,7 @@ namespace solarApp.Service
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
sql = @"
INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP)
select PowerStationId, reportdate, a.inverterid, KWH, TODAYKWH, (kwh/(capacity/4)) kwpkwp from
@ -605,15 +606,17 @@ ALTER TABLE `temp_invDay{_powerStationID}_s1` ADD INDEX `temp_indexs1` (report_d
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
cmd.CommandText = @$"select count(*) ct from temp_invDay{_powerStationID}_s1";
var rowCT = cmd.ExecuteScalar();
//select LAST_INSERT_ID()
TimeSpan duration = DateTime.Now - dt_start;
arclog.insert_log(_powerStationID, "report_day step1", duration.TotalSeconds, "inverter_history_hour", "temp_invDay", "", conn, cmd);
arclog.insert_log(_powerStationID, "report_day step1", duration.TotalSeconds, "inverter_history_hour", "temp_invDay", "0", "", rowCT.ToString(), conn, cmd);
}
catch (Exception ex)
{
TimeSpan duration = DateTime.Now - dt_start;
arclog.insert_log(_powerStationID, "report_day step1", duration.TotalSeconds, "inverter_history_hour", "temp_invDay", ex.Message, conn, cmd);
arclog.insert_log(_powerStationID, "report_day step1", duration.TotalSeconds, "inverter_history_hour", "temp_invDay", "1", "", ex.Message, conn, cmd);
}
#endregion
@ -647,15 +650,17 @@ from temp_invDay{_powerStationID}_s1 a join
try
{
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
int rowCT = cmd.ExecuteNonQuery();
//cmd.CommandText = @$"select count(*) ct from report_invday where powerStationID = {_powerStationID} and left(`TIMESTAMP`,10) = '{_date1}'";
//var rowCT = cmd.ExecuteScalar();
TimeSpan duration = DateTime.Now - dt_start2 ;
arclog.insert_log(_powerStationID, "report_day step2 inv_no01", duration.TotalSeconds, "inverter_history_hour", "report_invday", "", conn, cmd);
arclog.insert_log(_powerStationID, "report_day step2 inv_no01", duration.TotalSeconds, "inverter_history_hour", "report_invday", "0", "", rowCT.ToString(), conn, cmd);
}
catch (Exception ex)
{
TimeSpan duration = DateTime.Now - dt_start2 ;
arclog.insert_log(_powerStationID, "report_day step2 inv_no01", duration.TotalSeconds, "inverter_history_hour", "report_invday", ex.Message, conn, cmd);
arclog.insert_log(_powerStationID, "report_day step2 inv_no01", duration.TotalSeconds, "inverter_history_hour", "report_invday", "1", "", ex.Message, conn, cmd);
}
// conn.Execute(sql);
@ -719,23 +724,24 @@ set a.inv_02 = b.inv_02 ");
try
{
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
int rowCT = cmd.ExecuteNonQuery();
sql = @$"DROP TABLE IF EXISTS temp_invDay{_powerStationID}_s1; ";
//conn.Execute(ss);
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
if (_logger != null)
_logger.LogInformation("【Proc_inv_日報 table 】執行完成[{0}]在{1} inv_get_SQLStatement", _siteID, _date1);
TimeSpan duration = DateTime.Now - dt_start3;
arclog.insert_log(_powerStationID, "report_day step3 update inv02", duration.TotalSeconds, "inverter_history_hour", "report_invday", "", conn, cmd);
arclog.insert_log(_powerStationID, "report_day step3 update inv02", duration.TotalSeconds, "inverter_history_hour", "report_invday", "0", "", rowCT.ToString(), conn, cmd);
}
catch (Exception ex)
{
TimeSpan duration = DateTime.Now - dt_start3 ;
arclog.insert_log(_powerStationID, "report_day step3 update inv02", duration.TotalSeconds, "inverter_history_hour", "report_invday", ex.Message, conn, cmd);
arclog.insert_log(_powerStationID, "report_day step3 update inv02", duration.TotalSeconds, "inverter_history_hour", "report_invday", "1", "", ex.Message, conn, cmd);
if (_logger != null)
{
_logger.LogError("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement", _siteID, _date1);