Merge branch 'Willy'

This commit is contained in:
b110212000 2021-07-20 20:07:15 +08:00
commit 6bed833e3e
5 changed files with 254 additions and 40 deletions

View File

@ -2602,5 +2602,61 @@ namespace SolarPower.Controllers
return apiResult; return apiResult;
} }
[HttpPost]
public async Task<ApiResult<List<PowerStationImage>>> GetAllPowerStationsALLImage(List<int> powerStationId)
{
ApiResult<List<PowerStationImage>> apiResult = new ApiResult<List<PowerStationImage>>();
List<PowerStationImage> powerStationImages = null;
List<PowerStationImage> ALLpowerStationImages = new List<PowerStationImage>();
try
{
foreach(var ones in powerStationId)
{
var powerStation = await powerStationRepository.GetOneAsync(ones);
if (powerStation == null)
{
apiResult.Code = "9992";
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
else
{
if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId)
{
apiResult.Code = "9993";
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
powerStationImages = await powerStationRepository.GetAllPowerStationImageAsync(ones, powerStation.SiteDB);
foreach (var stationImage in powerStationImages)
{
stationImage.Image = Path.Combine(stationImageFilePath, powerStation.Id.ToString()) + "/" + stationImage.Image;
}
ALLpowerStationImages = ALLpowerStationImages.Concat(powerStationImages).ToList();
}
}
apiResult.Code = "0000";
apiResult.Data = ALLpowerStationImages;
}
catch (Exception exception)
{
apiResult.Code = "9999";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "PowerStationId=" + powerStationId);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
} }
} }

View File

@ -22,5 +22,6 @@ namespace SolarPower.Models
{ {
public List<int> StationIds { get; set; } public List<int> StationIds { get; set; }
public string Timerange { get; set; } public string Timerange { get; set; }
public int SeacrhType { get; set; }
} }
} }

View File

