新增電站總覽內頁

This commit is contained in:
b110212000 2021-07-07 19:03:18 +08:00
parent d821b5ff71
commit 6ac8172465
12 changed files with 299 additions and 36 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SolarPower.Models; using SolarPower.Models;
using SolarPower.Models.PowerStation; using SolarPower.Models.PowerStation;
using SolarPower.Repository.Interface; using SolarPower.Repository.Interface;
@ -24,11 +25,16 @@ namespace SolarPower.Controllers
{ {
return View(); return View();
} }
public IActionResult Info()
{
return View("~/Views/StationOverview/StationOverviewInfo.cshtml");
}
/// <summary> /// <summary>
/// 取得該使用者可看的所有電站分佈縣市以及各縣市電站數量 /// 取得該使用者可看的所有電站分佈縣市以及各縣市電站數量
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost]
public async Task<ApiResult<List<PowerStation>>> GetSolarByCity(UseStatusCityGetPowerStation post) public async Task<ApiResult<List<PowerStation>>> GetSolarByCity(UseStatusCityGetPowerStation post)
{ {
ApiResult<List<PowerStation>> apiResult = new ApiResult<List<PowerStation>>(); ApiResult<List<PowerStation>> apiResult = new ApiResult<List<PowerStation>>();
@ -53,5 +59,68 @@ namespace SolarPower.Controllers
return apiResult; return apiResult;
} }
[HttpPost]
public async Task<ApiResult<MapOverview>> GetStationCard(StationIds post)
{
ApiResult<MapOverview> apiResult = new ApiResult<MapOverview>();
MapOverview mapOverview = new MapOverview();
try
{
List<int> powerStationIds = new List<int>() { 1, 2, 3 };
var overview = await overviewRepository.GetOverviewByPowerStationIds(post.Ids);
mapOverview.Today_kwh = overview.Today_kwh;
mapOverview.Total_kwh = overview.Total_kwh;
mapOverview.Today_irradiance = overview.Today_irradiance;
mapOverview.Avg_irradiance = overview.Avg_irradiance;
mapOverview.Today_PR = overview.Today_PR;
mapOverview.Avg_PR = overview.Avg_PR;
mapOverview.Today_kwhkwp = overview.Today_kwhkwp;
mapOverview.Avg_kwhkwp = overview.Avg_kwhkwp;
mapOverview.Today_carbon = overview.Today_carbon;
mapOverview.Total_carbon = overview.Total_carbon;
mapOverview.CapacityDataTables = await overviewRepository.GetCapacityDataTableByPowerStationIds(post.Ids);
var totalPowerStationCount = 0;
var totalCapacity = 0.0;
foreach (var capacity in mapOverview.CapacityDataTables)
{
totalPowerStationCount += capacity.SubPowerStationCount;
totalCapacity += capacity.SubTotalCapacity;
}
mapOverview.TotalPowerStationCount = totalPowerStationCount;
mapOverview.TotalCapacity = totalCapacity;
mapOverview.PowerStations = await overviewRepository.GetListPowerStationByPowerStationIds(powerStationIds);
mapOverview.UpdatedAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
apiResult.Code = "0000";
apiResult.Data = mapOverview;
}
catch (Exception exception)
{
apiResult.Code = "9999";
Logger.LogError("【" + controllerName + "/" + actionName + "】");
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
} }
} }

View File

@ -38,8 +38,12 @@ namespace SolarPower.Models
public class UseStatusCityGetPowerStation public class UseStatusCityGetPowerStation
{ {
public List<int> CityId; //都市 public List<int> Cityid { get; set; } //都市
public List<int> Status; //狀態 public List<int> Status { get; set; } //狀態
} }
public class StationIds
{
public List<int> Ids { get; set; }
}
} }

View File

