From a1cee0456161b25175b3c3ac15b77173c9ba2be0 Mon Sep 17 00:00:00 2001 From: lxw Date: Tue, 2 Jul 2024 18:14:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E8=A1=A8=E5=88=86=E9=92=9F=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/lib/HybirdFrameworkCore.dll | Bin 51200 -> 51200 bytes Entity/Ammeter/EmeterMinutesEnergy.cs | 2 +- Service/MyJob/EmeterMinuteJob.cs | 49 ++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Common/lib/HybirdFrameworkCore.dll b/Common/lib/HybirdFrameworkCore.dll index c0fb98bd9851ccb28d0a26aefc647ee22d35e211..27488c38be0dd6ec201763a61a2f4c2b7289521a 100644 GIT binary patch delta 330 zcmZpez}zr_c|r$^(*2;*6MIS+S4?JP{Lgr2Gb0o8GJ(P^LC04Y_PXq7>Rg%9_S$Q+ z$O>0c4MP(X!&Fmq6LT}m6(dlMi&acc zMR`nleo=NzK~a88vhrku17Su`rTbt?LB?`b)_j^FtvvIbzJlllprJ7E3dB~Js3^vG zXY%<2nr#17859@IE> /// 时间 /// - [SugarColumn(ColumnName = "st")] + [SugarColumn(ColumnName = "time")] public string Time { get; set; } /// diff --git a/Service/MyJob/EmeterMinuteJob.cs b/Service/MyJob/EmeterMinuteJob.cs index 2eb9b98..5f007d7 100644 --- a/Service/MyJob/EmeterMinuteJob.cs +++ b/Service/MyJob/EmeterMinuteJob.cs @@ -13,22 +13,24 @@ namespace Service.Job; /// 分钟统计 /// [Scope] -public class EmeterMinuteJob : AbstrackCronJob +public class EmeterMinuteJob : AbstractCronJob { private static readonly ILog Log = LogManager.GetLogger(typeof(EmeterMinuteJob)); - public EmeterEnergyRepository EmeterEnergyRepository { get; set; } + public EmeterEnergyRepository EmeterEnergyRepository = AppInfo.Container.Resolve(); - public EmeterEnergyChangeRepository EmeterEnergyChangeRepository { get; set; } + public EmeterEnergyChangeRepository EmeterEnergyChangeRepository = + AppInfo.Container.Resolve(); - public EmeterMinutesEnergyRepository EmeterMinutesEnergyRepository { get; set; } + public EmeterMinutesEnergyRepository EmeterMinutesEnergyRepository = + AppInfo.Container.Resolve(); protected override Task Handle() { var now = DateTime.Now; - Log.Info($"EmeterMinuteJob execute time={now}"); + Log.Info($"EmeterMinuteJob execute start time={now}"); //查询上一分钟的数据 string dateTime = now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm"); @@ -38,6 +40,7 @@ public class EmeterMinuteJob : AbstrackCronJob List emeterEnergiesChange = EmeterEnergyChangeRepository.QueryListByClause(i => dateTime.Equals(i.UploadTime.ToString("yyyy-MM-dd HH:mm")), "upload_time desc"); + List db = new List(); if (emeterEnergies.Count > 0) { Dictionary> dictionary = @@ -48,6 +51,13 @@ public class EmeterMinuteJob : AbstrackCronJob EmeterMinutesEnergy emeterMinutesEnergy = new EmeterMinutesEnergy(); emeterMinutesEnergy.Code = keyValuePair.Key; emeterMinutesEnergy.Time = dateTime; + emeterMinutesEnergy.Type = 1; + var value = keyValuePair.Value; + var orderByDescending = value.OrderByDescending(i => i.UploadTime).ToList(); + emeterMinutesEnergy.RealTimeValue = float.Parse(orderByDescending[0].Value); + emeterMinutesEnergy.Value = float.Parse(orderByDescending[0].Value) - + float.Parse(orderByDescending[^1].Value); + db.Add(emeterMinutesEnergy); } } @@ -55,13 +65,40 @@ public class EmeterMinuteJob : AbstrackCronJob { Dictionary> dictionaryChange = emeterEnergiesChange.GroupBy(i => i.Code).ToDictionary(i => i.Key, i => i.ToList()); + + foreach (var keyValuePair in dictionaryChange) + { + EmeterMinutesEnergy emeterMinutesEnergy = new EmeterMinutesEnergy(); + emeterMinutesEnergy.Code = keyValuePair.Key; + emeterMinutesEnergy.Time = dateTime; + emeterMinutesEnergy.Type = 1; + var value = keyValuePair.Value; + var orderByDescending = value.OrderByDescending(i => i.UploadTime).ToList(); + emeterMinutesEnergy.RealTimeValue = orderByDescending[0].Value; + emeterMinutesEnergy.Value = orderByDescending[0].Value - + orderByDescending[^1].Value; + db.Add(emeterMinutesEnergy); + } } + if (db.Count > 0) + { + EmeterMinutesEnergyRepository.Insert(db); + } + + + Log.Info($"EmeterMinuteJob execute end "); return Task.CompletedTask; } + protected override string Key() + { + return nameof(EmeterMinuteJob); + } + protected override string Cron() { - return "0 0/1 * * * ?"; + //return "0 0/1 * * * ?"; + return "0 * * * * ? *"; } } \ No newline at end of file