diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 974f887..2e19f88 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -1046,6 +1046,10 @@ namespace SolarPower.Controllers } var sheet = workbook.CreateSheet(powerstationid.Name); var Formbody = GetForm(select_Table);//取body + if(Formbody.Result.Data.Count == 0) + { + continue; + } var Formhead = GetTableHead(select_Table);//取head int RowPosition = 0; @@ -1099,6 +1103,7 @@ namespace SolarPower.Controllers var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = ""; var GeneratingCapacity = ""; foreach (dynamic body in Formbody.Result.Data) { + index = 0; var dbody = body as IDictionary; thour = Checknull(Math.Round(Convert.ToDouble(dbody["tothour"]), 2).ToString()); diff --git a/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs b/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs index 8b25a1b..f5b8840 100644 --- a/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs +++ b/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs @@ -57,7 +57,7 @@ namespace SolarPower.Quartz.Jobs logger.LogInformation("【CalcInverter15minJob】【開始取得電站資料】"); var powerStations = await powerStationRepository.GetAllAsync(); logger.LogInformation("【CalcInverter15minJob】【取得成功電站資料】"); - logger.LogInformation("【CalcInverter15minJob】【電站資料】 - {0}", System.Text.Json.JsonSerializer.Serialize(powerStations)); + //logger.LogInformation("【CalcInverter15minJob】【電站資料】 - {0}", System.Text.Json.JsonSerializer.Serialize(powerStations)); #endregion List calcInverter15mins = new List(); @@ -75,44 +75,46 @@ namespace SolarPower.Quartz.Jobs //var dateNowTime = string.Format("2021-07-{0} {1}", day_array[i], time_array[j]); - #region step2. 從電站的DB及電站編號找出該電站的控制器 - foreach (var powerStation in powerStations) + #region step2. 從電站的DB及電站編號找出該電站的控制器 + foreach (var powerStation in powerStations) + { + try + { + //取得所有該電站的逆變器 + logger.LogInformation("【CalcInverter15minJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime); + var controllers = await powerStationRepository.GetAllDeviceControllerId(powerStation.Id, powerStation.SiteDB); + var inverters = await powerStationRepository.InverterTable(controllers, powerStation.SiteDB); + var inverterIds = inverters.Where(x => x.Enabled == 1 && x.Status != 0).Select(x => x.InverterId).ToList(); + logger.LogInformation("【CalcInverter15minJob】【取得成功電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime); + + #region step2-1. 計算該電站逆變器每15min 的值 + var table_name = String.Format("s{1}01_inv", powerStation.SiteDB, powerStation.Code); + var full_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, table_name); + var exist = await powerStationRepository.ExistTable(powerStation.SiteDB, table_name); + + if (!string.IsNullOrEmpty(exist)) { - - //取得所有該電站的逆變器 - logger.LogInformation("【CalcInverter15minJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime); - var controllers = await powerStationRepository.GetAllDeviceControllerId(powerStation.Id, powerStation.SiteDB); - var inverters = await powerStationRepository.InverterTable(controllers, powerStation.SiteDB); - var inverterIds = inverters.Where(x => x.Enabled == 1 && x.Status != 0).Select(x => x.InverterId).ToList(); - logger.LogInformation("【CalcInverter15minJob】【取得成功電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime); - - #region step2-1. 計算該電站逆變器每15min 的值 - var table_name = String.Format("s{1}01_inv", powerStation.SiteDB, powerStation.Code); - var full_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, table_name); - var exist = await powerStationRepository.ExistTable(powerStation.SiteDB, table_name); - - if (!string.IsNullOrEmpty(exist)) + logger.LogInformation("【CalcInverter15minJob】【開始計算電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime); + var calcInverter15min = await powerStationRepository.CalcInverterHisyort15minData(dateNowTime, powerStation.SiteDB, full_table_name, inverterIds); + logger.LogInformation("【CalcInverter15minJob】【計算完成電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime); + logger.LogInformation("【CalcInverter15minJob】【計算結果】 - {0}", System.Text.Json.JsonSerializer.Serialize(calcInverter15mins)); + if (calcInverter15min.Count() > 0) { - logger.LogInformation("【CalcInverter15minJob】【開始計算電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime); - var calcInverter15min = await powerStationRepository.CalcInverterHisyort15minData(dateNowTime, powerStation.SiteDB, full_table_name, inverterIds); - logger.LogInformation("【CalcInverter15minJob】【計算完成電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime); - logger.LogInformation("【CalcInverter15minJob】【計算結果】 - {0}", System.Text.Json.JsonSerializer.Serialize(calcInverter15mins)); - if (calcInverter15min.Count() > 0) + foreach (var inverterHistory in calcInverter15min) { - foreach (var inverterHistory in calcInverter15min) - { - inverterHistory.TIMESTAMP = Convert.ToDateTime(inverterHistory.TIMESTAMP + ":00").ToString("yyyy-MM-dd HH:mm:ss"); - inverterHistory.PowerStationId = powerStation.Id; + inverterHistory.TIMESTAMP = Convert.ToDateTime(inverterHistory.TIMESTAMP + ":00").ToString("yyyy-MM-dd HH:mm:ss"); + inverterHistory.PowerStationId = powerStation.Id; - calcInverter15mins.Add(inverterHistory); - } + calcInverter15mins.Add(inverterHistory); } } - - + } + } + catch (Exception ex) + { + logger.LogError("【CalcInverter15minJob】【電站[{0}]計算失敗】 - {1}", powerStation.Code, ex.ToString()); + } #endregion - - } #endregion @@ -127,7 +129,14 @@ namespace SolarPower.Quartz.Jobs "KWHKWP", }; - await powerStationRepository.AddInverter15minHistory(calcInverter15mins, inverter_history_properties); + try + { + await powerStationRepository.AddInverter15minHistory(calcInverter15mins, inverter_history_properties); + } + catch (Exception ex) + { + logger.LogError("【CalcInverter15minJob】【儲存15分鐘歷史紀錄失敗】 - {0}", ex.ToString()); + } #endregion // } //} @@ -166,11 +175,11 @@ namespace SolarPower.Quartz.Jobs logger.LogInformation("【CalcInverter15minJob】檢測完成逆變器狀態"); } - catch(Exception exception) + catch (Exception exception) { logger.LogError("【CalcInverter15minJob】檢測逆變器狀態失敗 - [Exception] {0}", exception.Message); } - + } catch (Exception exception) { diff --git a/SolarPower/Quartz/Jobs/OperationScheduleJob.cs b/SolarPower/Quartz/Jobs/OperationScheduleJob.cs index b1a9027..10a1d73 100644 --- a/SolarPower/Quartz/Jobs/OperationScheduleJob.cs +++ b/SolarPower/Quartz/Jobs/OperationScheduleJob.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json; using Quartz; using SolarPower.Models; +using SolarPower.Models.User; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; @@ -198,10 +199,25 @@ namespace SolarPower.Quartz.Jobs #region 寄送日月報 var users = userRepository.GetAllAsync(); - var ttt = new List() { - "s506488@gmail.com", - "cesarliuc@gmail.com" - }; + + //var usertest = new List(); + //var oneuser = new User() + //{ + // Account = "cesarliuc@gmail.com", + // Password = "np/F0eliIy3lPJe1tU18oiG7dzKRrpVw16/XZpHOph8=", + // Id = 13, + // Email = "cesarliuc@gmail.com", + // Status = 1, + // Name = "TEST" + //}; + //usertest.Add(oneuser); + + //var ttt = new List() { + // "s506488@gmail.com", + // "cesarliuc@gmail.com" + //}; + + foreach (var user in users.Result) { @@ -244,15 +260,15 @@ namespace SolarPower.Quartz.Jobs Type = 1 }; List properties = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Attachment", - "RecipientName", - "Type" - }; + { + "UserId", + "EmailType", + "RecipientEmail", + "Subject", + "Attachment", + "RecipientName", + "Type" + }; await noticeScheduleRepository.AddOneAsync(DaySchedule, properties); } } @@ -279,24 +295,24 @@ namespace SolarPower.Quartz.Jobs Type = 1 }; List properties = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Attachment", - "RecipientName", - "Type" - }; + { + "UserId", + "EmailType", + "RecipientEmail", + "Subject", + "Attachment", + "RecipientName", + "Type" + }; await noticeScheduleRepository.AddOneAsync(MaxSchedule, properties); if (DateTime.Now.ToString("dd") == "01") { Select_table2 maxmonthexcel = new Select_table2() { - FormType = 0, + FormType = 1, PowerStation = sentMaxpowerstations, - SearchType = 0, + SearchType = 1, Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM"), Userid = user.Id }; diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 1111802..596da1e 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -393,7 +393,7 @@ namespace SolarPower.Repository.Implement GROUP BY a.Id,a.time ) n ON n.Id = ps.Id WHERE ps.Id IN @ids ORDER BY ps.CityId"; - result = (await conn.QueryAsync(sql,new { ids = ids})).ToList(); + result = (await conn.QueryAsync(sql,new { ids = ids}, commandTimeout: 300)).ToList(); } catch (Exception exception) { @@ -597,7 +597,7 @@ namespace SolarPower.Repository.Implement break; } - a = await conn.QueryAsync(sql); + a = await conn.QueryAsync(sql,commandTimeout: 300); } catch (Exception exception) { diff --git a/SolarPower/Services/Implement/SendEmailService.cs b/SolarPower/Services/Implement/SendEmailService.cs index 397ad4f..7303192 100644 --- a/SolarPower/Services/Implement/SendEmailService.cs +++ b/SolarPower/Services/Implement/SendEmailService.cs @@ -53,7 +53,7 @@ namespace SolarPower.Services } catch (Exception ex) { - //_log.LogError("【SendEmailSMSService】 " + noticeInfo.Recipient_email + "寄送信件失敗"); + throw ex; return false; }