diff --git a/SolarPower/Controllers/PowerGenerationController.cs b/SolarPower/Controllers/PowerGenerationController.cs index ca1d0db..c14bc42 100644 --- a/SolarPower/Controllers/PowerGenerationController.cs +++ b/SolarPower/Controllers/PowerGenerationController.cs @@ -1,16 +1,52 @@ using Microsoft.AspNetCore.Mvc; +using SolarPower.Repository.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using SolarPower.Models; +using SolarPower.Models.PowerStation; +using Microsoft.Extensions.Logging; namespace SolarPower.Controllers { - public class PowerGenerationController : MyBaseController + public class PowerGenerationController : MyBaseController { + private readonly IElectricitySoldRecordRepository electricitySoldRecordRepository; + private readonly IPowerStationRepository powerStationRepository; + + public PowerGenerationController(IElectricitySoldRecordRepository electricitySoldRecordRepository, IPowerStationRepository powerStationRepository) : base() + { + this.electricitySoldRecordRepository = electricitySoldRecordRepository; + this.powerStationRepository = powerStationRepository; + } public IActionResult Index() { return View(); } + + [HttpPost] + public async Task>> GetGenerationList (SearchGeneration post) + { + ApiResult> apiResult = new ApiResult>(); + try + { + var GenerationList = await electricitySoldRecordRepository.GetGenerationList(post); + apiResult.Data = GenerationList; + apiResult.Code = "0000"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "info=" + System.Text.Json.JsonSerializer.Serialize(post)); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + return apiResult; + } + + + } } diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 4d0c358..23895fc 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -77,6 +77,48 @@ namespace SolarPower.Controllers return apiResult; } + + [HttpPost] + public async Task>>> GetPowerStationNameListForGeneration(string filter) + { + ApiResult>> apiResult = new ApiResult>>(); + try + { + var powerStations = new List(); + if (IsPlatformLayer(myUser.Role.Layer)) + { + powerStations = await powerStationRepository.GetPowerStationsAllWithfilterForGeneration(filter); + } + else + { + powerStations = await powerStationRepository.GetPowerStationsByCompanyIdWithfilterForGeneration(myUser, filter); + } + + var siteDBNamePowerStationId = new Dictionary>(); + + var powerStation_Group = powerStations.GroupBy(x => x.CityName).ToList(); + foreach (var stations in powerStation_Group) + { + siteDBNamePowerStationId.Add(stations.Key, stations.ToList()); + } + + apiResult.Code = "0000"; + + apiResult.Data = siteDBNamePowerStationId; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】"); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + + public async Task> GetTableHead(Select_table post) { ApiResult apiResult = new ApiResult(); diff --git a/SolarPower/Models/ElectricitySoldRecord.cs b/SolarPower/Models/ElectricitySoldRecord.cs index 1a2bf99..7dd1c68 100644 --- a/SolarPower/Models/ElectricitySoldRecord.cs +++ b/SolarPower/Models/ElectricitySoldRecord.cs @@ -52,4 +52,28 @@ namespace SolarPower.Models public string PowerName { get; set; } } + public class Generation + { + private string startAt; + public string StartAt { get { return Convert.ToDateTime(startAt).ToString("yyyy/MM/dd"); } set { startAt = value; } } + private string endAt; + public string EndAt { get { return Convert.ToDateTime(endAt).ToString("yyyy/MM/dd"); } set { endAt = value; } } + public double actualkwh { get; set; } + public double actualMoney { get; set; } + public double realKWH { get; set; } + public double realMoney { get; set; } + public double CBAkwh { get; set; } + public double CBAeff { get; set; } + public double capacity { get; set; } + public double rate { get; set; } + } + + public class SearchGeneration + { + public int DateType { get; set; } + public string Date { get; set; } + public int PowerstationId { get; set; } + } } + + diff --git a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs index 161f97b..e7ca7e0 100644 --- a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs +++ b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs @@ -100,5 +100,38 @@ namespace SolarPower.Repository.Implement return a; } } + + public async Task> GetGenerationList (SearchGeneration info) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + List a = new List(); + try + { + var sqlwhere = (info.DateType) switch + { + 0 => $"DATE_FORMAT(er.StartAt,'%Y-%m') = '{info.Date}'",//月 + _ => $"DATE_FORMAT(er.StartAt,'%Y') = '{info.Date}'"//年 + }; + + + + var sql = @$"SELECT aa.StartAt,aa.EndAt,aa.Kwh actualkwh,aa.Money actualMoney,SUM(pd.TODAYKWH) realKWH,SUM(pd.MONEY) realMoney,ps.Estimate_kwh CBAkwh,ps.EstimateEfficacy CBAeff ,ps.GeneratingCapacity capacity ,ps.PowerRate rate + FROM power_station_history_day pd + LEFT JOIN ( SELECT er.* FROM electricity_sold_record er WHERE {sqlwhere} AND er.Deleted = 0 ) aa + ON aa.PowerstationId = pd.PowerStationId + LEFT JOIN power_station ps ON ps.Id = pd.PowerStationId + WHERE pd.TIMESTAMP BETWEEN aa.StartAt AND aa.EndAt AND ps.Id = {info.PowerstationId} GROUP BY aa.Id"; + + + a = (await conn.QueryAsync(sql)).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return a; + } + } } } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 9c85142..cb40f09 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -5089,5 +5089,64 @@ namespace SolarPower.Repository.Implement } } + + public async Task> GetPowerStationsAllWithfilterForGeneration(string filter) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = @$"SELECT ps.Id AS PowerStationId , ps.`Name` AS PowerStationName,city.Name AS CityName FROM {tableName} ps + LEFT JOIN city ON city.Id = ps.CityId WHERE ps.Deleted = 0 AND SolarType = 0"; + + + if (!string.IsNullOrEmpty(filter)) + { + sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')"; + } + result = (await conn.QueryAsync(sql, new { Filter = filter })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + public async Task> GetPowerStationsByCompanyIdWithfilterForGeneration(MyUser myUser, string filter) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = $@"SELECT ps.Id AS PowerStationId , ps.`Name` AS PowerStationName,city.Name AS CityName FROM {tableName} ps + LEFT JOIN city ON city.Id = ps.CityId"; + + if (myUser.Role.Layer == 2) + { + sql += " WHERE ps.Deleted = 0 AND ps.CompanyId = @CompanyId AND SolarType = 0 "; + } + else + { + sql += @" LEFT JOIN power_station_operation_personnel op ON ps.Id = op.PowerStationId + WHERE ps.Deleted = 0 AND op.Deleted = 0 AND op.UserId = @UserId AND SolarType = 0 "; + } + + if (!string.IsNullOrEmpty(filter)) + { + sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')"; + } + result = (await conn.QueryAsync(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id, Filter = filter })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } } } diff --git a/SolarPower/Repository/Interface/IElectricitySoldRecordRepository.cs b/SolarPower/Repository/Interface/IElectricitySoldRecordRepository.cs index 32ba0bb..89651e0 100644 --- a/SolarPower/Repository/Interface/IElectricitySoldRecordRepository.cs +++ b/SolarPower/Repository/Interface/IElectricitySoldRecordRepository.cs @@ -10,5 +10,7 @@ namespace SolarPower.Repository.Interface { Task> RecordTable(ElectricitySoldRecordTablePost post); Task GetBill(int id); + Task> GetGenerationList(SearchGeneration info); } + } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 8b519bc..763e574 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -587,8 +587,9 @@ namespace SolarPower.Repository.Interface Task AddAfterPurgeSensorAvgHistory(string startDate, string endDate, byte type, List entity, List properties); Task CheckShowMoney(int userid); Task> GetAllInverterRowData(string date, string table_name); - Task> GetAllInverterInfo(List post, string site_table, string site_db); Task GetInverterInfoModal(int Id, string Time, string DB, string Table); + Task> GetPowerStationsAllWithfilterForGeneration(string filter); + Task> GetPowerStationsByCompanyIdWithfilterForGeneration(MyUser myUser, string filter); } } diff --git a/SolarPower/Views/PowerGeneration/Index.cshtml b/SolarPower/Views/PowerGeneration/Index.cshtml index e0ec9d1..806efda 100644 --- a/SolarPower/Views/PowerGeneration/Index.cshtml +++ b/SolarPower/Views/PowerGeneration/Index.cshtml @@ -188,7 +188,7 @@
- +
@@ -202,13 +202,18 @@
- -
-
- + +
+ +
+
+ +
+
+
+
- @@ -229,13 +234,13 @@ 平均發電度數小計
(/kW) - 發電效能 + 建置容量(kW) 總發電量(度數) - 總售電收入(NT$) - 總發電量(度數) - 總售電收入(NT$) - 總發電量(度數) - 總售電收入(NT$) + 售電單價(NT$/度) + 建置容量(kW) + 售電單價(NT$/度) + 建置容量(kW) + 售電單價(NT$/度) CBA 監控系統 v.s CBA @@ -243,7 +248,7 @@ v.s CBA - + @@ -264,7 +269,7 @@ 平均發電度數明細
(/kW/日) - + @@ -278,27 +283,46 @@ @section Scripts{ } \ No newline at end of file diff --git a/SolarPower/Views/PowerStation/_StationInfo.cshtml b/SolarPower/Views/PowerStation/_StationInfo.cshtml index b0ba183..d72790b 100644 --- a/SolarPower/Views/PowerStation/_StationInfo.cshtml +++ b/SolarPower/Views/PowerStation/_StationInfo.cshtml @@ -156,7 +156,7 @@
diff --git a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml index 864e69e..04b0b12 100644 --- a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml +++ b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml @@ -55,6 +55,14 @@ + @if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("StationOverview_Inverter")) + { + + } @if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("StationOverview_History")) { @@ -65,14 +73,7 @@ } - @if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("StationOverview_Inverter")) - { - - } + @if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("StationOverview_Exception")) { @@ -113,6 +114,13 @@ @Html.Partial("_InverterInfo")
+ @if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("StationOverview_Inverter")) + { +
+ @Html.Partial("_Inverter") +
+ } + @if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("StationOverview_History")) {
@@ -121,13 +129,6 @@ } - @if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("StationOverview_Inverter")) - { -
- @Html.Partial("_Inverter") -
- } - @if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("StationOverview_Exception")) {
@@ -2607,8 +2608,45 @@ } $("#Invertercard-type").html(TypeName); var time = new Date(rel.data.createdAt); - $("#Invertercard-date").html(time.getMonth() + "/" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes()) - $("#Invertercard").find('.card-img-top').attr('src', "../upload/power_station/" + rel.data.id + "/" + rel.data.mainDisplay); + $("#Invertercard-date").html(time.getMonth() + "/" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes()); + + + var urlPath = "../upload/power_station/" + rel.data.id + "/" + rel.data.mainDisplay; + var xmlhttp; + if (window.XMLHttpRequest) { + xmlhttp = new XMLHttpRequest();//其他浏览器 + } + else if (window.ActiveXObject) { + try { + xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");//旧版IE + } + catch (e) { } + try { + xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//新版IE + } + catch (e) { } + if (!xmlhttp) { + window.alert("不能创建XMLHttpRequest对象"); + } + } + + + xmlhttp.open("GET", urlPath, false); + xmlhttp.send(); + var roadtourl; + if (xmlhttp.readyState == 4) { + if (xmlhttp.status == 200) { + roadtourl = "../upload/power_station/" + rel.data.id + "/" + rel.data.mainDisplay; + } //url存在 + else if (xmlhttp.status == 404) { + roadtourl = "../img/blank.gif"; + } //url不存在 + else { + roadtourl = ""; + }//其他狀態 + } + + $("#Invertercard").find('.card-img-top').attr('src', roadtourl); $('#Invertercard-Temp').html(rel.data.todayWeatherTemp + '°C'); $('#Invertercard-weathericon').attr("class", 'fal fa-' + rel.data.todayWeather + ' fa-2x'); stationDB = rel.data.siteDB; diff --git a/SolarPower/Views/StationOverview/_Info.cshtml b/SolarPower/Views/StationOverview/_Info.cshtml index a024541..d8133c8 100644 --- a/SolarPower/Views/StationOverview/_Info.cshtml +++ b/SolarPower/Views/StationOverview/_Info.cshtml @@ -127,7 +127,7 @@
diff --git a/solarApp/Service/getSensorSvc.cs b/solarApp/Service/getSensorSvc.cs index 94a2e34..1be0d83 100644 --- a/solarApp/Service/getSensorSvc.cs +++ b/solarApp/Service/getSensorSvc.cs @@ -151,9 +151,17 @@ namespace solarApp.Service using (MySqlConnection conn = new MySqlConnection(Connection1)) { conn.Open(); - string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg + //string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg + // from sensor_history_day a join power_station b on a.PowerStationId = b.id + // where left(`TIMESTAMP`, 10) between '" + date1 + "' and '"+date2+"' and b.`code` = @siteID"; + string sql = @"select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg, c.count from sensor_history_day a join power_station b on a.PowerStationId = b.id - where left(`TIMESTAMP`, 10) between '" + date1 + "' and '"+date2+"' and b.`code` = @siteID"; + join ( + select PowerStationId, left(a.`TIMESTAMP`, 10) reportDate, count(*) count from sensor_history_hour a join power_station b on a.PowerStationId = b.id + where b.`code` = @siteID and left(`TIMESTAMP`, 10) between '" + date1 + "' and '" + date2 + @"' + group by PowerStationId, left(a.`TIMESTAMP`, 10) + )c on a.PowerStationId = c.PowerStationId and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = c.reportDate + where left(a.`TIMESTAMP`, 10) between '" + date1 + "' and '" + date2 + @"' and b.`code` = @siteID"; List ds = conn.Query(sql, new { siteID = siteID }).AsList(); conn.Close(); return ds; diff --git a/solarApp/fmMain.Designer.cs b/solarApp/fmMain.Designer.cs index 24a81cb..7f67405 100644 --- a/solarApp/fmMain.Designer.cs +++ b/solarApp/fmMain.Designer.cs @@ -1409,6 +1409,7 @@ namespace solarApp this.gv_web_sensor_day.RowTemplate.Height = 25; this.gv_web_sensor_day.Size = new System.Drawing.Size(666, 253); this.gv_web_sensor_day.TabIndex = 4; + this.gv_web_sensor_day.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.gv_web_sensor_day_CellFormatting); // // panel12 // @@ -1649,7 +1650,7 @@ namespace solarApp this.Controls.Add(this.tabControl1); this.Name = "fmMain"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "太陽能電站數據檢核 V0729"; + this.Text = "太陽能電站數據檢核 V0817"; this.Load += new System.EventHandler(this.fmMain_Load); this.tabControl1.ResumeLayout(false); this.tb_inv.ResumeLayout(false); diff --git a/solarApp/fmMain.cs b/solarApp/fmMain.cs index 71c2245..9dc3d64 100644 --- a/solarApp/fmMain.cs +++ b/solarApp/fmMain.cs @@ -267,5 +267,16 @@ namespace solarApp } } } + + private void gv_web_sensor_day_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) + { + if (gv_web_sensor_day.Rows[e.RowIndex].Cells["count"].Value != null && !string.IsNullOrWhiteSpace(gv_web_sensor_day.Rows[e.RowIndex].Cells["count"].Value.ToString())) + { + if (gv_web_sensor_day.Rows[e.RowIndex].Cells["count"].Value.ToString() != "24") + { + gv_web_sensor_day.Rows[e.RowIndex].Cells["count"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White }; + } + } + } } }