From 74998e73c28f21bdd55a0d49800f0591a7a2e7a6 Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 11 Aug 2021 15:47:18 +0800 Subject: [PATCH 1/3] 1. bug fix --- SolarPower/Repository/Implement/OverviewRepository.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SolarPower/Repository/Implement/OverviewRepository.cs b/SolarPower/Repository/Implement/OverviewRepository.cs index d9ecd60..2b34507 100644 --- a/SolarPower/Repository/Implement/OverviewRepository.cs +++ b/SolarPower/Repository/Implement/OverviewRepository.cs @@ -608,7 +608,7 @@ namespace SolarPower.Repository.Implement , (DENSE_RANK() OVER(ORDER BY C.TIMESTAMP)) - 1 AS PreROWID, C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance,P.Temperature AS Temp FROM {usedb} C - LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}') + LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}') AND P.PowerStationId = C.PowerStationId WHERE C.PowerStationId = {post.PowerstationId}{range2} GROUP BY C.TIMESTAMP ORDER BY C.TIMESTAMP ) A RIGHT OUTER JOIN @@ -617,7 +617,7 @@ namespace SolarPower.Repository.Implement , (DENSE_RANK() OVER(ORDER BY C.TIMESTAMP)) - 1 AS PreROWID, C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance,P.Temperature AS Temp FROM {usedb} C - LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}') + LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}') AND P.PowerStationId = C.PowerStationId WHERE C.PowerStationId = {post.PowerstationId}{range2} GROUP BY C.TIMESTAMP ORDER BY C.TIMESTAMP ) B ON A.ROWID = B.PreROWID From f39b7460ba15eda69295455d21851d340fa751cd Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 11 Aug 2021 18:27:43 +0800 Subject: [PATCH 2/3] 1. bug fix --- .../Controllers/PowerStationController.cs | 32 ++++ .../Implement/PowerStationRepository.cs | 32 ++++ .../Interface/IPowerStationRepository.cs | 8 + SolarPower/Views/MapOverview/Index.cshtml | 2 +- .../PowerStation/PowerStationEdit.cshtml | 177 +++++++----------- 5 files changed, 143 insertions(+), 108 deletions(-) diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index ac02bae..b017a3e 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using SolarPower.Models; +using SolarPower.Models.Company; using SolarPower.Models.PowerStation; using SolarPower.Models.User; using SolarPower.Repository.Interface; @@ -124,6 +125,37 @@ namespace SolarPower.Controllers return apiResult; } + [HttpGet] + public async Task>> GetCompanySelectOptionListAsync() + { + ApiResult> apiResult = new ApiResult>(); + + try + { + var companySelectItemLists = new List(); + + if (!IsPlatformLayer(myUser.Role.Layer)) + { + companySelectItemLists = await powerStationRepository.GetCompanySelectOptionListAsync(myUser.CompanyId); + } + else + { + companySelectItemLists = await powerStationRepository.GetCompanySelectOptionListAsync(0); + } + + apiResult.Code = "0000"; + apiResult.Data = companySelectItemLists; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + /// /// 取裝置類型下拉選單 /// diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 72bde0f..63d8644 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using System.Text.Json; using SolarPower.Models; using SolarPower.Models.Role; +using SolarPower.Models.Company; namespace SolarPower.Repository.Implement { @@ -54,6 +55,8 @@ namespace SolarPower.Repository.Implement sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')"; } + sql += " ORDER BY c.Priority"; + var myPowerStationInfos = conn.Query(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id, Filter = filter }).ToList(); var myPowerStationInfos_group = myPowerStationInfos.GroupBy(x => x.CityId); @@ -132,6 +135,35 @@ namespace SolarPower.Repository.Implement } } + /// + /// 取得下拉式公司選單,須為Deleted: 0 + /// + /// + /// + public async Task> GetCompanySelectOptionListAsync(int companyId = 0) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = $"SELECT Id AS Value, CONCAT(Name, '/', SiteDB) AS Text FROM company WHERE Deleted = 0"; + + if (companyId > 0) + { + sql += " AND Id = @SelectedCompanyId"; + } + + result = (await conn.QueryAsync(sql, new { SelectedCompanyId = companyId })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + /// /// 透過編號取得,縣市資訊 /// diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 10156af..fa85721 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -1,4 +1,5 @@ using SolarPower.Models; +using SolarPower.Models.Company; using SolarPower.Models.PowerStation; using SolarPower.Models.User; using System; @@ -34,6 +35,13 @@ namespace SolarPower.Repository.Interface Task> GetOperationPersonnelSelectOptionListAsync(int powerStationId); + /// + /// 取得下拉式公司選單,須為Deleted: 0、Status: 1 + /// + /// + /// + Task> GetCompanySelectOptionListAsync(int companyId); + /// /// 透過編號取得,縣市資訊 /// diff --git a/SolarPower/Views/MapOverview/Index.cshtml b/SolarPower/Views/MapOverview/Index.cshtml index 9ca1ebf..789fb5d 100644 --- a/SolarPower/Views/MapOverview/Index.cshtml +++ b/SolarPower/Views/MapOverview/Index.cshtml @@ -243,7 +243,7 @@ $("#today_carbon").html(mapOverview.today_carbon.toFixed(2)); $("#total_carbon").html(mapOverview.total_carbon.toFixed(2)); $("#total_power_station_count").html(mapOverview.totalPowerStationCount); - $("#total_capacity").html(mapOverview.totalCapacity); + $("#total_capacity").html(mapOverview.totalCapacity.toFixed(2)); $("#update_at").html(mapOverview.updatedAt); capacityTable.clear().rows.add(mapOverview.capacityDataTables).draw(); diff --git a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml index e009f6a..21888d5 100644 --- a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml +++ b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml @@ -100,7 +100,7 @@ stationId = url.searchParams.get('stationId'); //#region 預先載入公司下拉式選單select_option - var url_company_select_option = "/Company/GetCompanySelectOptionList"; + var url_company_select_option = "/PowerStation/GetCompanySelectOptionList"; $.get(url_company_select_option, function (rel) { if (rel.code != "0000") { toast_error(rel.msg); @@ -972,118 +972,31 @@ @if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformUser) { - Swal.fire( - { - title: "", - text: "你確定是否要將該電站加入至【" + ps_company_text + "】?", - type: "question", - icon: 'question', - showCancelButton: true, - confirmButtonText: "是", - cancelButtonText: "否" - }).then(function (result) { - if (result.value) { - var url = "/PowerStation/SavePowerStationInfo"; - var send_data = { - Id: stationId, - CityId: $("#select_city").val(), - AreaId: $("#select_area").val(), - Address: $("#address_detail").val(), - Name: $("#power_station_name").val(), - IsEscrow: $('#check_escrow').is(':checked') ? 1 : 0, - ElectricityMeterAt: $("#electricity_meter_at").val(), - EstimatedRecoveryTime: $("#estimated_recovery_time").val(), - GeneratingCapacity: $("#generating_capacity").val(), - EscrowName: $('#check_escrow').is(':checked') ? $("#escrow_name").val() : "", - PowerRate: $("#power_rate").val(), - Coordinate: $("#coordinate").val(), - OperationPersonnelIds: $("#power_station_operation_personnel").val(), - InverterBrand: $("#inverter_brand").val(), - InverterProductModel: $("#inverter_product_model").val(), - InverterAmount: $("#inverter_amount").val(), - PhotovoltaicPanelBrand: $("#photovoltaic_panel_brand").val(), - PhotovoltaicPanelSpecification: $("#photovoltaic_panel_specification").val(), - PhotovoltaicPanelAmount: $("#photovoltaic_panel_amount").val(), - PhotovoltaicPanelProductModel: $("#photovoltaic_panel_product_model").val(), - SolarType: $("#select_solar_tpye").val(), - line_token: $("#line_token").val(), - Estimate_kwh: $("#estimate_kwh").val(), - EstimateEfficacy: $("#estimate_efficacy").val(), - CompanyId: $("#select_power_station_company").val(), - } - - $.post(url, send_data, function (rel) { - if (rel.code != "0000") { - toast_error(rel.msg); - return; - } - - toast_ok(rel.msg); - - if (stationId == "new") { - window.location = "/PowerStation/Edit?stationId=" + rel.data.id - } else { - //回填資料 - powerStationData = rel.data; - SetStationInfo(); - ChangeMode("station_info", "view"); - } - }, 'json'); - } - }); + if (stationId == 'new') { + Swal.fire( + { + title: "", + text: "你確定是否要將該電站加入至【" + ps_company_text + "】?", + type: "question", + icon: 'question', + showCancelButton: true, + confirmButtonText: "是", + cancelButtonText: "否" + }).then(function (result) { + if (result.value) { + PostPowerStationDate(); + } + }); + } else { + PostPowerStationDate(); + } } else { - var url = "/PowerStation/SavePowerStationInfo"; - - var send_data = { - Id: stationId, - CityId: $("#select_city").val(), - AreaId: $("#select_area").val(), - Address: $("#address_detail").val(), - Name: $("#power_station_name").val(), - IsEscrow: $('#check_escrow').is(':checked') ? 1 : 0, - ElectricityMeterAt: $("#electricity_meter_at").val(), - EstimatedRecoveryTime: $("#estimated_recovery_time").val(), - GeneratingCapacity: $("#generating_capacity").val(), - EscrowName: $('#check_escrow').is(':checked') ? $("#escrow_name").val() : "", - PowerRate: $("#power_rate").val(), - Coordinate: $("#coordinate").val(), - OperationPersonnelIds: $("#power_station_operation_personnel").val(), - InverterBrand: $("#inverter_brand").val(), - InverterProductModel: $("#inverter_product_model").val(), - InverterAmount: $("#inverter_amount").val(), - PhotovoltaicPanelBrand: $("#photovoltaic_panel_brand").val(), - PhotovoltaicPanelSpecification: $("#photovoltaic_panel_specification").val(), - PhotovoltaicPanelAmount: $("#photovoltaic_panel_amount").val(), - PhotovoltaicPanelProductModel: $("#photovoltaic_panel_product_model").val(), - SolarType: $("#select_solar_tpye").val(), - line_token: $("#line_token").val(), - Estimate_kwh: $("#estimate_kwh").val(), - EstimateEfficacy: $("#estimate_efficacy").val(), - CompanyId: $("#select_power_station_company").val(), - } - - $.post(url, send_data, function (rel) { - if (rel.code != "0000") { - toast_error(rel.msg); - return; - } - - toast_ok(rel.msg); - - if (stationId == "new") { - window.location = "/PowerStation/Edit?stationId=" + rel.data.id - } else { - //回填資料 - powerStationData = rel.data; - SetStationInfo(); - ChangeMode("station_info", "view"); - } - }, 'json'); + PostPowerStationDate(); } @@ -1091,6 +1004,56 @@ } //#endregion + function PostPowerStationDate() { + var url = "/PowerStation/SavePowerStationInfo"; + + var send_data = { + Id: stationId, + CityId: $("#select_city").val(), + AreaId: $("#select_area").val(), + Address: $("#address_detail").val(), + Name: $("#power_station_name").val(), + IsEscrow: $('#check_escrow').is(':checked') ? 1 : 0, + ElectricityMeterAt: $("#electricity_meter_at").val(), + EstimatedRecoveryTime: $("#estimated_recovery_time").val(), + GeneratingCapacity: $("#generating_capacity").val(), + EscrowName: $('#check_escrow').is(':checked') ? $("#escrow_name").val() : "", + PowerRate: $("#power_rate").val(), + Coordinate: $("#coordinate").val(), + OperationPersonnelIds: $("#power_station_operation_personnel").val(), + InverterBrand: $("#inverter_brand").val(), + InverterProductModel: $("#inverter_product_model").val(), + InverterAmount: $("#inverter_amount").val(), + PhotovoltaicPanelBrand: $("#photovoltaic_panel_brand").val(), + PhotovoltaicPanelSpecification: $("#photovoltaic_panel_specification").val(), + PhotovoltaicPanelAmount: $("#photovoltaic_panel_amount").val(), + PhotovoltaicPanelProductModel: $("#photovoltaic_panel_product_model").val(), + SolarType: $("#select_solar_tpye").val(), + line_token: $("#line_token").val(), + Estimate_kwh: $("#estimate_kwh").val(), + EstimateEfficacy: $("#estimate_efficacy").val(), + CompanyId: $("#select_power_station_company").val(), + } + + $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + toast_ok(rel.msg); + + if (stationId == "new") { + window.location = "/PowerStation/Edit?stationId=" + rel.data.id + } else { + //回填資料 + powerStationData = rel.data; + SetStationInfo(); + ChangeMode("station_info", "view"); + } + }, 'json'); + } + //#region 儲存能源局台電資料資訊 function SaveBoETPCInfo() { var url = "/PowerStation/SaveBoETPCInfo"; From 866b47cd438a7e0dc91ef316dccb9e9bfa14bdfe Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 11 Aug 2021 18:39:01 +0800 Subject: [PATCH 3/3] =?UTF-8?q?1.=E8=83=8C=E6=99=AF=E5=9F=B7=E8=A1=8C=20bu?= =?UTF-8?q?g=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index a042ccd..73ebb94 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -363,7 +363,7 @@ namespace SolarPower.Quartz.Jobs calcPowerStation.TodayWeatherTemp = Convert.ToDouble(Location.WeatherElement[0].ElementValue); weatherObservation.PowerStationId = powerStation.Id; weatherObservation.Temp = Convert.ToDouble(Location.WeatherElement[0].ElementValue); - weatherObservation.ObsTime = Convert.ToInt32(Location.Time.ObsTime.Substring(0, 4)) < 1970 ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : Location.Time.ObsTime; + weatherObservation.ObsTime = !string.IsNullOrEmpty(Location.Time.ObsTime)? Convert.ToInt32(Location.Time.ObsTime.Substring(0, 4)) >= 1971 ? Location.Time.ObsTime : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); calcPowerStation.WeathersStationId = powerStation.WeathersStationId; break; }