歷史(無柱狀圖及溫度)

This commit is contained in:
b110212000 2021-07-10 19:40:55 +08:00
parent 6d6ddf6a98
commit 2236bc9717
8 changed files with 277 additions and 27 deletions

View File

@ -358,5 +358,48 @@ namespace SolarPower.Controllers
return result; return result;
} }
public async Task<ApiResult<List<HistoryTable>>> GetTotalTableToHistory(HistorySent post)
{
var History = new List<HistoryTable>();
ApiResult<List<HistoryTable>> apiResult = new ApiResult<List<HistoryTable>>();
var powerStation = await powerStationRepository.GetOneAsync(post.PowerstationId);
try
{
History = await overviewRepository.GethistoryTable(post);
foreach(var a in History)
{
switch (post.GroupType)
{
case 0:
a.TOTALTIME = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy-MM-dd");
a.TIMESTAMP = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy-MM-dd hh:mm:ss");
break;
case 1:
a.TOTALTIME = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy-MM");
a.TIMESTAMP = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy-MM-dd");
break;
case 2:
a.TOTALTIME = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy");
a.TIMESTAMP = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy-MM");
break;
case 3:
a.TOTALTIME = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy");
a.TIMESTAMP = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy");
break;
}
}
apiResult.Code = "0000";
apiResult.Data = History;
}
catch (Exception exception)
{
apiResult.Code = "9999";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + post);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
} }
} }

View File

@ -125,5 +125,22 @@ namespace SolarPower.Models
public double Value { get; set; } public double Value { get; set; }
} }
public class HistorySent
{
public int GroupType { get; set; }
public string HistoryRange { get; set; }
public int PowerstationId { get; set; }
}
public class HistoryTable
{
public string TIMESTAMP { get; set; }
public double KWH { get; set; }
public double SOLARHOUR { get; set; }
public double Irradiance { get; set; }
public double PR { get; set; }
public double Temp { get; set; }
public double DiffSOLARHOUR { get; set; }
public string TOTALTIME { get; set; }
}
} }

View File

@ -110,12 +110,12 @@ namespace SolarPower.Quartz.Jobs
pyrheliometerHistoryDays.Add(pyrheliometerHistorDay); pyrheliometerHistoryDays.Add(pyrheliometerHistorDay);
} }
//逆變器 ////逆變器
var inverterHistorDay = await powerStationRepository.CalcPyrheliometerHistoryDayDataByPowerStationId(dateNowDay, powerStation.Id); //var inverterHistorDay = await powerStationRepository.CalcPyrheliometerHistoryDayDataByPowerStationId(dateNowDay, powerStation.Id);
if (inverterHistorDay != null) //if (inverterHistorDay != null)
{ //{
inverterHistorDays.Add(inverterHistorDay); // inverterHistorDays.Add(inverterHistorDay);
} //}
#endregion #endregion
#region step2-4. #region step2-4.

View File

@ -378,5 +378,81 @@ namespace SolarPower.Repository.Implement
} }
} }
public async Task<List<HistoryTable>> GethistoryTable(HistorySent post)
{
List<HistoryTable> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
var kwh = "";
var usedb = "";
var pyrdb = "";
var timeGroup = "";
var range = "";
switch(post.GroupType)
{
case 0:
kwh = "C.KWH";
usedb = "power_station_history_hour";
pyrdb = "pyrheliometer_history_hour";
timeGroup = "%Y-%m-%d %H:%M:%S";
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y-%m-%d') = '{post.HistoryRange}'";
break;
case 1:
kwh = "C.TODAYKWH";
usedb = "power_station_history_day";
pyrdb = "pyrheliometer_history_day";
timeGroup = "%Y-%m-%d";
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y-%m') = '{post.HistoryRange}'";
break;
case 2:
kwh = "C.MONTHKWH";
usedb = "power_station_history_month";
pyrdb = "pyrheliometer_history_month";
timeGroup = "%Y-%m";
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y') = '{post.HistoryRange}'";
break;
case 3:
kwh = "C.TOTALKWH";
usedb = "power_station_history_month";
pyrdb = "pyrheliometer_history_month";
timeGroup = "%Y-%m";
range = "";
break;
}
try
{
var sql = @$"SELECT *, SOLARHOUR-PSValue AS DiffSOLARHOUR
FROM
(
SELECT B.*, IFNULL(A.SOLARHOUR,0) AS PSValue
FROM
(
SELECT DENSE_RANK() OVER(ORDER BY C.TIMESTAMP) AS ROWID
, (DENSE_RANK() OVER(ORDER BY C.TIMESTAMP)) - 1 AS PreROWID,
C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance
FROM {usedb} C
LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}') WHERE C.PowerStationId = {post.PowerstationId} GROUP BY C.TIMESTAMP
) A
RIGHT OUTER JOIN
(
SELECT DENSE_RANK() OVER(ORDER BY C.TIMESTAMP) AS ROWID
, (DENSE_RANK() OVER(ORDER BY C.TIMESTAMP)) - 1 AS PreROWID,
C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance
FROM {usedb} C
LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}') WHERE C.PowerStationId = {post.PowerstationId} GROUP BY C.TIMESTAMP
) B
ON A.ROWID = B.PreROWID
) V {range}" ;
result = (await conn.QueryAsync<HistoryTable>(sql)).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
} }
} }

