更新电表,充电机启动完成帧更新启动状态和 启动时间

zw
CZ 6 months ago
parent e229aa459b
commit 73b0c361fa

@ -24,12 +24,15 @@ public static class ChargerConst
/// </summary> /// </summary>
public enum ChargingStatus public enum ChargingStatus
{ {
UnKnown, UnKnown=0,
Authed, StartChargingSuccess=1,
AuthFailed,
StartChargingSuccess, StopChargingSuccess=4,
StartChargingFailed, Authed=5,
Charging, AuthFailed=6,
StopChargingSuccess,
StopChargingFailed StartChargingFailed=7,
// Charging,
StopChargingFailed=8
} }

@ -1,6 +1,8 @@
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using log4net; using log4net;
using Repository.Station;
using Service.Charger.Client; using Service.Charger.Client;
using Service.Charger.Common; using Service.Charger.Common;
using Service.Charger.Msg.Charger.Resp; using Service.Charger.Msg.Charger.Resp;
@ -19,6 +21,9 @@ namespace Service.Charger.Handler
public class RemoteStartChargingResHandler : SimpleChannelInboundHandler<RemoteStartChargingRes>, IBaseHandler public class RemoteStartChargingResHandler : SimpleChannelInboundHandler<RemoteStartChargingRes>, IBaseHandler
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(RemoteStartChargingResHandler)); private static readonly ILog Log = LogManager.GetLogger(typeof(RemoteStartChargingResHandler));
public ChargeOrderRepository ChargeOrderRepository { get; set; }
protected override void ChannelRead0(IChannelHandlerContext ctx, RemoteStartChargingRes msg) protected override void ChannelRead0(IChannelHandlerContext ctx, RemoteStartChargingRes msg)
{ {
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
@ -29,6 +34,16 @@ namespace Service.Charger.Handler
client.IsStopped = false; client.IsStopped = false;
client.ChargingStatus = (int)ChargingStatus.StartChargingSuccess; client.ChargingStatus = (int)ChargingStatus.StartChargingSuccess;
client.ChargingStartTime = DateTime.Now; client.ChargingStartTime = DateTime.Now;
//查找最新的充电订单
List<ChargeOrder> chargeOrders = ChargeOrderRepository.QueryListByClause(i => i.BatteryNo == client.BatteryNo, "created_time desc")
.Take(1).ToList();
if (chargeOrders.Count > 0)
{
ChargeOrder one = chargeOrders[0];
ChargeOrderRepository.Update(i => i.CmdStatus == 1 && i.StartTime == client.ChargingStartTime,
it => it.Id == one.Id);
}
} }
else else
{ {

@ -34,6 +34,8 @@ public class EmeterEnergyRecordTask : ITask
{ {
try try
{ {
List<EmeterEnergy> list = new List<EmeterEnergy>();
List<EmeterEnergyChange> listEmeterEnergyChanges = new List<EmeterEnergyChange>();
foreach (var keyValuePair in ClientMgr.Dictionary) foreach (var keyValuePair in ClientMgr.Dictionary)
{ {
var chargerClient = keyValuePair.Value; var chargerClient = keyValuePair.Value;
@ -41,27 +43,43 @@ public class EmeterEnergyRecordTask : ITask
{ {
string id = DateTime.Now.ToString("yyyyMMddHHmmss"); string id = DateTime.Now.ToString("yyyyMMddHHmmss");
string code = StaticStationInfo.StationNo + "_" + chargerClient.Sn;
id = id + "_" + chargerClientSn;
EmeterEnergy emeterEnergy = new() EmeterEnergy emeterEnergy = new()
{ {
Id = id, Id = id,
UploadFlag = 0, UploadFlag = 0,
Value = chargerClient.UploadTelemetryData.DcMeterCurrentPower, Value = chargerClient.UploadTelemetryData.DcMeterCurrentPower,
Code = StaticStationInfo.StationNo + "_" + chargerClient.Sn, Code =code ,
UploadTime = DateTime.Now UploadTime = DateTime.Now
}; };
EmeterEnergyRepository.Insert(emeterEnergy); list.Add(emeterEnergy);
EmeterEnergyChange emeterEnergyChange = new() EmeterEnergyChange emeterEnergyChange = new()
{ {
Id = id, Id = id,
UploadFlag = 0, UploadFlag = 0,
Value = chargerClient.UploadTelemetryData.ACMeterCurrentBatteryValue, Value = chargerClient.UploadTelemetryData.ACMeterCurrentBatteryValue,
Code = StaticStationInfo.StationNo + "_" + chargerClient.Sn, Code = code,
UploadTime = DateTime.Now UploadTime = DateTime.Now
}; };
EmeterEnergyChangeRepository.Insert(emeterEnergyChange); listEmeterEnergyChanges.Add(emeterEnergyChange);
} }
} }
if (list.Count > 0)
{
EmeterEnergyRepository.Insert(list);
}
if (listEmeterEnergyChanges.Count > 0)
{
EmeterEnergyChangeRepository.Insert(listEmeterEnergyChanges);
}
} }
catch (Exception e) catch (Exception e)
{ {

Loading…
Cancel
Save