|
|
|
|
using DotNetty.Transport.Channels;
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
|
using HybirdFrameworkCore.Configuration;
|
|
|
|
|
using HybirdFrameworkCore.Redis;
|
|
|
|
|
using log4net;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Repository.Station;
|
|
|
|
|
using Service.Charger.Client;
|
|
|
|
|
using Service.Charger.Msg.Charger.Req;
|
|
|
|
|
|
|
|
|
|
namespace Service.Charger.Handler
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 遥测数据上报Handler
|
|
|
|
|
/// </summary>
|
|
|
|
|
//TODO::Order 应该是多少
|
|
|
|
|
[Order(8)]
|
|
|
|
|
[Scope("InstancePerDependency")]
|
|
|
|
|
public class UploadTelemetryDataHandler : SimpleChannelInboundHandler<UploadTelemetryData>, IBaseHandler
|
|
|
|
|
{
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(UploadTelemetryDataHandler));
|
|
|
|
|
public ChargeOrderRepository ChargeOrderRepository { get; set; }
|
|
|
|
|
public RedisHelper RedisHelper { get; set; }
|
|
|
|
|
protected override void ChannelRead0(IChannelHandlerContext ctx, UploadTelemetryData msg)
|
|
|
|
|
{
|
|
|
|
|
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
|
|
|
|
|
{
|
|
|
|
|
msg.ChargerNo = sn;
|
|
|
|
|
|
|
|
|
|
float DcMeterCurrentPower = client.UploadTelemetryData.DcMeterCurrentPower;
|
|
|
|
|
if (DcMeterCurrentPower==0)
|
|
|
|
|
{
|
|
|
|
|
List<ChargeOrder> chargeOrders = ChargeOrderRepository
|
|
|
|
|
.QueryListByClause(i => i.ChargerNo == client.BinNo&&i.StopDcElec!=null, "created_time desc")
|
|
|
|
|
.Take(1).ToList();
|
|
|
|
|
if (chargeOrders.Count>0)
|
|
|
|
|
{
|
|
|
|
|
DcMeterCurrentPower = (float)chargeOrders[0].StopDcElec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Log.Info($"receive {msg} from {sn}");
|
|
|
|
|
|
|
|
|
|
/*if (!AppSettingsConstVars.DisabledTask.Contains("UploadTelemetryData"))
|
|
|
|
|
{
|
|
|
|
|
RedisHelper.PublishAsync("UploadTelemetryData", JsonConvert.SerializeObject(msg));
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
client.UploadTelemetryData = msg;
|
|
|
|
|
if (msg.DcMeterCurrentPower< DcMeterCurrentPower)//处理电表数据在电池移走之后值变小的问题
|
|
|
|
|
{
|
|
|
|
|
client.UploadTelemetryData.DcMeterCurrentPower = DcMeterCurrentPower;
|
|
|
|
|
}
|
|
|
|
|
//充电机实时充电功率
|
|
|
|
|
client.RealTimeChargePower = msg.DcMeterCurrent * msg.DcMeterVoltage;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|