电表数据落库

master
lxw 6 months ago
parent e62cd8272c
commit 4997beda76

@ -2,6 +2,9 @@ using SqlSugar;
namespace Entity.DbModel.Station; namespace Entity.DbModel.Station;
/// <summary>
/// 直流电表实时插入数据
/// </summary>
[SugarTable("emeter_energy")] [SugarTable("emeter_energy")]
public class EmeterEnergy public class EmeterEnergy
{ {
@ -19,15 +22,15 @@ public class EmeterEnergy
/// 电表当前读数 /// 电表当前读数
/// </summary> /// </summary>
[SugarColumn(ColumnName = "value")] [SugarColumn(ColumnName = "value")]
public virtual string Value { get; set; } public virtual float Value { get; set; }
/// <summary> /// <summary>
/// 充电机上报时间 /// 充电机上报时间
/// </summary> /// </summary>
[SugarColumn(ColumnName = "upload_time")] [SugarColumn(ColumnName = "upload_time")]
public virtual string UploadTime { get; set; } public virtual DateTime UploadTime { get; set; }
/// <summary> /// <summary>
/// 上报标识0未上传 1上传 /// 上报标识0未上传 1上传
/// </summary> /// </summary>
[SugarColumn(ColumnName = "upload_flag")] [SugarColumn(ColumnName = "upload_flag")]
public virtual string UploadFlag { get; set; } public virtual int UploadFlag { get; set; }
} }

@ -2,6 +2,9 @@ using SqlSugar;
namespace Entity.DbModel.Station; namespace Entity.DbModel.Station;
/// <summary>
/// 交流电表实时插入数据
/// </summary>
[SugarTable("emeter_energy_change")] [SugarTable("emeter_energy_change")]
public class EmeterEnergyChange public class EmeterEnergyChange
{ {
@ -19,16 +22,16 @@ public class EmeterEnergyChange
/// 电表当前读数 /// 电表当前读数
/// </summary> /// </summary>
[SugarColumn(ColumnName = "value")] [SugarColumn(ColumnName = "value")]
public virtual string Value { get; set; } public virtual float Value { get; set; }
/// <summary> /// <summary>
/// 充电机上报时间 /// 充电机上报时间
/// </summary> /// </summary>
[SugarColumn(ColumnName = "upload_time")] [SugarColumn(ColumnName = "upload_time")]
public virtual string UploadTime { get; set; } public virtual DateTime UploadTime { get; set; }
/// <summary> /// <summary>
/// 上报标识0未上传 1上传 /// 上报标识0未上传 1上传
/// </summary> /// </summary>
[SugarColumn(ColumnName = "upload_flag")] [SugarColumn(ColumnName = "upload_flag")]
public virtual string UploadFlag { get; set; } public virtual int UploadFlag { get; set; }
} }

@ -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;
}
}
Loading…
Cancel
Save