diff --git a/SolarPower/Startup.cs b/SolarPower/Startup.cs index a22c6d0..05a2700 100644 --- a/SolarPower/Startup.cs +++ b/SolarPower/Startup.cs @@ -96,7 +96,7 @@ namespace SolarPower #region 加入背景執行 //services.AddHostedService(); //if (envName == "Production") - if (!envName != "Production") + if (envName == "Production") { ////添加Quartz服務 services.AddSingleton(); diff --git a/solarApp/Service/archiveLowData.cs b/solarApp/Service/archiveLowData.cs index 9e1727e..cdb6640 100644 --- a/solarApp/Service/archiveLowData.cs +++ b/solarApp/Service/archiveLowData.cs @@ -33,8 +33,7 @@ namespace solarApp.Service public bool archiveData(string siteID) { bool result = false; - try - { + _siteID = siteID; //_date1 = date1; get_siteInfo(); @@ -44,11 +43,7 @@ namespace solarApp.Service moveData_inv(); moveData_sensor(); result = true; - } - catch (Exception ex) - { - throw ex; - } + return result; } @@ -302,6 +297,8 @@ namespace solarApp.Service // log TimeSpan duration = DateTime.Now - dt_start1; arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID}_station", $"{_siteDB}_history.s{_siteID}_station", "0", "", rowCT.ToString(), conn, null); + + dt_start1 = DateTime.Now; //芷文祉鞈 @@ -310,7 +307,9 @@ namespace solarApp.Service rowCT = conn.Execute(for_delete_station, commandTimeout: 600); //System.Diagnostics.Debug.WriteLine($"ArchiveRowData{_siteDB}.s{_siteID}_sensoravg祉宏逢_siteDB}_history.s{_siteID}_sensoravg祉宏鞈慮dateTime} {delete_station.ToString()} 蝑"); duration = DateTime.Now - dt_start1; + arclog.insert_log(_powerStationID, "delete raw s2", duration.TotalSeconds, $"{_siteDB}.s{_siteID}_station", "", "0", "", rowCT.ToString(), conn, null); + #endregion @@ -322,6 +321,7 @@ namespace solarApp.Service //System.Diagnostics.Debug.WriteLine("ArchiveRowData[祉宏鞈憭望"); TimeSpan duration = DateTime.Now - dt_start1; arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID}_station", $"{_siteDB}_history.s{_siteID}_station", "1", ex.Message, "0", conn, null); + throw ex; } @@ -344,15 +344,16 @@ namespace solarApp.Service #region inv祉宏 dt_start1 = DateTime.Now; // System.Diagnostics.Debug.WriteLine($"ArchiveRowData憪瑁[{_siteDB}.s{_siteID}_inv]鞈銵典[{_siteDB}_history.s{_siteID}_inv]祉宏"); - string for_insert_inv = $@"INSERT {_siteDB}_history.s{_siteID01}_inv - SELECT * FROM {_siteDB}.s{_siteID01}_inv + string for_insert_inv = $@"INSERT {_siteDB}_history.s{_siteID01}_inv(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `INVERTERID`, `SN`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `ACRUNTIME`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `DCRUNTIME`, `WH`, `TODAYKWH`, `TOTALKWH`, `PR`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `CrdTime`) + SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `INVERTERID`, `SN`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `ACRUNTIME`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `DCRUNTIME`, `WH`, `TODAYKWH`, `TOTALKWH`, `PR`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `CrdTime` FROM {_siteDB}.s{_siteID01}_inv WHERE LEFT(crdTime, 7) < '2022-07' "; int rowCT = conn.Execute(for_insert_inv, commandTimeout: 6000); //System.Diagnostics.Debug.WriteLine($"ArchiveRowData{_siteDB}.s{_siteID}_inv銝鞈撖怠亥逢_siteDB}_history.s{_siteID}_inv撖怠交慮dateTime}"); // log TimeSpan duration = DateTime.Now - dt_start1; arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_inv", $"{_siteDB}_history.s{_siteID01}_inv", "0", "", rowCT.ToString(), conn, null); - dt_start1 = DateTime.Now; + //arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd); + dt_start1 = DateTime.Now; string for_delete_inv = $@"DELETE FROM {_siteDB}.s{_siteID01}_inv WHERE LEFT(crdTime, 7) < '2022-07'"; @@ -365,6 +366,7 @@ namespace solarApp.Service { TimeSpan duration = DateTime.Now - dt_start1; arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_station", $"{_siteDB}_history.s{_siteID01}_station", "1", ex.Message, "0", conn, null); + //arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd); throw ex; } #endregion @@ -387,8 +389,8 @@ namespace solarApp.Service #region sensoravg祉宏 dt_start1 = DateTime.Now; //System.Diagnostics.Debug.WriteLine($"ArchiveRowData憪瑁[{_siteDB}.s{_siteID}_sensoravg]鞈銵典[{_siteDB}_history.s{_siteID}_sensoravg]祉宏"); - string for_insert_sensoravg = $@"INSERT {_siteDB}_history.s{_siteID01}_sensoravg - SELECT * FROM {_siteDB}.s{_siteID01}_sensoravg + string for_insert_sensoravg = $@"INSERT {_siteDB}_history.s{_siteID01}_sensoravg(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `SENSORAVG01`, `SENSORAVG02`, `SENSORAVG03`, `SENSORAVG04`, `SENSORAVG05`, `SENSORAVG06`, `SENSORAVG07`, `SENSORAVG08`, `SENSORAVG09`, `SENSORAVG10`, `SENSORAVG11`, `SENSORAVG12`, `SENSORAVG13`, `SENSORAVG14`, `SENSORAVG15`, `SENSORAVG16`, `SENSORAVG17`, `SENSORAVG18`, `SENSORAVG19`, `SENSORAVG20`, `SENSORAVG21`, `SENSORAVG22`, `SENSORAVG23`, `SENSORAVG24`, `SENSORAVG25`, `SENSORAVG26`, `SENSORAVG27`, `SENSORAVG28`, `SENSORAVG29`, `SENSORAVG30`, `SENSORAVG31`, `SENSORAVG32`, `SENSORAVG33`, `SENSORAVG34`, `SENSORAVG35`, `SENSORAVG36`, `SENSORAVG37`, `SENSORAVG38`, `SENSORAVG39`, `SENSORAVG40`, `SENSORAVG41`, `SENSORAVG42`, `SENSORAVG43`, `SENSORAVG44`, `SENSORAVG45`, `SENSORAVG46`, `SENSORAVG47`, `SENSORAVG48`, `SENSORAVG49`, `SENSORAVG50`, `CrdTime`) + SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `SENSORAVG01`, `SENSORAVG02`, `SENSORAVG03`, `SENSORAVG04`, `SENSORAVG05`, `SENSORAVG06`, `SENSORAVG07`, `SENSORAVG08`, `SENSORAVG09`, `SENSORAVG10`, `SENSORAVG11`, `SENSORAVG12`, `SENSORAVG13`, `SENSORAVG14`, `SENSORAVG15`, `SENSORAVG16`, `SENSORAVG17`, `SENSORAVG18`, `SENSORAVG19`, `SENSORAVG20`, `SENSORAVG21`, `SENSORAVG22`, `SENSORAVG23`, `SENSORAVG24`, `SENSORAVG25`, `SENSORAVG26`, `SENSORAVG27`, `SENSORAVG28`, `SENSORAVG29`, `SENSORAVG30`, `SENSORAVG31`, `SENSORAVG32`, `SENSORAVG33`, `SENSORAVG34`, `SENSORAVG35`, `SENSORAVG36`, `SENSORAVG37`, `SENSORAVG38`, `SENSORAVG39`, `SENSORAVG40`, `SENSORAVG41`, `SENSORAVG42`, `SENSORAVG43`, `SENSORAVG44`, `SENSORAVG45`, `SENSORAVG46`, `SENSORAVG47`, `SENSORAVG48`, `SENSORAVG49`, `SENSORAVG50`, `CrdTime` FROM {_siteDB}.s{_siteID01}_sensoravg WHERE LEFT(crdTime, 7) < '2022-07'"; int rowCT = conn.Execute(for_insert_sensoravg, commandTimeout: 600); // log diff --git a/solarApp/Service/getStationSvc.cs b/solarApp/Service/getStationSvc.cs index 4bfbb73..a1b6b08 100644 --- a/solarApp/Service/getStationSvc.cs +++ b/solarApp/Service/getStationSvc.cs @@ -180,7 +180,7 @@ namespace solarApp.Service conn.Open(); // 01 批嗅函楊 string sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName from power_station - where deleted = 0 and `status`= 1 "; + where deleted = 0 and `status`= 1"; // id <> 14";and id > 24 List ds = conn.Query(sql).AsList(); conn.Close(); diff --git a/solarApp/Service/procArchiveLog.cs b/solarApp/Service/procArchiveLog.cs index 4a429a0..260e6f5 100644 --- a/solarApp/Service/procArchiveLog.cs +++ b/solarApp/Service/procArchiveLog.cs @@ -26,12 +26,18 @@ namespace solarApp.Service } else _cmd = cmd; + string errMsg = string.Empty; + if (!string.IsNullOrEmpty(errMessage)) + { + errMsg = errMessage.Replace("'", "''"); + } + 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`, `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 + "', '"+ note +"');"; // err_txt + errMsg + "', '"+ note +"');"; // err_txt _cmd.CommandText = sql; _cmd.ExecuteNonQuery(); }