@ -27,15 +27,113 @@ namespace SolarPower.Repository.Implement
{ {
try try
{ {
string sql = @"SELECT AVG(KWHKWP),TOTALMONEY,TOTALKWH,TOTALCARBON,PR"; string sql = "";
switch(post.SeacrhType)
{
case 0:
string timerange = Convert.ToDateTime(post.Timerange).ToString("yyyy-MM-dd");
sql = $@"SELECT m.*,n.* FROM
(
SELECT AVG(KWHKWP) AS All_KWH_KWP ,SUM(TOTALMONEY) AS All_money,
SUM(TOTALKWH) AS All_kwh,SUM(TOTALCARBON) AS All_Carbon,
AVG(PR) AS All_PR
from power_station_history_month
WHERE PowerStationId IN @ids
)
AS m,
(
SELECT
SUM(b.TODAYKWH) AS Now_kwh,
SUM(b.TODAYMONEY) AS Now_money,
AVG(b.KWHKWP) AS Now_KWH_KWP ,
AVG(b.PR) AS Now_PR,
SUM(b.TODAYCARBON) AS Now_Carbon
FROM (SELECT MAX(a.`TIMESTAMP`) AS maxTIMESTAMP FROM
(SELECT * FROM power_station_history_hour hr WHERE DATE_FORMAT(hr.`TIMESTAMP`,'%Y-%m-%d') = '{timerange}') a ) c
LEFT JOIN
(SELECT * FROM power_station_history_hour hr WHERE DATE_FORMAT(hr.`TIMESTAMP`,'%Y-%m-%d') = '{timerange}' ) b
ON c.maxTIMESTAMP = b.`TIMESTAMP`
WHERE PowerStationId IN @ids
)
AS n";
break;
case 1:
var time = post.Timerange.Split('-');
sql = $@"SELECT m.*,n.* FROM
(
SELECT AVG(KWHKWP) AS All_KWH_KWP, SUM(TOTALMONEY) AS All_money,
SUM(TOTALKWH) AS All_kwh, SUM(TOTALCARBON) AS All_Carbon,
AVG(PR) AS All_PR
from power_station_history_month
WHERE PowerStationId IN @ids
)
AS m,
(
SELECT
SUM(b.TODAYKWH) AS Now_kwh,
SUM(b.MONEY) AS Now_money,
AVG(b.KWHKWP) AS Now_KWH_KWP,
AVG(b.PR) AS Now_PR,
SUM(b.CARBON) AS Now_Carbon
FROM power_station_history_day b
WHERE PowerStationId IN @ids AND TIMESTAMP BETWEEN '{time[0]}' AND '{time[1]}'
)
AS n";
break;
case 2:
sql = $@"SELECT m.*,n.* FROM
(
SELECT
AVG(KWHKWP) AS All_KWH_KWP,
SUM(TOTALMONEY) AS All_money,
SUM(TOTALKWH) AS All_kwh,
SUM(TOTALCARBON) AS All_Carbon,
AVG(PR) AS All_PR
from power_station_history_month
WHERE PowerStationId IN @ids
)
AS m,
(
SELECT
SUM(b.TODAYKWH) AS Now_kwh,
SUM(b.MONEY) AS Now_money,
AVG(b.KWHKWP) AS Now_KWH_KWP,
AVG(b.PR) AS Now_PR,
SUM(b.CARBON) AS Now_Carbon
FROM power_station_history_day b
WHERE PowerStationId IN @ids AND DATE_FORMAT(TIMESTAMP, '%Y-%m') = '{post.Timerange}'
)
AS n";
break;
case 3:
sql = $@"SELECT m.*,n.* FROM
(
SELECT AVG(KWHKWP) AS All_KWH_KWP, SUM(TOTALMONEY) AS All_money,
SUM(TOTALKWH) AS All_kwh, SUM(TOTALCARBON) AS All_Carbon,
AVG(PR) AS All_PR
from power_station_history_month
WHERE PowerStationId IN @ids
)
AS m,
(
SELECT
a = await conn.QueryFirstOrDefaultAsync<AnalysisStationCombine>(sql); SUM(b.MONTHKWH) AS Now_kwh,
SUM(b.MONEY) AS Now_money,
AVG(b.KWHKWP) AS Now_KWH_KWP,
AVG(b.PR) AS Now_PR,
SUM(b.CARBON) AS Now_Carbon
FROM power_station_history_month b
WHERE PowerStationId IN @ids AND DATE_FORMAT(TIMESTAMP, '%Y') = '{post.Timerange}'
)
AS n";
break;
}
trans.Commit(); a = await conn.QueryFirstOrDefaultAsync<AnalysisStationCombine>(sql,new { ids = post.StationIds});
} }
catch (Exception exception) catch (Exception exception)
{ {
trans.Rollback();
throw exception; throw exception;
} }
finally finally

View File

@ -78,28 +78,29 @@
<div class="frame-wrap"> <div class="frame-wrap">
<div class="row mb-5"> <div class="row mb-5">
<div class="card-columns"> <div class="card-columns">
<div class="card"> <div class="card">
<div class="card-header bg-fusion-25 pr-3 d-flex align-items-center flex-wrap"> <div class="card-header bg-fusion-25 pr-3 d-flex align-items-center flex-wrap">
<h4 class="mb-0 font-weight-bold"><span class="fal fa-bolt mr-1"></span> 發電量</h4> <h4 class="mb-0 font-weight-bold"><span class="fal fa-bolt mr-1"></span> 發電量</h4>
<div class="ml-auto">kwh</div> <div class="ml-auto">kwh</div>
</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" id="today_kwh">126,161.72</span></p> <p><span class="color-info-700" id="total_kwh">126,161.72</span></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" id="total_kwh">4,069.73</span></p> <p><span class="color-info-700" id="today_kwh">4,069.73</span></p>
</div> </div>
</div> </div>
</div> </div>
<div class="card money-card"> <div class="card">
<div class="card-header bg-fusion-25 pr-3 d-flex align-items-center flex-wrap"> <div class="card-header bg-fusion-25 pr-3 d-flex align-items-center flex-wrap">
<h4 class="mb-0 font-weight-bold"><span class="fal fa-dollar-sign mr-1"></span> <span id="money-card-title">發電金額</span></h4> <h4 class="mb-0 font-weight-bold"><span class="fal fa-dollar-sign mr-1"></span> <span id="money-card-title">發電金額</span></h4>
<div class="ml-auto">NTD</div> <div class="ml-auto">NTD</div>
</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 id="money-card-subtitle-total">總發金額</p> <p id="money-card-subtitle-total">總發金額</p>
<p><span class="color-info-700" id="total_money">126,161.72</span></p> <p><span class="color-info-700" id="total_money">126,161.72</span></p>
@ -110,6 +111,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="card"> <div class="card">
<div class="card-header bg-fusion-25 pr-3 d-flex align-items-center flex-wrap"> <div class="card-header bg-fusion-25 pr-3 d-flex align-items-center flex-wrap">
<h4 class="mb-0 font-weight-bold"><span class="fal fa-sun mr-1"></span> kWh / kWp</h4> <h4 class="mb-0 font-weight-bold"><span class="fal fa-sun mr-1"></span> kWh / kWp</h4>
@ -117,11 +119,11 @@
<div class="card-body"> <div class="card-body">
<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" id="today_kwhkwp">140.39</span></p> <p><span class="color-info-700" id="total_kwhkwp">140.39</span></p>
</div> </div>
<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" id="avg_kwhkwp">4.53</span></p> <p><span class="color-info-700" id="today_kwhkwp">4.53</span></p>
</div> </div>
</div> </div>
</div> </div>
@ -129,14 +131,14 @@
<div class="card-header bg-fusion-25 pr-3 d-flex align-items-center flex-wrap"> <div class="card-header bg-fusion-25 pr-3 d-flex align-items-center flex-wrap">
<h4 class="mb-0 font-weight-bold"><span class="fal fa-bolt mr-1"></span> PR值</h4> <h4 class="mb-0 font-weight-bold"><span class="fal fa-bolt mr-1"></span> PR值</h4>
</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>平均 PR 值</p> <p>平均 PR 值</p>
<p><span class="color-info-700" id="today_PR">119.04</span></p> <p><span class="color-info-700" id="total_PR">119.04</span></p>
</div> </div>
<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" id="avg_PR">3.84</span></p> <p><span class="color-info-700" id="today_PR">3.84</span></p>
</div> </div>
</div> </div>
</div> </div>
@ -146,14 +148,14 @@
<h4 class="mb-0 font-weight-bold"><span class="fal fa-cow mr-1"></span> 減碳量</h4> <h4 class="mb-0 font-weight-bold"><span class="fal fa-cow mr-1"></span> 減碳量</h4>
<div class="ml-auto">kG</div> <div class="ml-auto">kG</div>
</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" id="today_carbon">6,091.78</span></p> <p><span class="color-info-700" id="total_carbon">6,091.78</span></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" id="total_carbon">985.98</span></p> <p><span class="color-info-700" id="today_carbon">985.98</span></p>
</div> </div>
</div> </div>
</div> </div>
@ -277,20 +279,11 @@
powerids.push(String(val.id)); powerids.push(String(val.id));
Allpowerids.push(String(val.id)); Allpowerids.push(String(val.id));
}); });
//GetStationsCard(); GetStationsCard();
//modal 電站 下拉式選單 photoshow();
//$("#power_station_select_modal").empty();
//$.each(rel.data, function (index, val) {
// $("#power_station_select_modal").append($("<option />").val(val.id).text(val.name));
//});
//預設查詢第一個
//$("#power_station_select_modal").val($("#power_station_select_modal option:first").val()).trigger('change');
}) })
}) })
//#endregion //#endregion
}) })
@ -344,21 +337,21 @@
document.getElementById("DateGettextdiv").style.display = "";//隱藏 document.getElementById("DateGettextdiv").style.display = "";//隱藏
document.getElementById("DateGet").style.display = "none";//隱藏 document.getElementById("DateGet").style.display = "none";//隱藏
//#endregion //#endregion
$('#DateGettext').val(dateLimit_format + ' - ' + today_format); $('#DateGettext').val(dateLimit_format + ' - ' + today_format).trigger('change');
break; break;
case 2: $('#DateGet').prop({ 'type': 'month' }); case 2: $('#DateGet').prop({ 'type': 'month' });
$(".btn-change-quickSearch1").html("本月"); $(".btn-change-quickSearch1").html("本月");
$(".btn-change-quickSearch2").html("上個月"); $(".btn-change-quickSearch2").html("上個月");
var now_month = new Date().toISOString().substring(0, 7); var now_month = new Date().toISOString().substring(0, 7);
$('#DateGet').val(now_month); $('#DateGet').val(now_month).trigger('change');
break; break;
case 3: case 3:
$(".btn-change-quickSearch1").html("今年"); $(".btn-change-quickSearch1").html("今年");
$(".btn-change-quickSearch2").html("去年"); $(".btn-change-quickSearch2").html("去年");
var now_year = new Date().toISOString().substring(0, 4); var now_year = new Date().toISOString().substring(0, 4);
$('#DateGet').prop({ 'type': 'number', 'min': 1900, 'max': now_year, 'step': 1 }); $('#DateGet').prop({ 'type': 'number', 'min': 1900, 'max': now_year, 'step': 1 });
$('#DateGet').val(now_year); $('#DateGet').val(now_year).trigger('change');
break; break;
} }
if (type == 2) { if (type == 2) {
@ -379,9 +372,11 @@
if (day == 0) { if (day == 0) {
var today = new Date().toISOString().substring(0, 10); var today = new Date().toISOString().substring(0, 10);
$('#DateGet').val(today); $('#DateGet').val(today);
$('#testwww').html('123');
} else { } else {
var dateLimit = new Date(new Date().setDate(new Date().getDate() - 1)).toISOString().substring(0, 10); var dateLimit = new Date(new Date().setDate(new Date().getDate() - 1)).toISOString().substring(0, 10);
$('#DateGet').val(dateLimit); $('#DateGet').val(dateLimit);
$('#testwww').html('456');
} }
break; break;
case 1: case 1:
@ -394,9 +389,9 @@
datepicker.data('daterangepicker').setStartDate(dateLimit_format); datepicker.data('daterangepicker').setStartDate(dateLimit_format);
datepicker.data('daterangepicker').setEndDate(today_format); datepicker.data('daterangepicker').setEndDate(today_format);
//#endregion //#endregion
$('#DateGettext').val(dateLimit_format + ' - ' + today_format); $('#DateGettext').val(dateLimit_format + ' - ' + today_format).trigger('change');
} else { } else {
//#region 預設近7 //#region 預設近30
var today = new Date(); var today = new Date();
var dateLimit = new Date(new Date().setDate(today.getDate() - 30)); var dateLimit = new Date(new Date().setDate(today.getDate() - 30));
var today_format = today.toISOString().slice(0, 10).replace(/-/g, "/"); var today_format = today.toISOString().slice(0, 10).replace(/-/g, "/");
@ -404,46 +399,54 @@
datepicker.data('daterangepicker').setStartDate(dateLimit_format); datepicker.data('daterangepicker').setStartDate(dateLimit_format);
datepicker.data('daterangepicker').setEndDate(today_format); datepicker.data('daterangepicker').setEndDate(today_format);
//#endregion //#endregion
$('#DateGettext').val(dateLimit_format + ' - ' + today_format); $('#DateGettext').val(dateLimit_format + ' - ' + today_format).trigger('change');
} }
break; break;
case 2: case 2:
if (day == 0) { if (day == 0) {
var now_month = new Date().toISOString().substring(0, 7); var now_month = new Date().toISOString().substring(0, 7);
$('#DateGet').val(now_month); $('#DateGet').val(now_month).trigger('change');
} else { } else {
var dateLimit = new Date(new Date().setMonth(new Date().getMonth() - 1)).toISOString().substring(0, 7); var dateLimit = new Date(new Date().setMonth(new Date().getMonth() - 1)).toISOString().substring(0, 7);
$('#DateGet').val(dateLimit); $('#DateGet').val(dateLimit).trigger('change');
} }
break; break;
case 3: case 3:
if (day == 0) { if (day == 0) {
var now_year = new Date().toISOString().substring(0, 4); var now_year = new Date().toISOString().substring(0, 4);
$('#DateGet').val(now_year); $('#DateGet').val(now_year).trigger('change');
} else { } else {
var dateLimit = new Date(new Date().setFullYear(new Date().getFullYear() - 1)).toISOString().substring(0, 4); var dateLimit = new Date(new Date().setFullYear(new Date().getFullYear() - 1)).toISOString().substring(0, 4);
$('#DateGet').val(dateLimit); $('#DateGet').val(dateLimit).trigger('change');
} }
break; break;
} }
} }
//#endregion //#endregion
//#region 更換input
$('#DateGet').on('change', function () { $('#DateGet').on('change', function () {
timerange = $('#DateGet').val(); timerange = $('#DateGet').val();
console.log('a');
GetStationsCard(); GetStationsCard();
}); });
//#endregion
//#region 更換inputtext
$('#DateGettext').on('change', function () { $('#DateGettext').on('change', function () {
timerange = $('#DateGettext').val(); timerange = $('#DateGettext').val();
console.log('b');
GetStationsCard(); GetStationsCard();
}); });
//#endregion
//#region 5張卡片值
function GetStationsCard() function GetStationsCard()
{ {
var send_data = { var send_data = {
stationIds: powerids, stationIds: powerids,
timerange: timerange timerange: timerange,
seacrhType: searchType
} }
var Nurl = "/AnalysisStationCombine/GetStationsCard"; var Nurl = "/AnalysisStationCombine/GetStationsCard";
@ -452,8 +455,64 @@
toast_error(rel.msg); toast_error(rel.msg);
return; return;
} }
$('#total_kwh').html(rel.data.all_kwh.toFixed(2));
$('#total_money').html(rel.data.all_money.toFixed(2));
$('#total_kwhkwp').html(rel.data.all_KWH_KWP.toFixed(2));
$('#total_PR').html(rel.data.all_PR.toFixed(2));
$('#total_carbon').html(rel.data.all_Carbon.toFixed(2));
$('#today_kwh').html(rel.data.now_kwh.toFixed(2));
$('#today_money').html(rel.data.now_money.toFixed(2));
$('#today_kwhkwp').html(rel.data.now_KWH_KWP.toFixed(2));
$('#today_PR').html(rel.data.now_PR.toFixed(2));
$('#today_carbon').html(rel.data.now_Carbon.toFixed(2));
}) })
} }
//#endregion
//#region 圖片輪播
function photoshow()
{
var url_image = "/PowerStation/GetAllPowerStationsALLImage";
var send_data = {
powerStationId: powerids
};
$.post(url_image, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
carouselExampleIndicators = $("#carouselExampleIndicators");
carouselExampleIndicators.find(".carousel-indicators").empty();
carouselExampleIndicators.find(".carousel-inner").empty();
rel.data.forEach(function (value, index) {
CreatePowerStationImagecarousel(carouselExampleIndicators, value, index);
});
carouselExampleIndicators.find(".carousel-indicators > li").first().addClass("active");
carouselExampleIndicators.find(".carousel-inner > .carousel-item").first().addClass("active");
}, 'json');
}
function CreatePowerStationImagecarousel(dom, value, index) {
var indicators = '<li data-target="#carouselExampleIndicators" data-slide-to="' + index + '"></li>'
var carousel_item = '<div class="carousel-item">' +
'<img class="d-block w-100" src="' + value.image + '">' +
'</div>'
dom.find(".carousel-indicators").append(indicators);
dom.find(".carousel-inner").append(carousel_item);
}
//#endregion
</script> </script>
} }

View File

@ -226,7 +226,7 @@
}, 'json'); }, 'json');
//#region 載入電站圖片 //#region 載入電站圖片
var url_image = "/PowerStation/GetAllPowerStationImage"; var url_image = "/PowerStation/GetAllPowerStationsALLImage";
var send_data = { var send_data = {
powerStationId: stationId powerStationId: stationId
}; };