|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 车辆管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("[controller]")]
|
|
|
|
|
public class CarController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(CarController));
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取车辆数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/getCarInfo")]
|
|
|
|
|
public CarInfoResp GetCarInfo()
|
|
|
|
|
{
|
|
|
|
|
CarInfoResp carInfoResp = new CarInfoResp()
|
|
|
|
|
{
|
|
|
|
|
Connected = CarServerMgr.CarServer != null && CarServerMgr.CarServer.Connected,
|
|
|
|
|
CarNo = CarServerMgr.CarServer?.HeartBeatMsg?.CarNo,
|
|
|
|
|
ElecMsg = CarServerMgr.CarServer?.ElecMsg,
|
|
|
|
|
HeartBeatMsg = CarServerMgr.CarServer?.HeartBeatMsg
|
|
|
|
|
};
|
|
|
|
|
return carInfoResp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加锁
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="carNo">vin码</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/lock/{carNo}")]
|
|
|
|
|
public bool Lock(string carNo)
|
|
|
|
|
{
|
|
|
|
|
Log.Info("Lock ");
|
|
|
|
|
if (CarServerMgr.CarServer == null || !CarServerMgr.CarServer.Connected)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var lockMsg = new LockMsg()
|
|
|
|
|
{
|
|
|
|
|
CarNo = carNo
|
|
|
|
|
};
|
|
|
|
|
CarServerMgr.CarServer.LockMsgPair.Req = lockMsg;
|
|
|
|
|
SessionMgr.Broadcast(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 ");
|
|
|
|
|
if (CarServerMgr.CarServer == null || !CarServerMgr.CarServer.Connected)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UnLockMsg unLockMsg = new UnLockMsg()
|
|
|
|
|
{
|
|
|
|
|
CarNo = carNo
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CarServerMgr.CarServer.UnLockMsgPair.Req = unLockMsg;
|
|
|
|
|
SessionMgr.Broadcast(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 ");
|
|
|
|
|
if (CarServerMgr.CarServer == null || !CarServerMgr.CarServer.Connected)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var settleConfirmMsg = new SettleConfirmMsg() { CarNo = carNo };
|
|
|
|
|
CarServerMgr.CarServer.SettleConfirmMsgPair.Req = settleConfirmMsg;
|
|
|
|
|
SessionMgr.Broadcast(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");
|
|
|
|
|
if (CarServerMgr.CarServer == null || !CarServerMgr.CarServer.Connected)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
SessionMgr.Broadcast(setParamMsg);
|
|
|
|
|
|
|
|
|
|
return CarServerMgr.CarServer.SetParamMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result ==0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 清空数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/clear")]
|
|
|
|
|
public bool Clear()
|
|
|
|
|
{
|
|
|
|
|
if (CarServerMgr.CarServer?.CarNo == null)
|
|
|
|
|
{
|
|
|
|
|
CarServerMgr.CarServer.Clean();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IoSession? session = SessionMgr.GetSession(CarServerMgr.CarServer.CarNo);
|
|
|
|
|
if (session == null)
|
|
|
|
|
{
|
|
|
|
|
CarServerMgr.CarServer.Clean();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
session.Close();
|
|
|
|
|
CarServerMgr.CarServer.Clean();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|