優化每日結算 累計日照 SQL 語法
This commit is contained in:
parent
d306aeb7af
commit
782ddaf512
@ -2706,8 +2706,10 @@ namespace SolarPower.Repository.Implement
|
|||||||
|
|
||||||
foreach (var device in deviceInfos)
|
foreach (var device in deviceInfos)
|
||||||
{
|
{
|
||||||
var str = @$"SELECT DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/ 1000), '%Y-%m-%d %H') AS TIMESTAMP, s.SITEID, CASE WHEN AVG(CASE WHEN s.{device.ColName} != 0 THEN s.{device.ColName} END) IS NOT NULL THEN AVG(CASE WHEN s.{device.ColName} != 0 THEN s.{device.ColName} END)
|
var str = @$"SELECT DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/ 1000), '%Y-%m-%d %H') AS TIMESTAMP, s.SITEID,
|
||||||
ELSE 0 END AS SENSOR
|
CASE WHEN AVG(CASE WHEN s.{device.ColName} != 0 THEN s.{device.ColName} END) IS NOT NULL
|
||||||
|
THEN AVG(CASE WHEN s.{device.ColName} != 0 THEN s.{device.ColName} END)
|
||||||
|
ELSE 0 END AS SENSOR
|
||||||
FROM {device.DBName}.{device.TableName} s
|
FROM {device.DBName}.{device.TableName} s
|
||||||
WHERE DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/ 1000), '%Y-%m-%d %H') = @DateTime
|
WHERE DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/ 1000), '%Y-%m-%d %H') = @DateTime
|
||||||
GROUP BY DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/ 1000), '%Y-%m-%d %H')";
|
GROUP BY DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/ 1000), '%Y-%m-%d %H')";
|
||||||
|
|||||||
@ -96,8 +96,8 @@ namespace SolarPower
|
|||||||
#region ¥[¤JI´º°õ¦æ
|
#region ¥[¤JI´º°õ¦æ
|
||||||
//services.AddHostedService<OperationScheduleBackgroundService>();
|
//services.AddHostedService<OperationScheduleBackgroundService>();
|
||||||
//if (envName == "Production")
|
//if (envName == "Production")
|
||||||
if (envName == "Production")
|
//if (envName != "Production")
|
||||||
{
|
//{
|
||||||
////²K¥[QuartzªA°È
|
////²K¥[QuartzªA°È
|
||||||
services.AddSingleton<IJobFactory, SingletonJobFactory>();
|
services.AddSingleton<IJobFactory, SingletonJobFactory>();
|
||||||
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
|
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
|
||||||
@ -147,7 +147,7 @@ namespace SolarPower
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
services.AddHostedService<QuartzHostedService>();
|
services.AddHostedService<QuartzHostedService>();
|
||||||
}
|
//}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
services.AddApplicationInsightsTelemetry();
|
services.AddApplicationInsightsTelemetry();
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
// "Password": "y4uPqlH9ncTgR/I07qpwaA=="
|
// "Password": "y4uPqlH9ncTgR/I07qpwaA=="
|
||||||
//},
|
//},
|
||||||
"BackgroundServiceCron": {
|
"BackgroundServiceCron": {
|
||||||
"CalcPowerStationJob": "0 5 * * * ?",
|
"CalcPowerStationJob": "0 14 * * * ?",
|
||||||
"CalcAvgPowerStationJob": "0 12 0 * * ?",
|
"CalcAvgPowerStationJob": "0 12 0 * * ?",
|
||||||
"OperationScheduleJob": "0 0 8 * * ?",
|
"OperationScheduleJob": "0 0 8 * * ?",
|
||||||
"CalcInverter15minJob": "0 2/15 * * * ?",
|
"CalcInverter15minJob": "0 2/15 * * * ?",
|
||||||
|
|||||||
@ -35,7 +35,7 @@
|
|||||||
"Password": "8WMHBEWuT0XoAB4kzduQHA=="
|
"Password": "8WMHBEWuT0XoAB4kzduQHA=="
|
||||||
},
|
},
|
||||||
"BackgroundServiceCron": {
|
"BackgroundServiceCron": {
|
||||||
"CalcPowerStationJob": "0 5 * * * ?",
|
"CalcPowerStationJob": "0 14 * * * ?",
|
||||||
"CalcAvgPowerStationJob": "0 12 0 * * ?",
|
"CalcAvgPowerStationJob": "0 12 0 * * ?",
|
||||||
"OperationScheduleJob": "0 0 8 * * ?",
|
"OperationScheduleJob": "0 0 8 * * ?",
|
||||||
"CalcInverter15minJob": "0 2/15 * * * ?",
|
"CalcInverter15minJob": "0 2/15 * * * ?",
|
||||||
|
|||||||
@ -288,14 +288,23 @@ namespace solarApp.Service
|
|||||||
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd);
|
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd);
|
||||||
|
|
||||||
// irrDayHour計算
|
// irrDayHour計算
|
||||||
sql = $@"update sensor_history_hour a join (
|
//sql = $@"update sensor_history_hour a join (
|
||||||
select LEFT(DATE_ADD(`TIMESTAMP`, INTERVAL +1 hour), 13) hour_1, irrday
|
// select LEFT(DATE_ADD(`TIMESTAMP`, INTERVAL +1 hour), 13) hour_1, irrday
|
||||||
from sensor_history_hour a
|
// from sensor_history_hour a
|
||||||
where powerstationID = {_powerStationID} and LEFT(a.TIMESTAMP, 10 ) = '{_date1}'
|
// where powerstationID = {_powerStationID} and LEFT(a.TIMESTAMP, 10 ) = '{_date1}'
|
||||||
|
|
||||||
)b on LEFT(a.`TIMESTAMP`, 13) = hour_1
|
// )b on LEFT(a.`TIMESTAMP`, 13) = hour_1
|
||||||
Set irrDayhour = case when a.`irrday` - b.`irrday` < 0 then 0 else a.`irrday` - b.`irrday` end
|
// Set irrDayhour = case when a.`irrday` - b.`irrday` < 0 then 0 else a.`irrday` - b.`irrday` end
|
||||||
where a.powerstationID = {_powerStationID}";
|
// where a.powerstationID = {_powerStationID}";
|
||||||
|
sql = $@"DROP TEMPORARY TABLE IF EXISTS `temp_s1`;
|
||||||
|
create TEMPORARY TABLE temp_s1
|
||||||
|
select `TIMESTAMP`, irrday
|
||||||
|
from sensor_history_hour a
|
||||||
|
where powerstationID = {_powerStationID} and LEFT(a.TIMESTAMP, 10 ) = '{_date1}';
|
||||||
|
|
||||||
|
update sensor_history_hour a join temp_s1 b on LEFT(a.`TIMESTAMP`, 13) = LEFT(b.`TIMESTAMP`, 13)
|
||||||
|
Set irrDayhour = case when a.`irrday` - b.`irrday` < 0 then 0 else a.`irrday` - b.`irrday` end
|
||||||
|
where LEFT(a.TIMESTAMP, 10 ) = '{_date1}' and a.powerstationID = {_powerStationID}";
|
||||||
|
|
||||||
dt_start2 = DateTime.Now;
|
dt_start2 = DateTime.Now;
|
||||||
cmd.CommandText = sql;
|
cmd.CommandText = sql;
|
||||||
@ -610,7 +619,10 @@ namespace solarApp.Service
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 當天-前一小時 累計日照相減值
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
bool update_invdayhour()
|
bool update_invdayhour()
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|||||||
@ -57,6 +57,7 @@ namespace solarApp
|
|||||||
|
|
||||||
private void fmArchive_Load(object sender, EventArgs e)
|
private void fmArchive_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
MessageBox.Show(" loading ");
|
||||||
#region 電站清單
|
#region 電站清單
|
||||||
int i = 0;
|
int i = 0;
|
||||||
var site_list = stationSvc.get_station_list();
|
var site_list = stationSvc.get_station_list();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user