View File

@ -2203,6 +2203,32 @@ namespace SolarPower.Repository.Implement
return result; return result;
} }
} }
public async Task<List<DeviceInfo>> GetListTempByPowerStationId(int powerStationId, string db_name)
{
List<DeviceInfo> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $@"SELECT *
FROM {db_name}.device d
WHERE d.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0
UNION
SELECT d.*
FROM {db_name}.sharedevice sd
LEFT JOIN {db_name}.device d ON sd.DeviceId = d.Id
WHERE sd.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0
";
result = (await conn.QueryAsync<DeviceInfo>(sql, new { PowerStationId = powerStationId })).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task<PyrheliometerHistory> GetPyrheliometerHistoryPerHour(string dateTime, List<DeviceInfo> deviceInfos) public async Task<PyrheliometerHistory> GetPyrheliometerHistoryPerHour(string dateTime, List<DeviceInfo> deviceInfos)
{ {

View File

@ -22,7 +22,7 @@ namespace SolarPower.Repository.Interface
Task<List<PowerIrradiance>> GetListPowerIrradianceYearByPowerStationId(int powerStationId, string nowDay); Task<List<PowerIrradiance>> GetListPowerIrradianceYearByPowerStationId(int powerStationId, string nowDay);
Task<List<ExceptionDataTable>> GetExceptionTable(ExceptionSent post); Task<List<ExceptionDataTable>> GetExceptionTable(ExceptionSent post);
Task<List<CheckBox>> GetInvertCheckBoxByPowerStationId(int powerStationId, string db_name); Task<List<CheckBox>> GetInvertCheckBoxByPowerStationId(int powerStationId, string db_name);
Task<List<InverterHistory>> GetListInverterByPowerStationIdAndDate(int powerStationId, string nowDay); Task<List<InverterHistory>> GetListInverterByPowerStationIdAndDate(int powerStationId, string nowDay);
Task<List<HistoryTable>> GethistoryTable(HistorySent post);
} }
} }

View File

