using Entity.Constant; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac; using log4net; using Newtonsoft.Json; using Repository.Station; using Service.Cloud.Client; using Service.Cloud.Msg.Cloud.Req; using Service.Cloud.Msg.Cloud.Resp; using Service.Cloud.Msg.Host.Req; using Service.Cloud.Msg.Host.Req.OutCharger; using Service.Execute.Model; using Service.Execute.Model.Tbox; using Service.Init; using System.Security.Cryptography; namespace Service.Execute.Api; public abstract class CloudApi { private const int TimeSpan = 10; private static readonly ILog Log = LogManager.GetLogger("CloudApi"); /// /// 云平台车辆认证 /// /// /// public static CarAuthRes? VehicleCheck(RfidReadModel rfidReadModel, SwapOrder swapOrder) { CarAuth carAuth = new() { ty = 2, rfid = rfidReadModel.VelVin, cn = rfidReadModel.VelNo, vi = rfidReadModel.VelVin, // mac = rfidReadModel.VelMac, en = 0, dt = swapOrder.VehicleEnterTime, mode = 0, }; Log.Info( $" CloudApi VehicleCheck SendVehicleCertification param={JsonConvert.SerializeObject(carAuth)}"); CarAuthRes? sendVehicleCertification = CloudClientMgr.CloudClient?.SendVehicleCertification(carAuth, global::System.TimeSpan.FromSeconds(TimeSpan)); Log.Info( $" CloudApi VehicleCheck SendVehicleCertification resp={JsonConvert.SerializeObject(sendVehicleCertification)}"); return sendVehicleCertification; } /// /// 上报换电订单 /// /// /// /// public static int UploadSwapOrder(SwapOrder swapOrder, int seq, SwapOrderBattery swapOrderBattery, int uploadType ,SwapOrderReportCloud orderReportCloud) { StaSwapRecord staSwapRecord = new() { rfid = swapOrder.VehicleVin, sn = StaticStationInfo.StationNo, son = swapOrder.CloudSn, cn = swapOrder.VehicleNo, so = seq, ct = swapOrder.VehicleEnterTime, st = swapOrder.SwapBeginTime, dbid = swapOrderBattery.UpBatteryNo, deno = swapOrderBattery.UpBatteryBinNo, dsoc = swapOrderBattery.UpBatterySoc.ToInt(), //dsoe = swapOrderBattery.UpBatterySoe.ToInt(), et = swapOrder.SwapEndTime, od = 0, ot = swapOrder.VehicleLeaveTime, rs = 0, sflx = 0, sfs = uploadType, ubid = swapOrderBattery.DownBatteryNo, ueno = swapOrderBattery.DownBatteryBinNo, usoc = swapOrderBattery.DownBatterySoc.ToInt(), // usoe = swapOrderBattery.DownBatterySoe.ToInt(), vin = swapOrder.VehicleVin, wt = new TimeSpan((swapOrder.SwapEndTime.ToDateTime().Ticks - swapOrder.SwapBeginTime.ToDateTime().Ticks)) .TotalSeconds.ToInt(), vtm=orderReportCloud.Vtm, }; Log.Info( $" CloudApi UploadSwapOrder seq={seq} SendUploadPowerChangeOrder param={JsonConvert.SerializeObject(staSwapRecord)}"); StaSwapRecordRes? sendUploadPowerChangeOrder = CloudClientMgr.CloudClient?.SendUploadPowerChangeOrder( staSwapRecord, global::System.TimeSpan.FromSeconds(TimeSpan)); Log.Info( $" CloudApi UploadSwapOrder seq={seq} SendUploadPowerChangeOrder resp={JsonConvert.SerializeObject(sendUploadPowerChangeOrder)}"); if (sendUploadPowerChangeOrder == null) { return -1; } return sendUploadPowerChangeOrder.re; } public static InfoEnum.BusinessSwappingForCloudState BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.Idle; /// /// 上报换电步序到云端 /// public static void SendStateLog( ) { if (BusinessSwappingForCloudState!= StationSoftMgr.SwappingStateMachine.BusinessSwappingForCloudState) { StationChnRunStatus stationChnRunStatus = null; if (StationSoftMgr.SwappingStateMachine.BusinessSwappingForCloudState != InfoEnum.BusinessSwappingForCloudState.Idle|| StationSoftMgr.SwappingStateMachine.BusinessSwappingForCloudState != InfoEnum.BusinessSwappingForCloudState.UnKnown) { stationChnRunStatus = new() { ec = 0, ws = StationSoftMgr.SwappingStateMachine.SwapStatus == 0 ? 2 : 3, cs = (int)StationSoftMgr.SwappingStateMachine.BusinessSwappingForCloudState, iv = StationSoftMgr.SwappingStateMachine.RadarInFlag == true ? 1 : 2, ls = StationSoftMgr.SwappingStateMachine.VelUnlockFlag == true ? 2 : 1, fl = Convert.ToInt32(StaticStationInfo.Faultlevel), ut = DateTime.Now, }; } else//空闲 { stationChnRunStatus = new() { ec = 0, ws = 1, cs = 1, iv = 2, ls = 0, fl = Convert.ToInt32(StaticStationInfo.Faultlevel), ut = DateTime.Now, }; } CloudClientMgr.CloudClient?.SendChannelStatusReporting(stationChnRunStatus, global::System.TimeSpan.FromSeconds(TimeSpan)); for (int i = 0; i < 3; i++) { } } BusinessSwappingForCloudState = StationSoftMgr.SwappingStateMachine.BusinessSwappingForCloudState; return; } /// /// 上报车辆数据 /// public static void UploadTBoxCarInfo(SwapOrder swapOrder, TboxCarInfoModel model) { return; } /// /// 换电车辆数据上报 /// /// public static void SendVehicleDataReporting(SwappingStateMachine machine,int vet) { var carInfoBatteryInfos = machine.BoxCarInfoModel?.CarInfo?.BatteryInfos; CardataReport cardataReport = new() { on = machine.SwapOrder.Sn, ct = DateTime.Now, cn = machine.SwapOrder.VehicleNo, rfid = "", Vi = machine.SwapOrder.VehicleVin, mc = "", bn = carInfoBatteryInfos.Count > 0 ? carInfoBatteryInfos[0].BatteryNo : "", ec = 0, soc = carInfoBatteryInfos.Count > 0 ? Convert.ToSingle(carInfoBatteryInfos[0].Soc) : 0, bskm = Convert.ToSingle(machine.BoxCarInfoModel?.ElecMsg?.SubMile), btkm = Convert.ToSingle(machine.BoxCarInfoModel?.ElecMsg?.TotalMile), soh = carInfoBatteryInfos.Count > 0 ? Convert.ToSingle(carInfoBatteryInfos[0].Soh) : 0, soe = carInfoBatteryInfos.Count > 0 ? Convert.ToSingle(carInfoBatteryInfos[0].Soe) : 0, vtm = Convert.ToSingle(machine.BoxCarInfoModel?.ElecMsg?.TotalMile), vet = vet, vtdc = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.AccDischargeCount), vtfe = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.AccFallbackCount), vtcc = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.AccChargeCount), vtec = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.AccKgce), rtdc = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.ThisTimeRealDischarge), lsdc = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.LastTimeBalanceDischarge), rtfc = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.ThisTimeRealFeedbackPower), lsfc = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.LastTimeBalanceFeedbackPower), rtcc = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.ThisTimeRealChargeCount), lscc = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.LastTimeBalanceChargeCount), rtec = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.ThisTimeRealKgce), ltfc = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.LastTimeBalanceKgce), wsec = Convert.ToInt32(machine.BoxCarInfoModel?.ElecMsg?.ElectricityToBeSettled), }; //CloudClientMgr.CloudClient?.SendVehicleDataReporting(cardataReport, // global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 云平台下发换电指令 /// /// public static CarCanStart CarCanStart() { Log.Info( $" CloudApi CarCanStart "); var cloudClientCarCanStart = CloudClientMgr.CloudClient.CarCanStart; Log.Info( $" CloudApi CarCanStart resp= {JsonConvert.SerializeObject(cloudClientCarCanStart)}"); return cloudClientCarCanStart; } /// /// 清除下发的换电指令 /// /// public static bool ClearCarCanStartInfo() { CloudClientMgr.CloudClient.CarCanStart = null; return true; } /// /// 9.2.1.3 站控上报充电枪充电结束事件 /// /// public static void SendPileEndCharge(PileEndCharge req) { CloudClientMgr.CloudClient?.SendPileEndCharge(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 9.2.1.7 站控上报充电枪充电遥测数据 /// /// public static void SendPileChargeRealtime(PileChargeRealtime req) { CloudClientMgr.CloudClient?.SendPileChargeRealtime(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 9.2.1.5 站控上报充电枪实时数据上报 /// /// public static void SendPileRealtime(PileRealtime req) { CloudClientMgr.CloudClient?.SendPileRealtime(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 换电站状态上报 /// /// public static void SendHostStatusReported(StationRunStatus req) { CloudClientMgr.CloudClient?.SendHostStatusReported(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 空调信息 /// /// public static void SendAirConditioningData(AcDataInfo req) { CloudClientMgr.CloudClient?.SendAirConditioningData(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 换电站温湿度数据信息 /// /// public static void SendEvmDataInfo(EvmDataInfo req) { CloudClientMgr.CloudClient?.SendEvmDataInfo(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 电能表累计值信息 /// /// public static void SendPowerTotal(PowerTotal req) { CloudClientMgr.CloudClient?.SendPowerTotal(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 换电站电能表变化值信息 /// /// public static void SendStaChargingTotal(StaChargingTotal req) { CloudClientMgr.CloudClient?.SendStaChargingTotal(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 换电站分时用电统计信息 /// /// public static void SendStaHourEnergyVal(StaHourEnergyVal req) { CloudClientMgr.CloudClient?.SendStaHourEnergyVal(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 电能表小时能耗值信息 /// /// public static void SendMeterEnergyKwh(MeterEnergyKwh req) { CloudClientMgr.CloudClient?.SendMeterEnergyKwh(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 电能表每天能耗值信息 /// /// public static void SendMeterDayEnergyVal(MeterDayEnergyVal req) { CloudClientMgr.CloudClient?.SendMeterDayEnergyVal(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 换电站每天用电统计信息 /// /// public static void SendStaDayEnergyVal(StaDayEnergyVal req) { CloudClientMgr.CloudClient?.SendStaDayEnergyVal(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 换电站日运行统计结果信息 /// /// public static void SendStaDayOpeEnergyVal(StaDayOpeEnergyVal req) { CloudClientMgr.CloudClient?.SendStaDayOpeEnergyVal(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 换电站分时用电计费信息 /// /// public static void SendStaHourAmountVal(StaHourAmountVal req) { CloudClientMgr.CloudClient?.SendStaHourAmountVal(req, global::System.TimeSpan.FromSeconds(TimeSpan)); } //TODO 未调试,先注释上传 /// /// 换电站进行签到认证 /// /// public static void SendSignIn() { SignIn signIn = new() { sn = StaticStationInfo.StationNo, ky = StaticStationInfo.StationSn, st = "02", dv = "", sv = StaticStationInfo.StationSftVer, ss = StaticStationInfo.Sevstatus, ca = Convert.ToSingle(StaticStationInfo.DistributionCapacity), VS = "1.0", cp = Convert.ToInt32(StaticStationInfo.TotalPower), bs= StaticStationInfo.StationVersion, lo= StaticStationInfo.Longitude, la= StaticStationInfo.Latitude, en=1, cn=7, eid= Convert.ToInt32(StaticStationInfo.Ceid), oid = Convert.ToInt32(StaticStationInfo.Oid), }; //CloudClientMgr.CloudClient?.SendSignIn(signIn, // global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 换电站上报设备列表 /// /// public static void SendDevList(DevList req) { // CloudClientMgr.CloudClient?.SendReportingDeviceList(req, // global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 实时故障上报 /// /// public static void SendRealTimeFaultInfo(FaultReport req) { //CloudClientMgr.CloudClient?.SendRealTimeFaultInfo(req, // global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 换电站设备状态开始日志信息 /// /// public static void SendStartLogMessage(EqmStateStartLogInfo req) { // CloudClientMgr.CloudClient?.SendStartLogMessage(req, // global::System.TimeSpan.FromSeconds(TimeSpan)); } /// /// 换电站设备状态结束日志信息 /// /// public static void SendEndLogMessage(EqmStateEndLogInfo req) { //CloudClientMgr.CloudClient?.SendEndLogMessage(req, // global::System.TimeSpan.FromSeconds(TimeSpan)); } public static void SendBatteryTotal(BatteryTotal req) { // CloudClientMgr.CloudClient?.SendBatteryTotal(req, // global::System.TimeSpan.FromSeconds(TimeSpan)); } public static void SendChargingTotalDis(ChargingTotalDis req) { // CloudClientMgr.CloudClient?.SendChargingTotalDis(req, // global::System.TimeSpan.FromSeconds(TimeSpan)); } }