using HybirdFrameworkDriver.Session; using log4net; using Microsoft.AspNetCore.Mvc; using Service.Car.Msg.Host.Req; using Service.Car.Server; using WebStarter.Dto.Req; using WebStarter.Dto.Resp; namespace WebStarter.Controllers; /// /// 车辆管理 /// [ApiController] [Route("[controller]")] public class CarController : ControllerBase { private static readonly ILog Log = LogManager.GetLogger(typeof(CarController)); /// /// 获取车辆数据 /// /// [HttpGet("/getCarInfo")] public CarInfoResp GetCarInfo() { CarInfoResp carInfoResp = new CarInfoResp() { Connected = CarServerMgr.CarServer?.Connected ?? false, CarNo = CarServerMgr.CarServer?.HeartBeatMsg?.CarNo, ElecMsg = CarServerMgr.CarServer?.ElecMsg, HeartBeatMsg = CarServerMgr.CarServer?.HeartBeatMsg }; return carInfoResp; } /// /// 锁车 /// /// 发送结果 [HttpGet("/lock")] public bool Lock() { Log.Info("Lock "); if (CarServerMgr.CarServer == null || (CarServerMgr.CarServer?.Connected ?? false)) { return false; } CarServerMgr.CarServer.LockMsgResp = null; SessionMgr.Broadcast(new LockMsg()); return true; } /// /// 解锁 /// /// 发送结果 [HttpGet("/unLock")] public bool UnLock() { Log.Info("UnLock "); if (CarServerMgr.CarServer == null || (CarServerMgr.CarServer?.Connected ?? false)) { return false; } CarServerMgr.CarServer.UnLockMsgResp = null; SessionMgr.Broadcast(new UnLockMsg()); return true; } /// /// 结算 /// /// 发送结果 [HttpGet("/SettleConfirm")] public bool SettleConfirm() { Log.Info("SettleConfirm "); if (CarServerMgr.CarServer == null || (CarServerMgr.CarServer?.Connected ?? false)) { return false; } CarServerMgr.CarServer.SettleConfirmMsgResp = null; SessionMgr.Broadcast(new SettleConfirmMsg()); return true; } /// /// 设置参数 /// /// [HttpPost("/setParam")] public bool SetParam(SetParam setParam) { Log.Info("SetParam"); if (CarServerMgr.CarServer == null || (CarServerMgr.CarServer?.Connected ?? false)) { return false; } CarServerMgr.CarServer.SetParamMsgResp = null; SetParamMsg setParamMsg = new SetParamMsg() { AccDischargeCount = setParam.AccDischargeCount, AccFallbackCount = setParam.AccFallbackCount, AccChargeCount = setParam.AccChargeCount, AccKgce = setParam.AccKgce, ThisTimeRealDischarge = setParam.ThisTimeRealDischarge, LastTimeBalanceDischarge = setParam.LastTimeBalanceDischarge, ThisTimeRealFeedbackPower = setParam.ThisTimeRealFeedbackPower, LastTimeBalanceFeedbackPower = setParam.LastTimeBalanceFeedbackPower, ThisTimeRealChargeCount = setParam.ThisTimeRealChargeCount, LastTimeBalanceChargeCount = setParam.LastTimeBalanceChargeCount, ThisTimeRealKgce = setParam.ThisTimeRealKgce, LastTimeBalanceKgce = setParam.LastTimeBalanceKgce, ElectricityToBeSettled = setParam.ElectricityToBeSettled, }; SessionMgr.Broadcast(setParamMsg); return true; } }