using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using Dapper;
using solarApp.Model;
using System.Configuration;
namespace solarApp.Service
{
///
/// 電站原始資料 rawData
///
public class getStationSvc
{
string Connection1 = ConfigurationManager.ConnectionStrings["mySql"].ConnectionString;
public List 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 ds = conn.Query(sql, new { reportDate = reportDate }).AsList();
conn.Close();
return ds;
}
}
///
/// 電站每天平均 from RawData
///
///
///
///
public List 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 ds = conn.Query(sql, new { date1 = date1, date2 = date2 }).AsList();
conn.Close();
return ds;
}
}
///
/// web 呈現值 station - hour
///
///
///
public List 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 ds = conn.Query(sql).AsList();
conn.Close();
return ds;
}
}
///
/// web 呈現值 station - day
///
///
///
///
public List 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 ds = conn.Query(sql, new { date1 = date1, date2 = date2 }).AsList();
conn.Close();
return ds;
}
}
}
}