優化每日結算 累計日照 SQL 語法

This commit is contained in:
cesar liu 2022-08-07 16:31:04 +08:00
parent d306aeb7af
commit 782ddaf512
6 changed files with 31 additions and 16 deletions

View File

@ -2706,8 +2706,10 @@ namespace SolarPower.Repository.Implement
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)
ELSE 0 END AS SENSOR
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)
ELSE 0 END AS SENSOR
FROM {device.DBName}.{device.TableName} s
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')";

View File

@ -96,8 +96,8 @@ namespace SolarPower
#region ¥[¤J­I´º°õ¦æ
//services.AddHostedService<OperationScheduleBackgroundService>();
//if (envName == "Production")
if (envName == "Production")
{
//if (envName != "Production")
//{
////²K¥[QuartzªA°È
services.AddSingleton<IJobFactory, SingletonJobFactory>();
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
@ -147,7 +147,7 @@ namespace SolarPower
//#endregion
services.AddHostedService<QuartzHostedService>();
}
//}
#endregion
services.AddApplicationInsightsTelemetry();

View File

@ -33,7 +33,7 @@
// "Password": "y4uPqlH9ncTgR/I07qpwaA=="
//},
"BackgroundServiceCron": {
"CalcPowerStationJob": "0 5 * * * ?",
"CalcPowerStationJob": "0 14 * * * ?",
"CalcAvgPowerStationJob": "0 12 0 * * ?",
"OperationScheduleJob": "0 0 8 * * ?",
"CalcInverter15minJob": "0 2/15 * * * ?",

View File

@ -35,7 +35,7 @@
"Password": "8WMHBEWuT0XoAB4kzduQHA=="
},
"BackgroundServiceCron": {
"CalcPowerStationJob": "0 5 * * * ?",
"CalcPowerStationJob": "0 14 * * * ?",
"CalcAvgPowerStationJob": "0 12 0 * * ?",
"OperationScheduleJob": "0 0 8 * * ?",
"CalcInverter15minJob": "0 2/15 * * * ?",

View File

@ -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);
// irrDayHour計算
sql = $@"update sensor_history_hour a join (
select LEFT(DATE_ADD(`TIMESTAMP`, INTERVAL +1 hour), 13) hour_1, irrday
from sensor_history_hour a
where powerstationID = {_powerStationID} and LEFT(a.TIMESTAMP, 10 ) = '{_date1}'
)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
where a.powerstationID = {_powerStationID}";
//sql = $@"update sensor_history_hour a join (
// select LEFT(DATE_ADD(`TIMESTAMP`, INTERVAL +1 hour), 13) hour_1, irrday
// from sensor_history_hour a
// where powerstationID = {_powerStationID} and LEFT(a.TIMESTAMP, 10 ) = '{_date1}'
// )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
// 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;
cmd.CommandText = sql;
@ -610,7 +619,10 @@ namespace solarApp.Service
return result;
}
/// <summary>
/// 當天-前一小時 累計日照相減值
/// </summary>
/// <returns></returns>
bool update_invdayhour()
{
bool result = false;

View File

@ -57,6 +57,7 @@ namespace solarApp
private void fmArchive_Load(object sender, EventArgs e)
{
MessageBox.Show(" loading ");
#region
int i = 0;
var site_list = stationSvc.get_station_list();