FIC_Solar/solarApp/Service/getStationSvc.cs
2021-08-05 02:42:34 +08:00

93 lines
4.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using Dapper;
using solarApp.Model;
using System.Configuration;
namespace solarApp.Service
{
/// <summary>
/// 電站原始資料 rawData
/// </summary>
public class getStationSvc
{
string Connection1 = ConfigurationManager.ConnectionStrings["mySql"].ConnectionString;
public List<raw_statino> get_station_raw(string reportDate)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @"select id , reportdate, siteid, KWH, TODAYKWH, TOTALKWH, PR, SOLARHOUR, kwhkwp
from v_station_temp
where siteid = '022020001' and left(reportdate, 10) = @reportDate";
List<raw_statino> ds = conn.Query<raw_statino>(sql, new { reportDate = reportDate }).AsList<raw_statino>();
conn.Close();
return ds;
}
}
/// <summary>
/// 電站每天平均 from RawData
/// </summary>
/// <param name="date1"></param>
/// <param name="date2"></param>
/// <returns></returns>
public List<raw_station_day> get_station_rawAvg(string date1, string date2)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @" select siteid, left(reportdate, 10) reportdate, round((sum(KWH)), 2) KWH, round((max(TODAYKWH)), 2) TODAYKWH, round((max(TOTALKWH)), 2) TOTALKWH,
round((max(PR)), 2) PR, round((max(SOLARHOUR)), 2) SOLARHOUR, round((max(KWHKWP)), 2) KWHKWP, count(*) count
from v_station_temp
where left(reportdate, 10) between @date1 and @date2
group by siteid, left(reportdate, 10)";
List<raw_station_day> ds = conn.Query<raw_station_day>(sql, new { date1 = date1, date2 = date2 }).AsList<raw_station_day>();
conn.Close();
return ds;
}
}
/// <summary>
/// web 呈現值 station - hour
/// </summary>
/// <param name="reportDate"></param>
/// <returns></returns>
public List<web_station_hour> get_web_station_hour(string reportDate)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, siteid, round(KWH, 2) KWH, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH,
round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, money
from power_station_history_hour where left(`TIMESTAMP`, 10) = '" + reportDate + "' ";
List<web_station_hour> ds = conn.Query<web_station_hour>(sql).AsList<web_station_hour>();
conn.Close();
return ds;
}
}
/// <summary>
/// web 呈現值 station - day
/// </summary>
/// <param name="reportDate"></param>
/// <param name="invID"></param>
/// <returns></returns>
public List<web_station_hour> get_web_station_day(string date1, string date2)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, siteid, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH,
round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, money
from power_station_history_day where left(`TIMESTAMP`, 10) between @date1 and @date2 ";
List<web_station_hour> ds = conn.Query<web_station_hour>(sql, new { date1 = date1, date2 = date2 }).AsList<web_station_hour>();
conn.Close();
return ds;
}
}
}
}