1、新增Task仓位上报云平台 2、预约电池、取消预约、电价模型接收修改

master
tq 1 month ago
parent aba8ee8f68
commit 630de2e06b

@ -4,7 +4,7 @@ using SqlSugar;
namespace Repository.Station;
[Scope]
[Scope("SingleInstance")]
public class ElecPriceModelVersionRepository : BaseRepository<ElecPriceModelVersion>
{
public ElecPriceModelVersionRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)

@ -114,6 +114,9 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
public MsgPair<StaHourAmountVal, StaHourAmountValRes> StaHourAmountVal { get; set; } = new();
public MsgPair<BinDataInfo, BinDataInfoRes> BinDataInfo { get; set; } = new();
/// <summary>
/// 云端发-站端收
@ -568,6 +571,20 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
this.Publish(staSwapRecord);
return UploadPowerChange.GetResp(timeSpan);
}
/// <summary>
/// 上传仓位数据
/// </summary>
/// <param name="binDataInfo"></param>
/// <param name="timeSpan"></param>
/// <returns></returns>
public BinDataInfoRes? SendBinDataInfo(BinDataInfo binDataInfo, TimeSpan timeSpan)
{
this.BinDataInfo.Req = binDataInfo;
this.Publish(binDataInfo);
return BinDataInfo.GetResp(timeSpan);
}
public CardataReportRes? SendVehicleDataReporting(CardataReport cardataReport,
TimeSpan timeSpan)
{

@ -59,6 +59,10 @@ public class CloudConst
public static readonly string staHourAmountVal = "staHourAmountVal";
public static readonly string staHourAmountValRes = "staHourAmountValRes";
public static readonly string binReq = "binReq";
public static readonly string binResp = "binResp";
#endregion
#region 云端发站端收
@ -90,6 +94,9 @@ public class CloudConst
public static readonly string amtBat = "amtBat";
public static readonly string amtBatRes = "amtBatRes";
public static readonly string cancleAmtBat = "cancleAmtBat";
public static readonly string cancleAmtBatRes = "cancleAmtBatRes";
/// <summary>
/// 站外

@ -3,6 +3,7 @@ using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using Newtonsoft.Json;
using Repository.Station;
using Service.Cloud.Client;
using Service.Cloud.Common;
using Service.Cloud.Msg.Cloud.Req;
using Service.Cloud.Msg.Host.Resp;
@ -21,35 +22,34 @@ public class AmtBatHandler : IBaseHandler
_binInfoRepository = binInfoRepository;
_swapAmtOrderRepository = swapAmtOrderRepository;
}
public void Handle(string t)
{
AmtBatRes abRes = new AmtBatRes();
abRes.rs = 3;
AmtBat? amtBat = JsonConvert.DeserializeObject<AmtBat>(t);
abRes.result = 3;
if (amtBat != null)
{
int count = _swapAmtOrderRepository.GetCount(it =>
it.CarNo == amtBat.cn && it.Status == (byte)InfoEnum.AmtOrderStatus.Success);
it.CarNo == amtBat.carNo && it.Status == (byte)InfoEnum.AmtOrderStatus.Success);
if (count > 0)
{
abRes.rs = 1;
abRes.result = 1;
CloudClientMgr.CloudClient?.Publish(abRes);
}
else
{
SwapAmtOrder amtOrderInfo = new SwapAmtOrder()
{
Sn = StaticStationInfo.StationNo,
CarNo = amtBat.cn,
BatteryCount = amtBat.bm,
BatteryType = amtBat.bn,
AmtTime = amtBat.at,
ExpireTime = amtBat.at.AddMinutes(amtBat.am)
};
SwapAmtOrder amtOrderInfo = new SwapAmtOrder();
amtOrderInfo.CarNo = amtBat.carNo;
amtOrderInfo.Status = (byte)InfoEnum.AmtOrderStatus.Success;
amtOrderInfo.BatteryCount = amtBat.batteryCount;
amtOrderInfo.BatteryType = amtBat.batteryTypeNo;
amtOrderInfo.AmtTime = amtBat.appointmentTime;
amtOrderInfo.ExpireTime = amtBat.appointmentTime.AddMinutes(amtBat.lockTime);
_swapAmtOrderRepository.Insert(amtOrderInfo);
CloudClientMgr.CloudClient?.Publish(abRes);
}
}
}

@ -0,0 +1,22 @@
using HybirdFrameworkCore.Autofac.Attribute;
using Newtonsoft.Json;
using Service.Cloud.Common;
using Service.Cloud.Msg.Cloud.Resp;
namespace Service.Cloud.Handler;
[Scope("InstancePerDependency")]
public class BinDataInfoResHandler : IBaseHandler
{
public bool CanHandle(string cmd)
{
return CloudConst.binResp == cmd;
}
public void Handle(string t)
{
BinDataInfoRes? resp = JsonConvert.DeserializeObject<BinDataInfoRes>(t);
}
}

