|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
using Autofac;
|
|
|
|
|
using Autofac.Core;
|
|
|
|
|
using Common.Util;
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
|
using HybirdFrameworkCore.Autofac;
|
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
|
using HybirdFrameworkDriver.Common;
|
|
|
|
@ -11,18 +12,17 @@ using MQTTnet.Client;
|
|
|
|
|
using MQTTnet.Client.Connecting;
|
|
|
|
|
using MQTTnet.Client.Disconnecting;
|
|
|
|
|
using MQTTnet.Client.Options;
|
|
|
|
|
using MQTTnet.Client.Publishing;
|
|
|
|
|
using MQTTnet.Client.Receiving;
|
|
|
|
|
using MQTTnet.Formatter;
|
|
|
|
|
using MQTTnet.Protocol;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using Repository.Station;
|
|
|
|
|
using Service.Cloud.Handler;
|
|
|
|
|
using Service.Cloud.Msg;
|
|
|
|
|
using Service.Cloud.Msg.Cloud.Req;
|
|
|
|
|
using Service.Cloud.Msg.Cloud.Resp;
|
|
|
|
|
using Service.Cloud.Msg.Host.Req;
|
|
|
|
|
using Service.Init;
|
|
|
|
|
|
|
|
|
|
namespace Service.Cloud.Client;
|
|
|
|
|
|
|
|
|
@ -31,6 +31,8 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
|
|
|
|
|
IMqttClientDisconnectedHandler
|
|
|
|
|
{
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(CloudClient));
|
|
|
|
|
|
|
|
|
|
public SwapOrderRepository SwapOrderRepository { get; set;}
|
|
|
|
|
|
|
|
|
|
#region tcp param
|
|
|
|
|
|
|
|
|
@ -82,8 +84,10 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
|
|
|
|
|
public MsgPair<SignIn, SignInResp> Sign { get; set; } = new();
|
|
|
|
|
public MsgPair<StartLogMessage, StartLogMessageResp> StartLog { get; set; } = new();
|
|
|
|
|
public MsgPair<TemperatureHumidityData, TemperatureHumidityDataResp> TemperatureHumidity { get; set; } = new();
|
|
|
|
|
public MsgPair<UploadPowerChangeOrder, UploadPowerChangeOrderResp> UploadPowerChange { get; set; } = new();
|
|
|
|
|
public MsgPair<UploadSwapOrder, UploadSwapOrderResp> UploadPowerChange { get; set; } = new();
|
|
|
|
|
public MsgPair<VehicleDataReporting, VehicleDataReportingResp> VehicleData { get; set; } = new();
|
|
|
|
|
public MsgPair<ChargeRecordUpLoad, ChargeRecordUploadRes> ChargeRecordUpLoad { get; set; } = new();
|
|
|
|
|
public MsgPair<ChargeDevDataInfo, ChargeDevDataInfoRes> ChargeDevDataInfo { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
@ -193,14 +197,23 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
|
|
|
|
|
{
|
|
|
|
|
await DoSubTopic(SubTopic);
|
|
|
|
|
|
|
|
|
|
SendSignIn(new SignIn()
|
|
|
|
|
SendVehicleCertification(new VehicleCertification()
|
|
|
|
|
{
|
|
|
|
|
sn = StaticStationInfo.StationNo,
|
|
|
|
|
st = "01",
|
|
|
|
|
ss = StaticStationInfo.StationStatus,
|
|
|
|
|
dt = DateTime.Now,
|
|
|
|
|
en = 1,
|
|
|
|
|
cn = 7
|
|
|
|
|
mode =1,
|
|
|
|
|
rfid= "LZ5NB6D33RB000438",
|
|
|
|
|
ty= 2,
|
|
|
|
|
vi ="LZ5NB6D33RB000438"
|
|
|
|
|
});
|
|
|
|
|
// SendSignIn(new SignIn()
|
|
|
|
|
// {
|
|
|
|
|
// sn = StaticStationInfo.StationNo,
|
|
|
|
|
// st = "01",
|
|
|
|
|
// ss = StaticStationInfo.StationStatus,
|
|
|
|
|
// en = 1,
|
|
|
|
|
// cn = 7
|
|
|
|
|
// });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task DoSubTopic(string topic)
|
|
|
|
@ -229,7 +242,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
|
|
|
|
|
Header = new Header()
|
|
|
|
|
{
|
|
|
|
|
cmd = data.GetCmd(),
|
|
|
|
|
chipherFlag = Encrypt,
|
|
|
|
|
cipherFlag = Encrypt,
|
|
|
|
|
id = GetIncrementId(),
|
|
|
|
|
sid = StationNo,
|
|
|
|
|
timeStamp = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000
|
|
|
|
@ -237,7 +250,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
|
|
|
|
|
body = data
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
model.dataSign = SignData(model);
|
|
|
|
|
model.dataSign = "";//SignData(model);
|
|
|
|
|
|
|
|
|
|
var settings = new JsonSerializerSettings()
|
|
|
|
|
{
|
|
|
|
@ -245,6 +258,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
|
|
|
|
|
DateFormatString = "yyyy-MM-dd HH:mm:ss",
|
|
|
|
|
NullValueHandling = NullValueHandling.Ignore
|
|
|
|
|
};
|
|
|
|
|
Log.Info(JsonConvert.SerializeObject(model, settings));
|
|
|
|
|
var appMsg = new MqttApplicationMessage
|
|
|
|
|
{
|
|
|
|
|
Topic = PubTopic,
|
|
|
|
@ -253,12 +267,8 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
|
|
|
|
|
Retain = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Task<MqttClientPublishResult> task = MqttClient.PublishAsync(appMsg);
|
|
|
|
|
var result = task.Result;
|
|
|
|
|
if (result.ReasonCode == MqttClientPublishReasonCode.Success)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"send {JsonConvert.SerializeObject(model, settings)} success");
|
|
|
|
|
}
|
|
|
|
|
MqttClient.PublishAsync(appMsg);
|
|
|
|
|
MqttClient.PublishAsync(appMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string SignData<T>(Model<T> model) where T : ICmd
|
|
|
|
@ -460,14 +470,13 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上传换电订单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uploadPowerChangeOrder"></param>
|
|
|
|
|
/// <param name="uploadSwapOrder"></param>
|
|
|
|
|
/// <param name="timeSpan"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public UploadPowerChangeOrderResp? SendUploadPowerChangeOrder(UploadPowerChangeOrder uploadPowerChangeOrder,
|
|
|
|
|
TimeSpan timeSpan)
|
|
|
|
|
public UploadSwapOrderResp? SendUploadPowerChangeOrder(UploadSwapOrder uploadSwapOrder, TimeSpan? timeSpan = null)
|
|
|
|
|
{
|
|
|
|
|
this.UploadPowerChange.Req = uploadPowerChangeOrder;
|
|
|
|
|
this.Publish(uploadPowerChangeOrder);
|
|
|
|
|
this.UploadPowerChange.Req = uploadSwapOrder;
|
|
|
|
|
this.Publish(uploadSwapOrder);
|
|
|
|
|
return UploadPowerChange.GetResp(timeSpan);
|
|
|
|
|
}
|
|
|
|
|
public VehicleDataReportingResp? SendVehicleDataReporting(VehicleDataReporting vehicleDataReporting,
|
|
|
|
@ -477,5 +486,61 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
|
|
|
|
|
this.Publish(vehicleDataReporting);
|
|
|
|
|
return VehicleData.GetResp(timeSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ChargeRecordUploadRes? SendChargeRecordUpLoad(ChargeRecordUpLoad req, TimeSpan? timeSpan = null)
|
|
|
|
|
{
|
|
|
|
|
this.ChargeRecordUpLoad.Req = req;
|
|
|
|
|
this.Publish(req);
|
|
|
|
|
return ChargeRecordUpLoad.GetResp(timeSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ChargeDevDataInfoRes? SendChargeDevDataInfo(ChargeDevDataInfo req, TimeSpan? timeSpan = null)
|
|
|
|
|
{
|
|
|
|
|
this.ChargeDevDataInfo.Req = req;
|
|
|
|
|
this.Publish(req);
|
|
|
|
|
return ChargeDevDataInfo.GetResp(timeSpan);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region business func
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="chargeOrder"></param>
|
|
|
|
|
/// <param name="op">1: 自动; 2: 人工手动</param>
|
|
|
|
|
/// <param name="timeSpan">超时等待</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool PublishChargeOrder(ChargeOrder chargeOrder, int op, TimeSpan? timeSpan = null)
|
|
|
|
|
{
|
|
|
|
|
string swapOrderSn = chargeOrder.SwapOrderSn;
|
|
|
|
|
SwapOrder? swapOrder = SwapOrderRepository.QueryByClause(it => it.Sn == swapOrderSn);
|
|
|
|
|
ChargeRecordUpLoad req = new ChargeRecordUpLoad()
|
|
|
|
|
{
|
|
|
|
|
chrsn = chargeOrder.Sn,
|
|
|
|
|
son = swapOrderSn,
|
|
|
|
|
bid = chargeOrder.BatteryNo,
|
|
|
|
|
st = chargeOrder.StartTime ?? DateTime.Now,
|
|
|
|
|
et = chargeOrder.EndTime ?? DateTime.Now,
|
|
|
|
|
ssoc = chargeOrder.StartSoc ?? 0,
|
|
|
|
|
esoc = chargeOrder.StopSoc ?? 0,
|
|
|
|
|
//ssoe = chargeOrder.soe
|
|
|
|
|
//esoe
|
|
|
|
|
dcce = Convert.ToSingle(chargeOrder.StopDcElec ?? 0 - chargeOrder.StartDcElec ?? 0),
|
|
|
|
|
acce = Convert.ToSingle(chargeOrder.StopAcElec ?? 0 - chargeOrder.StartAcElec ?? 0),
|
|
|
|
|
tp = Convert.ToSingle(chargeOrder.SharpElecCount),
|
|
|
|
|
pp = Convert.ToSingle(chargeOrder.PeakElecCount),
|
|
|
|
|
fp = Convert.ToSingle(chargeOrder.FlatElecCount),
|
|
|
|
|
vp = Convert.ToSingle(chargeOrder.ValleyElecCount),
|
|
|
|
|
ct = ((chargeOrder.EndTime ?? DateTime.Now).Subtract(chargeOrder.StartTime ?? DateTime.Now)).Minutes,
|
|
|
|
|
cn = 1,
|
|
|
|
|
sfs = op,
|
|
|
|
|
vin = swapOrder?.VehicleVin,
|
|
|
|
|
sfoc = op,
|
|
|
|
|
};
|
|
|
|
|
this.SendChargeRecordUpLoad(req);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|