Merge branch 'Willy'

This commit is contained in:
b110212000 2021-08-05 15:46:44 +08:00
commit 2e36250db2
5 changed files with 205 additions and 19 deletions

View File

@ -1192,11 +1192,24 @@ namespace SolarPower.Controllers
return Path.Combine("\\" + "upload" ,"report", Datename, "FIC太陽能監控平台" + "_" + name + "報表" + "_" + postObject.Userid+ Datename + ".xlsx");
}
//public async Task<ApiResult<List<MaxFormbody>>> GetMaxForm (Select_table2 post)
//{
// return;
//}
public async Task<ApiResult<List<MaxFormbody>>> GetMaxForm(Select_table2 post)
{
ApiResult<List<MaxFormbody>> apiResult = new ApiResult<List<MaxFormbody>>();
List<MaxFormbody> body = new List<MaxFormbody>();
try
{
var a = await stationReportRepository.GetMaxtablebody(post);
apiResult.Code = "0000";
apiResult.Data = a;
}
catch (Exception exception)
{
apiResult.Code = "9999";
Logger.LogError("【" + controllerName + "/" + actionName + "】");
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
}
}

View File

@ -85,11 +85,12 @@ namespace SolarPower.Models
public string AreaName { get; set; }
public string PowerstationName { get; set; }
public int PowerstationId { get; set; }
public double Kwp { get; set; }
public double Kwh { get; set; }
public string PowerstationDB { get; set; }
public double SolarHour { get; set; }
public double AvgIrradiance { get; set; }
public double AvgPR { get; set; }
public double AvgKWHKWP { get; set; }
}

View File

@ -232,5 +232,86 @@ namespace SolarPower.Repository.Implement
return result;
}
}
public async Task<List<MaxFormbody>> GetMaxtablebody(Select_table2 post)
{
List<MaxFormbody> result = new List<MaxFormbody>();
using (IDbConnection conn = _databaseHelper.GetConnection())
{
conn.Open();
try
{
List<int> ids = new List<int>();
foreach (var i in post.PowerStation)
{
ids.Add(Convert.ToInt32(i.Value));
}
string[] times = { };
if(post.SearchType == 1)
{
times = post.Time.Replace('-', 'a').Replace('/', '-').Replace(" ", "").Split('a');
}
var wheretime = post.SearchType switch
{
0 => $"AND DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') = '{post.Time}'",
1 => $"AND DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') BETWEEN '{times[0]}' AND '{times[1]}'",
2 => $"AND DATE_FORMAT(ps.TIMESTAMP,'%Y-%m') = '{post.Time}'",
3 => $"AND DATE_FORMAT(ps.TIMESTAMP,'%Y') = '{post.Time}'",
_ => ""
};
string sql = @$"SELECT
c.Name AS 'CityName',
a.Name AS 'AreaName',
ps.Name AS 'PowerstationName',
ps.SiteDB AS 'PowerstationDB',
n.*
FROM power_station ps
LEFT JOIN city c ON c.Id = ps.CityId
LEFT JOIN area a ON a.Id = ps.AreaId
left JOIN
(
SELECT SUM(a.SolarHour) SolarHour,SUM(a.Kwh) Kwh,AVG(b.PR) AvgPR,AVG(b.KWHKWP) AvgKWHKWP,AVG(c.Irradiance) AvgIrradiance,a.PowerStationId FROM
(
SELECT Max(ps.SOLARHOUR) AS 'SolarHour',MAX(ps.TODAYKWH) 'Kwh' ,DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d ') AS 'time', ps.PowerStationId
FROM power_station_history_hour ps
WHERE ps.PowerStationId IN @ids {wheretime}
GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d')
) a
left JOIN
(
SELECT B.PR ,B.KWHKWP, DATE_FORMAT(A.bb,'%Y-%m-%d') time FROM
(
SELECT Max(ps.TIMESTAMP) AS bb FROM power_station_history_hour ps
WHERE ps.PowerStationId IN @ids {wheretime}
GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d')
) A
LEFT JOIN power_station_history_hour B ON A.bb = B.TIMESTAMP
) b
ON DATE_FORMAT(a.time,'%Y-%m-%d') = DATE_FORMAT(b.time,'%Y-%m-%d')
LEFT JOIN
(
SELECT SUM(ps.Irradiance) AS Irradiance , DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS TIME
from sensor_history_hour ps
WHERE ps.PowerStationId IN @ids {wheretime}
GROUP BY DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d')
) c
ON DATE_FORMAT(a.time,'%Y-%m-%d') = DATE_FORMAT(c.time,'%Y-%m-%d')
) n
ON n.PowerStationId = ps.Id
WHERE ps.Id IN @ids ORDER BY ps.CityId";
result = (await conn.QueryAsync<MaxFormbody>(sql,new { ids = ids})).ToList();
}
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
return result;
}
}
}
}

View File

@ -11,5 +11,6 @@ namespace SolarPower.Repository.Interface
Task<List<string>> GetInverterId(string DBname, Select_table post);
Task<dynamic> Gettablebody(Select_table post);
Task<List<Landinfo>> GetHire(PsIdAndSiteDB post);
Task<List<MaxFormbody>> GetMaxtablebody(Select_table2 post);
}
}

View File