@ -120,6 +120,7 @@ namespace SolarPower.Repository.Implement
public async Task<List<PowerStation>> GetSolarByCity(MyUser User, UseStatusCityGetPowerStation post) public async Task<List<PowerStation>> GetSolarByCity(MyUser User, UseStatusCityGetPowerStation post)
{ {
using IDbConnection conn = _databaseHelper.GetConnection(); using IDbConnection conn = _databaseHelper.GetConnection();
List<PowerStation> powerstation = new List<PowerStation>(); List<PowerStation> powerstation = new List<PowerStation>();
conn.Open(); conn.Open();
@ -127,7 +128,7 @@ namespace SolarPower.Repository.Implement
try try
{ {
var ids = ""; var ids = "";
foreach (var id in post.CityId) foreach (var id in post.Cityid)
{ {
ids = ids + id + ","; ids = ids + id + ",";
} }
@ -138,19 +139,19 @@ namespace SolarPower.Repository.Implement
if (User.Role.Layer == 0 || User.Role.Layer == 1) if (User.Role.Layer == 0 || User.Role.Layer == 1)
{ {
var sql = "SELECT * FROM power_station WHERE CityId IN @IDs AND HealthStatus IN @Status"; var sql = "SELECT * FROM power_station WHERE CityId IN @IDs AND HealthStatus IN @Status";
powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = post.CityId , Status = post.Status})).ToList(); powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = post.Cityid, Status = post.Status})).ToList();
trans.Commit(); trans.Commit();
} }
else if (User.Role.Layer == 2) else if (User.Role.Layer == 2)
{ {
var sql = "SELECT * FROM power_station WHERE CityId IN @IDs AND CompanyId=@CompanyId AND HealthStatus IN @Status"; var sql = "SELECT * FROM power_station WHERE CityId IN @IDs AND CompanyId=@CompanyId AND HealthStatus IN @Status";
powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = post.CityId, CompanyId = User.CompanyId , Status = post.Status })).ToList(); powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = post.Cityid, CompanyId = User.CompanyId , Status = post.Status })).ToList();
trans.Commit(); trans.Commit();
} }
else else
{ {
var sql = "SELECT power_station.* FROM power_station LEFT JOIN power_station_operation_personnel ON power_station.Id = power_station_operation_personnel.PowerStationId WHERE CityId IN @IDs AND Userid = @UserId AND HealthStatus IN @Status"; var sql = "SELECT power_station.* FROM power_station LEFT JOIN power_station_operation_personnel ON power_station.Id = power_station_operation_personnel.PowerStationId WHERE CityId IN @IDs AND Userid = @UserId AND HealthStatus IN @Status";
powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = post.CityId, UserId = User.Id , Status = post.Status })).ToList(); powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = post.Cityid, UserId = User.Id , Status = post.Status })).ToList();
trans.Commit(); trans.Commit();
} }
} }

View File

@ -79,11 +79,11 @@
</div> </div>
<div class="card-body"> <div class="card-body">
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>減碳量</p> <p>今日減碳量</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="today_carbon">6,091.78</span> KG</p> <p><span class="color-info-700 fs-xl font-weight-bold" id="today_carbon">6,091.78</span> KG</p>
</div> </div>
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>今日減碳量</p> <p>減碳量</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="total_carbon">985.98</span> KG</p> <p><span class="color-info-700 fs-xl font-weight-bold" id="total_carbon">985.98</span> KG</p>
</div> </div>
</div> </div>

View File

