From cde5bf66a02c1f10690376760171e07c56abd72d Mon Sep 17 00:00:00 2001 From: tq <1916474859@qq,com> Date: Fri, 14 Jun 2024 16:51:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E8=A1=A8=E5=AE=9E=E6=97=B6=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Ammeter/EmeterEnergyChangeService.cs | 23 +++++++++++++++++++ Service/Ammeter/EmeterEnergyService.cs | 22 ++++++++++++++++++ .../Controllers/Ammeter/AmmeterController.cs | 19 +++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/Service/Ammeter/EmeterEnergyChangeService.cs b/Service/Ammeter/EmeterEnergyChangeService.cs index c794f96..bba64a0 100644 --- a/Service/Ammeter/EmeterEnergyChangeService.cs +++ b/Service/Ammeter/EmeterEnergyChangeService.cs @@ -182,4 +182,27 @@ ORDER BY List emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql); return emeterEnergies; } + + /// + /// 获取交流电表实时数据 + /// + /// + public async Task> GetEnergyMeterRealTime() + { + // 根据code分组,取最新时间的一条数据,数据范围7天 + string sql = @" + SELECT t1.* +FROM emeter_energy_change t1 +JOIN ( + SELECT code, MAX(upload_time) as latest_upload_time + FROM emeter_energy_change + WHERE upload_time >= NOW() - INTERVAL 7 DAY + GROUP BY code +) t2 ON t1.code = t2.code AND t1.upload_time = t2.latest_upload_time +WHERE t1.upload_time >= NOW() - INTERVAL 7 DAY; +"; + + List emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql); + return emeterEnergies; + } } \ No newline at end of file diff --git a/Service/Ammeter/EmeterEnergyService.cs b/Service/Ammeter/EmeterEnergyService.cs index 134fbfa..ee33709 100644 --- a/Service/Ammeter/EmeterEnergyService.cs +++ b/Service/Ammeter/EmeterEnergyService.cs @@ -192,6 +192,28 @@ ORDER BY m.`code`, m.`Minute`; "; + List emeterEnergies = await this.BaseDal.SqlQueryable(sql); + return emeterEnergies; + } + /// + /// 获取直流电表实时数据 + /// + /// + public async Task> GetEnergyMeterRealTime() + { + // 根据code分组,取最新时间的一条数据,数据范围7天 + string sql = @" + SELECT t1.* +FROM emeter_energy t1 +JOIN ( + SELECT code, MAX(upload_time) as latest_upload_time + FROM emeter_energy + WHERE upload_time >= NOW() - INTERVAL 7 DAY + GROUP BY code +) t2 ON t1.code = t2.code AND t1.upload_time = t2.latest_upload_time +WHERE t1.upload_time >= NOW() - INTERVAL 7 DAY; +"; + List emeterEnergies = await this.BaseDal.SqlQueryable(sql); return emeterEnergies; } diff --git a/WebStarter/Controllers/Ammeter/AmmeterController.cs b/WebStarter/Controllers/Ammeter/AmmeterController.cs index 9b7ca6a..1591e95 100644 --- a/WebStarter/Controllers/Ammeter/AmmeterController.cs +++ b/WebStarter/Controllers/Ammeter/AmmeterController.cs @@ -153,6 +153,25 @@ namespace WebStarter.Controllers.Ammeter return Result.Success(resp,"成功"); } + /// + /// 获取直流交流电表实时数据 + /// + /// + [HttpGet("GetEnergyMeterRealTime")] + public async Task> GetEnergyMeterRealTime() + { + // 获取实时直流和交流表数据 + List minutesElectrical = await _emeterEnergyService.GetEnergyMeterRealTime(); + List minutesElectricalChange = await _emeterEnergyChangeService.GetEnergyMeterRealTime(); + + EmeterEnergyResp resp = new EmeterEnergyResp(); + + ChargeAssignment(minutesElectrical, minutesElectricalChange, resp); + + + return Result.Success(resp,"成功"); + } + private static void ChargeAssignment(List emeterEnergy, List emeterEnergyChanges, EmeterEnergyResp resp) {