diff --git a/Repository/Station/ElecPriceModelVersionRepository.cs b/Repository/Station/ElecPriceModelVersionRepository.cs index ae06c30..15054bf 100644 --- a/Repository/Station/ElecPriceModelVersionRepository.cs +++ b/Repository/Station/ElecPriceModelVersionRepository.cs @@ -4,7 +4,7 @@ using SqlSugar; namespace Repository.Station; -[Scope] +[Scope("SingleInstance")] public class ElecPriceModelVersionRepository : BaseRepository { public ElecPriceModelVersionRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) diff --git a/Service/Cloud/Client/CloudClient.cs b/Service/Cloud/Client/CloudClient.cs index d6f5ad5..ee040a3 100644 --- a/Service/Cloud/Client/CloudClient.cs +++ b/Service/Cloud/Client/CloudClient.cs @@ -114,6 +114,9 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR public MsgPair StaHourAmountVal { get; set; } = new(); + public MsgPair BinDataInfo { get; set; } = new(); + + /// /// 云端发-站端收 @@ -568,6 +571,20 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR this.Publish(staSwapRecord); return UploadPowerChange.GetResp(timeSpan); } + + /// + /// 上传仓位数据 + /// + /// + /// + /// + 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) { diff --git a/Service/Cloud/Common/CloudConst.cs b/Service/Cloud/Common/CloudConst.cs index 9d778ff..fe99ec8 100644 --- a/Service/Cloud/Common/CloudConst.cs +++ b/Service/Cloud/Common/CloudConst.cs @@ -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"; /// /// 站外 diff --git a/Service/Cloud/Handler/AmtBatHandler.cs b/Service/Cloud/Handler/AmtBatHandler.cs index 7d5900f..c3a690a 100644 --- a/Service/Cloud/Handler/AmtBatHandler.cs +++ b/Service/Cloud/Handler/AmtBatHandler.cs @@ -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(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); } - } } diff --git a/Service/Cloud/Handler/BinDataInfoResHandler.cs b/Service/Cloud/Handler/BinDataInfoResHandler.cs new file mode 100644 index 0000000..718a500 --- /dev/null +++ b/Service/Cloud/Handler/BinDataInfoResHandler.cs @@ -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(t); + } +} \ No newline at end of file diff --git a/Service/Cloud/Handler/CancelAmtBatHandler.cs b/Service/Cloud/Handler/CancelAmtBatHandler.cs new file mode 100644 index 0000000..89e5c32 --- /dev/null +++ b/Service/Cloud/Handler/CancelAmtBatHandler.cs @@ -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(t); + + if (amtBat==null) + { + return; + } + + List 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); + } +} \ No newline at end of file diff --git a/Service/Cloud/Handler/ChargerElectricityPriceModelHandler.cs b/Service/Cloud/Handler/ChargerElectricityPriceModelHandler.cs index 76845c2..3ca2bf6 100644 --- a/Service/Cloud/Handler/ChargerElectricityPriceModelHandler.cs +++ b/Service/Cloud/Handler/ChargerElectricityPriceModelHandler.cs @@ -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(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? segs = priceModel.seg; + List? segs = priceModel.timeList; if (segs is { Count: > 0 }) { List 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); } diff --git a/Service/Cloud/Msg/Cloud/Req/AmtBat.cs b/Service/Cloud/Msg/Cloud/Req/AmtBat.cs index 8749788..3a276ca 100644 --- a/Service/Cloud/Msg/Cloud/Req/AmtBat.cs +++ b/Service/Cloud/Msg/Cloud/Req/AmtBat.cs @@ -11,29 +11,29 @@ public class AmtBat : ICmd /// station no /// 换电站唯一码,区域码+类型码+流水号 /// - public string sn { get; set; } + public string stationNo { get; set; } /// /// car no /// - public string cn { get; set; } + public string carNo { get; set; } /// /// 电池型号编号 /// - public string bn { get; set; } + public string batteryTypeNo { get; set; } /// /// battery count /// 默认为 1,特殊车辆可能有 2 块电池 /// - public int bm { get; set; } + public int batteryCount { get; set; } /// /// 预约时间 格式:yyyy-MM-dd HH:mm:ss /// - public DateTime at { get; set; } + public DateTime appointmentTime { get; set; } /// /// 锁定时长 单位:分钟 /// 单位:分钟,一般锁定时长是 30 分钟 /// - public int am { get; set; } + public int lockTime { get; set; } public string GetCmd() { return CloudConst.amtBat; diff --git a/Service/Cloud/Msg/Cloud/Req/CancelAmt.cs b/Service/Cloud/Msg/Cloud/Req/CancelAmt.cs new file mode 100644 index 0000000..c68e5d6 --- /dev/null +++ b/Service/Cloud/Msg/Cloud/Req/CancelAmt.cs @@ -0,0 +1,25 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg.Cloud.Req; + +/// +/// 5.2.3.1 后台服务器下发取消电池预约信息 +/// +public class CancelAmt : ICmd +{ + /// + /// station no + /// 换电站唯一码,区域码+类型码+流水号 + /// + public string stationNo { get; set; } + + /// + /// 车牌号 + /// + public string carNo { get; set; } + + public string GetCmd() + { + return CloudConst.cancleAmtBat; + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Cloud/Req/SetChargePrice.cs b/Service/Cloud/Msg/Cloud/Req/SetChargePrice.cs index d6382b6..d2de86c 100644 --- a/Service/Cloud/Msg/Cloud/Req/SetChargePrice.cs +++ b/Service/Cloud/Msg/Cloud/Req/SetChargePrice.cs @@ -11,16 +11,16 @@ namespace Service.Cloud.Msg.Cloud.Req /// 更新时间 /// 格式”yyyy-MM-dd HH:mm:ss” /// - public string ut { get; set; } + public DateTime updateTime { get; set; } /// /// 电价模型id /// 由服务器统一进行分配 /// - public int ceid { get; set; } + public int electricityId { get; set; } - public List? seg { get; set; } + public List? timeList { get; set; } public string GetCmd() { @@ -34,25 +34,25 @@ namespace Service.Cloud.Msg.Cloud.Req /// 电价 /// 精度 0.0001 元 /// - public float ep { get; set; } + public float price { get; set; } /// /// 开始时段 /// 格式”HH:mm:ss”精确到小时 /// - public DateTime st { get; set; } + public DateTime startTime { get; set; } /// /// 结束时段 /// 格式“HH:mm:ss” 精确到小时 /// - public DateTime et { get; set; } + public DateTime endTime { get; set; } /// /// 时段序号 /// 对应尖峰平谷序号1:尖; 2:峰; 3:平; 4:谷 /// /// - public int pr { get; set; } + public int type { get; set; } } } \ No newline at end of file diff --git a/Service/Cloud/Msg/Cloud/Resp/BinDataInfoRes.cs b/Service/Cloud/Msg/Cloud/Resp/BinDataInfoRes.cs new file mode 100644 index 0000000..561f821 --- /dev/null +++ b/Service/Cloud/Msg/Cloud/Resp/BinDataInfoRes.cs @@ -0,0 +1,17 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg.Cloud.Resp; +/// +/// 4.2.6.2 应答换电站上传仓位数据 +/// +public class BinDataInfoRes : ICmd +{ + + public byte result { get; set; } + + + public string GetCmd() + { + return CloudConst.binResp; + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Host/Req/BinDataInfo.cs b/Service/Cloud/Msg/Host/Req/BinDataInfo.cs new file mode 100644 index 0000000..0a54df2 --- /dev/null +++ b/Service/Cloud/Msg/Host/Req/BinDataInfo.cs @@ -0,0 +1,102 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg.Host.Req; + +public class BinDataInfo: ICmd +{ + /// + /// 场站编码 换电站唯一码 + /// + public string stationNo { get; set; } + + public List binInfoList { get; set; } + + + public string GetCmd() + { + return CloudConst.binReq; + } +} + +public class BinData +{ + /// + /// 仓位编码 + /// + public string? binCode { get; set; } + + /// + /// 在位状态 + /// + public int? existsFlag { get; set; } + + /// + /// 电池编码 + /// + public string? batteryNo { get; set; } + + /// + /// 充电机编码 + /// + public string? chargerNo { get; set; } + + /// + /// 水冷编号 + /// + public string? waterCoolNo { get; set; } + + /// + /// 是否有电插头 + /// + public int? elecPluginFlag { get; set; } + + /// + /// 电插头状态 + /// + public int elecPluginStatus { get; set; } + + /// + /// 是否有水插头 + /// + public int waterPluginFlag { get; set; } + + /// + /// 预约锁定 + /// + public int? amtLock { get; set; } + + /// + /// 充电状态 + /// + public int? chargeStatus { get; set; } + + /// + /// 仓位状态 + /// + public int? status { get; set; } + + /// + /// 最后结束充电时间 + /// + public DateTime? lastChargeFinishTime { get; set; } + + /// + /// 缓存仓标记 + /// + public int? cacheBinFlag { get; set; } + + /// + /// 是否可以换电 + /// + public int? canSwapFlag { get; set; } + + /// + /// 是否可以充电 + /// + public int? canChargeFlag { get; set; } + + /// + /// 入仓时间 + /// + public DateTime? inTime { get; set; } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Host/Resp/AmtBatRes.cs b/Service/Cloud/Msg/Host/Resp/AmtBatRes.cs index 6ca255d..6da0aaa 100644 --- a/Service/Cloud/Msg/Host/Resp/AmtBatRes.cs +++ b/Service/Cloud/Msg/Host/Resp/AmtBatRes.cs @@ -10,7 +10,7 @@ public class AmtBatRes : ICmd /// 1:预约电池失败; 2:换电站无电池可预约; 3:预约成功; /// /// - public int rs { get; set; } + public int result { get; set; } public string GetCmd() { diff --git a/Service/Cloud/Msg/Host/Resp/CancelAmtRes.cs b/Service/Cloud/Msg/Host/Resp/CancelAmtRes.cs new file mode 100644 index 0000000..98fe253 --- /dev/null +++ b/Service/Cloud/Msg/Host/Resp/CancelAmtRes.cs @@ -0,0 +1,31 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg.Host.Resp; + +/// +/// 5.2.3.2 站控应答后台服务器下发取消电池预约信息 +/// +public class CancelAmtRes : ICmd +{ + /// + /// 1:预约电池失败; 2:换电站无电池可预约; 3:预约成功; + /// + /// + public int result { get; set; } + + /// + /// station no + /// 换电站唯一码,区域码+类型码+流水号 + /// + public string stationNo { get; set; } + + /// + /// 车牌号 + /// + public string carNo { get; set; } + + public string GetCmd() + { + return CloudConst.cancleAmtBatRes; + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Host/Resp/SetChargePriceRes.cs b/Service/Cloud/Msg/Host/Resp/SetChargePriceRes.cs index 7cb45f3..e861398 100644 --- a/Service/Cloud/Msg/Host/Resp/SetChargePriceRes.cs +++ b/Service/Cloud/Msg/Host/Resp/SetChargePriceRes.cs @@ -17,7 +17,7 @@ namespace Service.Cloud.Msg.Host.Resp /// 0:成功 1:失败 /// /// - public int re { get; set; } + public int result { get; set; } public string GetCmd() { diff --git a/Service/Execute/Api/CloudApi.cs b/Service/Execute/Api/CloudApi.cs index ec54782..8587adb 100644 --- a/Service/Execute/Api/CloudApi.cs +++ b/Service/Execute/Api/CloudApi.cs @@ -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 未调试,先注释上传 /// diff --git a/Service/MyTask/BinInfoReportCloudTask.cs b/Service/MyTask/BinInfoReportCloudTask.cs new file mode 100644 index 0000000..17a0e80 --- /dev/null +++ b/Service/MyTask/BinInfoReportCloudTask.cs @@ -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; + +/// +/// 仓位上传至云平台 +/// +[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 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; + } +} \ No newline at end of file