From 4997beda765dec2f9c5bfcf04162d39cf82cdcc3 Mon Sep 17 00:00:00 2001 From: lxw Date: Fri, 7 Jun 2024 15:00:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E8=A1=A8=E6=95=B0=E6=8D=AE=E8=90=BD?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/DbModel/Station/EmeterEnergy.cs | 9 +- Entity/DbModel/Station/EmeterEnergyChange.cs | 9 +- .../Charger/MyTask/EmeterEnergyRecordTask.cs | 88 +++++++++++++++++++ 3 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 Service/Charger/MyTask/EmeterEnergyRecordTask.cs diff --git a/Entity/DbModel/Station/EmeterEnergy.cs b/Entity/DbModel/Station/EmeterEnergy.cs index 157944d..6ee10e4 100644 --- a/Entity/DbModel/Station/EmeterEnergy.cs +++ b/Entity/DbModel/Station/EmeterEnergy.cs @@ -2,6 +2,9 @@ using SqlSugar; namespace Entity.DbModel.Station; +/// +/// 直流电表实时插入数据 +/// [SugarTable("emeter_energy")] public class EmeterEnergy { @@ -19,15 +22,15 @@ public class EmeterEnergy /// 电表当前读数 /// [SugarColumn(ColumnName = "value")] - public virtual string Value { get; set; } + public virtual float Value { get; set; } /// /// 充电机上报时间 /// [SugarColumn(ColumnName = "upload_time")] - public virtual string UploadTime { get; set; } + public virtual DateTime UploadTime { get; set; } /// /// 上报标识:0未上传 1上传 /// [SugarColumn(ColumnName = "upload_flag")] - public virtual string UploadFlag { get; set; } + public virtual int UploadFlag { get; set; } } \ No newline at end of file diff --git a/Entity/DbModel/Station/EmeterEnergyChange.cs b/Entity/DbModel/Station/EmeterEnergyChange.cs index 28c6042..0350c98 100644 --- a/Entity/DbModel/Station/EmeterEnergyChange.cs +++ b/Entity/DbModel/Station/EmeterEnergyChange.cs @@ -2,6 +2,9 @@ using SqlSugar; namespace Entity.DbModel.Station; +/// +/// 交流电表实时插入数据 +/// [SugarTable("emeter_energy_change")] public class EmeterEnergyChange { @@ -19,16 +22,16 @@ public class EmeterEnergyChange /// 电表当前读数 /// [SugarColumn(ColumnName = "value")] - public virtual string Value { get; set; } + public virtual float Value { get; set; } /// /// 充电机上报时间 /// [SugarColumn(ColumnName = "upload_time")] - public virtual string UploadTime { get; set; } + public virtual DateTime UploadTime { get; set; } /// /// 上报标识:0未上传 1上传 /// [SugarColumn(ColumnName = "upload_flag")] - public virtual string UploadFlag { get; set; } + public virtual int UploadFlag { get; set; } } \ No newline at end of file diff --git a/Service/Charger/MyTask/EmeterEnergyRecordTask.cs b/Service/Charger/MyTask/EmeterEnergyRecordTask.cs new file mode 100644 index 0000000..2aa62a5 --- /dev/null +++ b/Service/Charger/MyTask/EmeterEnergyRecordTask.cs @@ -0,0 +1,88 @@ +using Common.Const; +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.AutoTask; +using HybirdFrameworkCore.Entity; +using HybirdFrameworkCore.Utils; +using log4net; +using Repository.Station; +using Service.Charger.Client; +using Service.Init; + +namespace Service.Charger.MyTask; + +[Scope] +public class EmeterEnergyRecordTask : ITask +{ + private static readonly ILog Log = LogManager.GetLogger(typeof(EmeterEnergyRecordTask)); + private volatile bool _stop; + + public EmeterEnergyRepository EmeterEnergyRepository { get; set; } + public EmeterEnergyChangeRepository EmeterEnergyChangeRepository { get; set; } + + public string Name() + { + return "EmeterEnergyRecordTask"; + } + + public int Interval() + { + return 1000 * 15; + } + + public void Handle() + { + try + { + foreach (var keyValuePair in ClientMgr.Dictionary) + { + var chargerClient = keyValuePair.Value; + if (chargerClient.Connected) + { + //充电机工作中,正在充电中 + if (chargerClient.Workstate == 2 && chargerClient.ChargingStatus == 5) + { + string id = DateTime.Now.ToString("yyyyMMddHHmmss"); + EmeterEnergy emeterEnergy = new() + { + Id = id, + UploadFlag = 0, + Value = chargerClient.UploadTelemetryData.DcMeterCurrentPower, + Code = StaticStationInfo.StationNo + "_" + chargerClient.Sn, + UploadTime = DateTime.Now + }; + EmeterEnergyRepository.Insert(emeterEnergy); + EmeterEnergyChange emeterEnergyChange = new() + { + Id = id, + UploadFlag = 0, + Value = chargerClient.UploadTelemetryData.ACMeterCurrentBatteryValue, + Code = StaticStationInfo.StationNo + "_" + chargerClient.Sn, + UploadTime = DateTime.Now + }; + EmeterEnergyChangeRepository.Insert(emeterEnergyChange); + } + } + } + } + catch (Exception e) + { + Log.Error("handle with error", e); + } + } + + public bool Stoped() + { + return _stop; + } + + public void Stop() + { + _stop = true; + } + + public void ResetStop() + { + _stop = false; + } +} \ No newline at end of file