|
|
|
@ -1,254 +0,0 @@
|
|
|
|
|
using Common.Util;
|
|
|
|
|
using DotNetty.Transport.Channels;
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
|
using log4net;
|
|
|
|
|
using Repository.Station;
|
|
|
|
|
using Service.Charger.Client;
|
|
|
|
|
using Service.Charger.Common;
|
|
|
|
|
using Service.Charger.Msg.Charger.OutCharger.Req;
|
|
|
|
|
using Service.Charger.Msg.Host.Resp.OutCharger;
|
|
|
|
|
using Service.Charger.Msg.Http.Req;
|
|
|
|
|
using Service.Init;
|
|
|
|
|
|
|
|
|
|
namespace Service.Charger.Handler.OutCharger;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 3.7.13 充电桩上送充电记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Order(8)]
|
|
|
|
|
[Scope("InstancePerDependency")]
|
|
|
|
|
public class PileUploadChargeRecordHandler : SimpleChannelInboundHandler<PileUploadChargeRecord>, IBaseHandler
|
|
|
|
|
{
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(PileUploadChargeRecordHandler));
|
|
|
|
|
|
|
|
|
|
public ChargeOrderRepository ChargeOrderRepository { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void ChannelRead0(IChannelHandlerContext ctx, PileUploadChargeRecord msg)
|
|
|
|
|
{
|
|
|
|
|
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
|
|
|
|
|
{
|
|
|
|
|
if (client == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float[] powersPeriods = new float[4] { 0, 0, 0, 0 }; //元素索引顺序代表值;1:尖;2:峰;3:平;4:谷
|
|
|
|
|
var acPowersPeriods = PeaksAndValleys(msg, powersPeriods);
|
|
|
|
|
|
|
|
|
|
Log.Info($"receive {msg} from {sn}");
|
|
|
|
|
ChargeOrder chargeOrder = ChargeOrderRepository.QueryByClause(it => it.Sn == msg.ChargeOrderNo);
|
|
|
|
|
|
|
|
|
|
var startTime = new DateTime(msg.StartYear + 2000, msg.StartMonth, msg.StartDay, msg.StartHour,
|
|
|
|
|
msg.StartMinute, msg.StartSecond);
|
|
|
|
|
var endTime = new DateTime(msg.EndYear + 2000, msg.EndMonth, msg.EndDay, msg.EndHour, msg.EndMinute,
|
|
|
|
|
msg.EndSecond);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float chargingPower = msg.ChargingPower;
|
|
|
|
|
var socBefore = msg.SocBefore;
|
|
|
|
|
byte socAfter = msg.SocAfter;
|
|
|
|
|
|
|
|
|
|
void UpdateChargeOrder(ChargeOrder order)
|
|
|
|
|
{
|
|
|
|
|
order.StartTime = startTime;
|
|
|
|
|
order.EndTime = endTime;
|
|
|
|
|
order.StartSoc = socBefore;
|
|
|
|
|
order.StopSoc = socAfter;
|
|
|
|
|
order.ChargeTimeCount = (int)(endTime - startTime).TotalMinutes;
|
|
|
|
|
order.ElecCount = Convert.ToDecimal(chargingPower);
|
|
|
|
|
order.AcElecCount = Convert.ToDecimal(msg.AcMeterElecCount);
|
|
|
|
|
order.StartAcElec = Convert.ToDecimal(msg.AcMeterDataBefore);
|
|
|
|
|
order.StopAcElec = Convert.ToDecimal(msg.AcMeterDataAfter);
|
|
|
|
|
order.StartDcElec = Convert.ToDecimal(msg.DcMeterDataBefore);
|
|
|
|
|
order.StopDcElec = Convert.ToDecimal(msg.DcMeterDataAfter);
|
|
|
|
|
order.SharpElecCount = Convert.ToDecimal(powersPeriods[0]);
|
|
|
|
|
order.PeakElecCount = Convert.ToDecimal(powersPeriods[1]);
|
|
|
|
|
order.FlatElecCount = Convert.ToDecimal(powersPeriods[2]);
|
|
|
|
|
order.ValleyElecCount = Convert.ToDecimal(powersPeriods[3]);
|
|
|
|
|
order.AcSharpElecCount = Convert.ToDecimal(acPowersPeriods[0]);
|
|
|
|
|
order.AcPeakElecCount = Convert.ToDecimal(acPowersPeriods[1]);
|
|
|
|
|
order.AcFlatElecCount = Convert.ToDecimal(acPowersPeriods[2]);
|
|
|
|
|
order.AcValleyElecCount = Convert.ToDecimal(acPowersPeriods[3]);
|
|
|
|
|
order.ChargeMode = msg.ChargeMode;
|
|
|
|
|
order.StartMode = msg.StartMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (chargeOrder == null)
|
|
|
|
|
{
|
|
|
|
|
ChargeOrder newOrder = new ChargeOrder()
|
|
|
|
|
{
|
|
|
|
|
Sn = msg.ChargeOrderNo
|
|
|
|
|
};
|
|
|
|
|
UpdateChargeOrder(newOrder);
|
|
|
|
|
ChargeOrderRepository.Insert(newOrder);
|
|
|
|
|
|
|
|
|
|
PileEndChargeReq req = new PileEndChargeReq();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
req.sn = StaticStationInfo.StationNo;
|
|
|
|
|
|
|
|
|
|
req.con = msg.ChargeOrderNo;
|
|
|
|
|
req.cosn = msg.ChargeOrderNo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UploadChargeRecord(msg, client, req, sn, startTime, endTime, chargingPower, socBefore, socAfter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UpdateChargeOrder(chargeOrder);
|
|
|
|
|
// 充电完成入库
|
|
|
|
|
ChargeOrderRepository.Update(chargeOrder);
|
|
|
|
|
|
|
|
|
|
PileEndChargeReq req = new PileEndChargeReq();
|
|
|
|
|
|
|
|
|
|
req.sn = StaticStationInfo.StationNo;
|
|
|
|
|
req.con = chargeOrder.CloudChargeOrder;
|
|
|
|
|
req.cosn = chargeOrder.Sn;
|
|
|
|
|
|
|
|
|
|
// 充电完成上报云平台
|
|
|
|
|
UploadChargeRecord(msg, client, req, sn, startTime, endTime, chargingPower, socBefore, socAfter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.Channel.WriteAndFlushAsync(new PileUploadChargeRecordRes(msg.Pn));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UploadChargeRecord(PileUploadChargeRecord msg, ChargerClient client, PileEndChargeReq req,
|
|
|
|
|
string sn, DateTime startTime, DateTime endTime, float chargingPower, byte socBefore, byte socAfter)
|
|
|
|
|
{
|
|
|
|
|
ChargerPile chargerPile = client.ChargerPile[msg.Pn];
|
|
|
|
|
req.pn = ChargerUtils.ReverseCalculateChargerGun(msg.Pn, sn);
|
|
|
|
|
req.ct = chargerPile.ct;
|
|
|
|
|
req.cp = chargerPile.cp;
|
|
|
|
|
req.st = chargerPile.st;
|
|
|
|
|
req.cst = startTime;
|
|
|
|
|
req.cet = endTime;
|
|
|
|
|
req.ceq = chargingPower;
|
|
|
|
|
req.cssoc = socBefore;
|
|
|
|
|
req.cesoc = socAfter;
|
|
|
|
|
|
|
|
|
|
req.ctn = msg.ChargingTimeCount;
|
|
|
|
|
|
|
|
|
|
List<PeriodReq> periodList = new List<PeriodReq>();
|
|
|
|
|
// 利用反射组装充电时间段数据
|
|
|
|
|
for (int i = 1; i <= msg.ChargingTimeCount; i++)
|
|
|
|
|
{
|
|
|
|
|
PeriodReq periodReq = new PeriodReq();
|
|
|
|
|
// 获取属性
|
|
|
|
|
var startTimeHourProperty = typeof(PileUploadChargeRecord).GetProperty($"StartTime{i}");
|
|
|
|
|
var startTimeMinuteProperty = typeof(PileUploadChargeRecord).GetProperty($"StartTimeMinute{i}");
|
|
|
|
|
|
|
|
|
|
if (startTimeHourProperty != null && startTimeMinuteProperty != null)
|
|
|
|
|
{
|
|
|
|
|
// 获取值
|
|
|
|
|
byte startTimeHour = (byte)startTimeHourProperty.GetValue(msg);
|
|
|
|
|
byte startTimeMinute = (byte)startTimeMinuteProperty.GetValue(msg);
|
|
|
|
|
periodReq.StartTimeMinute = DateUtils.GetFormattedTime(startTimeHour, startTimeMinute);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var chargingPowerProperty = typeof(PileUploadChargeRecord).GetProperty($"ChargingPowerOfTime{i}");
|
|
|
|
|
var flagOfTimeProperty = typeof(PileUploadChargeRecord).GetProperty($"FlagOfTime{i}");
|
|
|
|
|
if (chargingPowerProperty != null && flagOfTimeProperty != null)
|
|
|
|
|
{
|
|
|
|
|
periodReq.ChargingPowerOfTime = (float)chargingPowerProperty.GetValue(msg);
|
|
|
|
|
periodReq.FlagOfTime = (byte)flagOfTimeProperty.GetValue(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
periodList.Add(periodReq);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req.ctl = periodList;
|
|
|
|
|
|
|
|
|
|
req.cvin = chargerPile.Vin;
|
|
|
|
|
|
|
|
|
|
HttpUtil.SendPostRequest(req, "http://127.0.0.1:5034/api/OutCharger/SendPileEndCharge");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static float[] PeaksAndValleys(PileUploadChargeRecord msg, float[] powersPeriods)
|
|
|
|
|
{
|
|
|
|
|
if (msg.FlagOfTime1 >= 1 && msg.FlagOfTime1 <= 4)
|
|
|
|
|
{
|
|
|
|
|
powersPeriods[msg.FlagOfTime1 - 1] += msg.ChargingPowerOfTime1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.FlagOfTime2 >= 1 && msg.FlagOfTime2 <= 4)
|
|
|
|
|
{
|
|
|
|
|
powersPeriods[msg.FlagOfTime2 - 1] += msg.ChargingPowerOfTime2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.FlagOfTime3 >= 1 && msg.FlagOfTime3 <= 4)
|
|
|
|
|
{
|
|
|
|
|
powersPeriods[msg.FlagOfTime3 - 1] += msg.ChargingPowerOfTime3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.FlagOfTime4 >= 1 && msg.FlagOfTime4 <= 4)
|
|
|
|
|
{
|
|
|
|
|
powersPeriods[msg.FlagOfTime4 - 1] += msg.ChargingPowerOfTime4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.FlagOfTime5 >= 1 && msg.FlagOfTime5 <= 4)
|
|
|
|
|
{
|
|
|
|
|
powersPeriods[msg.FlagOfTime5 - 1] += msg.ChargingPowerOfTime5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.FlagOfTime6 >= 1 && msg.FlagOfTime6 <= 4)
|
|
|
|
|
{
|
|
|
|
|
powersPeriods[msg.FlagOfTime6 - 1] += msg.ChargingPowerOfTime6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.FlagOfTime7 >= 1 && msg.FlagOfTime7 <= 4)
|
|
|
|
|
{
|
|
|
|
|
powersPeriods[msg.FlagOfTime7 - 1] += msg.ChargingPowerOfTime7;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.FlagOfTime8 >= 1 && msg.FlagOfTime8 <= 4)
|
|
|
|
|
{
|
|
|
|
|
powersPeriods[msg.FlagOfTime8 - 1] += msg.ChargingPowerOfTime8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float[] acPowersPeriods = new float[4] { 0, 0, 0, 0 }; //元素索引顺序代表值;1:尖;2:峰;3:平;4:谷
|
|
|
|
|
if (msg.AcFlagOfTime1 >= 1 && msg.AcFlagOfTime1 <= 4)
|
|
|
|
|
{
|
|
|
|
|
acPowersPeriods[msg.AcFlagOfTime1 - 1] += msg.AcChargingPowerOfTime1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.AcFlagOfTime2 >= 1 && msg.AcFlagOfTime2 <= 4)
|
|
|
|
|
{
|
|
|
|
|
acPowersPeriods[msg.AcFlagOfTime2 - 1] += msg.AcChargingPowerOfTime2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.AcFlagOfTime3 >= 1 && msg.AcFlagOfTime3 <= 4)
|
|
|
|
|
{
|
|
|
|
|
acPowersPeriods[msg.AcFlagOfTime3 - 1] += msg.AcChargingPowerOfTime3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.AcFlagOfTime4 >= 1 && msg.AcFlagOfTime4 <= 4)
|
|
|
|
|
{
|
|
|
|
|
acPowersPeriods[msg.AcFlagOfTime4 - 1] += msg.AcChargingPowerOfTime4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.AcFlagOfTime5 >= 1 && msg.AcFlagOfTime5 <= 4)
|
|
|
|
|
{
|
|
|
|
|
acPowersPeriods[msg.AcFlagOfTime5 - 1] += msg.AcChargingPowerOfTime5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.AcFlagOfTime6 >= 1 && msg.AcFlagOfTime6 <= 4)
|
|
|
|
|
{
|
|
|
|
|
acPowersPeriods[msg.AcFlagOfTime6 - 1] += msg.AcChargingPowerOfTime6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.AcFlagOfTime7 >= 1 && msg.AcFlagOfTime7 <= 4)
|
|
|
|
|
{
|
|
|
|
|
acPowersPeriods[msg.AcFlagOfTime7 - 1] += msg.AcChargingPowerOfTime7;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.AcFlagOfTime8 >= 1 && msg.AcFlagOfTime8 <= 4)
|
|
|
|
|
{
|
|
|
|
|
acPowersPeriods[msg.AcFlagOfTime8 - 1] += msg.AcChargingPowerOfTime8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return acPowersPeriods;
|
|
|
|
|
}
|
|
|
|
|
}
|