diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index 9b20909..8608b20 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -12,6 +12,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using System.Transactions; +using System.Text.RegularExpressions; namespace SolarPower.Controllers { @@ -676,30 +677,36 @@ namespace SolarPower.Controllers _ => "" }; var user = await userRepository.GetOneAsync(person); - NoticeSchedule schedule = new NoticeSchedule() + if (user.Email != null && IsValidEmail(user.Email)) { - EmailType = 3, - Type = 1, - UserId = person, - RecipientName = user.Name, - RecipientEmail = user.Email, - Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime, - Content = "維修項目" + post.FixDo + "
注意事項 :" + post.Notice, - }; - noticeSchedules.Add(schedule); + NoticeSchedule schedule = new NoticeSchedule() + { + EmailType = 3, + Type = 1, + UserId = person, + RecipientName = user.Name, + RecipientEmail = user.Email, + Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime, + Content = "維修項目" + post.FixDo + "
注意事項 :" + post.Notice, + }; + noticeSchedules.Add(schedule); + } } properties = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Content", - "RecipientName", - "Type", - "ExceptionId" - }; - await noticeScheduleRepository.AddAnyThing>(noticeSchedules, properties, "notice_schedule"); + { + "UserId", + "EmailType", + "RecipientEmail", + "Subject", + "Content", + "RecipientName", + "Type", + "ExceptionId" + }; + if (noticeSchedules.Count > 0) + { + await noticeScheduleRepository.AddAnyThing>(noticeSchedules, properties, "notice_schedule"); + } } if (post.FixFirm != 0) @@ -714,27 +721,31 @@ namespace SolarPower.Controllers }; //var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId); var firm = await operationRepository.GetOneWithCustomDBNameAndTableAsync(post.FixFirm, powerstations.SiteDB, "operation_firm"); - NoticeSchedule schedule = new NoticeSchedule() + if (firm.Email != null && IsValidEmail(firm.Email)) { - EmailType = 3, - Type = 1, - RecipientName = firm.Name, - RecipientEmail = firm.Email, - Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime, - Content = "維修項目" + post.FixDo + "
注意事項 :" + post.Notice, - }; - properties = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Content", - "RecipientName", - "Type", - "ExceptionId" - }; - await noticeScheduleRepository.AddAnyThing(schedule, properties, "notice_schedule"); + NoticeSchedule schedule = new NoticeSchedule() + { + EmailType = 3, + Type = 1, + RecipientName = firm.Name, + RecipientEmail = firm.Email, + Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime, + Content = "維修項目" + post.FixDo + "
注意事項 :" + post.Notice, + }; + + properties = new List() + { + "UserId", + "EmailType", + "RecipientEmail", + "Subject", + "Content", + "RecipientName", + "Type", + "ExceptionId" + }; + await noticeScheduleRepository.AddAnyThing(schedule, properties, "notice_schedule"); + } } } //using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Suppress)) @@ -898,30 +909,36 @@ namespace SolarPower.Controllers _ => "" }; var user = await userRepository.GetOneAsync(person); - NoticeSchedule schedule = new NoticeSchedule() + if (user.Email != null && IsValidEmail(user.Email)) { - EmailType = 3, - Type = 1, - UserId = person, - RecipientName = user.Name, - RecipientEmail = user.Email, - Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime, - Content = "維修項目:" + post.FixDo + "
注意事項 :" + post.Notice, - }; - noticeSchedules.Add(schedule); + NoticeSchedule schedule = new NoticeSchedule() + { + EmailType = 3, + Type = 1, + UserId = person, + RecipientName = user.Name, + RecipientEmail = user.Email, + Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime, + Content = "維修項目:" + post.FixDo + "
注意事項 :" + post.Notice, + }; + noticeSchedules.Add(schedule); + } } properties = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Content", - "RecipientName", - "Type", - "ExceptionId" - }; - await noticeScheduleRepository.AddAnyThing>(noticeSchedules, properties, "notice_schedule"); + { + "UserId", + "EmailType", + "RecipientEmail", + "Subject", + "Content", + "RecipientName", + "Type", + "ExceptionId" + }; + if (noticeSchedules.Count > 0) + { + await noticeScheduleRepository.AddAnyThing>(noticeSchedules, properties, "notice_schedule"); + } } if (post.FixFirm != 0) { @@ -935,29 +952,31 @@ namespace SolarPower.Controllers }; // var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId); var firm = await operationRepository.GetOneWithCustomDBNameAndTableAsync(post.FixFirm, powerstations.SiteDB, "operation_firm"); - NoticeSchedule schedule = new NoticeSchedule() + if (firm.Email != null && IsValidEmail(firm.Email)) { - EmailType = 3, - Type = 1, - RecipientName = firm.Name, - RecipientEmail = firm.Email, - Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime, - Content = "維修項目:" + post.FixDo + "
注意事項 :" + post.Notice, - }; - properties = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Content", - "RecipientName", - "Type", - "ExceptionId" - }; - await noticeScheduleRepository.AddAnyThing(schedule, properties, "notice_schedule"); - + NoticeSchedule schedule = new NoticeSchedule() + { + EmailType = 3, + Type = 1, + RecipientName = firm.Name, + RecipientEmail = firm.Email, + Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime, + Content = "維修項目:" + post.FixDo + "
注意事項 :" + post.Notice, + }; + properties = new List() + { + "UserId", + "EmailType", + "RecipientEmail", + "Subject", + "Content", + "RecipientName", + "Type", + "ExceptionId" + }; + await noticeScheduleRepository.AddAnyThing(schedule, properties, "notice_schedule"); + } } } @@ -1325,5 +1344,11 @@ namespace SolarPower.Controllers } } + bool IsValidEmail(string strIn) + { + // Return true if strIn is in valid e-mail format. + return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); + } + } } diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 2bce9d5..cd3e674 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -1177,7 +1177,9 @@ namespace SolarPower.Controllers "Status", "Enabled", "InstallDate", - "BrandNum" + "BrandNum", + "SensorTypeId", + "SensorTypeDetailId" }; if (Device.WarrantyDate != "0001-01-01") { @@ -1246,7 +1248,9 @@ namespace SolarPower.Controllers "Status", "Enabled", "InstallDate", - "BrandNum" + "BrandNum", + "SensorTypeId", + "SensorTypeDetailId" }; if (Device.WarrantyDate != "0001-01-01") { @@ -2474,6 +2478,27 @@ namespace SolarPower.Controllers } await powerStationRepository.AddInverter(inverter, properties, powerStation.SiteDB); + #region 在master底下的inv_Status 新增inverter + InverterForMaster inverterForMasterInvs = new InverterForMaster() + { + DBName = powerStation.SiteDB, + InverterId = deviceController.ControllerId + Newnum, + Deleted = 0, + Enabled = post.Enabled, + Status = post.Status + }; + + List propertiesForMasterInvs = new List() + { + "DBName", + "InverterId", + "Deleted", + "Enabled", + "Status" + }; + await powerStationRepository.AddMasterInverter(inverterForMasterInvs, propertiesForMasterInvs); + #endregion + BackFillSchedule backFillSchedule = new BackFillSchedule() { UID = deviceController.ControllerId + Newnum, @@ -2537,6 +2562,26 @@ namespace SolarPower.Controllers properties.Add("WarrantyDate"); } await powerStationRepository.UpdateInverter(inverter, properties, powerStation.SiteDB); + + #region 在master底下的inv_Status更新inverter + InverterForMaster inverterForMasterInvs = new InverterForMaster() + { + DBName = powerStation.SiteDB, + Enabled = post.Enabled, + Status = post.Status, + Id = post.Id + }; + + List propertiesForMasterInvs = new List() + { + "DBName", + "Enabled", + "Status", + "Id" + }; + await powerStationRepository.UpdateMasterInverter(inverterForMasterInvs, propertiesForMasterInvs); + #endregion + await powerStationRepository.StationStatus(post.PowerStationId, 0); await powerStationRepository.StationStatus(post.PowerStationId, 0, powerStation.SiteDB + "."); apiResult.Code = "0000"; @@ -2659,6 +2704,15 @@ namespace SolarPower.Controllers await powerStationRepository.DeleteOneByIdWithCustomDBNameAndTable(post.SelectedId, powerStation.SiteDB, "inverter"); + var inverter = await powerStationRepository.GetOneMasterInverter(post.SelectedId, powerStation.SiteDB); + if (inverter == null ) + { + apiResult.Code = "0001"; + apiResult.Msg = "該電站沒有啟用的逆變器"; + return apiResult; + } + await powerStationRepository.DeleteOneMasterInverter(inverter.InverterId, "inv_status"); + apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; } @@ -2997,7 +3051,7 @@ namespace SolarPower.Controllers apiResult.Msg = "該電站沒有啟用的逆變器"; return apiResult; } - var inverterIds = inverters.Where(x => x.Enabled == 1).Select(x => new { InverterId = x.InverterId, Type = x.Status,Name = x.InverterName}).ToList(); + var inverterIds = inverters.Where(x => x.Enabled == 1).Select(x => new { InverterId = x.InverterId, Type = x.InverterStatus, Name = x.InverterName}).ToList(); var inverterIdsname = inverterIds.Select(x => x.InverterId).ToList(); if (inverterIds.Count > 0) { @@ -3271,7 +3325,7 @@ namespace SolarPower.Controllers { status.Add($"s{powerStation.Code}01_inv SITEID錯誤"); } - if (powerStation.Code + "01" != sitecheck.Inv_inveter.Substring(0,11) && sitecheck.Inv_inveter != null) + if (sitecheck.Inv_inveter != null && powerStation.Code + "01" != sitecheck.Inv_inveter.Substring(0,11)) { status.Add($"s{powerStation.Code}01_Inv inveter格式錯誤"); } diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index e7803e8..0f58032 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -267,24 +267,32 @@ namespace SolarPower.Controllers #region 顯示body //RowPosition = 1 RowPosition++; var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = "";var GeneratingCapacity = "";var AverageDailyProfit = ""; + int vForDataCount = 0; foreach (dynamic body in Formbody.Result.Data) { index = 0; var dbody = body as IDictionary; - thour = Checknull(Math.Round(Convert.ToDouble(dbody["tothour"]), 2).ToString()); - tpr = Checknull(Math.Round(Convert.ToDouble(dbody["pr"]), 2).ToString()); - tkwh = Checknull(Math.Round(Convert.ToDouble(dbody["totKWH"]), 2).ToString()); - kWhkwp = Checknull(Math.Round(Convert.ToDouble(dbody["totKWHKWP"]), 2).ToString()); - ntd = Checknull(Math.Round(Convert.ToDouble(dbody["totmoney"]), 2).ToString()); - GeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); - - double onemoney = Convert.ToDouble(ntd) / Convert.ToDouble(tkwh); - if (double.IsNaN(onemoney)) + if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆(總計),不須取值 { - onemoney = 0; + vForDataCount++; + thour = Checknull(Math.Round(Convert.ToDouble(dbody["tothour"]), 2).ToString()); + tpr = Checknull(Math.Round(Convert.ToDouble(dbody["pr"]), 2).ToString()); + tkwh = Checknull(Math.Round(Convert.ToDouble(dbody["totKWH"]), 2).ToString()); + kWhkwp = Checknull(Math.Round(Convert.ToDouble(dbody["totKWHKWP"]), 2).ToString()); + ntd = Checknull(Math.Round(Convert.ToDouble(dbody["totmoney"]), 2).ToString()); + GeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); + + double kwp = Convert.ToDouble(tkwh) / Convert.ToDouble(GeneratingCapacity); + kWhkwp = Checknull(Math.Round(kwp, 2).ToString()); + + double onemoney = Convert.ToDouble(ntd) / Convert.ToDouble(tkwh); + if (double.IsNaN(onemoney)) + { + onemoney = 0; + } + ntdone = Checknull(Math.Round(onemoney, 2).ToString()); + AverageDailyProfit = Checknull(Math.Round((Convert.ToDouble(ntd) / Convert.ToDouble(GeneratingCapacity)), 2).ToString()); } - ntdone = Checknull(Math.Round(onemoney, 4).ToString()); - AverageDailyProfit = Checknull(Math.Round((Convert.ToDouble(ntd) / Convert.ToDouble(GeneratingCapacity)), 2).ToString()); row = sheet.CreateRow(RowPosition); cell = row.CreateCell(index); @@ -302,7 +310,7 @@ namespace SolarPower.Controllers List bodynames = new List(){ "hourKWH", "hourKWHp", - "irradiance", + "irrDayHour", "temperature" }; if (Formhead.Result.Data.ShowMoney == 1) @@ -467,18 +475,27 @@ namespace SolarPower.Controllers var monthGeneratingCapacity = ""; var check_hire = false; var sitedb = ""; + vForDataCount = 0; foreach (dynamic body in Formbody.Result.Data) { index2 = 0; var dbody = body as IDictionary; + if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆(總計),不須取值 + { + vForDataCount++; + avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString(); + avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString(); + avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString(); + monthKWH = dbody["monthKWH"] == null ? "0" : dbody["monthKWH"].ToString(); + monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); + monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); + monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); + + + double kwp = Convert.ToDouble(monthKWH) / Convert.ToDouble(monthGeneratingCapacity); + avgKWHKWP = Checknull(Math.Round(kwp, 2).ToString()); + } - avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString(); - avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString(); - avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString(); - monthKWH = dbody["monthKWH"] == null ? "0": dbody["monthKWH"].ToString(); - monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); - monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); - monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用 { check_hire = true; @@ -533,7 +550,7 @@ namespace SolarPower.Controllers #region 顯示總量//RowPosition = body + 2 RowPosition += 2;//空兩行 index = 0; - var Useday = Formbody.Result.Data.Count; + var Useday = (Formbody.Result.Data.Count - 1);//最後一筆為總計,故減1 row = sheet.CreateRow(RowPosition); //cell = row.CreateCell(index); @@ -610,7 +627,7 @@ namespace SolarPower.Controllers if (Formhead.Result.Data.ShowMoney == 1) { cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity), 3)); + cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity), 2)); cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); @@ -618,7 +635,7 @@ namespace SolarPower.Controllers cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 4)); + cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 2)); cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); @@ -741,18 +758,24 @@ namespace SolarPower.Controllers check_hire = false; sitedb = ""; monthGeneratingCapacity = ""; + string days = "0"; + vForDataCount = 0; foreach (dynamic body in Formbody.Result.Data) { index3 = 0; var dbody = body as IDictionary; - - avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString(); - avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString(); - avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString(); - monthKWH = dbody["monthKWH"] == null ? "0" : dbody["monthKWH"].ToString(); - monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); - monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); - monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); + if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆(總計),不須取值 + { + vForDataCount++; + avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString(); + avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString(); + avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString(); + monthKWH = dbody["monthKWH"] == null ? "0" : dbody["monthKWH"].ToString(); + monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); + monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); + monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); + days = Checknull(Math.Round(Convert.ToDouble(dbody["Days"])).ToString()); + } if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用 { check_hire = true; @@ -807,7 +830,7 @@ namespace SolarPower.Controllers #region 顯示總量//RowPosition = body + 2 RowPosition += 2;//空兩行 index = 0; - Useday = Formbody.Result.Data.Count; + Useday = (Formbody.Result.Data.Count - 1);//最後一筆為總計,故減1 row = sheet.CreateRow(RowPosition); cell = row.CreateCell(index); @@ -819,6 +842,10 @@ namespace SolarPower.Controllers cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); + cell.SetCellValue("裝置容量"); + cell.CellStyle = styleLine12; + index++; + cell = row.CreateCell(index); cell.SetCellValue("發電量平均(kWh)(月)"); cell.CellStyle = styleLine12; index++; @@ -856,7 +883,11 @@ namespace SolarPower.Controllers cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(Convert.ToDouble(avgKWHKWP) / Useday, 2)); + cell.SetCellValue(Math.Round(Convert.ToDouble(monthKWH) / Convert.ToDouble(monthGeneratingCapacity), 2)); + cell.CellStyle = styleLine12; + index++; + cell = row.CreateCell(index); + cell.SetCellValue(Math.Round(Convert.ToDouble(monthGeneratingCapacity), 2));/// cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); @@ -878,7 +909,7 @@ namespace SolarPower.Controllers cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity) / Useday / 30, 2));//一個月為30天 + cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity) / Convert.ToDouble(days), 2));//一個月為30天 Useday / 30 cell.CellStyle = styleLine12; index++; } @@ -976,7 +1007,10 @@ namespace SolarPower.Controllers { AllowClose = false }; - string companyName = postObject.PowerStation[0].Name; + + int powerStationId = int.Parse(postObject.PowerStation[0].Value); + var getCompany = stationReportRepository.GetCompanyNameByPowerStationId(powerStationId); + string companyName = getCompany.Result; workbook.Write(ms); ms.Flush(); ms.Seek(0, SeekOrigin.Begin); @@ -1073,7 +1107,7 @@ namespace SolarPower.Controllers var getinvsql = k.Result[0] as IDictionary; if (getinvsql["mySelect"] == null) { - if(postObject.PowerStation.Count > 1) + if(postObject.PowerStation.Count > 1)//因為有總計 所以最少會有一筆 { continue; } @@ -1084,7 +1118,7 @@ namespace SolarPower.Controllers } var sheet = workbook.CreateSheet(powerstationid.Name); var Formbody = GetForm(select_Table);//取body - if(Formbody.Result.Data.Count == 0) + if(Formbody.Result.Data.Count <= 1) { continue; } @@ -1139,25 +1173,32 @@ namespace SolarPower.Controllers #region 顯示body //RowPosition = 1 RowPosition++; var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = ""; var GeneratingCapacity = ""; var AverageDailyProfit = ""; + int vForDataCount = 0; foreach (dynamic body in Formbody.Result.Data) { - index = 0; var dbody = body as IDictionary; - thour = Checknull(Math.Round(Convert.ToDouble(dbody["tothour"]), 2).ToString()); - tpr = Checknull(Math.Round(Convert.ToDouble(dbody["pr"]), 2).ToString()); - tkwh = Checknull(Math.Round(Convert.ToDouble(dbody["totKWH"]), 2).ToString()); - kWhkwp = Checknull(Math.Round(Convert.ToDouble(dbody["totKWHKWP"]), 2).ToString()); - ntd = Checknull(Math.Round(Convert.ToDouble(dbody["totmoney"]), 2).ToString()); - GeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); - - double onemoney = Convert.ToDouble(ntd) / Convert.ToDouble(tkwh); - if (double.IsNaN(onemoney)) + if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆為總計,不須取值 { - onemoney = 0; + vForDataCount++; + thour = Checknull(Math.Round(Convert.ToDouble(dbody["tothour"]), 2).ToString()); + tpr = Checknull(Math.Round(Convert.ToDouble(dbody["pr"]), 2).ToString()); + tkwh = Checknull(Math.Round(Convert.ToDouble(dbody["totKWH"]), 2).ToString()); + kWhkwp = Checknull(Math.Round(Convert.ToDouble(dbody["totKWHKWP"]), 2).ToString()); + ntd = Checknull(Math.Round(Convert.ToDouble(dbody["totmoney"]), 2).ToString()); + GeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); + + double kwp = Convert.ToDouble(tkwh) / Convert.ToDouble(GeneratingCapacity); + kWhkwp = Checknull(Math.Round(kwp, 2).ToString()); + + double onemoney = Convert.ToDouble(ntd) / Convert.ToDouble(tkwh); + if (double.IsNaN(onemoney)) + { + onemoney = 0; + } + ntdone = Checknull(Math.Round(onemoney, 2).ToString()); + AverageDailyProfit = Checknull(Math.Round((Convert.ToDouble(ntd) / Convert.ToDouble(GeneratingCapacity)), 2).ToString()); } - ntdone = Checknull(Math.Round(onemoney, 4).ToString()); - AverageDailyProfit = Checknull(Math.Round((Convert.ToDouble(ntd) / Convert.ToDouble(GeneratingCapacity)), 2).ToString()); row = sheet.CreateRow(RowPosition); cell = row.CreateCell(index); @@ -1175,7 +1216,7 @@ namespace SolarPower.Controllers List bodynames = new List(){ "hourKWH", "hourKWHp", - "irradiance", + "irrDayHour", "temperature" }; if (Formhead.Result.Data.ShowMoney == 1) @@ -1341,18 +1382,26 @@ namespace SolarPower.Controllers var monthGeneratingCapacity = ""; var check_hire = false; var sitedb = ""; + vForDataCount = 0; foreach (dynamic body in Formbody.Result.Data) { index2 = 0; var dbody = body as IDictionary; + if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆為總計,不須取值 + { + vForDataCount++; + avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString(); + avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString(); + avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString(); + monthKWH = dbody["monthKWH"] == null ? "0" : dbody["monthKWH"].ToString(); + monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); + monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); + monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); + + double kwp = Convert.ToDouble(monthKWH) / Convert.ToDouble(monthGeneratingCapacity); + avgKWHKWP = Checknull(Math.Round(kwp, 2).ToString()); + } - avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString(); - avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString(); - avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString(); - monthKWH = dbody["monthKWH"] == null ? "0" : dbody["monthKWH"].ToString(); - monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString(); - monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString(); - monthGeneratingCapacity = Checknull(Math.Round(Convert.ToDouble(dbody["GeneratingCapacity"]), 2).ToString()); if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用 { check_hire = true; @@ -1407,7 +1456,7 @@ namespace SolarPower.Controllers #region 顯示總量//RowPosition = body + 2 RowPosition += 2;//空兩行 index = 0; - var Useday = Formbody.Result.Data.Count; + var Useday = (Formbody.Result.Data.Count - 1);//最後一筆為總計,故減1 row = sheet.CreateRow(RowPosition); //cell = row.CreateCell(index); @@ -1484,7 +1533,7 @@ namespace SolarPower.Controllers if (Formhead.Result.Data.ShowMoney == 1) { cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity), 3)); + cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) / Convert.ToDouble(monthGeneratingCapacity), 2)); cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); @@ -1492,7 +1541,7 @@ namespace SolarPower.Controllers cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 4)); + cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 2)); cell.CellStyle = styleLine12; index++; cell = row.CreateCell(index); @@ -1591,7 +1640,9 @@ namespace SolarPower.Controllers { Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename)); } - string companyName = postObject.PowerStation[0].Name; + int powerStationId = int.Parse(postObject.PowerStation[0].Value); + var getCompany = stationReportRepository.GetCompanyNameByPowerStationId(powerStationId); + string companyName = getCompany.Result; var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename, companyName + "_" + name + "報表" + "_" + postObject.Userid + Datename + ".xlsx"); FileStream FS = new FileStream(n, FileMode.Create, FileAccess.Write); workbook.Write(FS); @@ -1732,7 +1783,7 @@ namespace SolarPower.Controllers index++; cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(form.AvgKWHKWP, 2));//日均發電度數 + cell.SetCellValue(Math.Round((form.Kwh/form.GeneratingCapacity), 2));//日均發電度數 cell.CellStyle = styleLine12; index++; @@ -1797,7 +1848,7 @@ namespace SolarPower.Controllers { City = form.CityName, Count = 1, - Kwh = form.TotalKWH, + Kwh = form.Kwh, SolarHour = form.SolarHour, Kwhkwp = form.AvgKWHKWP, GeneratingCapacity = form.GeneratingCapacity @@ -1829,7 +1880,7 @@ namespace SolarPower.Controllers "電站類型", "掛錶日期", "躉售費率", - "每kw日均獲利", + "日均獲利", "日均發電度數", "發電量", //"平均日照", @@ -1879,7 +1930,7 @@ namespace SolarPower.Controllers index++; cell = row.CreateCell(index); - cell.SetCellValue(Math.Round(cityArray.Kwh, 3)); + cell.SetCellValue(Math.Round(cityArray.Kwh, 2)); cell.CellStyle = styleLine12; region = new CellRangeAddress(cityRowPosition, cityRowPosition, index, index + 1); sheet.AddMergedRegion(region); @@ -2017,7 +2068,9 @@ namespace SolarPower.Controllers { AllowClose = false }; - string companyName = postObject.PowerStation[0].Name; + int powerStationId = int.Parse(postObject.PowerStation[0].Value); + var getCompany = stationReportRepository.GetCompanyNameByPowerStationId(powerStationId); + string companyName = getCompany.Result; workbook.Write(ms); ms.Flush(); ms.Seek(0, SeekOrigin.Begin); @@ -2236,7 +2289,7 @@ namespace SolarPower.Controllers "電站類型", "掛錶日期", "躉售費率", - "每kw日均獲利", + "日均獲利", "日均發電度數", "發電量", //"平均日照", @@ -2428,7 +2481,9 @@ namespace SolarPower.Controllers { Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename)); } - string companyName = postObject.PowerStation[0].Name; + int powerStationId = int.Parse(postObject.PowerStation[0].Value); + var getCompany = stationReportRepository.GetCompanyNameByPowerStationId(powerStationId); + string companyName = getCompany.Result; var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename, companyName + "_" + "綜合比較" + "_" + postObject.Userid + Datename + ".xlsx"); FileStream FS = new FileStream(n, FileMode.Create, FileAccess.Write); workbook.Write(FS); diff --git a/SolarPower/Models/Overview.cs b/SolarPower/Models/Overview.cs index f5fc772..663b031 100644 --- a/SolarPower/Models/Overview.cs +++ b/SolarPower/Models/Overview.cs @@ -204,6 +204,8 @@ namespace SolarPower.Models /// public double IrrDay { get; set; } public double IrrDayHour { get; set; } + public double GeneratingCapacity { get; set; } + public int days { get; set; } } public class ExceptionEmailInfo diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index 5e7403e..08bf78f 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -442,6 +442,8 @@ namespace SolarPower.Models.PowerStation public string InstallDate { get { return Convert.ToDateTime(installDate).ToString("yyyy-MM-dd"); } set { installDate = value; } } //安裝日期 public string BrandNum { get; set; }//廠商序號 public string WarrantyDate { get { return Convert.ToDateTime(warrantyDate).ToString("yyyy-MM-dd"); } set { warrantyDate = value; } } //保固日期 + public int SensorTypeId { get; set; } + public int SensorTypeDetailId { get; set; } } public class Device : DeviceInfo @@ -627,7 +629,22 @@ namespace SolarPower.Models.PowerStation public string EnabledName { get; set; } public string StatusName { get; set; } public string PyrheliometerName { get; set; } + public int InverterStatus { get; set; } } + + /// + /// Master底下的逆變器資料表 + /// + public class InverterForMaster + { + public string DBName { get; set; }//資料庫名稱 + public string InverterId { get; set; }//逆變器id + public int Deleted { get; set; }//是否刪除 + public int Enabled { get; set; }//是否啟用 + public int Status { get; set; }//狀態 + public int Id { get; set; } + } + /// /// 下拉式選單用 /// diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 6d28052..a7d8118 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -53,7 +53,7 @@ namespace SolarPower.Quartz.Jobs logger.LogInformation("【CalcPowerStationJob】【開始取得電站資料】"); var powerStations = await powerStationRepository.GetAllAsync(); logger.LogInformation("【CalcPowerStationJob】【取得成功電站資料】"); - logger.LogInformation("【CalcPowerStationJob】【電站資料】 - {0}", System.Text.Json.JsonSerializer.Serialize(powerStations)); + logger.LogInformation("【CalcPowerStationJob】【電站資料"); #endregion List powerStationHistoriesHour = new List(); @@ -269,7 +269,7 @@ namespace SolarPower.Quartz.Jobs #endregion #region 計算單一電站每小時發電量、發電金額等資料 for calcPowerStation - var dateTimeforPowerStation = DateTime.Now.ToString("yyyy-MM-dd");//取當天 + var dateTimeforPowerStation = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd");//取當天 logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料 for calcPowerStation】", powerStation.Code, dateTimeforPowerStation); var history_for_powerStation = await powerStationRepository.GetPowerStationHistoryPerHourForPowerStation(dateTimeforPowerStation, full_table_name); if (history_for_powerStation == null) @@ -608,14 +608,31 @@ namespace SolarPower.Quartz.Jobs sensorHistory.IrrDay = TPYHistory.IrrDay; logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); - var ss = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id); - if (ss != null) + var twoHourAgoIrrDay = await powerStationRepository.CalcIrrDayHistoryPerTwoHour(dateTime, powerStation.Id); + if (twoHourAgoIrrDay != null) { - sensorHistory.IrrDayHour = double.Parse(ss); + + if (DateTimeNow.AddHours(-1).Hour == 0)//半夜12點的值 + { + sensorHistory.IrrDayHour = 0; + } + else + { + sensorHistory.IrrDayHour = sensorHistory.IrrDay - double.Parse(twoHourAgoIrrDay);// 前一小時的IrrDay - 前兩小時的IrrDay + } logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); } + else + { + sensorHistory.IrrDayHour = 0; + } } + else + { + sensorHistory.IrrDay = 0; + sensorHistory.IrrDayHour = 0; + } } } catch (Exception ex) @@ -1073,98 +1090,5 @@ namespace SolarPower.Quartz.Jobs } } - public async Task setHistoryPerHourForPowerStation(string dateTime, string full_table_name, PowerStation powerStation) - { - var calcPowerStation = new PowerStation(); - calcPowerStation.Id = powerStation.Id; - var history_for_powerStation = await powerStationRepository.GetPowerStationHistoryPerHourForPowerStation(dateTime, full_table_name); - if (history_for_powerStation == null) - { - //logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); - //每小時發電量(直接填寫 - calcPowerStation.kwh = 0; - //今日發電量(直接填寫 - calcPowerStation.Today_kWh = 0; - //總發電量(直接填寫 - calcPowerStation.Total_kWh = 0; - } - else - { - //每小時發電量(直接填寫 - calcPowerStation.kwh = history_for_powerStation.KWH; - //今日發電量(直接填寫 - calcPowerStation.Today_kWh = history_for_powerStation.TodayKWh; - //總發電量(直接填寫 - calcPowerStation.Total_kWh = history_for_powerStation.TotalKWH; - - #region 發電金額 - - history_for_powerStation.MONEY = history_for_powerStation.KWH * powerStation.PowerRate; - history_for_powerStation.TODAYMONEY = history_for_powerStation.TodayKWh * powerStation.PowerRate; - history_for_powerStation.TOTALMONEY = history_for_powerStation.TotalKWH * powerStation.PowerRate; - - //即時發電金額 - switch (powerStation.SolarType) - { - case (int)SolarTypeEnum.SelfSold: //自建躉售 - - //今日發電金額 計算方式:todaykWh * 授電費率 - calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate; - - ////總發電金額 計算方式:totalkWh * 授電費率 - calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate; - break; - case (int)SolarTypeEnum.HireSold: //租建躉售 - //找出該電站的所有土地房屋資訊 - var landBuildings = await powerStationRepository.GetAllLandBuildingInfoByPowerStationId(powerStation.Id, powerStation.SiteDB); - var sumLeaseRate = 0.00; - var avgLeaseRate = 0.00; - - foreach (var landBuilding in landBuildings) - { - sumLeaseRate += landBuilding.LeaseRate; - } - - calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100; - calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100; - - break; - case (int)SolarTypeEnum.SelfUse: //自建自用 - - //今日發電金額 計算方式:todaykWh * 授電費率 - calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate; - - //總發電金額 計算方式:totalkWh * 授電費率 - calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate; - break; - } - #endregion - - #region PR - //直接填寫 - calcPowerStation.Today_PR = history_for_powerStation.PR; - #endregion - - #region 減碳量 - carbonRate = Convert.ToDouble(await powerStationRepository.GetOneVariableByName("CarbonRate")); - - history_for_powerStation.CARBON = history_for_powerStation.KWH * carbonRate; - history_for_powerStation.TODAYCARBON = history_for_powerStation.TodayKWh * carbonRate; - history_for_powerStation.TOTALCARBON = history_for_powerStation.TotalKWH * carbonRate; - - //今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值] - calcPowerStation.Today_Carbon = history_for_powerStation.TodayKWh * carbonRate; - - //總減碳量(總發電量 * (0.554/1000)[抓資料庫值] - calcPowerStation.Total_Carbon = history_for_powerStation.TotalKWH * carbonRate; - - #endregion - - #region 發電時間 - calcPowerStation.SolarHour = history_for_powerStation.SolarHour; - #endregion - } - - } } } diff --git a/SolarPower/Quartz/Jobs/OperationScheduleJob.cs b/SolarPower/Quartz/Jobs/OperationScheduleJob.cs index e97cdde..911a475 100644 --- a/SolarPower/Quartz/Jobs/OperationScheduleJob.cs +++ b/SolarPower/Quartz/Jobs/OperationScheduleJob.cs @@ -10,6 +10,7 @@ using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; +using System.Text.RegularExpressions; namespace SolarPower.Quartz.Jobs { @@ -249,27 +250,30 @@ namespace SolarPower.Quartz.Jobs var stationReportName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(dayexcel, Formatting.Indented)); if (stationReportName != "") { - NoticeSchedule DaySchedule = new NoticeSchedule() + if (user.Email != null && IsValidEmail(user.Email)) { - 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); + 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); + } } } //綜合報表 每日 @@ -284,17 +288,19 @@ namespace SolarPower.Quartz.Jobs Userid = user.Id }; var stationMaxReportName = stationReportController.ExportExcelmaxtableBackDownload(JsonConvert.SerializeObject(maxdayexcel, Formatting.Indented)); - NoticeSchedule MaxSchedule = new NoticeSchedule() + if (user.Email != null && IsValidEmail(user.Email)) { - UserId = user.Id, - EmailType = 2, - RecipientEmail = user.Email, - Subject = "綜合報表", - Attachment = stationMaxReportName, - RecipientName = user.Name, - Type = 1 - }; - List properties = new List() + 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", @@ -304,7 +310,8 @@ namespace SolarPower.Quartz.Jobs "RecipientName", "Type" }; - await noticeScheduleRepository.AddOneAsync(MaxSchedule, properties); + await noticeScheduleRepository.AddOneAsync(MaxSchedule, properties); + } if (DateTime.Now.ToString("dd") == "01") { @@ -317,27 +324,30 @@ namespace SolarPower.Quartz.Jobs Userid = user.Id }; var stationReportmaxmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(maxmonthexcel, Formatting.Indented)); - NoticeSchedule MaxmonthSchedule = new NoticeSchedule() + if (user.Email != null && IsValidEmail(user.Email)) { - 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); + 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); + } } } @@ -360,27 +370,30 @@ namespace SolarPower.Quartz.Jobs var stationReportmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(monthexcel, Formatting.Indented)); if (stationReportmonthName != "") { - NoticeSchedule MonthSchedule = new NoticeSchedule() + if (user.Email != null && IsValidEmail(user.Email)) { - 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); + 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); + } } } @@ -437,5 +450,11 @@ namespace SolarPower.Quartz.Jobs return tempSerialNumber.ToString().Trim().PadRight(pad, '0'); } } + + bool IsValidEmail(string strIn) + { + // Return true if strIn is in valid e-mail format. + return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); + } } } diff --git a/SolarPower/Quartz/Jobs/SendEmailJob.cs b/SolarPower/Quartz/Jobs/SendEmailJob.cs index 71a356e..25ac79f 100644 --- a/SolarPower/Quartz/Jobs/SendEmailJob.cs +++ b/SolarPower/Quartz/Jobs/SendEmailJob.cs @@ -9,6 +9,7 @@ using System.IO; using System.Linq; using System.Net.Mail; using System.Threading.Tasks; +using System.Text.RegularExpressions; namespace SolarPower.Quartz.Jobs { @@ -43,46 +44,48 @@ namespace SolarPower.Quartz.Jobs var updateNoticeSchedules = new List(); foreach (var notice in noticeSchedules) { - var attachments = new List(); - var recipientEmails = new List() - { - notice.RecipientEmail - }; - if (!string.IsNullOrEmpty(notice.Attachment)) - { - attachments = notice.Attachment.Split(',').ToList(); + if (notice.RecipientEmail != null && IsValidEmail(notice.RecipientEmail)) { + var attachments = new List(); + var recipientEmails = new List() + { + notice.RecipientEmail + }; + if (!string.IsNullOrEmpty(notice.Attachment)) + { + attachments = notice.Attachment.Split(',').ToList(); + } + + var result = Send(recipientEmails, notice.Subject, notice.Content, attachments); + + if (result.CompareTo("成功") == 0) + { + NoticeSchedule noticeSchedule = new NoticeSchedule(); + noticeSchedule.Id = notice.Id; + noticeSchedule.IsDelivery = 1; + noticeSchedule.DeliveryAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + + updateNoticeSchedules.Add(noticeSchedule); + } + else + { + NoticeSchedule noticeSchedule = new NoticeSchedule(); + noticeSchedule.Id = notice.Id; + noticeSchedule.IsDelivery = 2; + noticeSchedule.DeliveryAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + noticeSchedule.Reason = result; + + updateNoticeSchedules.Add(noticeSchedule); + } + + List properties = new List() + { + "Id", + "IsDelivery", + "DeliveryAt" + }; + + await noticeScheduleRepository.UpdateList(updateNoticeSchedules, properties); } - - var result = Send(recipientEmails, notice.Subject, notice.Content, attachments); - - if (result.CompareTo("成功") == 0) - { - NoticeSchedule noticeSchedule = new NoticeSchedule(); - noticeSchedule.Id = notice.Id; - noticeSchedule.IsDelivery = 1; - noticeSchedule.DeliveryAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - - updateNoticeSchedules.Add(noticeSchedule); - } - else - { - NoticeSchedule noticeSchedule = new NoticeSchedule(); - noticeSchedule.Id = notice.Id; - noticeSchedule.IsDelivery = 2; - noticeSchedule.DeliveryAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - noticeSchedule.Reason = result; - - updateNoticeSchedules.Add(noticeSchedule); - } - - List properties = new List() - { - "Id", - "IsDelivery", - "DeliveryAt" - }; - - await noticeScheduleRepository.UpdateList(updateNoticeSchedules, properties); } logger.LogInformation("【SendEmailJob】【任務完成】"); @@ -160,5 +163,12 @@ namespace SolarPower.Quartz.Jobs } } + + bool IsValidEmail(string strIn) + { + // Return true if strIn is in valid e-mail format. + return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); + } + } } diff --git a/SolarPower/Repository/Implement/OperationRepository.cs b/SolarPower/Repository/Implement/OperationRepository.cs index 2f1a88c..2ba0976 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; using System.Threading.Tasks; +using System.Text.RegularExpressions; namespace SolarPower.Repository.Implement { @@ -648,15 +649,20 @@ namespace SolarPower.Repository.Implement List value = new List(); foreach (MyUser a in personal) { - value.Add($@"(1,'{a.Name}','{a.Email}','{Title}','{content}',{a.Id}, {emailType})"); + if (a.Email != null && IsValidEmail(a.Email)) + { + value.Add($@"(1,'{a.Name}','{a.Email}','{Title}','{content}',{a.Id}, {emailType})"); + } } string values = string.Join(",", value.ToArray()); + if (value.Count > 0) + { + var sql = $"INSERT INTO `notice_schedule` (`Type`, `RecipientName`, `RecipientEmail`, `Subject`, `Content`,`UserId`,`EmailType`) VALUES {values};"; - var sql = $"INSERT INTO `notice_schedule` (`Type`, `RecipientName`, `RecipientEmail`, `Subject`, `Content`,`UserId`,`EmailType`) VALUES {values};"; - - await conn.ExecuteAsync(sql, trans); - - trans.Commit(); + await conn.ExecuteAsync(sql, trans); + + trans.Commit(); + } } catch (Exception exception) { @@ -797,5 +803,11 @@ namespace SolarPower.Repository.Implement } } + bool IsValidEmail(string strIn) + { + // Return true if strIn is in valid e-mail format. + return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); + } + } } diff --git a/SolarPower/Repository/Implement/OverviewRepository.cs b/SolarPower/Repository/Implement/OverviewRepository.cs index 8dca441..d187aa1 100644 --- a/SolarPower/Repository/Implement/OverviewRepository.cs +++ b/SolarPower/Repository/Implement/OverviewRepository.cs @@ -731,12 +731,18 @@ namespace SolarPower.Repository.Implement // LEFT JOIN sensor_history_month P ON P.`TIMESTAMP` = C.`TIMESTAMP` AND P.PowerStationId = C.PowerStationId // WHERE C.PowerStationId = {post.PowerstationId} // GROUP BY left(c.`TIMESTAMP`, 4) ORDER BY C.`TIMESTAMP` "; - sql = $@" select left(c.`TIMESTAMP`, 4) AS `TIMESTAMP`, sum(monthKWH) AS KWH, round(AVG(PR), 2) AS PR , round(AVG(PR), 2) AS avgPR , - ifnull(avg( P.IrrDay), 0) irrDay, avg(P.Temperature) AS Temp - FROM power_station_history_month C - LEFT JOIN sensor_history_month P ON DATE_FORMAT(P.TIMESTAMP, '%Y') = DATE_FORMAT(C.TIMESTAMP, '%Y') AND P.PowerStationId = C.PowerStationId - WHERE C.PowerStationId = {post.PowerstationId} - group by left(c.`TIMESTAMP`, 4) "; + sql = $@"select * from ( + select left(c.`TIMESTAMP`, 4) AS `TIMESTAMP`, sum(monthKWH) AS KWH, round(AVG(PR), 2) AS PR , round(AVG(PR), 2) AS avgPR , + ifnull(avg( P.IrrDay), 0) irrDay, avg(P.Temperature) AS Temp, ps.GeneratingCapacity AS GeneratingCapacity + FROM power_station_history_month C + LEFT JOIN sensor_history_month P ON DATE_FORMAT(P.TIMESTAMP, '%Y-%M') = DATE_FORMAT(C.TIMESTAMP, '%Y-%M') AND P.PowerStationId = C.PowerStationId + LEFT JOIN power_station ps ON ps.id = C.PowerStationId + WHERE C.PowerStationId = {post.PowerstationId} + group by left(c.`TIMESTAMP`, 4) + )x join + ( + select year(timestamp) yyyy, count(*) days from sensor_history_day where PowerStationId = {post.PowerstationId} group by year(timestamp) + )y on x.`TIMESTAMP` = y.yyyy"; break; } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 4f59599..5d1a34b 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -1018,6 +1018,10 @@ namespace SolarPower.Repository.Implement var trans = conn.BeginTransaction(); try { + string getSensorTypeId = $@"SELECT id from sensor_type + WHERE SensorEName = '{DeviceInfo.Type}' AND Deleted = 0"; + DeviceInfo.SensorTypeId = await conn.QueryFirstOrDefaultAsync(getSensorTypeId); + DeviceInfo.SensorTypeDetailId = DeviceInfo.SensorTypeId; string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "device"); await conn.ExecuteAsync(sql, DeviceInfo); @@ -1050,6 +1054,11 @@ namespace SolarPower.Repository.Implement var trans = conn.BeginTransaction(); try { + string getSensorTypeId = $@"SELECT id from sensor_type + WHERE SensorEName = '{DeviceInfo.Type}' AND Deleted = 0"; + DeviceInfo.SensorTypeId = await conn.QueryFirstOrDefaultAsync(getSensorTypeId); + DeviceInfo.SensorTypeDetailId = DeviceInfo.SensorTypeId; + var updateQuery = GenerateUpdateQueryWithCustomDBNameAndTable(properties, db_name, "device"); await conn.ExecuteAsync(updateQuery.ToString(), DeviceInfo, trans); trans.Commit(); @@ -1906,6 +1915,34 @@ namespace SolarPower.Repository.Implement } } + /// + /// 在master.inv_status資料表中 新增逆變器 + /// + /// + /// + /// + public async Task AddMasterInverter(InverterForMaster inverter, List properties) + { + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + int count; + conn.Open(); + try + { + var sql = GenerateInsertQueryWithCustomTable(properties, "inv_status"); + count = await conn.ExecuteAsync(sql, inverter); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + } + } + /// /// 取得控制器所有id /// @@ -1980,11 +2017,12 @@ namespace SolarPower.Repository.Implement try { string sql = @$"SELECT - inv.*, con.ControllerId AS ControllerName,user.Name As CreatedName,de.UID AS PyrheliometerName + inv.*, con.ControllerId AS ControllerName,user.Name As CreatedName,de.UID AS PyrheliometerName, invs.status AS InverterStatus FROM {db_name}.inverter inv LEFT JOIN {db_name}.controller con ON inv.ControllerId = con.id LEFT JOIN user ON inv.CreatedBy = user.id LEFT JOIN {db_name}.device de ON inv.Pyrheliometer = de.id + LEFT JOIN inv_status invs ON inv.InverterId = invs.InverterId WHERE inv.Deleted = 0 AND inv.ControllerId IN @Controllerid"; inverterTable = (await conn.QueryAsync(sql, new { Controllerid = controllerid }, commandTimeout: 600)).ToList(); @@ -2001,6 +2039,39 @@ namespace SolarPower.Repository.Implement } } + /// + /// 取單一逆變器 + /// + /// + /// + /// + public async Task GetOneMasterInverter(int id, string db_name) + { + + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + InverterTable inverter = new InverterTable(); + conn.Open(); + try + { + string sql = $@"SELECT a.InverterId + FROM solar_master.inv_status a join {db_name}.inverter b on a.inverterid = b.inverterid + WHERE a.Deleted = 0 AND b.Id = {id}"; + inverter = (await conn.QueryFirstOrDefaultAsync(sql, commandTimeout: 600)); + + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return inverter; + } + } + /// /// 其餘電站列表 /// @@ -2558,41 +2629,75 @@ namespace SolarPower.Repository.Implement } } - //public virtual async Task DeleteOneInverter(int id, string db_name, string table_name) - //{ - // using (IDbConnection conn = this._databaseHelper.GetConnection()) - // { - // conn.Open(); - // using (var trans = conn.BeginTransaction()) - // { - // try - // { - // var sql = $"UPDATE {db_name}.{table_name} SET Deleted = 1 WHERE Id = @Id"; + public async Task UpdateMasterInverter(InverterForMaster entity, List properties) + { + int count; + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + string sql = $@"UPDATE solar_master.inv_status a join {entity.DBName}.inverter b on a.inverterid = b.inverterid + SET + a.Enabled = {entity.Enabled}, + a.Status = {entity.Status} + WHERE b.id = {entity.Id}"; - // await conn.ExecuteAsync(sql, new { Id = id }, trans); + count = await conn.ExecuteAsync(sql, entity, trans); - // string updateToInv_Status = @"DROP TABLE IF EXISTS solar_master.`inv_status`; - // create table solar_master.inv_status - // select * from solar_master.v_company_inv - // where enabled = 1; - // ALTER TABLE solar_master.`inv_status` ADD INDEX inv_status_index (`inverterid`);"; + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + } - // await conn.ExecuteAsync(updateToInv_Status, new { Id = id }, trans); + return count; + } + } - // trans.Commit(); - // } - // catch (Exception exception) - // { - // trans.Rollback(); - // throw exception; - // } - // finally - // { - // conn.Close(); - // } - // } - // } - //} + /// + /// 透過table_name、inverterId,軟刪除指定資料表的單一筆inverter + /// + /// + /// + /// + public async Task DeleteOneMasterInverter(string inverterId, string table_name) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + var sql = $"UPDATE {table_name} SET Deleted = 1 WHERE InverterId = {inverterId}"; + + await conn.ExecuteAsync(sql, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + + } + } + } public async Task> GetListPyrheliometerByPowerStationId(int powerStationId, string db_name) { @@ -6447,36 +6552,21 @@ namespace SolarPower.Repository.Implement } } - public async Task CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId) + public async Task CalcIrrDayHistoryPerTwoHour(string dateTime, int powerStationId) { string result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { try { - //var sql = $@"update sensor_history_hour a join - // ( - // select powerstationID, `TIMESTAMP`, irrday - - // (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(dateTime).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour - // from sensor_history_hour z - // where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(dateTime).ToString("yyyy-MM-dd HH")}' - // ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP` - // Set a.irrdayhour = b.irrdayhour where a.powerstationID = {powerStationId}"; string d1 = dateTime + ":00:00"; - //string sql = $@"update sensor_history_hour a join - // ( - // select powerstationID, `TIMESTAMP`, irrday - - // (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour - // from sensor_history_hour z - // where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{dateTime}' - // ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP` - // Set a.irrdayhour = case when b.irrdayhour < 0 then 0 else b.irrdayhour end - // where a.powerstationID = {powerStationId}"; - //result = await conn.QueryFirstOrDefaultAsync(sql, commandTimeout: 600); - string sql = $@" select irrday - - (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour + //string sql = $@" select irrday - + // (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour + // from sensor_history_hour z + // where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{dateTime}' "; + string sql = $@" select IrrDay from sensor_history_hour z - where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{dateTime}' "; + where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' "; result = await conn.QueryFirstOrDefaultAsync(sql, commandTimeout: 600); } catch (Exception exception) diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 9036209..4f2e7ee 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -114,9 +114,9 @@ namespace SolarPower.Repository.Implement select * from temp_inv union SELECT '總計' report_date, {inv} - round(sum(hourKWH), 2) hourKWH, round(sum(hourKWHp), 2) hourKWHp, round(avg(irrDay),2) irrDay, round(avg(irrDayHour),2) irrDayHour, - round( avg(temperature), 2) temperature, round(sum(hourmoney), 2) hourmoney, round(avg(totKWH), 2) totKWH, round(avg(totKWHKWP),2) totKWHKWP, round(avg(totmoney),2) totmoney, '電站名稱' stationName, - round( avg(daymoney), 2) daymoney, round(avg(tothour), 2) tothour, round(avg(pr), 2) pr, avg(GeneratingCapacity) GeneratingCapacity + round(sum(hourKWH), 2) hourKWH, round(sum(hourKWHp), 2) hourKWHp, round(sum(irrDay),2) irrDay, round(sum(irrDayHour),2) irrDayHour, + round( avg(temperature), 2) temperature, round(sum(hourmoney), 2) hourmoney, round(sum(totKWH), 2) totKWH, round(sum(totKWHKWP),2) totKWHKWP, round(sum(totmoney),2) totmoney, '電站名稱' stationName, + round( sum(daymoney), 2) daymoney, round(sum(tothour), 2) tothour, round(sum(pr), 2) pr, avg(GeneratingCapacity) GeneratingCapacity from temp_inv2 a; "; break; @@ -166,7 +166,7 @@ namespace SolarPower.Repository.Implement SELECT '總計' report_date, {inv} round(sum(dayKWH), 2) dayKWH, round(sum(dayKWHp), 2) dayKWHp, round(max(tothour), 2) tothour, round(avg(KWHKWP), 2) KWHKWP, round(avg(PR), 2) PR, GeneratingCapacity, round(sum(irradiance), 2) irradiance, round(avg(temperature), 2) temperature, round(sum(soldmoney), 2) soldmoney, - round(monthKWH, 2) monthKWH, monthmoney, stationName, monthmoneyone, SolarType, SiteDB, IrrDay + round(monthKWH, 2) monthKWH, monthmoney, stationName, monthmoneyone, SolarType, SiteDB, round(avg(IrrDay), 2) IrrDay from temp_inv2 a; "; } else @@ -264,7 +264,7 @@ namespace SolarPower.Repository.Implement SELECT '總計' report_date, {inv} round(sum(dayKWH), 2) dayKWH, round(sum(dayKWHp), 2) dayKWHp, round(max(tothour), 2) tothour, avg(KWHKWP) KWHKWP, round(avg(PR), 2) PR, GeneratingCapacity, round(sum(irradiance), 2) irradiance, round(avg(temperature), 2) temperature, round(sum(soldmoney), 2) soldmoney, - round( monthKWH,2) monthKWH , monthmoney, stationName, monthmoneyone, SolarType, SiteDB, round(IrrDay , 2) IrrDay + round( monthKWH,2) monthKWH , monthmoney, stationName, monthmoneyone, SolarType, SiteDB, round(avg(IrrDay), 2) IrrDay from temp_inv2 a; "; } @@ -315,12 +315,24 @@ namespace SolarPower.Repository.Implement // EXECUTE stmt; // DEALLOCATE PREPARE stmt;"; #endregion + DateTime firstDay = new DateTime(int.Parse(post.Time), 01, 01); + DateTime lastDay; + if (DateTime.Now.Year == int.Parse(post.Time)) + { + lastDay = DateTime.Now.Date; + } + else + { + lastDay = new DateTime(int.Parse(post.Time), 12, 31); + } + string days = (lastDay - firstDay).TotalDays.ToString(); + sql = @$" DROP TABLE IF EXISTS temp_inv; create TEMPORARY TABLE temp_inv as SELECT DATE_FORMAT(a.report_date,'%Y/%m') report_date, {inv} b.todayKWH 'dayKWH', round((b.todayKWH / c.monthKWH)*100,2) 'dayKWHp', b.SOLARHOUR 'tothour', b.KWHKWP 'KWHKWP', b.PR,z.GeneratingCapacity, d.irradiance 'irradiance', d.Temperature 'temperature', b.money 'soldmoney', - c.monthKWH 'monthKWH', c.money 'monthmoney', stationName, powerRate 'monthmoneyone',SolarType,SiteDB, d.IrrDay + c.monthKWH 'monthKWH', c.money 'monthmoney', stationName, powerRate 'monthmoneyone',SolarType,SiteDB, d.IrrDay, {days} Days FROM report_invday a left join ( # 每日加總 inv select powerStationid, DATE_FORMAT(TIMESTAMP,'%Y-%m') report_date, siteid, sitetype, @@ -358,7 +370,7 @@ namespace SolarPower.Repository.Implement SELECT '總計' report_date, {inv} round(sum(dayKWH), 2) dayKWH, round(sum(dayKWHp), 2) dayKWHp, round(max(tothour), 2) tothour, avg(KWHKWP) KWHKWP, round(avg(PR), 2) PR, GeneratingCapacity, round(sum(irradiance), 2) irradiance, avg(temperature) temperature, round(sum(soldmoney), 2) soldmoney, - round(monthKWH, 2) monthKWH, monthmoney, stationName, monthmoneyone, SolarType, SiteDB, IrrDay + round(monthKWH, 2) monthKWH, monthmoney, stationName, monthmoneyone, SolarType, SiteDB, round(avg(IrrDay), 2) IrrDay, 0 from temp_inv2 a; "; break; @@ -805,5 +817,35 @@ namespace SolarPower.Repository.Implement return a; } } + + public async Task GetCompanyNameByPowerStationId(int powerStationId) + { + string result; + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + try + { + var sql = @$"SELECT c.Name + FROM power_station ps + LEFT JOIN company c ON ps.CompanyId = c.id + WHERE ps.id = {powerStationId} AND ps.Deleted = 0"; + + result = await conn.QueryFirstOrDefaultAsync(sql); + + + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return result; + } + } + } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 7ee71f8..fbb84f7 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -399,6 +399,13 @@ namespace SolarPower.Repository.Interface /// Task AddInverter(Inverter inverter, List properties, string db_name); /// + /// 新增Master逆變器 + /// + /// + /// + /// + Task AddMasterInverter(InverterForMaster inverter, List properties); + /// /// 取得控制器所有id /// Task> GetAllDeviceControllerId(int stationId, string db_name); @@ -539,6 +546,8 @@ namespace SolarPower.Repository.Interface Task UpdatePyrheliometerHistoryMonthList(List entity); Task UpdateInverter(Inverter entity, List properties, string db_name); + Task UpdateMasterInverter(InverterForMaster entity, List properties); + Task DeleteOneMasterInverter(string inverterId, string table_name); Task Getonediv(string where, string db_name, string table_name); @@ -632,7 +641,8 @@ namespace SolarPower.Repository.Interface Task AlertColStationTableColumn(string dbname, string code); Task> GetAllNoStatusAsync(); - Task CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId); + Task CalcIrrDayHistoryPerTwoHour(string dateTime, int powerStationId); Task GetPowerStationHistoryPerHourForPowerStation(string dateTime, string table_name); + Task GetOneMasterInverter(int id, string db_name); } } diff --git a/SolarPower/Repository/Interface/IStationReportRepository.cs b/SolarPower/Repository/Interface/IStationReportRepository.cs index 3edc23f..b1f38c3 100644 --- a/SolarPower/Repository/Interface/IStationReportRepository.cs +++ b/SolarPower/Repository/Interface/IStationReportRepository.cs @@ -14,5 +14,6 @@ namespace SolarPower.Repository.Interface Task> GetMaxtablebody(Select_table2 post); Task Findhaveinv(Select_table post); Task CheckExcelAsync(Select_table post); + Task GetCompanyNameByPowerStationId(int powerStationId); } } diff --git a/SolarPower/Views/AnalysisInverter/Index.cshtml b/SolarPower/Views/AnalysisInverter/Index.cshtml index 1189e5b..adeba19 100644 --- a/SolarPower/Views/AnalysisInverter/Index.cshtml +++ b/SolarPower/Views/AnalysisInverter/Index.cshtml @@ -4,16 +4,8 @@ ViewData["Title"] = "逆變器交叉分析"; } - -
- - - - - - - - +
+
diff --git a/SolarPower/Views/AnalysisStationCombine/Index.cshtml b/SolarPower/Views/AnalysisStationCombine/Index.cshtml index 0f9afd7..ad6772d 100644 --- a/SolarPower/Views/AnalysisStationCombine/Index.cshtml +++ b/SolarPower/Views/AnalysisStationCombine/Index.cshtml @@ -6,16 +6,8 @@ @using SolarPower.Models.Role @model RoleLayerEnum - -
- - - - - - - - +
+
diff --git a/SolarPower/Views/AnalysisStationInfo/Index.cshtml b/SolarPower/Views/AnalysisStationInfo/Index.cshtml index e2016c5..fe998f6 100644 --- a/SolarPower/Views/AnalysisStationInfo/Index.cshtml +++ b/SolarPower/Views/AnalysisStationInfo/Index.cshtml @@ -4,16 +4,8 @@ ViewData["Title"] = "電站交叉分析"; } - -
- - - - - - - - +
+
diff --git a/SolarPower/Views/Company/Index.cshtml b/SolarPower/Views/Company/Index.cshtml index 57bd79b..389277a 100644 --- a/SolarPower/Views/Company/Index.cshtml +++ b/SolarPower/Views/Company/Index.cshtml @@ -19,16 +19,8 @@
- -
- - - - - - - - +
+
diff --git a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml index 84516eb..bc29fec 100644 --- a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml +++ b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml @@ -6,16 +6,8 @@ @using SolarPower.Models.Role @model RoleLayerEnum - -
- - - - - - - - +
+
diff --git a/SolarPower/Views/ExceptionRecord/Index.cshtml b/SolarPower/Views/ExceptionRecord/Index.cshtml index 13de8ab..6056b16 100644 --- a/SolarPower/Views/ExceptionRecord/Index.cshtml +++ b/SolarPower/Views/ExceptionRecord/Index.cshtml @@ -12,16 +12,8 @@
  • - -
    - - - - - - - - +
    +
    diff --git a/SolarPower/Views/Login/Index.cshtml b/SolarPower/Views/Login/Index.cshtml index 2ea9727..b25dc1a 100644 --- a/SolarPower/Views/Login/Index.cshtml +++ b/SolarPower/Views/Login/Index.cshtml @@ -25,20 +25,8 @@ - - -
    - - - - - - - - -