@ -0,0 +1,56 @@
using Entity.Constant;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using Newtonsoft.Json;
using Repository.Station;
using Service.Cloud.Client;
using Service.Cloud.Common;
using Service.Cloud.Msg.Cloud.Req;
using Service.Cloud.Msg.Host.Resp;
namespace Service.Cloud.Handler;
[Scope("InstancePerDependency")]
public class CancelAmtBatHandler : IBaseHandler
{
private SwapAmtOrderRepository _swapAmtOrderRepository;
public CancelAmtBatHandler(SwapAmtOrderRepository swapAmtOrderRepository)
{
_swapAmtOrderRepository = swapAmtOrderRepository;
}
public bool CanHandle(string cmd)
{
return CloudConst.cancleAmtBat == cmd;
}
public void Handle(string t)
{
CancelAmt? amtBat = JsonConvert.DeserializeObject<CancelAmt>(t);
if (amtBat==null)
{
return;
}
List<SwapAmtOrder> swapAmtOrderList = _swapAmtOrderRepository.QueryListByClause(i =>
i.CarNo ==amtBat.carNo&&i.Status==(byte)InfoEnum.AmtOrderStatus.Success);
if (swapAmtOrderList.Any())
{
swapAmtOrderList.ForEach(order => order.Status = (byte)InfoEnum.AmtOrderStatus.Cancel);
_swapAmtOrderRepository.Update(swapAmtOrderList);
}
CancelAmtRes res = new CancelAmtRes
{
stationNo = amtBat.stationNo,
result = 0,
carNo = amtBat.carNo
};
CloudClientMgr.CloudClient?.Publish(res);
}
}