@ -742,7 +742,6 @@
}, 'json'); }, 'json');
//#endregion //#endregion
//#endregion //#endregion
});
//#region 維修單運維人員(異常紀錄) //#region 維修單運維人員(異常紀錄)
var url_power_station_operation_personnel = "/PowerStation/GetOperationPersonnelSelectOptionList"; var url_power_station_operation_personnel = "/PowerStation/GetOperationPersonnelSelectOptionList";
@ -844,9 +843,12 @@
}); });
//#endregion //#endregion
//歷史第一個table
getTable();
}); });
//#region 產生檔案html //#region 產生檔案html
function CreateRecodeFileBox(dom, value, show_del_btn) { function CreateRecodeFileBox(dom, value, show_del_btn) {
var str = ""; var str = "";
@ -1765,7 +1767,7 @@
document.getElementById("DateGet").style.display = "";//隱藏 document.getElementById("DateGet").style.display = "";//隱藏
document.getElementById("MonthGet").style.display = "none";//隱藏 document.getElementById("MonthGet").style.display = "none";//隱藏
document.getElementById("YearGet").style.display = "none";//隱藏 document.getElementById("YearGet").style.display = "none";//隱藏
$('#DateGet').val('');
groupType = type; groupType = type;
break; break;
case 1: case 1:
@ -1776,6 +1778,7 @@
document.getElementById("DateGet").style.display = "none";//隱藏 document.getElementById("DateGet").style.display = "none";//隱藏
document.getElementById("MonthGet").style.display = "";//隱藏 document.getElementById("MonthGet").style.display = "";//隱藏
document.getElementById("YearGet").style.display = "none";//隱藏 document.getElementById("YearGet").style.display = "none";//隱藏
$('#MonthGet').val('');
groupType = type; groupType = type;
break; break;
case 2: case 2:
@ -1786,6 +1789,7 @@
document.getElementById("DateGet").style.display = "none";//隱藏 document.getElementById("DateGet").style.display = "none";//隱藏
document.getElementById("MonthGet").style.display = "none";//隱藏 document.getElementById("MonthGet").style.display = "none";//隱藏
document.getElementById("YearGet").style.display = "";//隱藏 document.getElementById("YearGet").style.display = "";//隱藏
$('#YearGet').val('');
groupType = type; groupType = type;
break; break;
case 3: case 3:
@ -1797,6 +1801,8 @@
document.getElementById("MonthGet").style.display = "none";//隱藏 document.getElementById("MonthGet").style.display = "none";//隱藏
document.getElementById("YearGet").style.display = "none";//隱藏 document.getElementById("YearGet").style.display = "none";//隱藏
groupType = type; groupType = type;
historyRange = '';
getTable();
break; break;
default: default:
console.log('壞掉了'); console.log('壞掉了');
@ -1860,10 +1866,86 @@
} }
//#endregion //#endregion
$('#DateGet').on('change', function () {
historyRange = $('#DateGet').val();
getTable();
});
$('#MonthGet').on('change', function () {
historyRange = $('#MonthGet').val();
getTable();
});
$('#YearGet').on('change', function () {
$('#YearGet').val(today_format);
getTable();
});
function getTable() function getTable()
{ {
console.log(groupType); if (historyRange == "")
console.log(historyRange); {
var today = new Date();
var today_format = today.toISOString().slice(0, 10).replace(/-/g, "-");
$('#DateGet').val(today_format);
historyRange = $('#DateGet').val();
}
var send_data = {
GroupType: groupType,
HistoryRange: historyRange,
PowerstationId: stationId
}
var Nurl = "/StationOverview/GetTotalTableToHistory";
$.post(Nurl, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$('#HistoryTotalTable').empty();
$('#HistoryDetailTable').empty();
var TimestampALL;
var kwhALL = 0;
var diffSOLARHOURALL = 0;
var irradianceALL = 0;
var prALL;
var tempALL;
$.each(rel.data, function (index, val) {
TimestampALL = val.totaltime;
kwhALL += val.kwh;
diffSOLARHOURALL += val.diffSOLARHOUR;
irradianceALL += val.irradiance;
prALL = val.pr;
tempALL = val.temp;
if (val.length != 0) {
$('#HistoryDetailTable').append('<tr>' +
'<td>' + val.timestamp + '</td>' +
'<td>' + val.kwh + '</td>' +
'<td>' + val.diffSOLARHOUR + '</td>' +
'<td>' + val.irradiance + '</td>' +
'<td>' + val.pr + '</td>' +
'<td>' + val.temp + '</td>' +
'</tr>');
}
})
if (rel.data.length == 0) {
$('#HistoryTotalTable').append('<tr>' + '<td colspan="6" style="text-align:center;">' + '無資料' + '</td>' + '</tr>');
$('#HistoryDetailTable').append('<tr>' + '<td colspan="6" style="text-align:center;">' + '無資料' + '</td>' + '</tr>');
}
else
{
$('#HistoryTotalTable').append('<tr>' +
'<td>' + TimestampALL + '</td>' +
'<td>' + kwhALL + '</td>' +
'<td>' + diffSOLARHOURALL + '</td>' +
'<td>' + irradianceALL + '</td>' +
'<td>' + prALL + '</td>' +
'<td>' + tempALL + '</td>' +
'</tr>');
}
})
} }

View File

@ -59,20 +59,13 @@
<th>時間</th> <th>時間</th>
<th>發電量(kWh)</th> <th>發電量(kWh)</th>
<th>發電小時</th> <th>發電小時</th>
<th>日射量(kWh/m2)</th> <th>日照度(kWh/m2)</th>
<th>PR(%)</th> <th>PR(%)</th>
<th>溫度(℃)</th> <th>溫度(℃)</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody id="HistoryTotalTable">
<tr>
<th scope="row">2021-05</th>
<td>126,121.7</td>
<td>119.04</td>
<td>140.39</td>
<td>84.8</td>
<td>91.9</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -80,8 +73,21 @@
<div class="row mb-5"> <div class="row mb-5">
<div class="card p-3 w-100"> <div class="card p-3 w-100">
<div class="row mb-5 d-flex justify-content-end"> <h5 class="font-weight-bold mb-3 pl-5 pb-3">詳細資訊</h5>
</div> <table class="table m-0">
<p>放圖表</p> <thead>
<tr>
<th>時間</th>
<th>發電量(kWh)</th>
<th>發電小時</th>
<th>日照度(kWh/m2)</th>
<th>PR(%)</th>
<th>溫度(℃)</th>
</tr>
</thead>
<tbody id="HistoryDetailTable">
</tbody>
</table>
</div> </div>
</div> </div>