diff --git a/SolarPower/Controllers/PowerGenerationController.cs b/SolarPower/Controllers/PowerGenerationController.cs new file mode 100644 index 0000000..ca1d0db --- /dev/null +++ b/SolarPower/Controllers/PowerGenerationController.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SolarPower.Controllers +{ + public class PowerGenerationController : MyBaseController + { + public IActionResult Index() + { + return View(); + } + } +} diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 331873f..3febd9a 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -740,6 +740,11 @@ namespace SolarPower.Controllers PowerStation = Convert.ToInt32(powerstationid.Value), Userid = postObject.Userid }; + var k = stationReportRepository.Findhaveinv(select_Table); + if(k.Result[0].values == null) + { + return ""; + } var Formbody = GetForm(select_Table);//取body var Formhead = GetTableHead(select_Table);//取head int RowPosition = 0; diff --git a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs index dbcc79c..c6fea55 100644 --- a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs @@ -39,6 +39,8 @@ namespace SolarPower.Quartz.Jobs foreach (var user in users.Result) { + + List powerstations = new List(); powerstations = await noticeScheduleRepository.GetPowerStationOperationPersonnel(user.Id); if(powerstations.Count == 0) @@ -61,25 +63,26 @@ namespace SolarPower.Quartz.Jobs Userid = user.Id }; var stationReportName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(dayexcel, Formatting.Indented)); - NoticeSchedule DaySchedule = new NoticeSchedule() + if(stationReportName != "") { - RecipientEmail = user.Email, - Subject = "日報表", - Attachment = stationReportName, - RecipientName = user.Name, - Type = 1 - }; - List properties = new List() - { - "RecipientEmail", - "Subject", - "Attachment", - "RecipientName", - "Type" - }; - await noticeScheduleRepository.AddOneAsync(DaySchedule, properties); - - + NoticeSchedule DaySchedule = new NoticeSchedule() + { + RecipientEmail = user.Email, + Subject = "日報表", + Attachment = stationReportName, + RecipientName = user.Name, + Type = 1 + }; + List properties = new List() + { + "RecipientEmail", + "Subject", + "Attachment", + "RecipientName", + "Type" + }; + await noticeScheduleRepository.AddOneAsync(DaySchedule, properties); + } } //綜合報表 每日 if(sentMaxpowerstations.Count != 0) @@ -159,15 +162,17 @@ namespace SolarPower.Quartz.Jobs Userid = user.Id }; var stationReportmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(monthexcel, Formatting.Indented)); - NoticeSchedule MonthSchedule = new NoticeSchedule() + if (stationReportmonthName != "") { - RecipientEmail = user.Email, - Subject = "月報表", - Attachment = stationReportmonthName, - RecipientName = user.Name, - Type = 1 - }; - List properties2 = new List() + NoticeSchedule MonthSchedule = new NoticeSchedule() + { + RecipientEmail = user.Email, + Subject = "月報表", + Attachment = stationReportmonthName, + RecipientName = user.Name, + Type = 1 + }; + List properties2 = new List() { "RecipientEmail", "Subject", @@ -175,7 +180,9 @@ namespace SolarPower.Quartz.Jobs "RecipientName", "Type" }; - await noticeScheduleRepository.AddOneAsync(MonthSchedule, properties2); + await noticeScheduleRepository.AddOneAsync(MonthSchedule, properties2); + } + } diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 5e07297..aedf0ec 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -324,5 +324,173 @@ namespace SolarPower.Repository.Implement return result; } } + + public async Task Findhaveinv(Select_table post) + { + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + dynamic a; + conn.Open(); + try + { + string sql = ""; + switch (post.FormType) + { + case 0: + sql = @$" + SET @sql = NULL; + SELECT + GROUP_CONCAT(DISTINCT + CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then a.KWH end) ''inv_', right(INVERTERID, 4), '''') + ) INTO @sql + FROM inverter_history_hour where powerstationId = {post.PowerStation}; + SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m-%d %H'') report_date, ', @sql, + ', b.KWH hourKWH, round((b.KWH / (SELECT MAX(TODAYKWH) FROM power_station_history_hour WHERE DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' and powerstationid = {post.PowerStation}))*100,2) ''hourKWHp'', d.irradiance ''irradiance'', d.Temperature ''temperature'', + b.money ''hourmoney'', c.TODAYKWH ''totKWH'', c.KWHKWP ''totKWHKWP'', c.money ''totmoney'', stationName, powerRate daymoney, c.SOLARHOUR tothour,round(b.PR, 2) as pr + FROM inverter_history_hour a left join + ( # 每小時加總 inv + select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:%i'') report_date, siteid, sitetype, round(KWH, 2) KWH, + round(TODAYKWH, 2) TODAYKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, round(money, 2) money + from power_station_history_hour + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' + ) b on a.powerStationid = b.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d %H:%i'') = b.report_date + left join + ( # day + select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') report_date, sitetype, round(TODAYKWH, 2) TODAYKWH,round(KWHKWP, 2) KWHKWP + , round(PR, 2) PR, round(money, 2) money , round(SOLARHOUR, 2) SOLARHOUR + from power_station_history_day + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' + ) c on a.powerStationid = c.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') = c.report_date + left join + ( + select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:%i'')report_date, irradiance, Temperature + from sensor_history_hour + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' + ) d on a.powerStationid = d.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d %H:%i'') = d.report_date + join + ( + select id, name stationName, powerRate from power_station where id = {post.PowerStation} + )z on a.powerstationid = z.id + where DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') = ''{post.Time}'' + GROUP BY DATE_FORMAT(TIMESTAMP,''%Y-%m-%d %H:%i'') + order by DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d %H:%i'') '); + + select @sql as 'mySelect'; #顯示動態語法 + #PREPARE stmt FROM @sql; + #EXECUTE stmt; + #DEALLOCATE PREPARE stmt;"; + break; + case 1: + if (post.SearchType == 2) + { + sql = @$" + SET @sql = NULL; + SELECT + GROUP_CONCAT(DISTINCT + CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 4), '''') + ) INTO @sql + FROM inverter_history_hour where powerstationId = {post.PowerStation}; + SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql, + ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR, + d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', + c.monthKWH ''monthKWH'', c.money ''monthmoney'', stationName, powerRate ''monthmoneyone'',SolarType,SiteDB + FROM inverter_history_day a left join + ( # 每日加總 inv + select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') report_date, siteid, sitetype, #, round(KWH, 2) KWH, + round(todayKWH, 2) todayKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, ifnull(round(money, 2),0) money, round(SOLARHOUR, 2) SOLARHOUR + from power_station_history_day + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m'') = ''{post.Time}'' + ) b on a.powerStationid = b.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') = b.report_date + left join + ( # month + select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m'') report_date, sitetype, round(monthKWH, 2) monthKWH,round(KWHKWP, 2) KWHKWP + , round(PR, 2) PR, round(money, 2) money , round(SOLARHOUR, 2) SOLARHOUR + from power_station_history_month + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m'') = ''{post.Time}'' + ) c on a.powerStationid = c.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m'') = c.report_date + left join + ( + select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'')report_date, irradiance, Temperature + from sensor_history_day + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m'') = ''{post.Time}'' + ) d on a.powerStationid = d.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') = d.report_date + join + ( + select id, name stationName, powerRate,SolarType,SiteDB from power_station where id = {post.PowerStation} + )z on a.powerstationid = z.id + where DATE_FORMAT(a.TIMESTAMP,''%Y-%m'') = ''{post.Time}'' + GROUP BY DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') + order by DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') '); + + select @sql as 'mySelect'; #顯示動態語法 + #PREPARE stmt FROM @sql; + #EXECUTE stmt; + #DEALLOCATE PREPARE stmt;"; + } + else + { + var times = post.Time.Replace('-', 'a').Replace('/', '-').Replace(" ", "").Split('a'); + + sql = @$"SET @sql = NULL; + SELECT + GROUP_CONCAT(DISTINCT + CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 4), '''') + ) INTO @sql + FROM inverter_history_hour where powerstationId = {post.PowerStation}; + SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql, + ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR, + d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', + c.monthKWH ''monthKWH'', c.money ''monthmoney'', stationName, powerRate ''monthmoneyone'',SolarType,SiteDB + FROM inverter_history_day a left join + ( # 每日加總 inv + select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') report_date, siteid, sitetype, #, round(KWH, 2) KWH, + round(todayKWH, 2) todayKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, ifnull(round(money, 2),0) money, round(SOLARHOUR, 2) SOLARHOUR + from power_station_history_day + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') BETWEEN ''{times[0]}'' AND ''{times[1]}'' + ) b on a.powerStationid = b.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') = b.report_date + left join + ( # month + SELECT powerStationid, ROUND(AVG(TODAYKWH),2) AS monthKWH, + ROUND(AVG(KWHKWP),2) AS KWHKWP, + ROUND(AVG(PR),2) AS PR, + ROUND(SUM(MONEY),2) AS money, + ROUND(SUM(SOLARHOUR),2) AS SOLARHOUR + FROM power_station_history_day where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') BETWEEN ''{times[0]}'' AND ''{times[1]}'' + ) c on a.powerStationid = c.powerStationid + left join + ( + select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'')report_date, irradiance, Temperature + from sensor_history_day + where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') BETWEEN ''{times[0]}'' AND ''{times[1]}'' + ) d on a.powerStationid = d.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') = d.report_date + join + ( + select id, name stationName, powerRate, SolarType, SiteDB from power_station where id = {post.PowerStation} + )z on a.powerstationid = z.id + where DATE_FORMAT(TIMESTAMP,''%Y-%m-%d'') BETWEEN ''{times[0]}'' AND ''{times[1]}'' + GROUP BY DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') + order by DATE_FORMAT(a.TIMESTAMP,''%Y-%m-%d'') '); + + select @sql as 'mySelect'; #顯示動態語法 + #PREPARE stmt FROM @sql; + #EXECUTE stmt; + #DEALLOCATE PREPARE stmt;"; + } + + break; + } + a = await conn.QueryAsync(sql); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return a; + } + } } } diff --git a/SolarPower/Repository/Interface/IStationReportRepository.cs b/SolarPower/Repository/Interface/IStationReportRepository.cs index 81de8fd..c3f1f8a 100644 --- a/SolarPower/Repository/Interface/IStationReportRepository.cs +++ b/SolarPower/Repository/Interface/IStationReportRepository.cs @@ -12,5 +12,6 @@ namespace SolarPower.Repository.Interface Task Gettablebody(Select_table post); Task> GetHire(PsIdAndSiteDB post); Task> GetMaxtablebody(Select_table2 post); + Task Findhaveinv(Select_table post); } } diff --git a/SolarPower/Views/PowerGeneration/Index.cshtml b/SolarPower/Views/PowerGeneration/Index.cshtml new file mode 100644 index 0000000..e0ec9d1 --- /dev/null +++ b/SolarPower/Views/PowerGeneration/Index.cshtml @@ -0,0 +1,462 @@ +@{ + ViewData["MainNum"] = "4"; + ViewData["SubNum"] = "3"; + ViewData["Title"] = "電站發電收入"; +} +@using SolarPower.Models.Role +@model RoleLayerEnum + +
+
+ + + +
+
+

+ @ViewData["Title"] +

+
+ + +
+
+
+
+
+
+
+
+ + +
+
+
+ + +
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
預估值 CBA監控系統台電售電記錄平均發電度數小計
(/kW)
發電效能總發電量(度數)總售電收入(NT$)總發電量(度數)總售電收入(NT$)總發電量(度數)總售電收入(NT$)CBA監控系統v.s CBAActualv.s CBA
+
+
+ + + + + + + + + + + + + + + + + + +
起日起訖天數發電效能總發電量(度數)總售電收入(NT$)總發電量(度數)總售電收入(NT$)總發電量(度數)總售電收入(NT$)平均發電度數明細
(/kW/日)
+
+
+
+
+
+ +
+
+
+@section Scripts{ + +} \ No newline at end of file diff --git a/SolarPower/Views/Shared/_Layout.cshtml b/SolarPower/Views/Shared/_Layout.cshtml index b69ef46..b787054 100644 --- a/SolarPower/Views/Shared/_Layout.cshtml +++ b/SolarPower/Views/Shared/_Layout.cshtml @@ -271,6 +271,11 @@ 台電售電記錄 +
  • + + 電廠發電效能統計 + +
  • 報告發送記錄