@ -304,6 +304,7 @@
var a = $('#collapse').trigger("click");
//document.getElementById("collapse").click();
$('.overflow-auto').hide();
$('#maxtable').hide();
$('#hiretable').hide();
$('#DateGet').val(new Date().toISOString().substring(0, 10));
document.getElementById("DateGettextdiv").style.display = "none";//隱藏
@ -311,7 +312,7 @@
$('#DateGettext').attr('style', 'width:205px');
timerange = $('#DateGet').val();
document.getElementById("monthbtn").disabled = true;//月報表鎖定
document.getElementById("yearbtn").disabled = true;//綜合報表鎖定
document.getElementById("yearbtn").disabled = false;//綜合報表鎖定
document.getElementById("daybtn").disabled = false;//日報表鎖定
//#endregion
@ -336,7 +337,7 @@
var today = new Date().toISOString().substring(0, 10);
$('#DateGet').val(today);
document.getElementById("monthbtn").disabled = true;//月報表鎖定
document.getElementById("yearbtn").disabled = true;//綜合報表鎖定
document.getElementById("yearbtn").disabled = false;//綜合報表鎖定
document.getElementById("daybtn").disabled = false;//日報表鎖定
break;
case 1:
@ -505,6 +506,9 @@
$('#selectOneStation').find('.btn-station').removeClass("btn-success").addClass("btn-outline-success");
}
$(e).removeClass("btn-outline-success").addClass("btn-success");
if (nowform != null && nowform != 2) {
Dateform(nowform);
}
}
//#endregion
@ -659,16 +663,14 @@
}
$('#TableHead').empty();
var str = "<tr>";
if (form != 2) {
$.each(rel.data.inv, function (index, inverter) {
haveinvertName.push(inverter);
str += "<th>" + inverter + "</th>";
})
}
switch (form)
{
case 0:
str += "<th>Date</th>";
$.each(rel.data.inv, function (index, inverter) {
haveinvertName.push(inverter);
str += "<th>" + inverter + "</th>";
})
str += "<th>小時<br />發電量<br />(kWh)</th>";
str += "<th>小時<br />發電量<br />百分比<br />(%)</th>";
str += "<th>小時<br />平均<br />日照度<br />(W/㎡)</th>";
@ -679,6 +681,10 @@
break;
case 1:
str += "<th>Date</th>";
$.each(rel.data.inv, function (index, inverter) {
haveinvertName.push(inverter);
str += "<th>" + inverter + "</th>";
})
str += "<th>日<br />發電量<br />(kWh)</th>";
str += "<th>日<br />發電量<br />百分比<br />(%)</th>";
str += "<th>日照小時(hr)</th>";
@ -711,15 +717,12 @@
} else {
maxtableinfobody(rel.data.showMoney);
}
}, 'json');
}
function Dateform(form) {
$('#hiretable').hide();
$('#maxtable').hide();
tablehand(form);
}
@ -953,12 +956,99 @@
{
SearchType: searchType,
Time: timerange,
FormType: form,
FormType: 2,
PowerStation: selecterd_invert
}
var url = "/StationReport/GetMaxForm";
var StrInfoBody;
var CityArray = [];
var CityInfoBody;
var TotalHead;
var TotalBody;
var kwhkwp = 0;
var kwp = 0;
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_warning(rel.msg);
return;
}
//下方
$.each(rel.data, function (index, data) {
var cityinfo = {
city: data.cityName,
kwp: data.kwh,
hour: data.solarHour,
count : 1
}
if (CityArray.length == 0) {
CityArray.push(cityinfo);
}
else
{
var npush = true;
CityArray.filter(function (n, i) {
if (n.city == data.cityName) {
n.kwp += cityinfo.kwp;
n.hour += cityinfo.hour;
n.count += cityinfo.count;
npush = false;
}
});
if (npush) {
CityArray.push(cityinfo);
}
}
StrInfoBody += "<tr>";
StrInfoBody += "<td>" + data.cityName + data.areaName + "</td>";
StrInfoBody += "<td>" + data.powerstationName + "</td>";
StrInfoBody += "<td>" + data.kwh.toFixed(2) + "</td>";
StrInfoBody += "<td>" + data.solarHour.toFixed(2) + "</td>";
StrInfoBody += "<td>" + data.avgIrradiance.toFixed(2) + "</td>";
StrInfoBody += "<td>" + data.avgPR.toFixed(2) + "</td>";
StrInfoBody += "</tr>";
kwp += data.kwh;
kwhkwp += data.avgKWHKWP;
})
//中間
$.each(CityArray, function (index, data) {
CityInfoBody += "<tr>";
CityInfoBody += "<td>" + data.city + "</td>";
CityInfoBody += "<td>" + (data.kwp / data.count).toFixed(2) + "</td>";
CityInfoBody += "<td>" + (data.hour / data.count).toFixed(2) + "</td>";
CityInfoBody += "</tr>";
})
//上面
//#region TotalHead
TotalHead += "<tr>";
TotalHead += "<th>" + "時間" + "</th>";
TotalHead += "<th>" + "發電量" + "</th>";
TotalHead += "<th>" + "有效日照時數" + "</th>";
TotalHead += "</tr>";
//#endregion
//#region TotalBody
TotalBody += "<tr>";
TotalBody += "<th>" + timerange + "</th>";
TotalBody += "<th>" + kwp.toFixed(2) + "</th>";
TotalBody += "<th>" + (kwhkwp / rel.data.length).toFixed(2) + "</th>";
TotalBody += "</tr>";
//#endregion
$('#totbody').empty();
$('#totbody').append(TotalBody);
$('#tothead').empty();
$('#tothead').append(TotalHead);
$('#TableBody').empty();
$('#TableBody').append(StrInfoBody);
$('#maxtableBody').empty();
$('#maxtableBody').append(CityInfoBody);
$('#maxtable').show();
$('.overflow-auto').show();
nowform = 2;
})
}
</script>