diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index eb63f51..5b2b420 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -2280,7 +2280,8 @@ namespace SolarPower.Controllers ControllerId = post.ControllerId, SerialNumber = Newnum, InverterId = deviceController.ControllerId + Newnum, - CreatedBy = myUser.Id + CreatedBy = myUser.Id, + BrandNum = post.BrandNum }; List properties = new List() { @@ -2295,7 +2296,8 @@ namespace SolarPower.Controllers "ControllerId", "SerialNumber", "CreatedBy", - "InverterId" + "InverterId", + "BrandNum" }; await powerStationRepository.AddInverter(inverter, properties, powerStation.SiteDB); apiResult.Code = "0000"; @@ -2322,7 +2324,8 @@ namespace SolarPower.Controllers InverterName = post.InverterName, Pyrheliometer = post.Pyrheliometer, ControllerId = post.ControllerId, - UpdatedBy = myUser.Id + UpdatedBy = myUser.Id, + BrandNum = post.BrandNum }; List properties = new List() { @@ -2336,7 +2339,8 @@ namespace SolarPower.Controllers "InverterName", "Pyrheliometer", "ControllerId", - "UpdatedBy" + "UpdatedBy", + "BrandNum" }; await powerStationRepository.UpdateInverter(inverter, properties, powerStation.SiteDB); apiResult.Code = "0000"; diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index c37bcde..74c785f 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -553,6 +553,7 @@ namespace SolarPower.Models.PowerStation public int Status { get; set; }//狀態 public string SerialNumber { get; set; }//流水號 public string InverterId { get; set; }//逆變器id + public string BrandNum { get; set; }//廠商序號 } /// /// 控制器datatable diff --git a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs index 7263bbc..8b8bd1f 100644 --- a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs @@ -36,180 +36,6 @@ namespace SolarPower.Quartz.Jobs { logger.LogInformation("【CalcAvgPowerStationJob】【任務開始】"); - #region 寄送日月報 - var users = userRepository.GetAllAsync(); - - foreach (var user in users.Result) - { - - - List powerstations = new List(); - powerstations = await noticeScheduleRepository.GetPowerStationOperationPersonnel(user.Id); - if (powerstations.Count == 0) - { - continue; - } - List sentdaypowerstations = powerstations.Where(x => x.EmailDayReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); - List sentMaxpowerstations = powerstations.Where(x => x.EmailComplexReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); - - Controllers.StationReportController stationReportController = new Controllers.StationReportController(powerStationRepository, stationReportRepository); - //日報表 - if (sentdaypowerstations.Count != 0) - { - Excel dayexcel = new Excel() - { - FormType = 0, - PowerStation = sentdaypowerstations, - SearchType = 0, - Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"), - Userid = user.Id - }; - var stationReportName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(dayexcel, Formatting.Indented)); - if(stationReportName != "") - { - NoticeSchedule DaySchedule = new NoticeSchedule() - { - UserId = user.Id, - EmailType = 0, - RecipientEmail = user.Email, - Subject = "日報表", - Attachment = stationReportName, - RecipientName = user.Name, - Type = 1 - }; - List properties = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Attachment", - "RecipientName", - "Type" - }; - await noticeScheduleRepository.AddOneAsync(DaySchedule, properties); - } - } - //綜合報表 每日 - if (sentMaxpowerstations.Count != 0) - { - Select_table2 maxdayexcel = new Select_table2() - { - FormType = 0, - PowerStation = sentMaxpowerstations, - SearchType = 0, - Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"), - Userid = user.Id - }; - var stationMaxReportName = stationReportController.ExportExcelmaxtableBackDownload(JsonConvert.SerializeObject(maxdayexcel, Formatting.Indented)); - NoticeSchedule MaxSchedule = new NoticeSchedule() - { - UserId = user.Id, - EmailType = 2, - RecipientEmail = user.Email, - Subject = "綜合報表", - Attachment = stationMaxReportName, - RecipientName = user.Name, - Type = 1 - }; - List properties = new List() - { - "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, - PowerStation = sentMaxpowerstations, - SearchType = 0, - Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM"), - Userid = user.Id - }; - var stationReportmaxmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(maxmonthexcel, Formatting.Indented)); - NoticeSchedule MaxmonthSchedule = new NoticeSchedule() - { - RecipientEmail = user.Email, - Subject = "綜合報表", - Attachment = stationReportmaxmonthName, - RecipientName = user.Name, - Type = 1, - UserId = user.Id, - EmailType = 2 - }; - List properties2 = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Attachment", - "RecipientName", - "Type" - }; - await noticeScheduleRepository.AddOneAsync(MaxmonthSchedule, properties2); - } - - } - - if (DateTime.Now.ToString("dd") == "01") - { - List sentmonthpowerstations = powerstations.Where(x => x.EmailMonthReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); - if (sentmonthpowerstations.Count == 0) - { - break; - } - Excel monthexcel = new Excel() - { - FormType = 1, - PowerStation = sentmonthpowerstations, - SearchType = 2, - Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM"), - Userid = user.Id - }; - var stationReportmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(monthexcel, Formatting.Indented)); - if (stationReportmonthName != "") - { - NoticeSchedule MonthSchedule = new NoticeSchedule() - { - RecipientEmail = user.Email, - Subject = "月報表", - Attachment = stationReportmonthName, - RecipientName = user.Name, - Type = 1, - UserId = user.Id, - EmailType = 1 - }; - List properties2 = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Attachment", - "RecipientName", - "Type" - }; - await noticeScheduleRepository.AddOneAsync(MonthSchedule, properties2); - } - - } - - - - } - - #endregion - - #region step1. 找出所有電站 logger.LogInformation("【CalcAvgPowerStationJob】【開始取得電站資料】"); var powerStations = await powerStationRepository.GetAllAsync(); @@ -917,7 +743,178 @@ namespace SolarPower.Quartz.Jobs } #endregion + #region 寄送日月報 + var users = userRepository.GetAllAsync(); + foreach (var user in users.Result) + { + + + List powerstations = new List(); + powerstations = await noticeScheduleRepository.GetPowerStationOperationPersonnel(user.Id); + if (powerstations.Count == 0) + { + continue; + } + List sentdaypowerstations = powerstations.Where(x => x.EmailDayReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); + List sentMaxpowerstations = powerstations.Where(x => x.EmailComplexReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); + + Controllers.StationReportController stationReportController = new Controllers.StationReportController(powerStationRepository, stationReportRepository); + //日報表 + if (sentdaypowerstations.Count != 0) + { + Excel dayexcel = new Excel() + { + FormType = 0, + PowerStation = sentdaypowerstations, + SearchType = 0, + Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"), + Userid = user.Id + }; + var stationReportName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(dayexcel, Formatting.Indented)); + if (stationReportName != "") + { + NoticeSchedule DaySchedule = new NoticeSchedule() + { + UserId = user.Id, + EmailType = 0, + RecipientEmail = user.Email, + Subject = "日報表", + Attachment = stationReportName, + RecipientName = user.Name, + Type = 1 + }; + List properties = new List() + { + "UserId", + "EmailType", + "RecipientEmail", + "Subject", + "Attachment", + "RecipientName", + "Type" + }; + await noticeScheduleRepository.AddOneAsync(DaySchedule, properties); + } + } + //綜合報表 每日 + if (sentMaxpowerstations.Count != 0) + { + Select_table2 maxdayexcel = new Select_table2() + { + FormType = 0, + PowerStation = sentMaxpowerstations, + SearchType = 0, + Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"), + Userid = user.Id + }; + var stationMaxReportName = stationReportController.ExportExcelmaxtableBackDownload(JsonConvert.SerializeObject(maxdayexcel, Formatting.Indented)); + NoticeSchedule MaxSchedule = new NoticeSchedule() + { + UserId = user.Id, + EmailType = 2, + RecipientEmail = user.Email, + Subject = "綜合報表", + Attachment = stationMaxReportName, + RecipientName = user.Name, + Type = 1 + }; + List properties = new List() + { + "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, + PowerStation = sentMaxpowerstations, + SearchType = 0, + Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM"), + Userid = user.Id + }; + var stationReportmaxmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(maxmonthexcel, Formatting.Indented)); + NoticeSchedule MaxmonthSchedule = new NoticeSchedule() + { + RecipientEmail = user.Email, + Subject = "綜合報表", + Attachment = stationReportmaxmonthName, + RecipientName = user.Name, + Type = 1, + UserId = user.Id, + EmailType = 2 + }; + List properties2 = new List() + { + "UserId", + "EmailType", + "RecipientEmail", + "Subject", + "Attachment", + "RecipientName", + "Type" + }; + await noticeScheduleRepository.AddOneAsync(MaxmonthSchedule, properties2); + } + + } + + if (DateTime.Now.ToString("dd") == "01") + { + List sentmonthpowerstations = powerstations.Where(x => x.EmailMonthReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); + if (sentmonthpowerstations.Count == 0) + { + break; + } + Excel monthexcel = new Excel() + { + FormType = 1, + PowerStation = sentmonthpowerstations, + SearchType = 2, + Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM"), + Userid = user.Id + }; + var stationReportmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(monthexcel, Formatting.Indented)); + if (stationReportmonthName != "") + { + NoticeSchedule MonthSchedule = new NoticeSchedule() + { + RecipientEmail = user.Email, + Subject = "月報表", + Attachment = stationReportmonthName, + RecipientName = user.Name, + Type = 1, + UserId = user.Id, + EmailType = 1 + }; + List properties2 = new List() + { + "UserId", + "EmailType", + "RecipientEmail", + "Subject", + "Attachment", + "RecipientName", + "Type" + }; + await noticeScheduleRepository.AddOneAsync(MonthSchedule, properties2); + } + + } + + + + } + + #endregion } catch (Exception exception) diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 73ebb94..ec69123 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -368,6 +368,7 @@ namespace SolarPower.Quartz.Jobs break; } } + weatherObservations.Add(weatherObservation); } logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的天氣預報的資訊】", powerStation.Code, dateTime); @@ -379,7 +380,7 @@ namespace SolarPower.Quartz.Jobs calcPowerStation.RateOfRain = weather.PoP; } - weatherObservations.Add(weatherObservation); + } #endregion diff --git a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml index 8142cae..cd0ed05 100644 --- a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml +++ b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml @@ -317,6 +317,8 @@ "data": "installDate" }, { "data": "brand" + }, { + "data": "brandNum" }, { "data": "model" }, { @@ -2256,6 +2258,7 @@ InverterName: $("#Inverter_InverterName_modal").val(), InstallDate: $("#Inverter_InstallDate_modal").val(), Brand: $("#Inverter_Brand_modal").val(), + BrandNum: $("#Inverter_BrandNum_modal").val(), Model: $("#Inverter_Model_modal").val(), Capacity: $("#Inverter_Capacity_modal").val(), Pyrheliometer: $("#Inverter_Pyrheliometer_modal").val(), @@ -2386,6 +2389,7 @@ $("#Inverter_InverterName_modal").val(rel.data.inverterName); $("#Inverter_InstallDate_modal").val(rel.data.installDate); $("#Inverter_Brand_modal").val(rel.data.brand); + $("#Inverter_BrandNum_modal").val(rel.data.brandNum); $("#Inverter_Model_modal").val(rel.data.model); $("#Inverter_Capacity_modal").val(rel.data.capacity); $("#Inverter_Pyrheliometer_modal").val(rel.data.pyrheliometer); diff --git a/SolarPower/Views/PowerStation/_DeviceSetting.cshtml b/SolarPower/Views/PowerStation/_DeviceSetting.cshtml index a17e3d6..09e72b2 100644 --- a/SolarPower/Views/PowerStation/_DeviceSetting.cshtml +++ b/SolarPower/Views/PowerStation/_DeviceSetting.cshtml @@ -49,6 +49,7 @@ 狀態 安裝日期 廠牌 + 廠商序號 型號 裝置容量 kWp 日照計編號 @@ -199,6 +200,10 @@ +
+ + +
@@ -215,7 +220,6 @@