@ -84,11 +84,11 @@
<div class="card-body" style="min-height: 148px;"> <div class="card-body" style="min-height: 148px;">
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>今日發電量</p> <p>今日發電量</p>
<p><span class="color-info-700">126,161.72</span> kWh</p> <p><span class="color-info-700" id="today_kwh">126,161.72</span> kWh</p>
</div> </div>
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>累積發電量</p> <p>累積發電量</p>
<p><span class="color-info-700">4,069.73</span> kWh</p> <p><span class="color-info-700" id="total_kwh">4,069.73</span> kWh</p>
</div> </div>
</div> </div>
</div> </div>
@ -99,11 +99,11 @@
<div class="card-body" style="min-height: 148px;"> <div class="card-body" style="min-height: 148px;">
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>即時平均日照度</p> <p>即時平均日照度</p>
<p><span class="color-info-700">126,161.72</span> kW/m<sup>2</sup></p> <p><span class="color-info-700" id="today_irradiance">126,161.72</span> kW/m<sup>2</sup></p>
</div> </div>
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>平均日照度(30天)</p> <p>平均日照度(30天)</p>
<p><span class="color-info-700">4,069.73</span> kW/m<sup>2</sup></p> <p><span class="color-info-700" id="avg_irradiance">4,069.73</span> kW/m<sup>2</sup></p>
</div> </div>
</div> </div>
</div> </div>
@ -114,11 +114,11 @@
<div class="card-body" style="min-height: 148px;"> <div class="card-body" style="min-height: 148px;">
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>即時平均 PR 值</p> <p>即時平均 PR 值</p>
<p><span class="color-info-700">119.04</span></p> <p><span class="color-info-700" id="today_PR">119.04</span></p>
</div> </div>
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>平均 PR 值(30天)</p> <p>平均 PR 值(30天)</p>
<p><span class="color-info-700">3.84</span></p> <p><span class="color-info-700" id="avg_PR">3.84</span></p>
</div> </div>
</div> </div>
</div> </div>
@ -129,11 +129,11 @@
<div class="card-body" style="min-height: 148px;"> <div class="card-body" style="min-height: 148px;">
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>即時平均 kWh / kWp</p> <p>即時平均 kWh / kWp</p>
<p><span class="color-info-700">140.39</span></p> <p><span class="color-info-700" id="today_kwhkwp">140.39</span></p>
</div> </div>
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>平均 kWh / kWp (30天)</p> <p>平均 kWh / kWp (30天)</p>
<p><span class="color-info-700">4.53</span></p> <p><span class="color-info-700" id="avg_kwhkwp">4.53</span></p>
</div> </div>
</div> </div>
</div> </div>
@ -144,11 +144,11 @@
<div class="card-body" style="min-height: 148px;"> <div class="card-body" style="min-height: 148px;">
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>今日減碳量</p> <p>今日減碳量</p>
<p><span class="color-info-700">6,091.78</span> kG</p> <p><span class="color-info-700" id="today_carbon">6,091.78</span> kG</p>
</div> </div>
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<p>累積減碳量</p> <p>累積減碳量</p>
<p><span class="color-info-700">985.98</span> kG</p> <p><span class="color-info-700" id="total_carbon">985.98</span> kG</p>
</div> </div>
</div> </div>
</div> </div>
@ -259,12 +259,21 @@
@section Scripts{ @section Scripts{
<script> <script>
var localurl = this.location.href;
var tablocation = ""; var tablocation = "";
var ids = new Array(0);//當前選擇縣市 var ids = new Array(0);//當前選擇縣市
var powerids = new Array(0);//當前選擇電站 var powerids = new Array(0);//當前選擇電站
var Allids = new Array(0);//全部縣市 var Allids = new Array(0);//全部縣市
var Allpowerids = new Array(0);//全部電站 var Allpowerids = new Array(0);//全部電站
var status = [1, 2, 3]; //#region Array.Remove
Array.prototype.remove = function (val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
//#endregion
$(function () { $(function () {
var Nurl = "/PowerStation/GetSolarCitySummary"; var Nurl = "/PowerStation/GetSolarCitySummary";
$.post(Nurl, function (rel) { $.post(Nurl, function (rel) {
@ -278,23 +287,45 @@
rel.data[i].city + rel.data[i].city +
"<span class= 'badge bg-success-700 ml-2' >" + rel.data[i].amount + "</span >" + "<span class= 'badge bg-success-700 ml-2' >" + rel.data[i].amount + "</span >" +
"</button >"); "</button >");
ids.push(String(rel.data[i].cityId)); ids.push(rel.data[i].cityId);
Allids.push(String(rel.data[i].cityId)); Allids.push(rel.data[i].cityId);
} }
//getStation(ids); getStation(ids);
}) }, 'json');
}); });
function getStation(ids)
{
var send_data = { $('#citytest').on("click", "button", function () {
cityid: ids, var clickid = $(this).attr('id');
status: status var classid = clickid.split("_");
} var Newpowerids = new Array(0);
var value = document.getElementById(clickid).className;
ids.sort(function (a, b) { ids.sort(function (a, b) {
return a - b; return a - b;
}); });
ids.sort(); if (value == 'btn btn-outline-success waves-effect waves-themed ml-2') { //選擇
document.getElementById(clickid).setAttribute("class", 'btn btn-success waves-effect waves-themed ml-2');
ids.push(Number(classid[1]));
}
else { //取消
document.getElementById(clickid).setAttribute("class", 'btn btn-outline-success waves-effect waves-themed ml-2');
ids.remove(Number(classid[1]));
}
getStation(ids);
})
function getStation(ids)
{
var status = [1,2,3];
var send_data = {
cityid: ids,
status: status,
};
//ids.sort(function (a, b) {
// return a - b;
//});
//ids.sort();
var Nurl = "/StationOverview/GetSolarByCity"; var Nurl = "/StationOverview/GetSolarByCity";
$.post(Nurl, send_data, function (rel) { $.post(Nurl, send_data, function (rel) {
if (rel.code != "0000") { if (rel.code != "0000") {
@ -308,24 +339,52 @@
$('#card_' + val.id).find('#Temp').html(val.todayWeatherTemp); $('#card_' + val.id).find('#Temp').html(val.todayWeatherTemp);
var type = ""; var type = "";
switch (val.solarType) { switch (val.solarType) {
case 0 : type = "自建躉售"; break; case 0: type = "自建躉售"; break;
case 1 : type = "租建躉售"; break; case 1: type = "租建躉售"; break;
case 2 : type = "自建自用"; break; case 2: type = "自建自用"; break;
default: default:
console.log(`Sorry, we are out of ${val.solarType}.`); console.log(`Sorry, we are out of ${val.solarType}.`);
} }
$('#card_' + val.id).find('#stationtype').html(type); $('#card_' + val.id).find('#stationtype').html(type);
var time = new Date(val.createdAt); var time = new Date(val.createdAt);
$('#card_' + val.id).find('#editSolarUrl').attr('href', localurl + '/Info?stationId=' + val.id);
$('#card_' + val.id).find('#date').html(time.getMonth() + "/" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes()); $('#card_' + val.id).find('#date').html(time.getMonth() + "/" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes());
$('#card_' + val.id).find('#Capacity').html(val.generatingCapacity); $('#card_' + val.id).find('#Capacity').html(val.generatingCapacity);
$('#card_' + val.id).find('#PowerRate').html(val.generatingCapacity * val.powerRate); $('#card_' + val.id).find('#PowerRate').html(val.generatingCapacity * val.powerRate);
$('#card_' + val.id).find('#PR').html(val.pr); $('#card_' + val.id).find('#PR').html(val.pr);
$('#card_' + val.id).find('#aria').attr('aria-valuenow', val.pr); $('#card_' + val.id).find('#aria').attr('aria-valuenow', val.pr);
$('#card_' + val.id).find('#aria').attr('style', "width:" + val.pr +"%;" ); $('#card_' + val.id).find('#aria').attr('style', "width:" + val.pr + "%;");
powerids.push(val.id);
}); });
}) GetStationCard();
}, 'json');
}
function GetStationCard()
{
var send_data = {
ids: powerids
};
var url = "/StationOverview/GetStationCard";
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
mapOverview = rel.data;
$("#today_kwh").html(mapOverview.today_kwh);
$("#total_kwh").html(mapOverview.total_kwh);
$("#today_irradiance").html(mapOverview.today_irradiance);
$("#avg_irradiance").html(mapOverview.avg_irradiance);
$("#today_PR").html(mapOverview.today_PR);
$("#avg_PR").html(mapOverview.avg_PR);
$("#today_kwhkwp").html(mapOverview.today_kwhkwp);
$("#avg_kwhkwp").html(mapOverview.avg_kwhkwp);
$("#today_carbon").html(mapOverview.today_carbon);
$("#total_power_station_count").html(mapOverview.totalPowerStationCount);
$("#total_capacity").html(mapOverview.totalCapacity);
$("#update_at").html(mapOverview.updatedAt);
});
} }

