using Entity.Ammeter; using HybirdFrameworkCore.Autofac.Attribute; using Repository.Ammeter; namespace Service.Ammeter; [Scope("SingleInstance")] public class EmeterEnergyChangeService : BaseServices { private readonly EmeterEnergyChangeRepository _emeterEnergyChangeRep; public EmeterEnergyChangeService(EmeterEnergyChangeRepository emeterEnergyChangeRep) { _emeterEnergyChangeRep = emeterEnergyChangeRep; } public async Task> SevenDaysElectrical() { string sql = @" SELECT code, date(upload_time) AS UploadTime, MAX(value) - MIN(value) AS Value FROM emeter_energy_change WHERE upload_time >= NOW() - INTERVAL 7 DAY GROUP BY code, date(upload_time) ORDER BY code, date(upload_time); "; List emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql); return emeterEnergies; } public async Task> GetAllElectricalData() { string sql = @" SELECT code, MAX(value) - MIN(value) AS Value FROM emeter_energy_change GROUP BY code ORDER BY code; "; List emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql); return emeterEnergies; } public async Task> 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_change WHERE DATE(upload_time) = CURDATE() GROUP BY code, DATE_FORMAT(upload_time, '%Y-%m-%d %H:00:00') ORDER BY code, Hour; "; List emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql); return emeterEnergies; } }