You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
256 lines
7.7 KiB
256 lines
7.7 KiB
|
|
using HybirdFrameworkDriver.Session;
|
|
using log4net;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using Service.Api.Resp;
|
|
using Service.Car.Msg.Car.Req;
|
|
using Service.Car.Msg.Host.Req;
|
|
using Service.Car.Server;
|
|
using Service.TBox.Service;
|
|
using WebStarter.Dto.Req;
|
|
|
|
namespace WebStarter.Controllers;
|
|
|
|
/// <summary>
|
|
/// 车辆管理
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class CarController : ControllerBase
|
|
{
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(CarController));
|
|
|
|
/// <summary>
|
|
/// 设置心跳返回信息
|
|
/// </summary>
|
|
/// <param name="status">
|
|
/// 1 换电站待机
|
|
/// 2 开始换电
|
|
/// 3 换电进行中
|
|
/// 4 换电完成
|
|
/// 5 换电站故障</param>
|
|
/// <returns></returns>
|
|
[HttpGet("Vin/{VIN}/SetStatus/{status}")]
|
|
public bool SetStatus(string VIN,byte status)
|
|
{
|
|
if (CarServerMgr.CarServer != null)
|
|
{
|
|
CarServerMgr.CarServer.VIN = VIN;
|
|
CarServerMgr.CarServer.StationStatus = status;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取车辆数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("getCarInfo/{carNo}")]
|
|
public CarInfoResp? GetCarInfo(string carNo)
|
|
{
|
|
return TBoxService.GetHnCZCarInfo(carNo);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取车辆数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("getCarInfoList")]
|
|
public List<CarInfoResp> GetCarInfoList()
|
|
{
|
|
List<CarInfoResp> result = new List<CarInfoResp>();
|
|
List<IoSession> sessionList = CarServerMgr.CarServer?.SessionMgr.GetSessionList();
|
|
foreach (var ioSession in sessionList)
|
|
{
|
|
CarInfoResp carInfoResp = new CarInfoResp()
|
|
{
|
|
Connected = true,
|
|
CarNo = ioSession.Key,
|
|
};
|
|
|
|
ioSession.BusinessMap.TryGetValue("ElecMsg", out var elecMsg);
|
|
if (elecMsg != null)
|
|
{
|
|
carInfoResp.ElecMsg = (ElecMsg)elecMsg;
|
|
}
|
|
|
|
ioSession.BusinessMap.TryGetValue("HeartBeatMsg", out var heartBeatMsg);
|
|
if (heartBeatMsg != null)
|
|
{
|
|
var beatMsg = (HeartBeatMsg)heartBeatMsg;
|
|
CarStatus carStatus = new CarStatus();
|
|
carStatus.LockStatus = beatMsg.LockStatus;
|
|
carStatus.Keys = beatMsg.KeyStatus;
|
|
carInfoResp.CarStatus = carStatus;
|
|
carInfoResp.HeartBeatMsg = beatMsg;
|
|
}
|
|
|
|
result.Add(carInfoResp);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加锁
|
|
/// </summary>
|
|
/// <param name="carNo">vin码</param>
|
|
/// <returns></returns>
|
|
[HttpGet("lock/{carNo}")]
|
|
public bool Lock(string carNo)
|
|
{
|
|
Log.Info($"Lock {carNo}");
|
|
|
|
IoSession? ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(carNo);
|
|
if (CarServerMgr.CarServer == null || ioSession?.Channel == null)
|
|
{
|
|
Log.Info("ioSession is null return false");
|
|
return false;
|
|
}
|
|
|
|
var lockMsg = new LockMsg()
|
|
{
|
|
CarNo = carNo
|
|
};
|
|
CarServerMgr.CarServer.LockMsgPair.Req = lockMsg;
|
|
ioSession.Send(lockMsg);
|
|
|
|
return CarServerMgr.CarServer.LockMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result == 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 解锁
|
|
/// </summary>
|
|
/// <param name="carNo">vin码</param>
|
|
/// <returns></returns>
|
|
[HttpGet("unLock/{carNo}")]
|
|
public bool UnLock(string carNo)
|
|
{
|
|
Log.Info($"UnLock {carNo} ");
|
|
IoSession? ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(carNo);
|
|
if (CarServerMgr.CarServer == null || ioSession?.Channel == null)
|
|
{
|
|
Log.Info("ioSession is null return false");
|
|
return false;
|
|
}
|
|
|
|
UnLockMsg unLockMsg = new UnLockMsg()
|
|
{
|
|
CarNo = carNo
|
|
};
|
|
|
|
CarServerMgr.CarServer.UnLockMsgPair.Req = unLockMsg;
|
|
ioSession.Send(unLockMsg);
|
|
|
|
return CarServerMgr.CarServer.UnLockMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result == 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结算
|
|
/// </summary>
|
|
/// <param name="carNo">vin码</param>
|
|
/// <returns></returns>
|
|
[HttpGet("SettleConfirm/{carNo}")]
|
|
public bool SettleConfirm(string carNo)
|
|
{
|
|
Log.Info($"SettleConfirm {carNo}");
|
|
IoSession? ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(carNo);
|
|
if (CarServerMgr.CarServer == null || ioSession?.Channel == null)
|
|
{
|
|
Log.Info("ioSession is null return false");
|
|
return false;
|
|
}
|
|
|
|
var settleConfirmMsg = new SettleConfirmMsg() { CarNo = carNo };
|
|
CarServerMgr.CarServer.SettleConfirmMsgPair.Req = settleConfirmMsg;
|
|
ioSession.Send(settleConfirmMsg);
|
|
|
|
return CarServerMgr.CarServer.SettleConfirmMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result == 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置参数
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("setParam")]
|
|
public bool SetParam(SetParam setParam)
|
|
{
|
|
Log.Info($"SetParam {JsonConvert.SerializeObject(setParam)}");
|
|
IoSession? ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(setParam.CarNo);
|
|
if (CarServerMgr.CarServer == null || ioSession?.Channel == null)
|
|
{
|
|
Log.Info("ioSession is null return false");
|
|
return false;
|
|
}
|
|
|
|
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,
|
|
};
|
|
CarServerMgr.CarServer.SetParamMsgPair.Req = setParamMsg;
|
|
ioSession.Send(setParamMsg);
|
|
|
|
return CarServerMgr.CarServer.SetParamMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result == 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清空数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("clear/{carNo}")]
|
|
public bool Clear(string carNo)
|
|
{
|
|
if (CarServerMgr.CarServer == null)
|
|
{
|
|
CarServerMgr.CarServer.Clean();
|
|
return true;
|
|
}
|
|
|
|
IoSession? session = CarServerMgr.CarServer?.SessionMgr.GetSession(carNo);
|
|
if (session == null)
|
|
{
|
|
CarServerMgr.CarServer.Clean();
|
|
return true;
|
|
}
|
|
|
|
session.Close();
|
|
CarServerMgr.CarServer.Clean();
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 货箱降下并且就绪
|
|
/// </summary>
|
|
/// <param name="carNo"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("BoxDown/{carNo}")]
|
|
public bool BoxDown(string carNo)
|
|
{
|
|
Log.Info($"BoxDown {carNo} ");
|
|
var carInfo = TBoxService.GetHnCZCarInfo(carNo);
|
|
if (carInfo != null)
|
|
{
|
|
if (carInfo.HeartBeatMsg != null)
|
|
{
|
|
return carInfo.HeartBeatMsg.CrateBrimStatus == 3 && carInfo.HeartBeatMsg.SwapStatus == 2;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |