You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.2 KiB
87 lines
2.2 KiB
using Entity.Ammeter;
|
|
using Entity.Api.Resp;
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
using Repository.Ammeter;
|
|
using SqlSugar;
|
|
|
|
namespace Service.Ammeter;
|
|
|
|
[Scope("SingleInstance")]
|
|
public class EmeterEnergyService : BaseServices<EmeterEnergy>
|
|
{
|
|
public EmeterEnergyService(EmeterEnergyRepository service)
|
|
{
|
|
this.BaseDal = service;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取七天用电量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<EmeterEnergy>> SevenDaysElectrical()
|
|
{
|
|
string sql = @"
|
|
SELECT
|
|
code,
|
|
date(upload_time) AS UploadTime,
|
|
MAX(value) - MIN(value) AS Value
|
|
FROM
|
|
emeter_energy
|
|
WHERE
|
|
upload_time >= NOW() - INTERVAL 7 DAY
|
|
GROUP BY
|
|
code, date(upload_time)
|
|
ORDER BY
|
|
code, date(upload_time);
|
|
";
|
|
List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql);
|
|
return emeterEnergies;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取全部用电量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<EmeterEnergy>> GetAllElectricalData()
|
|
{
|
|
string sql = @"
|
|
SELECT
|
|
code,
|
|
MAX(value) - MIN(value) AS Value
|
|
FROM
|
|
emeter_energy
|
|
GROUP BY
|
|
code
|
|
ORDER BY
|
|
code;
|
|
";
|
|
|
|
List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql);
|
|
return emeterEnergies;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据小时统计电量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<EmeterEnergy>> GetTodayHourlyElectricalData()
|
|
{
|
|
string sql = @"
|
|
SELECT
|
|
code,
|
|
DATE_FORMAT(upload_time, '%Y-%m-%d %H:00:00') AS Hour,
|
|
MAX(value) - MIN(value) AS Value
|
|
FROM
|
|
emeter_energy
|
|
WHERE
|
|
DATE(upload_time) = CURDATE()
|
|
GROUP BY
|
|
code, DATE_FORMAT(upload_time, '%Y-%m-%d %H:00:00')
|
|
ORDER BY
|
|
code, Hour;
|
|
";
|
|
|
|
List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql);
|
|
return emeterEnergies;
|
|
}
|
|
} |