View File

@ -0,0 +1,124 @@
@{
ViewData["MainNum"] = "1";
ViewData["SubNum"] = "2";
ViewData["Title"] = "電站總覽";
}
<ol class="breadcrumb page-breadcrumb">
<li class="breadcrumb-item"><a href="javascript:void(0);">總覽</a></li>
<li class="breadcrumb-item">@ViewData["Title"]</li>
<li class="breadcrumb-item city-name">新竹市</li>
<li class="breadcrumb-item power-station-name active">新竹巨城站</li>
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
</ol>
<div class="row">
<div class="col-xl-12">
<div id="panel-5" class="panel">
<div class="panel-container show">
<div class="panel-content">
<div class="row subheader">
<div class="col-xl-2">
<h1 class="subheader-title">
<span class="icon-stack fa-1x">
<i class="base-7 icon-stack-3x color-info-500"></i>
<i class="base-7 icon-stack-2x color-info-700"></i>
<i class="ni ni-graph icon-stack-1x text-white"></i>
</span>
<span id="power-station-title">新竹巨城站</span>
</h1>
</div>
<div class="col-xl-3 d-flex justify-content-start">
<p class="card-text px-3"><i class="fal fa-cloud-sun-rain fa-3x"></i></p>
<p class="font-weight-bold">27°C<br>降雨幾率: 15%</p>
</div>
</div>
<ul class="nav nav-tabs mb-5" role="tablist">
<li class="nav-item">
<a class="nav-link fs-lg px-4 active" data-toggle="tab" href="#tab-overview-uptodate" role="tab">
<i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">即時資訊</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link fs-lg px-4" data-toggle="tab" href="#tab-overview-info" role="tab">
<i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">基本資料</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link fs-lg px-4" data-toggle="tab" href="#tab-overview-history" role="tab">
<i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">歷史資料</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link fs-lg px-4" data-toggle="tab" href="#tab-overview-inverter" role="tab">
<i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">逆變器分析</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link fs-lg px-4" data-toggle="tab" href="#tab-overview-exception" role="tab">
<i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">異常記錄</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link fs-lg px-4" data-toggle="tab" href="#tab-overview-operationRecord" role="tab">
<i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">運維記錄</span>
</a>
</li>
</ul>
<div class="tab-content p-3">
<div class="tab-pane fade show active" id="tab-overview-uptodate" role="tabpanel" aria-labelledby="tab-overview-uptodate">
@Html.Partial("_UpToDate")
</div>
<div class="tab-pane fade" id="tab-overview-info" role="tabpanel" aria-labelledby="tab-overview-info">
@Html.Partial("_Info")
</div>
<div class="tab-pane fade" id="tab-overview-history" role="tabpanel" aria-labelledby="tab-overview-history">
@Html.Partial("_History")
</div>
<div class="tab-pane fade" id="tab-overview-inverter" role="tabpanel" aria-labelledby="tab-overview-inverter">
@Html.Partial("_Inverter")
</div>
<div class="tab-pane fade" id="tab-overview-exception" role="tabpanel" aria-labelledby="tab-overview-exception">
@Html.Partial("_Exception")
</div>
<div class="tab-pane fade" id="tab-overview-operationRecord" role="tabpanel" aria-labelledby="tab-overview-operationRecord">
@Html.Partial("_OperationRecord")
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@section Scripts{
<script>
var stationId;
var powerStationData;
$(function () {
var url = new URL(location.href);
stationId = url.searchParams.get('stationId');
var url = "/PowerStation/GetOnePowerStation"
var send_data = {
id: stationId
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
powerStationData = rel.data;
$(".city-name").html(powerStationData.cityName);
$(".power-station-name").html(powerStationData.name);
$("#power-station-title").html(powerStationData.name);
}, 'json');
})
</script>
}

View File

@ -0,0 +1 @@
<p>1</p>

View File

@ -0,0 +1 @@
<p>2</p>

View File

@ -0,0 +1 @@
<p>3</p>

View File

@ -0,0 +1 @@
<p>4</p>

View File

@ -0,0 +1 @@
<p>5</p>

View File

@ -0,0 +1 @@
<p>6</p>