using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using Dapper;
using solarApp.Model;
using System.Configuration;
using System.Threading.Tasks;
namespace solarApp.Service
{
public class get_inv_svc
{
string Connection1 = ConfigurationManager.ConnectionStrings["mySql"].ConnectionString;
///
/// inverter 原始資料 - 5 min
///
///
///
///
public List Get_rawInv(string reportDate, string invID)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
//string sql = @"select ID, TIMESTAMP, SITEID, SITETYPE, CONTROLLERID, INVERTERID, SN, AC1V, AC1A, AC1W, AC1F, AC1WH, AC2V, AC2A, AC2W, AC2F, AC2WH, AC3V, AC3A, AC3W, AC3F, AC3WH, ACRUNTIME, DC1V, DC1A, DC1W, DC1WH, DC2V, DC2A, DC2W, DC2WH, DC3V, DC3A, DC3W, DC3WH, DC4V, DC4A, DC4W, DC4WH, DC5V, DC5A, DC5W, DC5WH, DCRUNTIME, WH, TODAYKWH, TOTALKWH, PR, RA1, RA2, RA3, RA4, RA5
// from solar_com0002.s02202000101_inv order by id desc limit 100; ";
string sql = @"select id , reportdate, inverterid, WH, TODAYKWH, TOTALKWH, PR, RA1 from v_inv_temp where left(reportdate, 10) = '" + reportDate + "' and inverterid = '" + invID + "'";
//List ds = conn.Query(sql, new { kind = kind }).ToList();
List ds = conn.Query(sql).AsList();
conn.Close();
return ds;
}
}
///
/// 每小時平均值 inverter 原始資料 - hour
///
///
///
///
public List get_Inv_rawAvg(string reportDate, string invID)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
//string sql = @"select left(reportdate, 13)reportdate, inverterid, round((sum(WH)/1000), 2) KWH, round(max(TODAYKWH), 2) TODAYKWH,
// round(max(TOTALKWH), 2) TOTALKWH, round(max(PR), 2) PR, count(*) count
// from v_inv_temp where left(reportdate, 10) = '" + reportDate + "' and inverterid = '" + invID + "' " +
// "group by left(reportdate, 13), inverterid"; //round(avg(PR), 2) PR,
string sql = @" select a.reportdate, a.inverterid, a.KWH, b.TODAYKWH, b.TOTALKWH, b.PR, a.count from
(
select left(reportdate, 13)reportdate, inverterid
,round((sum(WH)/1000), 2) KWH, count(*) count
from v_inv_temp
where left(reportdate, 10) = '" + reportDate + "' and inverterid = '" + invID + @"'
group by left(reportdate, 13), inverterid
)a join (
select reportdate, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, inverterid, round(PR, 2) PR
from v_inv_temp
where left(reportdate, 10) = '" + reportDate + @"' and right(reportdate, 2) = '55' and inverterid = '" + invID + @"'
)b on a.reportdate = left(b.reportdate, 13) and a.inverterid = b.inverterid ";
List ds = conn.Query(sql).AsList();
conn.Close();
return ds;
}
}
///
/// web 呈現值 每小時平均值 inverter - hour
///
///
///
///
public List get_web_Inv_hour(string reportDate, string invID)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @"select `TIMESTAMP` reportdate, inverterid, KWH, TODAYKWH, TOTALKWH, round(PR, 2) PR
from inverter_history_hour where left(`TIMESTAMP`, 10) = '" + reportDate + "' and inverterid = '" + invID + "' ";
List ds = conn.Query(sql).AsList();
conn.Close();
return ds;
}
}
///
///
///
///
///
///
public List get_Inv_list()
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @"select dbname, inverterid from v_company_inv";
List ds = conn.Query(sql).AsList();
conn.Close();
return ds;
}
}
}
}