|
|
@ -1,6 +1,8 @@
|
|
|
|
using HybirdFrameworkDriver.Session;
|
|
|
|
using HybirdFrameworkDriver.Session;
|
|
|
|
using log4net;
|
|
|
|
using log4net;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
using Service.Car.Msg.Car.Req;
|
|
|
|
using Service.Car.Msg.Host.Req;
|
|
|
|
using Service.Car.Msg.Host.Req;
|
|
|
|
using Service.Car.Server;
|
|
|
|
using Service.Car.Server;
|
|
|
|
using WebStarter.Dto.Req;
|
|
|
|
using WebStarter.Dto.Req;
|
|
|
@ -13,27 +15,73 @@ namespace WebStarter.Controllers;
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
[ApiController]
|
|
|
|
[ApiController]
|
|
|
|
[Route("[controller]")]
|
|
|
|
[Route("[controller]")]
|
|
|
|
public class CarController : ControllerBase
|
|
|
|
public class CarController : ControllerBase{
|
|
|
|
{
|
|
|
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(CarController));
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(CarController));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 获取车辆数据
|
|
|
|
/// 获取车辆数据
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("/getCarInfo")]
|
|
|
|
[HttpGet("/getCarInfo/{carNo}")]
|
|
|
|
public CarInfoResp GetCarInfo()
|
|
|
|
public CarInfoResp? GetCarInfo(string carNo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
IoSession? ioSession = SessionMgr.GetSession(carNo);
|
|
|
|
CarInfoResp carInfoResp = new CarInfoResp()
|
|
|
|
CarInfoResp carInfoResp = new CarInfoResp()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Connected = CarServerMgr.CarServer != null && CarServerMgr.CarServer.Connected,
|
|
|
|
Connected = CarServerMgr.CarServer != null && ioSession != null,
|
|
|
|
CarNo = CarServerMgr.CarServer?.HeartBeatMsg?.CarNo,
|
|
|
|
|
|
|
|
ElecMsg = CarServerMgr.CarServer?.ElecMsg,
|
|
|
|
|
|
|
|
HeartBeatMsg = CarServerMgr.CarServer?.HeartBeatMsg
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ioSession.BusinessMap.TryGetValue("ElecMsg", out var elecMsg);
|
|
|
|
|
|
|
|
if (elecMsg != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
carInfoResp.ElecMsg = (ElecMsg)elecMsg;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ioSession.BusinessMap.TryGetValue("HeartBeatMsg", out var heartBeatMsg);
|
|
|
|
|
|
|
|
if (heartBeatMsg != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
carInfoResp.HeartBeatMsg = (HeartBeatMsg)heartBeatMsg;
|
|
|
|
|
|
|
|
}
|
|
|
|
return carInfoResp;
|
|
|
|
return carInfoResp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 获取车辆数据
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[HttpGet("/getCarInfoList")]
|
|
|
|
|
|
|
|
public List<CarInfoResp> GetCarInfoList()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
List<CarInfoResp> result = new List<CarInfoResp>();
|
|
|
|
|
|
|
|
List<IoSession> sessionList = 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)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
carInfoResp.HeartBeatMsg = (HeartBeatMsg)heartBeatMsg;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.Add(carInfoResp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 加锁
|
|
|
|
/// 加锁
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -42,9 +90,12 @@ public class CarController : ControllerBase
|
|
|
|
[HttpGet("/lock/{carNo}")]
|
|
|
|
[HttpGet("/lock/{carNo}")]
|
|
|
|
public bool Lock(string carNo)
|
|
|
|
public bool Lock(string carNo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log.Info("Lock ");
|
|
|
|
Log.Info($"Lock {carNo}");
|
|
|
|
if (CarServerMgr.CarServer == null || !CarServerMgr.CarServer.Connected)
|
|
|
|
|
|
|
|
|
|
|
|
IoSession? ioSession = SessionMgr.GetSession(carNo);
|
|
|
|
|
|
|
|
if (CarServerMgr.CarServer == null || ioSession?.Channel == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
Log.Info("ioSession is null return false");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -53,7 +104,7 @@ public class CarController : ControllerBase
|
|
|
|
CarNo = carNo
|
|
|
|
CarNo = carNo
|
|
|
|
};
|
|
|
|
};
|
|
|
|
CarServerMgr.CarServer.LockMsgPair.Req = lockMsg;
|
|
|
|
CarServerMgr.CarServer.LockMsgPair.Req = lockMsg;
|
|
|
|
SessionMgr.Broadcast(lockMsg);
|
|
|
|
ioSession.Channel.WriteAndFlushAsync(lockMsg);
|
|
|
|
|
|
|
|
|
|
|
|
return CarServerMgr.CarServer.LockMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result == 0;
|
|
|
|
return CarServerMgr.CarServer.LockMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -66,9 +117,11 @@ public class CarController : ControllerBase
|
|
|
|
[HttpGet("/unLock/{carNo}")]
|
|
|
|
[HttpGet("/unLock/{carNo}")]
|
|
|
|
public bool UnLock(string carNo)
|
|
|
|
public bool UnLock(string carNo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log.Info("UnLock ");
|
|
|
|
Log.Info($"UnLock {carNo} ");
|
|
|
|
if (CarServerMgr.CarServer == null || !CarServerMgr.CarServer.Connected)
|
|
|
|
IoSession? ioSession = SessionMgr.GetSession(carNo);
|
|
|
|
|
|
|
|
if (CarServerMgr.CarServer == null || ioSession?.Channel == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
Log.Info("ioSession is null return false");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -78,7 +131,7 @@ public class CarController : ControllerBase
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CarServerMgr.CarServer.UnLockMsgPair.Req = unLockMsg;
|
|
|
|
CarServerMgr.CarServer.UnLockMsgPair.Req = unLockMsg;
|
|
|
|
SessionMgr.Broadcast(unLockMsg);
|
|
|
|
ioSession.Channel.WriteAndFlushAsync(unLockMsg);
|
|
|
|
|
|
|
|
|
|
|
|
return CarServerMgr.CarServer.UnLockMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result == 0;
|
|
|
|
return CarServerMgr.CarServer.UnLockMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -91,15 +144,17 @@ public class CarController : ControllerBase
|
|
|
|
[HttpGet("/SettleConfirm/{carNo}")]
|
|
|
|
[HttpGet("/SettleConfirm/{carNo}")]
|
|
|
|
public bool SettleConfirm(string carNo)
|
|
|
|
public bool SettleConfirm(string carNo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log.Info("SettleConfirm ");
|
|
|
|
Log.Info($"SettleConfirm {carNo}");
|
|
|
|
if (CarServerMgr.CarServer == null || !CarServerMgr.CarServer.Connected)
|
|
|
|
IoSession? ioSession = SessionMgr.GetSession(carNo);
|
|
|
|
|
|
|
|
if (CarServerMgr.CarServer == null || ioSession?.Channel == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
Log.Info("ioSession is null return false");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var settleConfirmMsg = new SettleConfirmMsg() { CarNo = carNo };
|
|
|
|
var settleConfirmMsg = new SettleConfirmMsg() { CarNo = carNo };
|
|
|
|
CarServerMgr.CarServer.SettleConfirmMsgPair.Req = settleConfirmMsg;
|
|
|
|
CarServerMgr.CarServer.SettleConfirmMsgPair.Req = settleConfirmMsg;
|
|
|
|
SessionMgr.Broadcast(settleConfirmMsg);
|
|
|
|
ioSession.Channel.WriteAndFlushAsync(settleConfirmMsg);
|
|
|
|
|
|
|
|
|
|
|
|
return CarServerMgr.CarServer.SettleConfirmMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result == 0;
|
|
|
|
return CarServerMgr.CarServer.SettleConfirmMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -111,9 +166,11 @@ public class CarController : ControllerBase
|
|
|
|
[HttpPost("/setParam")]
|
|
|
|
[HttpPost("/setParam")]
|
|
|
|
public bool SetParam(SetParam setParam)
|
|
|
|
public bool SetParam(SetParam setParam)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log.Info("SetParam");
|
|
|
|
Log.Info($"SetParam {JsonConvert.SerializeObject(setParam)}");
|
|
|
|
if (CarServerMgr.CarServer == null || !CarServerMgr.CarServer.Connected)
|
|
|
|
IoSession? ioSession = SessionMgr.GetSession(setParam.CarNo);
|
|
|
|
|
|
|
|
if (CarServerMgr.CarServer == null || ioSession?.Channel == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
Log.Info("ioSession is null return false");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -138,21 +195,21 @@ public class CarController : ControllerBase
|
|
|
|
|
|
|
|
|
|
|
|
return CarServerMgr.CarServer.SetParamMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result ==0;
|
|
|
|
return CarServerMgr.CarServer.SetParamMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result ==0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 清空数据
|
|
|
|
/// 清空数据
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("/clear")]
|
|
|
|
[HttpGet("/clear/{carNo}")]
|
|
|
|
public bool Clear()
|
|
|
|
public bool Clear(string carNo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (CarServerMgr.CarServer?.CarNo == null)
|
|
|
|
if (CarServerMgr.CarServer == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CarServerMgr.CarServer.Clean();
|
|
|
|
CarServerMgr.CarServer.Clean();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IoSession? session = SessionMgr.GetSession(CarServerMgr.CarServer.CarNo);
|
|
|
|
IoSession? session = SessionMgr.GetSession(carNo);
|
|
|
|
if (session == null)
|
|
|
|
if (session == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CarServerMgr.CarServer.Clean();
|
|
|
|
CarServerMgr.CarServer.Clean();
|
|
|
@ -163,4 +220,4 @@ public class CarController : ControllerBase
|
|
|
|
CarServerMgr.CarServer.Clean();
|
|
|
|
CarServerMgr.CarServer.Clean();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|