@ -9,18 +9,18 @@ using Service.Cloud.Msg.Host.Resp;
namespace Service.Cloud.Handler;
[Scope]
[Scope("InstancePerDependency")]
public class ChargerElectricityPriceModelHandler : IBaseHandler
{
private ElecPriceModelVersionRepository _versionRepository;
private ElecPriceModelVersionDetailRepository _detailRepository;
private ElecPriceModelVersionRepository _versionRepository{ get; set; }
private ElecPriceModelVersionDetailRepository _detailRepository{ get; set; }
public ChargerElectricityPriceModelHandler(ElecPriceModelVersionRepository elecPriceModelVersionRepository,
ElecPriceModelVersionDetailRepository elecPriceModelVersionDetailRepository)
{
this._versionRepository = elecPriceModelVersionRepository;
this._detailRepository = elecPriceModelVersionDetailRepository;
_versionRepository = elecPriceModelVersionRepository;
_detailRepository = elecPriceModelVersionDetailRepository;
}
public bool CanHandle(string cmd)
@ -33,36 +33,38 @@ public class ChargerElectricityPriceModelHandler : IBaseHandler
SetChargePrice? priceModel = JsonConvert.DeserializeObject<SetChargePrice>(t);
if (priceModel != null)
{
ElecPriceModelVersion version = _versionRepository.QueryByClause(d => d.Version == priceModel.ceid);
ElecPriceModelVersion version = _versionRepository.QueryByClause(d => d.Version == priceModel.electricityId);
if (version == null)
{
version = new ElecPriceModelVersion
{
Version = priceModel.ceid
Version = priceModel.electricityId,
Ceid = priceModel.electricityId.ToString()
};
}
version.StartTime = DateTime.Now;
version.EndTime = DateTime.Now.AddYears(10);
_versionRepository.InsertOrUpdate(version);
List<Seg>? segs = priceModel.seg;
List<Seg>? segs = priceModel.timeList;
if (segs is { Count: > 0 })
{
List<ElecPriceModelVersionDetail> versionDetails = segs.Select(d => new ElecPriceModelVersionDetail()
{
Version = version.Version,
Price = (int)d.ep * 10000,
Type = d.pr,
StartHour = d.st.Hour,
StartMinute = d.st.Minute,
StartSecond = d.st.Second,
EndHour = d.et.Hour,
EndMinute = d.et.Minute,
EndSecond = d.et.Second
Price = d.price,
Type = d.type,
StartHour = d.startTime.Hour,
StartMinute = d.startTime.Minute,
StartSecond = d.startTime.Second,
EndHour = d.endTime.Hour,
EndMinute = d.endTime.Minute,
EndSecond = d.endTime.Second
}).ToList();
_detailRepository.Insert(versionDetails);
}
SetChargePriceRes resp = new SetChargePriceRes();
CloudClientMgr.CloudClient?.Publish(resp);
}

@ -11,29 +11,29 @@ public class AmtBat : ICmd
/// station no
/// 换电站唯一码,区域码+类型码+流水号
/// </summary>
public string sn { get; set; }
public string stationNo { get; set; }
/// <summary>
/// car no
/// </summary>
public string cn { get; set; }
public string carNo { get; set; }
/// <summary>
/// 电池型号编号
/// </summary>
public string bn { get; set; }
public string batteryTypeNo { get; set; }
/// <summary>
/// battery count
/// 默认为 1特殊车辆可能有 2 块电池
/// </summary>
public int bm { get; set; }
public int batteryCount { get; set; }
/// <summary>
/// 预约时间 格式yyyy-MM-dd HH:mm:ss
/// </summary>
public DateTime at { get; set; }
public DateTime appointmentTime { get; set; }
/// <summary>
/// 锁定时长 单位:分钟
/// 单位:分钟,一般锁定时长是 30 分钟
/// </summary>
public int am { get; set; }
public int lockTime { get; set; }
public string GetCmd()
{
return CloudConst.amtBat;

@ -0,0 +1,25 @@
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Cloud.Req;
/// <summary>
/// 5.2.3.1 后台服务器下发取消电池预约信息
/// </summary>
public class CancelAmt : ICmd
{
/// <summary>
/// station no
/// 换电站唯一码,区域码+类型码+流水号
/// </summary>
public string stationNo { get; set; }
/// <summary>
/// 车牌号
/// </summary>
public string carNo { get; set; }
public string GetCmd()
{
return CloudConst.cancleAmtBat;
}
}

@ -11,16 +11,16 @@ namespace Service.Cloud.Msg.Cloud.Req
/// 更新时间
/// 格式”yyyy-MM-dd HH:mm:ss”
/// </summary>
public string ut { get; set; }
public DateTime updateTime { get; set; }
/// <summary>
/// 电价模型id
/// 由服务器统一进行分配
/// </summary>
public int ceid { get; set; }
public int electricityId { get; set; }
public List<Seg>? seg { get; set; }
public List<Seg>? timeList { get; set; }
public string GetCmd()
{
@ -34,25 +34,25 @@ namespace Service.Cloud.Msg.Cloud.Req
/// 电价
/// 精度 0.0001 元
/// </summary>
public float ep { get; set; }
public float price { get; set; }
/// <summary>
/// 开始时段
/// 格式”HH:mm:ss”精确到小时
/// </summary>
public DateTime st { get; set; }
public DateTime startTime { get; set; }
/// <summary>
/// 结束时段
/// 格式“HH:mm:ss” 精确到小时
/// </summary>
public DateTime et { get; set; }
public DateTime endTime { get; set; }
/// <summary>
/// 时段序号
/// 对应尖峰平谷序号1:尖; 2:峰; 3:平; 4
/// <see cref="Entity.Constant.CloudEnum.PeriodNumber"/>
/// </summary>
public int pr { get; set; }
public int type { get; set; }
}
}

@ -0,0 +1,17 @@
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Cloud.Resp;
/// <summary>
/// 4.2.6.2 应答换电站上传仓位数据
/// </summary>
public class BinDataInfoRes : ICmd
{
public byte result { get; set; }
public string GetCmd()
{
return CloudConst.binResp;
}
}

@ -0,0 +1,102 @@
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
public class BinDataInfo: ICmd
{
/// <summary>
/// 场站编码 换电站唯一码
/// </summary>
public string stationNo { get; set; }
public List<BinData> binInfoList { get; set; }
public string GetCmd()
{
return CloudConst.binReq;
}
}
public class BinData
{
/// <summary>
/// 仓位编码
/// </summary>
public string? binCode { get; set; }
/// <summary>
/// 在位状态
/// </summary>
public int? existsFlag { get; set; }
/// <summary>
/// 电池编码
/// </summary>
public string? batteryNo { get; set; }
/// <summary>
/// 充电机编码
/// </summary>
public string? chargerNo { get; set; }
/// <summary>
/// 水冷编号
/// </summary>
public string? waterCoolNo { get; set; }
/// <summary>
/// 是否有电插头
/// </summary>
public int? elecPluginFlag { get; set; }
/// <summary>
/// 电插头状态
/// </summary>
public int elecPluginStatus { get; set; }
/// <summary>
/// 是否有水插头
/// </summary>
public int waterPluginFlag { get; set; }
/// <summary>
/// 预约锁定
/// </summary>
public int? amtLock { get; set; }
/// <summary>
/// 充电状态
/// </summary>
public int? chargeStatus { get; set; }
/// <summary>
/// 仓位状态
/// </summary>
public int? status { get; set; }
/// <summary>
/// 最后结束充电时间
/// </summary>
public DateTime? lastChargeFinishTime { get; set; }
/// <summary>
/// 缓存仓标记
/// </summary>
public int? cacheBinFlag { get; set; }
/// <summary>
/// 是否可以换电
/// </summary>
public int? canSwapFlag { get; set; }
/// <summary>
/// 是否可以充电
/// </summary>
public int? canChargeFlag { get; set; }
/// <summary>
/// 入仓时间
/// </summary>
public DateTime? inTime { get; set; }
}

@ -10,7 +10,7 @@ public class AmtBatRes : ICmd
/// 1:预约电池失败; 2:换电站无电池可预约; 3:预约成功;
/// <see cref="Entity.Constant.CloudEnum.BatteryAppointments"/>
/// </summary>
public int rs { get; set; }
public int result { get; set; }
public string GetCmd()
{

@ -0,0 +1,31 @@
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Resp;
/// <summary>
/// 5.2.3.2 站控应答后台服务器下发取消电池预约信息
/// </summary>
public class CancelAmtRes : ICmd
{
/// <summary>
/// 1:预约电池失败; 2:换电站无电池可预约; 3:预约成功;
/// <see cref="Entity.Constant.CloudEnum.BatteryAppointments"/>
/// </summary>
public int result { get; set; }
/// <summary>
/// station no
/// 换电站唯一码,区域码+类型码+流水号
/// </summary>
public string stationNo { get; set; }
/// <summary>
/// 车牌号
/// </summary>
public string carNo { get; set; }
public string GetCmd()
{
return CloudConst.cancleAmtBatRes;
}
}

@ -17,7 +17,7 @@ namespace Service.Cloud.Msg.Host.Resp
/// 0:成功 1:失败
/// <see cref="Entity.Constant.CloudEnum.ResultInt"/>
/// </summary>
public int re { get; set; }
public int result { get; set; }
public string GetCmd()
{

@ -386,6 +386,11 @@ public abstract class CloudApi
global::System.TimeSpan.FromSeconds(TimeSpan));
}
public static void SendBinDataInfo(BinDataInfo req)
{
CloudClientMgr.CloudClient?.SendBinDataInfo(req,
global::System.TimeSpan.FromSeconds(TimeSpan));
}
//TODO 未调试,先注释上传
/// <summary>

@ -0,0 +1,91 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.AutoTask;
using log4net;
using Repository.Station;
using Service.Cloud.Client;
using Service.Cloud.Msg.Host.Req;
using Service.Init;
namespace Service.MyTask;
/// <summary>
/// 仓位上传至云平台
/// </summary>
[Scope]
public class BinInfoReportCloudTask : ITask
{
private static readonly ILog Log = LogManager.GetLogger(typeof(BinInfoReportCloudTask));
private volatile bool _stop;
public BinInfoReportCloudTask(BinInfoRepository binInfoRepository)
{
BinInfoRepository = binInfoRepository;
}
private BinInfoRepository BinInfoRepository { get; set; }
public string Name()
{
return "BinInfoReportCloudTask";
}
public int Interval()
{
return 1000 * 3;
}
public void Handle()
{
List<BinInfo> binInfList = BinInfoRepository.Query();
if (binInfList.Count <= 0)
{
return;
}
BinDataInfo binDataInfo = new BinDataInfo
{
stationNo = StaticStationInfo.StationNo,
binInfoList = binInfList.Select(binInfo => new BinData
{
binCode = binInfo.No,
existsFlag = binInfo.Exists,
batteryNo = binInfo.BatteryNo,
chargerNo = binInfo.ChargerNo,
waterCoolNo = binInfo.WaterCoolNo,
elecPluginFlag = binInfo.ElecPluginFlag,
elecPluginStatus = Convert.ToInt32(binInfo.ElecPluginStatus),
waterPluginFlag = Convert.ToInt32(binInfo.WaterPluginFlag),
amtLock = binInfo.AmtLock,
chargeStatus = binInfo.ChargeStatus,
status = binInfo.Status,
lastChargeFinishTime = binInfo.LastChargeFinishTime,
cacheBinFlag = binInfo.CacheBinFlag,
canSwapFlag = binInfo.CanSwapFlag,
canChargeFlag = binInfo.CanChargeFlag,
inTime = binInfo.InTime
}).ToList()
};
CloudClientMgr.CloudClient?.Publish(binDataInfo);
Log.Info("上报仓位数据到云平台成功");
}
public bool Stoped()
{
return _stop;
}
public void Stop()
{
_stop = true;
}
public void ResetStop()
{
_stop = false;
}
}
Loading…
Cancel
Save