From ac0585055c1de1e6652910def1bff410b8b70066 Mon Sep 17 00:00:00 2001 From: cesar liu Date: Mon, 16 May 2022 12:45:44 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=84=AA=E5=8C=96=E9=A0=90=E8=A8=AD=E9=9B=BB?= =?UTF-8?q?=E7=AB=99=E8=B3=87=E8=A8=8A=20select=20table=20=E6=95=B8?= =?UTF-8?q?=E9=87=8F=202.=E6=9C=89=E6=95=88=E6=97=A5=E7=85=A7=E6=99=82?= =?UTF-8?q?=E6=95=B8=20=E6=94=B9=E7=82=BA=20=E6=97=A5=E5=9D=87=E7=99=BC?= =?UTF-8?q?=E9=9B=BB=E5=BA=A6=E6=95=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + SolarPower/Controllers/OperationController.cs | 15 ++++--- .../Controllers/PowerStationController.cs | 20 +++++---- .../Controllers/StationOverviewController.cs | 6 +-- .../Controllers/StationReportController.cs | 4 +- SolarPower/Properties/launchSettings.json | 3 +- .../Properties/serviceDependencies.json | 8 ++++ .../Properties/serviceDependencies.local.json | 10 +++++ .../Implement/PowerStationRepository.cs | 44 +++++++++++++++++++ .../Interface/IPowerStationRepository.cs | 7 +++ SolarPower/SolarPower.csproj | 8 +++- SolarPower/Startup.cs | 2 + .../Views/AnalysisStationCombine/Index.cshtml | 8 ++-- .../Views/AnalysisStationInfo/Index.cshtml | 2 +- SolarPower/Views/MapOverview/Index.cshtml | 8 ++-- SolarPower/Views/StationOverview/Index.cshtml | 6 +-- .../StationOverviewInfo.cshtml | 8 ++-- .../Views/StationOverview/_History.cshtml | 2 +- .../Views/StationOverview/_UpToDate.cshtml | 6 +-- SolarPower/Views/StationReport/Index.cshtml | 2 +- 20 files changed, 127 insertions(+), 43 deletions(-) create mode 100644 SolarPower/Properties/serviceDependencies.json create mode 100644 SolarPower/Properties/serviceDependencies.local.json diff --git a/.gitignore b/.gitignore index 3cc603f..ff54230 100644 --- a/.gitignore +++ b/.gitignore @@ -347,3 +347,4 @@ healthchecksdb /SolarPower/SolarPower.zip /SolarPower.zip /SolarPower/wwwroot/upload/report/20220227 +*.diagsession diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index 88ca4a2..9b20909 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -661,9 +661,10 @@ namespace SolarPower.Controllers if(post.Emailcheck == 1) { + var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId); if (post.WorkPersonIds != null) { - var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId); + List noticeSchedules = new List(); foreach (var person in post.WorkPersonIds) { @@ -703,7 +704,7 @@ namespace SolarPower.Controllers if (post.FixFirm != 0) { - var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId); + //var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId); var fixtype = operationRecord.WorkType switch { 0 => "清洗", @@ -711,7 +712,7 @@ namespace SolarPower.Controllers 2 => "維修", _ => "" }; - var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId); + //var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId); var firm = await operationRepository.GetOneWithCustomDBNameAndTableAsync(post.FixFirm, powerstations.SiteDB, "operation_firm"); NoticeSchedule schedule = new NoticeSchedule() { @@ -883,9 +884,9 @@ namespace SolarPower.Controllers #endregion if (post.Emailcheck == 1) { + var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId); if (post.WorkPersonIds != null) - { - var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId); + { List noticeSchedules = new List(); foreach (var person in post.WorkPersonIds) { @@ -924,7 +925,7 @@ namespace SolarPower.Controllers } if (post.FixFirm != 0) { - var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId); + //var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId); var fixtype = post.WorkType switch { 0 => "清洗", @@ -932,7 +933,7 @@ namespace SolarPower.Controllers 2 => "維修", _ => "" }; - var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId); + // var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId); var firm = await operationRepository.GetOneWithCustomDBNameAndTableAsync(post.FixFirm, powerstations.SiteDB, "operation_firm"); NoticeSchedule schedule = new NoticeSchedule() { diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 740d197..c751cc8 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -288,7 +288,8 @@ namespace SolarPower.Controllers try { - powerStation = await powerStationRepository.GetOneAsync(id); + //powerStation = await powerStationRepository.GetOneAsync(id); + powerStation = await powerStationRepository.GetStationExtraInfo(id); if (powerStation == null) { @@ -337,7 +338,7 @@ namespace SolarPower.Controllers try { - powerStation = await powerStationRepository.GetOneAsync(post.Id); + powerStation = await powerStationRepository.GetStationExtraInfo(post.Id); //取得該公司DB Name var company = await companyRepository.GetOneAsync(post.CompanyId); @@ -485,7 +486,8 @@ namespace SolarPower.Controllers apiResult.Code = "0000"; apiResult.Msg = "儲存成功"; - apiResult.Data = await powerStationRepository.GetOneAsync(id); + //apiResult.Data = await powerStationRepository.GetOneAsync(id); + apiResult.Data = await powerStationRepository.GetStationExtraInfo(id); #endregion } else @@ -610,7 +612,8 @@ namespace SolarPower.Controllers apiResult.Code = "0000"; apiResult.Msg = "儲存成功,請重新啟用電站"; - apiResult.Data = await powerStationRepository.GetOneAsync(powerStation.Id); + //apiResult.Data = await powerStationRepository.GetOneAsync(powerStation.Id); + apiResult.Data = await powerStationRepository.GetStationExtraInfo(powerStation.Id); #endregion } } @@ -734,7 +737,7 @@ namespace SolarPower.Controllers } //重新取得資料 - powerStation = await powerStationRepository.GetOneAsync(powerStation.Id); + powerStation = await powerStationRepository.GetStationExtraInfo(powerStation.Id); //替能源局換檔案路徑 if (!string.IsNullOrEmpty(powerStation.BoEFile)) @@ -835,7 +838,7 @@ namespace SolarPower.Controllers apiResult.Code = "0000"; apiResult.Msg = "儲存成功"; - apiResult.Data = await powerStationRepository.GetOneAsync(powerStation.Id); + apiResult.Data = await powerStationRepository.GetStationExtraInfo(powerStation.Id); #endregion } else @@ -871,7 +874,8 @@ namespace SolarPower.Controllers apiResult.Code = "0000"; apiResult.Msg = "修改成功"; - apiResult.Data = await powerStationRepository.GetOneAsync(powerStation.Id); + //apiResult.Data = await powerStationRepository.GetOneAsync(powerStation.Id); + apiResult.Data = await powerStationRepository.GetStationExtraInfo(powerStation.Id); #endregion } } @@ -1346,7 +1350,7 @@ namespace SolarPower.Controllers apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; - apiResult.Data = await powerStationRepository.GetOneAsync(landBuilding.PowerStationId); + apiResult.Data = await powerStationRepository.GetStationExtraInfo(landBuilding.PowerStationId); } catch (Exception exception) { diff --git a/SolarPower/Controllers/StationOverviewController.cs b/SolarPower/Controllers/StationOverviewController.cs index 4dd3419..9e308a4 100644 --- a/SolarPower/Controllers/StationOverviewController.cs +++ b/SolarPower/Controllers/StationOverviewController.cs @@ -514,7 +514,7 @@ namespace SolarPower.Controllers try { - powerStation = await powerStationRepository.GetOneAsync(post.Id); + // powerStation = await powerStationRepository.GetOneAsync(post.Id); exceptionDataTable = await overviewRepository.GetExceptionTable(post); foreach (ExceptionDataTable a in exceptionDataTable) @@ -794,8 +794,8 @@ namespace SolarPower.Controllers { var History = new List(); ApiResult> apiResult = new ApiResult>(); - var powerStation = await powerStationRepository.GetOneAsync(post.PowerstationId); - + // var powerStation = await powerStationRepository.GetOneAsync(post.PowerstationId); + //Logger.LogError("【 new add -------- " + controllerName + "/" + actionName + "】" + post); try { History = await overviewRepository.GethistoryTable(post); diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 2e19f88..0ad8c2d 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -1842,7 +1842,7 @@ namespace SolarPower.Controllers index++; cell = row.CreateCell(index); - cell.SetCellValue("有效日照時數"); + cell.SetCellValue("日均發電度數"); cell.CellStyle = styleLine12; region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); sheet.AddMergedRegion(region); @@ -2189,7 +2189,7 @@ namespace SolarPower.Controllers index++; cell = row.CreateCell(index); - cell.SetCellValue("有效日照時數"); + cell.SetCellValue("日均發電度數"); cell.CellStyle = styleLine12; region = new CellRangeAddress(RowPosition, RowPosition, index, index + 1); sheet.AddMergedRegion(region); diff --git a/SolarPower/Properties/launchSettings.json b/SolarPower/Properties/launchSettings.json index c7fa1ab..b75bf12 100644 --- a/SolarPower/Properties/launchSettings.json +++ b/SolarPower/Properties/launchSettings.json @@ -14,7 +14,8 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" - } + }, + "jsWebView2Debugging": true }, "SolarPower": { "commandName": "Project", diff --git a/SolarPower/Properties/serviceDependencies.json b/SolarPower/Properties/serviceDependencies.json new file mode 100644 index 0000000..66741d6 --- /dev/null +++ b/SolarPower/Properties/serviceDependencies.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "appInsights1": { + "type": "appInsights", + "connectionId": null + } + } +} \ No newline at end of file diff --git a/SolarPower/Properties/serviceDependencies.local.json b/SolarPower/Properties/serviceDependencies.local.json new file mode 100644 index 0000000..5b49047 --- /dev/null +++ b/SolarPower/Properties/serviceDependencies.local.json @@ -0,0 +1,10 @@ +{ + "dependencies": { + "appInsights1": { + "resourceId": null, + "type": "appInsights.sdk", + "connectionId": null, + "secretStore": null + } + } +} \ No newline at end of file diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 2bdb852..b4ca91b 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -444,6 +444,49 @@ namespace SolarPower.Repository.Implement { //base.GetOneAsync(id); + PowerStation result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + try + { + var sql = @$"SELECT ps.*, c.Name AS CityName, a.Name AS AreaName, u.Name AS CreatorName FROM {tableName} ps + LEFT JOIN user u ON ps.CreatedBy = u.Id + LEFT JOIN city c ON ps.CityId = c.Id + LEFT JOIN area a ON ps.AreaId = a.Id + WHERE ps.Deleted = 0 AND ps.Id = @Id"; + + result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); + + //if (result != null) + //{ + + // var db_name = result.SiteDB; + + // var sql_operation_personnel = @$"SELECT UserId FROM power_station_operation_personnel op WHERE Deleted = 0 AND op.PowerStationId = @PowerStationId"; + // result.OperationPersonnelIds = (await conn.QueryAsync(sql_operation_personnel, new { PowerStationId = result.Id })).ToList(); + // var sql_land_building = @$"SELECT lb.*, u.Name AS CreatorName FROM {db_name}.land_building lb + // LEFT JOIN user u ON lb.CreatedBy = u.Id + // WHERE lb.Deleted = 0 AND PowerStationId = @PowerStationId"; + // result.LandBuildings = (await conn.QueryAsync(sql_land_building, new { PowerStationId = result.Id })).ToList(); + //} + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return result; + } + } + + public async Task GetStationExtraInfo(int id) + { + //base.GetOneAsync(id); + PowerStation result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { @@ -483,6 +526,7 @@ namespace SolarPower.Repository.Implement } } + /// /// 新增電站資料至 主、子資料庫 /// diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index ba79456..0d97a40 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -516,6 +516,13 @@ namespace SolarPower.Repository.Interface /// Task> GetPowerstationPyrheliometerAsync(string db_name, int stationId); + /// + /// 取得完整電站資訊:包含維護人員及土地資訊 + /// + /// + /// + Task GetStationExtraInfo(int powerStationId); + Task> GetListPyrheliometerByPowerStationId(int powerStationId, string db_name); Task> GetListTempByPowerStationId(int powerStationId, string db_name); Task> GetDeviceListByPowerStationIdAndType(int powerStationId, string type, string db_name); diff --git a/SolarPower/SolarPower.csproj b/SolarPower/SolarPower.csproj index 406ed74..a8f00b1 100644 --- a/SolarPower/SolarPower.csproj +++ b/SolarPower/SolarPower.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 @@ -8,9 +8,13 @@ + + + + @@ -25,6 +29,7 @@ + @@ -35,7 +40,6 @@ - diff --git a/SolarPower/Startup.cs b/SolarPower/Startup.cs index 1edcb3f..6fa73b6 100644 --- a/SolarPower/Startup.cs +++ b/SolarPower/Startup.cs @@ -87,6 +87,7 @@ namespace SolarPower { options.IdleTimeout = TimeSpan.FromMinutes(loginExpireMinute); }); + services.AddApplicationInsightsTelemetry(); #region [JI //services.AddHostedService(); @@ -140,6 +141,7 @@ namespace SolarPower #endregion services.AddHostedService(); + services.AddApplicationInsightsTelemetry(); #endregion } diff --git a/SolarPower/Views/AnalysisStationCombine/Index.cshtml b/SolarPower/Views/AnalysisStationCombine/Index.cshtml index 945dcf0..eaca5c6 100644 --- a/SolarPower/Views/AnalysisStationCombine/Index.cshtml +++ b/SolarPower/Views/AnalysisStationCombine/Index.cshtml @@ -148,16 +148,16 @@
-

有效日照時數

+

日均發電度數

hr
-

當日有效日照時數

+

當日日均發電度數

0.00

-

平均有效日照時數(30天)

+

平均日均發電度數(30天)

0.00

@@ -325,7 +325,7 @@ $("#today_kwh_label").html(timename + "發電量"); $("#today_money_label").html(timename + "發電金額"); - $("#today_kwhkwp_label").html(timename + "有效日照時數"); + $("#today_kwhkwp_label").html(timename + "日均發電度數"); $("#today_PR_label").html(timename + "PR值"); $("#today_carbon_label").html(timename + "減碳量"); $("#today_irradiance_label").html(timename + "日照度"); diff --git a/SolarPower/Views/AnalysisStationInfo/Index.cshtml b/SolarPower/Views/AnalysisStationInfo/Index.cshtml index 2a4cd73..271b1f7 100644 --- a/SolarPower/Views/AnalysisStationInfo/Index.cshtml +++ b/SolarPower/Views/AnalysisStationInfo/Index.cshtml @@ -124,7 +124,7 @@ var PWS_compare_col = [ { key: "KWH", title: "發電量", default: true }, @*{ key: "Irradiance", title: "日照度", default: false },*@ - { key: "KWHKWP", title: "有效日照時數", default: false }, + { key: "KWHKWP", title: "日均發電度數", default: false }, { key: "PR", title: "PR %", default: false }, @*{ key: "Temperature", title: "模組溫度", default: false },*@ { key: "SolarHour", title: "日照小時", default: false }, diff --git a/SolarPower/Views/MapOverview/Index.cshtml b/SolarPower/Views/MapOverview/Index.cshtml index 35a9c93..c58849b 100644 --- a/SolarPower/Views/MapOverview/Index.cshtml +++ b/SolarPower/Views/MapOverview/Index.cshtml @@ -63,16 +63,16 @@
-

有效日照時數

+

日均發電度數

hr
-

今日有效日照時數(kwh/kwp)

+

今日日均發電度數(kwh/kwp)

0.00

-

平均有效日照時數 (30天)

+

平均日均發電度數 (30天)

0.00

@@ -284,7 +284,7 @@ '
' + '
今日發電量(kW h):' + item.today_kWh.toFixed(2) + '
'+ '
今日日照度(k W/m2):' + item.today_irradiance + '
'+ - '
有效日照時數(kwh/kwp):' + item.today_kwhkwp.toFixed(2) + '
' + + '
日均發電度數(kwh/kwp):' + item.today_kwhkwp.toFixed(2) + '
' + '
裝置容量(kWp):' + item.generatingCapacity.toFixed(3) + '
' + '
掛錶日期:' + item.electricityMeterAt + '
' + '
天氣:' + item.wx + '
'+ diff --git a/SolarPower/Views/StationOverview/Index.cshtml b/SolarPower/Views/StationOverview/Index.cshtml index ede6ce9..b75e1e1 100644 --- a/SolarPower/Views/StationOverview/Index.cshtml +++ b/SolarPower/Views/StationOverview/Index.cshtml @@ -121,16 +121,16 @@
-

有效日照時數

+

日均發電度數

hr
-

今日有效日照時數(kwh/kwp)

+

今日日均發電度數(kwh/kwp)

0.00

-

平均有效日照時數(30天)

+

平均日均發電度數(30天)

0.00

diff --git a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml index 047b59e..4eb45bb 100644 --- a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml +++ b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml @@ -2084,7 +2084,7 @@ }, title: { - text: '各逆變器當日有效日照時數' + text: '各逆變器當日日均發電度數' }, xAxis: { categories: HeatMap.xAxis, @@ -2421,7 +2421,9 @@ } //#endregion + console.log(" before onChange event"); $('#DateGet').on('change', function () { + console.log(" in onChange event"); historyRange = $('#DateGet').val(); getTable(); }); @@ -2646,7 +2648,7 @@ color: 'rgb(68, 114, 196)' }, { type: 'column', - name: "有效日照時數", + name: "日均發電度數", data: listkwhkwp, yAxis: "C", color: "rgb(165, 165, 165)" @@ -2702,7 +2704,7 @@ data: listpr },{ type: 'bar', - label: '有效日照時數', + label: '日均發電度數', yAxisID: 'C', backgroundColor: 'rgba(165, 165, 165)', borderWidth: 1, diff --git a/SolarPower/Views/StationOverview/_History.cshtml b/SolarPower/Views/StationOverview/_History.cshtml index 981d2df..ddead60 100644 --- a/SolarPower/Views/StationOverview/_History.cshtml +++ b/SolarPower/Views/StationOverview/_History.cshtml @@ -59,7 +59,7 @@ 時間 發電量(kWh) - 有效日照時數 + 日均發電度數 累積日照量(W/m2) PR(%) 溫度(℃) diff --git a/SolarPower/Views/StationOverview/_UpToDate.cshtml b/SolarPower/Views/StationOverview/_UpToDate.cshtml index 0002ad9..41975a6 100644 --- a/SolarPower/Views/StationOverview/_UpToDate.cshtml +++ b/SolarPower/Views/StationOverview/_UpToDate.cshtml @@ -66,16 +66,16 @@
-

有效日照時數

+

日均發電度數

hr
-

今日有效日照時數(kwh/kwp)

+

今日日均發電度數(kwh/kwp)

0.00

-

平均有效日照時數(30天)

+

平均日均發電度數(30天)

0.00

diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index 4e427b0..25458c6 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -1389,7 +1389,7 @@ TotalHead += ""; TotalHead += "" + "時間" + ""; TotalHead += "" + "發電量" + ""; - TotalHead += "" + "有效日照時數" + ""; + TotalHead += "" + "日均發電度數" + ""; TotalHead += ""; //#endregion //#region TotalBody