[solarApp]修正/優化歸檔邏輯,跑報表新增區間跑報表

[solarPower]逆便器分析因應資料搬遷修改語法。電站分析優化發電量圖表及歷史資料語法。
This commit is contained in:
張家睿 2025-11-14 14:48:15 +08:00
parent b4c7bac548
commit e647e6196b
10 changed files with 348 additions and 179 deletions

View File

@ -214,9 +214,10 @@ namespace SolarPower.Repository.Implement
{ {
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp,'%H %p') AS Label, ps.KWH AS PowerData, pyr.IrrDayHour AS IrrDayHourData, pyr.Temperature AS TemperatureData var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp,'%H %p') AS Label, ps.KWH AS PowerData, pyr.IrrDayHour AS IrrDayHourData, pyr.Temperature AS TemperatureData
FROM power_station_history_hour ps FROM power_station_history_hour ps
LEFT JOIN sensor_history_hour pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d %H') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d %H') LEFT JOIN sensor_history_hour pyr ON ps.PowerStationId = pyr.PowerStationId
AND ps.TIMESTAMP = pyr.TIMESTAMP
WHERE ps.PowerStationId = @PowerStationId WHERE ps.PowerStationId = @PowerStationId
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = @NowDay AND ps.timestamp >= @NowDay AND ps.timestamp < @NowDay + INTERVAL 1 DAY
ORDER BY ps.timestamp"; ORDER BY ps.timestamp";
result = (await conn.QueryAsync<PowerIrradiance>(sql_power, new { PowerStationId = powerStationId, NowDay = nowDay })).ToList(); result = (await conn.QueryAsync<PowerIrradiance>(sql_power, new { PowerStationId = powerStationId, NowDay = nowDay })).ToList();
@ -402,7 +403,7 @@ namespace SolarPower.Repository.Implement
end = Convert.ToDateTime(post.EndTime).AddHours(-8); end = Convert.ToDateTime(post.EndTime).AddHours(-8);
var startime = (Int64)(start.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; var startime = (Int64)(start.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
var endtime = (Int64)(end.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; var endtime = (Int64)(end.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
sql += @$" AND `timestamp` BETWEEN {startime*1000} AND {endtime*1000}"; sql += @$" AND `timestamp` BETWEEN {startime * 1000} AND {endtime * 1000}";
} }
@ -681,9 +682,12 @@ select pr.FormId as FormId, pr.Id as ErrorID, a.id, site_id, ps.Id PowerStationI
{ {
string d1 = post.HistoryRange.Substring(0, 10).Replace("/", "-"); string d1 = post.HistoryRange.Substring(0, 10).Replace("/", "-");
string d2 = post.HistoryRange.Substring(13, 10).Replace("/", "-"); string d2 = post.HistoryRange.Substring(13, 10).Replace("/", "-");
DateTime startTime = Convert.ToDateTime(d1);
DateTime endTime = Convert.ToDateTime(d2).AddDays(1);
if (d1 == d2) if (d1 == d2)
{ // range 查詢同一天 { // range 查詢同一天
range2 = @$" AND DATE_FORMAT(C.`TIMESTAMP`,'%Y-%m-%d') BETWEEN '{ d1 }' AND '{ d2 }'"; range2 = @$" AND C.`TIMESTAMP` >= '{startTime}' AND C.`TIMESTAMP` < '{endTime}'";
sql = $@" SELECT C.TIMESTAMP, C.KWH AS KWH,C.SOLARHOUR, C.PR, sql = $@" SELECT C.TIMESTAMP, C.KWH AS KWH,C.SOLARHOUR, C.PR,
P.Irradiance, P.IrrDayHour, P.Temperature AS Temp , C.KWHKWP, P.IrrDay, 0 AS DiffSOLARHOUR, C.PR avgPR P.Irradiance, P.IrrDayHour, P.Temperature AS Temp , C.KWHKWP, P.IrrDay, 0 AS DiffSOLARHOUR, C.PR avgPR
FROM power_station_history_hour C FROM power_station_history_hour C
@ -693,7 +697,7 @@ select pr.FormId as FormId, pr.Id as ErrorID, a.id, site_id, ps.Id PowerStationI
else else
{ // range 查詢不同天 { // range 查詢不同天
//string endDate = DateTime.Parse(d2).AddDays(1).ToString("yyyy-MM-dd"); //string endDate = DateTime.Parse(d2).AddDays(1).ToString("yyyy-MM-dd");
range = @$" AND DATE_FORMAT(C.`TIMESTAMP`,'%Y-%m-%d') BETWEEN '{ d1 }' AND '{ d2 }'"; range = @$" AND C.`TIMESTAMP` BETWEEN '{d1}' AND '{d2}'";
//sql = $@" SELECT left(C.`TIMESTAMP`, 10) `TIMESTAMP`, C.TODAYKWH AS KWH, C.SOLARHOUR, C.PR, P.Irradiance, P.Temperature AS Temp ,C.KWHKWP, P.IrrDay, 0 AS DiffSOLARHOUR, C.PR avgPR //sql = $@" SELECT left(C.`TIMESTAMP`, 10) `TIMESTAMP`, C.TODAYKWH AS KWH, C.SOLARHOUR, C.PR, P.Irradiance, P.Temperature AS Temp ,C.KWHKWP, P.IrrDay, 0 AS DiffSOLARHOUR, C.PR avgPR
// FROM power_station_history_day C // FROM power_station_history_day C

View File

@ -4747,69 +4747,72 @@ namespace SolarPower.Repository.Implement
var sql = ""; var sql = "";
foreach (var entity in entities) foreach (var entity in entities)
{ {
var table_name = string.Format("`{0}`.`s{1}01_inv`", entity.SiteDB, entity.Code); var table_name_hot = string.Format("`{0}`.`s{1}01_inv`", entity.SiteDB, entity.Code);
var sensor_table_name = string.Format("`{0}`.`s{1}01_sensoravg`", entity.SiteDB, entity.Code); var sensor_table_name_hot = string.Format("`{0}`.`s{1}01_sensoravg`", entity.SiteDB, entity.Code);
var table_name_cold = string.Format("`{0}_history`.`s{1}01_inv`", entity.SiteDB, entity.Code);
var sensor_table_name_cold = string.Format("`{0}_history`.`s{1}01_sensoravg`", entity.SiteDB, entity.Code);
var inverterIds = string.Join("','", entity.InverterIds); var inverterIds = string.Join("','", entity.InverterIds);
var temp_sql = $@"SELECT // 熱區 SQL
var sql_hot = $@"
SELECT
FROM_UNIXTIME(inv.TIMESTAMP/1000, '%H:%i') AS TIMESTAMP, FROM_UNIXTIME(inv.TIMESTAMP/1000, '%H:%i') AS TIMESTAMP,
inv.INVERTERID, inv.INVERTERID,
i.InverterName AS INVERTERName, i.InverterName AS INVERTERName,
sen.{entity.Sensor} AS Irradiance, sen.{entity.Sensor} AS Irradiance,
((inv.DC1W + inv.DC2W + inv.DC3W + inv.DC4W + inv.DC5W) / 1000) AS DCKW, ((inv.DC1W + inv.DC2W + inv.DC3W + inv.DC4W + inv.DC5W) / 1000) AS DCKW,
((inv.AC1W + inv.AC2W + inv.AC3W) / 1000) AS ACKW, ((inv.AC1W + inv.AC2W + inv.AC3W) / 1000) AS ACKW,
inv.AC1V, inv.AC1V, inv.AC1A, inv.AC1W, inv.AC1F, inv.AC1WH,
inv.AC1A, inv.AC2V, inv.AC2A, inv.AC2W, inv.AC2F, inv.AC2WH,
inv.AC1W, inv.AC3V, inv.AC3A, inv.AC3W, inv.AC3F, inv.AC3WH,
inv.AC1F, inv.DC1V, inv.DC1A, inv.DC1W, inv.DC1WH,
inv.AC1WH, inv.DC2V, inv.DC2A, inv.DC2W, inv.DC2WH,
inv.AC2V, inv.DC3V, inv.DC3A, inv.DC3W, inv.DC3WH,
inv.AC2A, inv.DC4V, inv.DC4A, inv.DC4W, inv.DC4WH,
inv.AC2W, inv.DC5V, inv.DC5A, inv.DC5W, inv.DC5WH,
inv.AC2F, inv.PR, inv.RA1, inv.RA2, inv.RA3, inv.RA4, inv.RA5
inv.AC2WH, FROM {table_name_hot} inv
inv.AC3V, LEFT JOIN (SELECT * FROM {sensor_table_name_hot} WHERE TIMESTAMP BETWEEN @start_timestamp AND @end_timestamp) sen
inv.AC3A,
inv.AC3W,
inv.AC3F,
inv.AC3WH,
inv.DC1V,
inv.DC1A,
inv.DC1W,
inv.DC1WH,
inv.DC2V,
inv.DC2A,
inv.DC2W,
inv.DC2WH,
inv.DC3V,
inv.DC3A,
inv.DC3W,
inv.DC3WH,
inv.DC4V,
inv.DC4A,
inv.DC4W,
inv.DC4WH,
inv.DC5V,
inv.DC5A,
inv.DC5W,
inv.DC5WH,
inv.PR,
inv.RA1,
inv.RA2,
inv.RA3,
inv.RA4,
inv.RA5
FROM {table_name} inv
LEFT JOIN (select * from {sensor_table_name} where TIMESTAMP between @start_timestamp and @end_timestamp)sen
ON inv.CrdTime = sen.CrdTime ON inv.CrdTime = sen.CrdTime
-- LEFT JOIN {sensor_table_name} sen ON FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') = FROM_UNIXTIME(sen.TIMESTAMP/1000, '%Y-%m-%d %H:%i')
LEFT JOIN {entity.SiteDB}.inverter i ON inv.INVERTERID = i.InverterId LEFT JOIN {entity.SiteDB}.inverter i ON inv.INVERTERID = i.InverterId
WHERE inv.`TIMESTAMP` between @start_timestamp and @end_timestamp WHERE inv.TIMESTAMP BETWEEN @start_timestamp AND @end_timestamp
-- WHERE FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d') = @NowDay AND inv.INVERTERID IN ('{inverterIds}')
AND inv.INVERTERID IN ('{inverterIds}')"; ";
// 冷區 SQL
var sql_cold = $@"
SELECT
FROM_UNIXTIME(inv.TIMESTAMP/1000, '%H:%i') AS TIMESTAMP,
inv.INVERTERID,
i.InverterName AS INVERTERName,
sen.{entity.Sensor} AS Irradiance,
((inv.DC1W + inv.DC2W + inv.DC3W + inv.DC4W + inv.DC5W) / 1000) AS DCKW,
((inv.AC1W + inv.AC2W + inv.AC3W) / 1000) AS ACKW,
inv.AC1V, inv.AC1A, inv.AC1W, inv.AC1F, inv.AC1WH,
inv.AC2V, inv.AC2A, inv.AC2W, inv.AC2F, inv.AC2WH,
inv.AC3V, inv.AC3A, inv.AC3W, inv.AC3F, inv.AC3WH,
inv.DC1V, inv.DC1A, inv.DC1W, inv.DC1WH,
inv.DC2V, inv.DC2A, inv.DC2W, inv.DC2WH,
inv.DC3V, inv.DC3A, inv.DC3W, inv.DC3WH,
inv.DC4V, inv.DC4A, inv.DC4W, inv.DC4WH,
inv.DC5V, inv.DC5A, inv.DC5W, inv.DC5WH,
inv.PR, inv.RA1, inv.RA2, inv.RA3, inv.RA4, inv.RA5
FROM {table_name_cold} inv
LEFT JOIN (SELECT * FROM {sensor_table_name_cold} WHERE TIMESTAMP BETWEEN @start_timestamp AND @end_timestamp) sen
ON inv.CrdTime = sen.CrdTime
LEFT JOIN {entity.SiteDB}.inverter i ON inv.INVERTERID = i.InverterId
WHERE inv.TIMESTAMP BETWEEN @start_timestamp AND @end_timestamp
AND inv.INVERTERID IN ('{inverterIds}')
";
// 熱區 + 冷區 合併
var temp_sql = $"({sql_hot}) UNION ALL ({sql_cold})";
sql_perSiteDB.Add(temp_sql); sql_perSiteDB.Add(temp_sql);
} }
sql = "SELECT * FROM (" + string.Join(" UNION ", sql_perSiteDB) + ") a ORDER BY a.TIMESTAMP ASC"; sql = "SELECT * FROM (" + string.Join(" UNION ", sql_perSiteDB) + ") a ORDER BY a.TIMESTAMP ASC";
result = (await conn.QueryAsync<InverterHistory>(sql, new { start_timestamp = start_timestamp, end_timestamp = end_timestamp }, commandTimeout: 300)).ToList(); result = (await conn.QueryAsync<InverterHistory>(sql, new { start_timestamp = start_timestamp, end_timestamp = end_timestamp }, commandTimeout: 300)).ToList();
@ -4839,7 +4842,8 @@ namespace SolarPower.Repository.Implement
{ {
var inverterIds = string.Join("','", entity.InverterIds); var inverterIds = string.Join("','", entity.InverterIds);
var temp_sql = $@"SELECT // 熱區 SQL
var sql_hot = $@"SELECT
DATE_FORMAT(inv.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP, DATE_FORMAT(inv.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP,
inv.INVERTERID, inv.INVERTERID,
i.InverterName AS INVERTERName, i.InverterName AS INVERTERName,
@ -4858,6 +4862,30 @@ namespace SolarPower.Repository.Implement
AND inv.INVERTERID IN ('{inverterIds}') AND inv.INVERTERID IN ('{inverterIds}')
AND inv.TIMESTAMP BETWEEN @StartDay AND @EndDay"; AND inv.TIMESTAMP BETWEEN @StartDay AND @EndDay";
// 冷區 SQL
var sql_cold = $@"SELECT
DATE_FORMAT(inv.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP,
inv.INVERTERID,
i.InverterName AS INVERTERName,
inv.Irradiance,
inv.KWH,
inv.TODAYKWH,
inv.PR,
inv.RA1,
inv.RA2,
inv.RA3,
inv.RA4,
inv.RA5
FROM solar_master_offline.inverter_history_day inv
LEFT JOIN {entity.SiteDBName}.inverter i ON inv.INVERTERID = i.InverterId
WHERE inv.PowerStationId = {entity.PowerStationId}
AND inv.INVERTERID IN ('{inverterIds}')
AND inv.TIMESTAMP BETWEEN @StartDay AND @EndDay
";
// 熱區 + 冷區 合併
var temp_sql = $"({sql_hot}) UNION ALL ({sql_cold})";
sql_perSiteDB.Add(temp_sql); sql_perSiteDB.Add(temp_sql);
} }
sql = "SELECT * FROM (" + string.Join(" UNION ", sql_perSiteDB) + ") a ORDER BY a.TIMESTAMP ASC"; sql = "SELECT * FROM (" + string.Join(" UNION ", sql_perSiteDB) + ") a ORDER BY a.TIMESTAMP ASC";

View File

@ -648,6 +648,8 @@
powerids.splice($.inArray(this.value, powerids), 1); powerids.splice($.inArray(this.value, powerids), 1);
} }
if (powerids.length === 0) return;
GetStationsCard();//5張卡片值 GetStationsCard();//5張卡片值
photoshow();//輪播圖片 photoshow();//輪播圖片

View File

@ -384,7 +384,7 @@ namespace solarApp.Service
catch (Exception ex) catch (Exception ex)
{ {
TimeSpan duration = DateTime.Now - dt_start1; TimeSpan duration = DateTime.Now - dt_start1;
arclog.insert_log(_powerStationID, @$"move raw s1 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_station", $"{_siteDB}_history.s{_siteID01}_station", "1", ex.Message, "err", conn, null); arclog.insert_log(_powerStationID, @$"move raw s1 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_inv", $"{_siteDB}_history.s{_siteID01}_inv", "1", ex.Message, "err", conn, null);
//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);
throw ex; throw ex;
} }

View File

@ -228,6 +228,20 @@ namespace solarApp.Service
} }
} }
public List<station_list> get_station_list32_by_range(int startId, int endId)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @"select id, CompanyId, `code`, SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName
from power_station
where deleted = 0 and `status`= 1 and id >= @startId and id <= @endId";
List<station_list> ds = conn.Query<station_list>(sql, new { startId, endId }).AsList<station_list>();
conn.Close();
return ds;
}
}
public List<PowerStation> get_powerStation() public List<PowerStation> get_powerStation()
{ {
using (MySqlConnection conn = new MySqlConnection(Connection1)) using (MySqlConnection conn = new MySqlConnection(Connection1))

View File

@ -1,7 +1,8 @@
using System; using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data;
using System.Text; using System.Text;
using MySql.Data.MySqlClient;
namespace solarApp.Service namespace solarApp.Service
{ {
@ -26,6 +27,10 @@ namespace solarApp.Service
} }
else _cmd = cmd; else _cmd = cmd;
if (myCon.State != ConnectionState.Open)
myCon.Open();
string errMsg = string.Empty; string errMsg = string.Empty;
if (!string.IsNullOrEmpty(errMessage)) if (!string.IsNullOrEmpty(errMessage))
{ {
@ -34,6 +39,10 @@ namespace solarApp.Service
string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//string procResult = (string.IsNullOrEmpty(errMessage)) ? "0" : "1"; //string procResult = (string.IsNullOrEmpty(errMessage)) ? "0" : "1";
if (procResult == "err")
{
procResult = "1"; // 1: error
}
string sql = @"INSERT INTO `solar_master`.`log_archive`(power_stationID, `action_name`, `action_time`, `duration_sec`, `src_table`, `dest_table`, `result`, `err_txt`, `note`) string sql = @"INSERT INTO `solar_master`.`log_archive`(power_stationID, `action_name`, `action_time`, `duration_sec`, `src_table`, `dest_table`, `result`, `err_txt`, `note`)
VALUES ("+ power_stationID + ", '" + action_name + "', '" + nowTime + "', " + duration_sec + ", '" + // action_time, duration_sec VALUES ("+ power_stationID + ", '" + action_name + "', '" + nowTime + "', " + duration_sec + ", '" + // action_time, duration_sec
src_table + "', '"+ dest_table + "', b'"+ procResult + "', '" + // src_table, dest_table, result src_table + "', '"+ dest_table + "', b'"+ procResult + "', '" + // src_table, dest_table, result

View File

@ -253,39 +253,63 @@ namespace solarApp.Service
{ {
logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器hour補償", _siteID, _date1); logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器hour補償", _siteID, _date1);
sql = @$"DROP TEMPORARY TABLE IF EXISTS Inv_day_" + _powerStationID + @"_s2; sql = @$"
CREATE TEMPORARY TABLE Inv_day_" + _powerStationID + @"_s2 --
SELECT " + _powerStationID + @" powerStationID, a.INVERTERID, a.reportDate,a.AC1V, a.AC1A, a.AC1W, a.AC1F, a.AC1WH, a.AC2V, a.AC2A, a.AC2W, a.AC2F, a.AC2WH, DROP TEMPORARY TABLE IF EXISTS Inv_day_{_powerStationID}_s2;
a.AC3V, a.AC3A, a.AC3W, a.AC3F, a.AC3WH, a.DC1V, a.DC1A, a.DC1W, a.DC1WH, a.DC2V, a.DC2A, a.DC2W, a.DC2WH, a.DC3V, a.DC3A, a.DC3W,
a.DC3WH, a.DC4V, a.DC4A, a.DC4W, a.DC4WH, a.DC5V, a.DC5A, a.DC5W, a.DC5WH, --
a.RA1, a.RA2, a.RA3, a.RA4, a.RA5, a.KWH, a.TODAYKWH, a.TOTALKWH, CREATE TEMPORARY TABLE Inv_day_{_powerStationID}_s2
IFNULL(Irradiance, 0) irr, IFNULL(IrrDay, 0) IrrDay, 0 as PR, ((DC1W + DC2W + DC3W + DC4W + DC5W) / 1000) DCKW, ((AC1W + AC2W + AC3W) / 1000) ACKW, (a.KWH / i.Capacity) AS KWHKWP SELECT
from {_powerStationID} AS powerStationID,
(-- KWH a.INVERTERID,
SELECT concat(left(crdTime, 13), ':00:00') reportDate, INVERTERID, a.reportDate,
AVG(AC1V) AS AC1V, AVG(AC1A) AS AC1A, round(SUM(AC1W), 5) AS AC1W, AVG(AC1F) AS AC1F, SUM(AC1WH) AS AC1WH, AVG(AC2V) AS AC2V, a.AC1V, a.AC1A, a.AC1W, a.AC1F, a.AC1WH,
AVG(AC2A) AS AC2A, round(SUM(AC2W), 5) AS AC2W, AVG(AC2F) AS AC2F, SUM(AC2WH) AS AC2WH, AVG(AC3V) AS AC3V, AVG(AC3A) AS AC3A, a.AC2V, a.AC2A, a.AC2W, a.AC2F, a.AC2WH,
round(SUM(AC3W), 5) AS AC3W, AVG(AC3F) AS AC3F, SUM(AC3WH) AS AC3WH, AVG(DC1V) AS DC1V, AVG(DC1A) AS DC1A, SUM(DC1W) AS DC1W, a.AC3V, a.AC3A, a.AC3W, a.AC3F, a.AC3WH,
SUM(DC1WH) AS DC1WH, AVG(DC2V) AS DC2V, AVG(DC2A) AS DC2A, SUM(DC2W) AS DC2W, SUM(DC2WH) AS DC2WH, AVG(DC3V) AS DC3V, a.DC1V, a.DC1A, a.DC1W, a.DC1WH,
AVG(DC3A) AS DC3A, AVG(DC3W) AS DC3W, AVG(DC3WH) AS DC3WH, AVG(DC4V) AS DC4V, AVG(DC4A) AS DC4A, SUM(DC4W) AS DC4W, a.DC2V, a.DC2A, a.DC2W, a.DC2WH,
SUM(DC4WH) AS DC4WH, AVG(DC5V) AS DC5V, AVG(DC5A) AS DC5A, SUM(DC5W) AS DC5W, SUM(DC5WH) AS DC5WH, a.DC3V, a.DC3A, a.DC3W, a.DC3WH,
AVG(RA1) AS RA1, AVG(RA2) AS RA2, AVG(RA3) AS RA3, a.DC4V, a.DC4A, a.DC4W, a.DC4WH,
AVG(RA4) AS RA4, AVG(RA5) AS RA5, MAX(TODAYKWH) AS TODAYKWH, MAX(TOTALKWH) AS TOTALKWH, (SUM(WH) / 1000) AS KWH a.DC5V, a.DC5A, a.DC5W, a.DC5WH,
FROM del_Inv_day_" + _powerStationID + @"_s1 a.RA1, a.RA2, a.RA3, a.RA4, a.RA5,
GROUP BY left(crdTime, 13), INVERTERID a.KWH, a.TODAYKWH, a.TOTALKWH,
COALESCE(irr.Irradiance, 0) AS irr,
COALESCE(irr.IrrDay, 0) AS IrrDay,
0 AS PR,
(a.DC1W + a.DC2W + a.DC3W + a.DC4W + a.DC5W) / 1000 AS DCKW,
(a.AC1W + a.AC2W + a.AC3W) / 1000 AS ACKW,
(a.KWH / IFNULL(i.Capacity, 1)) AS KWHKWP
FROM (
SELECT
DATE_FORMAT(crdTime, '%Y-%m-%d %H:00:00') AS reportDate,
INVERTERID,
AVG(AC1V) AS AC1V, AVG(AC1A) AS AC1A, ROUND(SUM(AC1W), 5) AS AC1W, AVG(AC1F) AS AC1F, SUM(AC1WH) AS AC1WH,
AVG(AC2V) AS AC2V, AVG(AC2A) AS AC2A, ROUND(SUM(AC2W), 5) AS AC2W, AVG(AC2F) AS AC2F, SUM(AC2WH) AS AC2WH,
AVG(AC3V) AS AC3V, AVG(AC3A) AS AC3A, ROUND(SUM(AC3W), 5) AS AC3W, AVG(AC3F) AS AC3F, SUM(AC3WH) AS AC3WH,
AVG(DC1V) AS DC1V, AVG(DC1A) AS DC1A, SUM(DC1W) AS DC1W, SUM(DC1WH) AS DC1WH,
AVG(DC2V) AS DC2V, AVG(DC2A) AS DC2A, SUM(DC2W) AS DC2W, SUM(DC2WH) AS DC2WH,
AVG(DC3V) AS DC3V, AVG(DC3A) AS DC3A, AVG(DC3W) AS DC3W, AVG(DC3WH) AS DC3WH,
AVG(DC4V) AS DC4V, AVG(DC4A) AS DC4A, SUM(DC4W) AS DC4W, SUM(DC4WH) AS DC4WH,
AVG(DC5V) AS DC5V, AVG(DC5A) AS DC5A, SUM(DC5W) AS DC5W, SUM(DC5WH) AS DC5WH,
AVG(RA1) AS RA1, AVG(RA2) AS RA2, AVG(RA3) AS RA3, AVG(RA4) AS RA4, AVG(RA5) AS RA5,
MAX(TODAYKWH) AS TODAYKWH, MAX(TOTALKWH) AS TOTALKWH,
SUM(WH) / 1000 AS KWH
FROM del_Inv_day_{_powerStationID}_s1
GROUP BY DATE_FORMAT(crdTime, '%Y-%m-%d %H:00:00'), INVERTERID
) a ) a
-- LEFT JOIN {_siteDB}.inverter i ON a.INVERTERID = i.InverterId AND i.enabled = 1
LEFT JOIN " + _siteDB + @".inverter i ON a.INVERTERID = i.InverterId LEFT JOIN (
-- -------------------- - SELECT
left join( CONCAT(DATE_FORMAT(`TIMESTAMP`, '%Y-%m-%d %H'), ':00:00') AS reportDate,
select concat(DATE_FORMAT(`TIMESTAMP`, '%Y-%m-%d %H'), ':00:00') AS reportDate, Irradiance, IrrDay Irradiance, IrrDay
from sensor_history_hour FROM sensor_history_hour
where powerstationID = " + _powerStationID + @" and DATE_FORMAT(`TIMESTAMP`, '%Y-%m-%d') = @date1 WHERE powerstationID = {_powerStationID} AND DATE(`TIMESTAMP`) = @date1
)irr on a.reportDate = irr.reportDate ) irr ON a.reportDate = irr.reportDate;
where i.enabled = 1;"; ";
//int ct = conn.Execute(sql, new { date1 = _date1 }); //int ct = conn.Execute(sql, new { date1 = _date1 });
cmd.Connection = conn; cmd.Connection = conn;
cmd.CommandTimeout = 720; cmd.CommandTimeout = 1200;
cmd.Parameters.AddWithValue("@date1", _date1); cmd.Parameters.AddWithValue("@date1", _date1);
cmd.Parameters.AddWithValue("@PowerStationID", _powerStationID); cmd.Parameters.AddWithValue("@PowerStationID", _powerStationID);
cmd.CommandText = sql; cmd.CommandText = sql;

View File

@ -257,9 +257,12 @@ namespace solarApp.Service
order by 1 desc limit 1 order by 1 desc limit 1
)a1 on a.siteID = a1.siteID join )a1 on a.siteID = a1.siteID join
( (
select a.id, `code` siteID, PowerRate, GeneratingCapacity Capacity, (select `value` from solar_master.`variable` where `name` = 'CarbonRate') as CarbonRate, SolarType, IrrDay select a.id, `code` siteID, PowerRate, GeneratingCapacity Capacity, (select `value` from solar_master.`variable` where `name` = 'CarbonRate') as CarbonRate, SolarType
from solar_master.power_station a join sensor_history_day b on a.id = b.PowerStationID -- , IrrDay
where `code` = @siteID and left(`TIMESTAMP`, 10) = @date1 from solar_master.power_station a
-- join sensor_history_day b on a.id = b.PowerStationID
where `code` = @siteID
-- and left(`TIMESTAMP`, 10) = @date1
) b on a.siteID = b.siteID "; ) b on a.siteID = b.siteID ";
// sql = @" INSERT INTO solar_master.power_station_history_day( PowerStationId, `TIMESTAMP`, SITEID, SITETYPE, TODAYKWH, TOTALKWH, KWHKWP, // sql = @" INSERT INTO solar_master.power_station_history_day( PowerStationId, `TIMESTAMP`, SITEID, SITETYPE, TODAYKWH, TOTALKWH, KWHKWP,
// PR, MP, SOLARHOUR, MONEY, TOTALMONEY, CARBON, TOTALCARBON) // PR, MP, SOLARHOUR, MONEY, TOTALMONEY, CARBON, TOTALCARBON)

View File

@ -89,6 +89,11 @@ namespace solarApp
lbUserName = new System.Windows.Forms.Label(); lbUserName = new System.Windows.Forms.Label();
tbUserName = new System.Windows.Forms.TextBox(); tbUserName = new System.Windows.Forms.TextBox();
btSendMail = new System.Windows.Forms.Button(); btSendMail = new System.Windows.Forms.Button();
this.lbStationIdRange = new System.Windows.Forms.Label();
this.tbStationIdStart = new System.Windows.Forms.TextBox();
this.lbStationIdDash = new System.Windows.Forms.Label();
this.tbStationIdEnd = new System.Windows.Forms.TextBox();
this.bt_procStep2Range = new System.Windows.Forms.Button();
timer1 = new System.Windows.Forms.Timer(components); timer1 = new System.Windows.Forms.Timer(components);
tabControl1.SuspendLayout(); tabControl1.SuspendLayout();
tabPage1.SuspendLayout(); tabPage1.SuspendLayout();
@ -165,6 +170,11 @@ namespace solarApp
splitContainer1.Panel1.Controls.Add(bt_site); splitContainer1.Panel1.Controls.Add(bt_site);
splitContainer1.Panel1.Controls.Add(bt_Inv); splitContainer1.Panel1.Controls.Add(bt_Inv);
splitContainer1.Panel1.Controls.Add(bt_Sensor); splitContainer1.Panel1.Controls.Add(bt_Sensor);
splitContainer1.Panel1.Controls.Add(this.lbStationIdRange);
splitContainer1.Panel1.Controls.Add(this.tbStationIdStart);
splitContainer1.Panel1.Controls.Add(this.lbStationIdDash);
splitContainer1.Panel1.Controls.Add(this.tbStationIdEnd);
splitContainer1.Panel1.Controls.Add(this.bt_procStep2Range);
// //
// splitContainer1.Panel2 // splitContainer1.Panel2
// //
@ -178,7 +188,7 @@ namespace solarApp
// //
// bt_procStep2 // bt_procStep2
// //
bt_procStep2.Location = new System.Drawing.Point(109, 910); bt_procStep2.Location = new System.Drawing.Point(10, 910);
bt_procStep2.Name = "bt_procStep2"; bt_procStep2.Name = "bt_procStep2";
bt_procStep2.Size = new System.Drawing.Size(166, 57); bt_procStep2.Size = new System.Drawing.Size(166, 57);
bt_procStep2.TabIndex = 21; bt_procStep2.TabIndex = 21;
@ -186,6 +196,42 @@ namespace solarApp
bt_procStep2.UseVisualStyleBackColor = true; bt_procStep2.UseVisualStyleBackColor = true;
bt_procStep2.Click += bt_procStep2_Click; bt_procStep2.Click += bt_procStep2_Click;
// //
// lbStationIdRange
//
this.lbStationIdRange.Name = "lbStationIdRange";
this.lbStationIdRange.Location = new System.Drawing.Point(384, 932);
this.lbStationIdRange.Size = new System.Drawing.Size(90, 27);
this.lbStationIdRange.Text = "電站ID區間:";
//
// tbStationIdStart
//
this.tbStationIdStart.Name = "tbStationIdStart";
this.tbStationIdStart.Location = new System.Drawing.Point(479, 930);
this.tbStationIdStart.Size = new System.Drawing.Size(60, 27);
//
// lbStationIdDash
//
this.lbStationIdDash.Name = "lbStationIdDash";
this.lbStationIdDash.Location = new System.Drawing.Point(544, 930);
this.lbStationIdDash.Size = new System.Drawing.Size(15, 27);
this.lbStationIdDash.Text = "~";
//
// tbStationIdEnd
//
this.tbStationIdEnd.Name = "tbStationIdEnd";
this.tbStationIdEnd.Location = new System.Drawing.Point(564, 930);
this.tbStationIdEnd.Size = new System.Drawing.Size(60, 27);
//
// bt_procStep2Range
//
this.bt_procStep2Range.Name = "bt_procStep2Range";
this.bt_procStep2Range.Location = new System.Drawing.Point(208, 910);
this.bt_procStep2Range.Size = new System.Drawing.Size(166, 57);
this.bt_procStep2Range.TabIndex = 22;
this.bt_procStep2Range.Text = "區間跑報告";
this.bt_procStep2Range.UseVisualStyleBackColor = true;
this.bt_procStep2Range.Click += new System.EventHandler(this.bt_procStep2Range_Click);
//
// button3 // button3
// //
button3.Font = new System.Drawing.Font("Microsoft JhengHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); button3.Font = new System.Drawing.Font("Microsoft JhengHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
@ -858,5 +904,11 @@ namespace solarApp
private System.Windows.Forms.Button btSyncErr; private System.Windows.Forms.Button btSyncErr;
private System.Windows.Forms.Button bt_MoveRawData; private System.Windows.Forms.Button bt_MoveRawData;
private System.Windows.Forms.Button bt_procStep2; private System.Windows.Forms.Button bt_procStep2;
// 在 bt_procStep2 附近新增
private System.Windows.Forms.Label lbStationIdRange;
private System.Windows.Forms.TextBox tbStationIdStart;
private System.Windows.Forms.Label lbStationIdDash;
private System.Windows.Forms.TextBox tbStationIdEnd;
private System.Windows.Forms.Button bt_procStep2Range;
} }
} }

View File

@ -872,8 +872,8 @@ namespace solarApp
//for sensor_history_hour //for sensor_history_hour
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
{ {
sensorSvc.archiveSensorHistoryHourData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd")); //sensorSvc.archiveSensorHistoryHourData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
sensorSvc.isFirst = false; //sensorSvc.isFirst = false;
invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd")); invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
} }
} }
@ -886,8 +886,8 @@ namespace solarApp
//for sensor_history_hour //for sensor_history_hour
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
{ {
sensorSvc.archiveSensorHistoryHourData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd")); //sensorSvc.archiveSensorHistoryHourData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
sensorSvc.isFirst = false; //sensorSvc.isFirst = false;
invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd")); invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
} }
} }
@ -895,6 +895,39 @@ namespace solarApp
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 完成!"; lbMsgTitle.Text = System.DateTime.Now.ToString() + " 完成!";
} }
private void bt_procStep2Range_Click(object sender, EventArgs e)
{
// 防呆:檢查是否有輸入
if (string.IsNullOrWhiteSpace(tbStationIdStart.Text) || string.IsNullOrWhiteSpace(tbStationIdEnd.Text))
{
MessageBox.Show("請輸入電站ID區間起始與結束");
return;
}
if (!int.TryParse(tbStationIdStart.Text, out int startId) || !int.TryParse(tbStationIdEnd.Text, out int endId))
{
MessageBox.Show("電站ID區間請輸入有效數字");
return;
}
var site_list = stationSvc.get_station_list32_by_range(startId, endId);
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
procSensorSvc sensorSvc = new procSensorSvc();
procInvSvc invSvc = new procInvSvc();
sensorSvc.isFirst = true;
foreach (var item in site_list)
{
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
{
invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
}
}
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 區間報告完成!";
}
//test for email format //test for email format
//private void button3_Click(object sender, EventArgs e) //private void button3_Click(object sender, EventArgs e)
//{ //{