新增查询全部车辆接口

master
rszn 6 months ago
parent 11a08e4349
commit e1efbf7282

@ -1,5 +1,4 @@
using System.Collections.Concurrent; using System.Collections.Concurrent;
using DotNetty.Buffers;
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
using log4net; using log4net;
@ -22,8 +21,8 @@ public class SessionMgr
IoSession? value; IoSession? value;
Dictionary.TryGetValue(key, out value); Dictionary.TryGetValue(key, out value);
return value; return value;
} }
return null; return null;
} }
@ -149,4 +148,4 @@ public class SessionMgr
return 0; return 0;
} }
} }

@ -1,33 +1,39 @@
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkDriver.Session;
using log4net;
using Service.Car.Msg.Car.Req; using Service.Car.Msg.Car.Req;
using Service.Car.Msg.Host.Resp; using Service.Car.Msg.Host.Resp;
using Service.Car.Server;
namespace Service.Car.Handler; namespace Service.Car.Handler;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Order(8)] [Order(8)]
[Scope("InstancePerDependency")] [Scope("InstancePerDependency")]
public class ElecMsgHandler : SimpleChannelInboundHandler<ElecMsg>, IBaseHandler public class ElecMsgHandler : SimpleChannelInboundHandler<ElecMsg>, IBaseHandler
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(ElecMsgHandler));
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="ctx"></param> /// <param name="ctx"></param>
/// <param name="msg"></param> /// <param name="msg"></param>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
protected override void ChannelRead0(IChannelHandlerContext ctx, ElecMsg msg) protected override void ChannelRead0(IChannelHandlerContext ctx, ElecMsg msg)
{ {
CarServerMgr.CarServer.Connected = true; Log.Info($"receive ElecMsg = {msg}");
CarServerMgr.CarServer.ElecMsg = msg; IoSession? ioSession = SessionMgr.GetSession(msg.CarNo);
ElecMsgResp resp = new ElecMsgResp( 0)
ioSession?.BusinessMap.AddOrUpdate("ElecMsg", msg, ((s, o) => msg));
ioSession?.BusinessMap.AddOrUpdate("Connected", true, ((s, o) => true));
ElecMsgResp resp = new ElecMsgResp(0)
{ {
CarNo = msg.CarNo CarNo = msg.CarNo
}; };
resp.InitCurrentTime(); resp.InitCurrentTime();
ctx.Channel.WriteAndFlushAsync(resp); ctx.Channel.WriteAndFlushAsync(resp);
} }
} }

@ -1,6 +1,7 @@
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkDriver.Session; using HybirdFrameworkDriver.Session;
using log4net;
using Service.Car.Msg.Car.Req; using Service.Car.Msg.Car.Req;
using Service.Car.Msg.Host.Resp; using Service.Car.Msg.Host.Resp;
using Service.Car.Server; using Service.Car.Server;
@ -8,35 +9,43 @@ using Service.Car.Server;
namespace Service.Car.Handler; namespace Service.Car.Handler;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Order(8)] [Order(8)]
[Scope("InstancePerDependency")] [Scope("InstancePerDependency")]
public class HeartBeatMsgHandler : SimpleChannelInboundHandler<HeartBeatMsg>, IBaseHandler public class HeartBeatMsgHandler : SimpleChannelInboundHandler<HeartBeatMsg>, IBaseHandler
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(HeartBeatMsgHandler));
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="ctx"></param> /// <param name="ctx"></param>
/// <param name="msg"></param> /// <param name="msg"></param>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
protected override void ChannelRead0(IChannelHandlerContext ctx, HeartBeatMsg msg) protected override void ChannelRead0(IChannelHandlerContext ctx, HeartBeatMsg msg)
{ {
CarServerMgr.CarServer.Connected = true;
Log.Info($"receive HeartBeatMsg = {msg}");
IoSession? ioSession = SessionMgr.GetSession(ctx.Channel.Id.ToString()); IoSession? ioSession = SessionMgr.GetSession(ctx.Channel.Id.ToString());
if (ioSession != null && ioSession.Key != msg.CarNo) if (ioSession != null && ioSession.Key != msg.CarNo)
{ {
SessionMgr.ChangeSessionKey(ioSession, msg.CarNo); SessionMgr.ChangeSessionKey(ioSession, msg.CarNo);
} }
CarServerMgr.CarServer.CarNo = msg.CarNo; if (ioSession == null)
CarServerMgr.CarServer.HeartBeatMsg = msg; {
HeartBeatMsgResp resp = new HeartBeatMsgResp( CarServerMgr.CarServer.StationStatus) ioSession = SessionMgr.GetSession(msg.CarNo);
}
ioSession.BusinessMap.AddOrUpdate("HeartBeatMsg", msg, ((s, o) => msg));
ioSession?.BusinessMap.AddOrUpdate("Connected", true, ((s, o) => true));
HeartBeatMsgResp resp = new HeartBeatMsgResp(CarServerMgr.CarServer.StationStatus)
{ {
CarNo = msg.CarNo CarNo = msg.CarNo
}; };
resp.InitCurrentTime(); resp.InitCurrentTime();
ctx.Channel.WriteAndFlushAsync(resp); ctx.Channel.WriteAndFlushAsync(resp);
} }
} }

@ -1,26 +1,35 @@
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Car.Msg.Car.Resp; using Service.Car.Msg.Car.Resp;
using Service.Car.Msg.Host.Req;
using Service.Car.Server; using Service.Car.Server;
namespace Service.Car.Handler; namespace Service.Car.Handler;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Order(8)] [Order(8)]
[Scope("InstancePerDependency")] [Scope("InstancePerDependency")]
public class LockMsgRespHandler : SimpleChannelInboundHandler<LockMsgResp>, IBaseHandler public class LockMsgRespHandler : SimpleChannelInboundHandler<LockMsgResp>, IBaseHandler
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(LockMsgRespHandler));
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="ctx"></param> /// <param name="ctx"></param>
/// <param name="msg"></param> /// <param name="msg"></param>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
protected override void ChannelRead0(IChannelHandlerContext ctx, LockMsgResp msg) protected override void ChannelRead0(IChannelHandlerContext ctx, LockMsgResp msg)
{ {
CarServerMgr.CarServer.Connected = true; LockMsg? lockMsg = CarServerMgr.CarServer.LockMsgPair.Req;
CarServerMgr.CarServer.LockMsgPair.SetResp(msg);
Log.Info($"receive LockMsgResp = {msg}, lockMsg={lockMsg}");
if (lockMsg != null && lockMsg.CarNo == msg.CarNo)
{
CarServerMgr.CarServer.LockMsgPair.SetResp(msg);
}
} }
} }

@ -1,26 +1,28 @@
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Car.Msg.Car.Resp; using Service.Car.Msg.Car.Resp;
using Service.Car.Server; using Service.Car.Server;
namespace Service.Car.Handler; namespace Service.Car.Handler;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Order(8)] [Order(8)]
[Scope("InstancePerDependency")] [Scope("InstancePerDependency")]
public class SetParamMsgRespHandler : SimpleChannelInboundHandler<SetParamMsgResp>, IBaseHandler public class SetParamMsgRespHandler : SimpleChannelInboundHandler<SetParamMsgResp>, IBaseHandler
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(SetParamMsgRespHandler));
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="ctx"></param> /// <param name="ctx"></param>
/// <param name="msg"></param> /// <param name="msg"></param>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
protected override void ChannelRead0(IChannelHandlerContext ctx, SetParamMsgResp msg) protected override void ChannelRead0(IChannelHandlerContext ctx, SetParamMsgResp msg)
{ {
CarServerMgr.CarServer.Connected = true; Log.Info($"receive SetParamMsgResp = {msg}");
CarServerMgr.CarServer.SetParamMsgPair.SetResp(msg); CarServerMgr.CarServer.SetParamMsgPair.SetResp(msg);
} }
} }

@ -1,26 +1,29 @@
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Car.Msg.Car.Resp; using Service.Car.Msg.Car.Resp;
using Service.Car.Server; using Service.Car.Server;
namespace Service.Car.Handler; namespace Service.Car.Handler;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Order(8)] [Order(8)]
[Scope("InstancePerDependency")] [Scope("InstancePerDependency")]
public class SettleConfirmMsgRespHandler : SimpleChannelInboundHandler<SettleConfirmMsgResp>, IBaseHandler public class SettleConfirmMsgRespHandler : SimpleChannelInboundHandler<SettleConfirmMsgResp>, IBaseHandler
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(SettleConfirmMsgRespHandler));
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="ctx"></param> /// <param name="ctx"></param>
/// <param name="msg"></param> /// <param name="msg"></param>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
protected override void ChannelRead0(IChannelHandlerContext ctx, SettleConfirmMsgResp msg) protected override void ChannelRead0(IChannelHandlerContext ctx, SettleConfirmMsgResp msg)
{ {
CarServerMgr.CarServer.Connected = true; Log.Info($"receive SettleConfirmMsgResp = {msg}");
CarServerMgr.CarServer.SettleConfirmMsgPair.SetResp(msg); CarServerMgr.CarServer.SettleConfirmMsgPair.SetResp(msg);
} }
} }

@ -1,26 +1,34 @@
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Car.Msg.Car.Resp; using Service.Car.Msg.Car.Resp;
using Service.Car.Msg.Host.Req;
using Service.Car.Server; using Service.Car.Server;
namespace Service.Car.Handler; namespace Service.Car.Handler;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Order(8)] [Order(8)]
[Scope("InstancePerDependency")] [Scope("InstancePerDependency")]
public class UnLockMsgRespHandler : SimpleChannelInboundHandler<UnLockMsgResp>, IBaseHandler public class UnLockMsgRespHandler : SimpleChannelInboundHandler<UnLockMsgResp>, IBaseHandler
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(UnLockMsgRespHandler));
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="ctx"></param> /// <param name="ctx"></param>
/// <param name="msg"></param> /// <param name="msg"></param>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
protected override void ChannelRead0(IChannelHandlerContext ctx, UnLockMsgResp msg) protected override void ChannelRead0(IChannelHandlerContext ctx, UnLockMsgResp msg)
{ {
CarServerMgr.CarServer.Connected = true; UnLockMsg? unLockMsg = CarServerMgr.CarServer.UnLockMsgPair.Req;
CarServerMgr.CarServer.UnLockMsgPair.SetResp(msg); Log.Info($"receive UnLockMsgResp = {msg} unLockMsg={unLockMsg}");
if (unLockMsg != null && unLockMsg.CarNo == msg.CarNo)
{
CarServerMgr.CarServer.UnLockMsgPair.SetResp(msg);
}
} }
} }

@ -3,7 +3,6 @@ using HybirdFrameworkDriver.Common;
using HybirdFrameworkDriver.TcpServer; using HybirdFrameworkDriver.TcpServer;
using Service.Car.Codec; using Service.Car.Codec;
using Service.Car.Handler; using Service.Car.Handler;
using Service.Car.Msg.Car.Req;
using Service.Car.Msg.Car.Resp; using Service.Car.Msg.Car.Resp;
using Service.Car.Msg.Host.Req; using Service.Car.Msg.Host.Req;
@ -12,31 +11,20 @@ namespace Service.Car.Server;
[Scope("SingleInstance")] [Scope("SingleInstance")]
public class CarServer : TcpServer<IBaseHandler, Decoder, Encoder> public class CarServer : TcpServer<IBaseHandler, Decoder, Encoder>
{ {
/// <summary>
/// 客户端连接状态
/// </summary>
public bool Connected { get; set; }
public string? CarNo { get; set; } public MsgPair<LockMsg, LockMsgResp> LockMsgPair { get; set; } = new ();
public MsgPair<UnLockMsg, UnLockMsgResp> UnLockMsgPair { get; set; } = new ();
public MsgPair<LockMsg, LockMsgResp> LockMsgPair { get; set; } = new (); public MsgPair<SetParamMsg, SetParamMsgResp> SetParamMsgPair { get; set; } = new ();
public MsgPair<UnLockMsg, UnLockMsgResp> UnLockMsgPair { get; set; } = new (); public MsgPair<SettleConfirmMsg, SettleConfirmMsgResp> SettleConfirmMsgPair { get; set; } = new ();
public MsgPair<SetParamMsg, SetParamMsgResp> SetParamMsgPair { get; set; } = new ();
public MsgPair<SettleConfirmMsg, SettleConfirmMsgResp> SettleConfirmMsgPair { get; set; } = new ();
public HeartBeatMsg? HeartBeatMsg { get; set; }
/// <summary> /// <summary>
/// 1 待机 2 换电 /// 1 待机 2 换电
/// </summary> /// </summary>
public byte StationStatus { get; set; } = 1; public byte StationStatus { get; set; } = 1;
/// <summary>
/// 度电数据车载设备连接上换电站的 Wifi 网络时,主动上送度电数据报文(命令代码: 0x01发送周期 60s服务器回复相应的报文(命令代码0x02)
/// </summary>
public ElecMsg? ElecMsg { get; set; }
public CarServer() : base() public CarServer() : base()
{ {
@ -49,13 +37,9 @@ public class CarServer : TcpServer<IBaseHandler, Decoder, Encoder>
/// </summary> /// </summary>
public void Clean() public void Clean()
{ {
Connected = false;
CarNo = null;
HeartBeatMsg = null;
ElecMsg = null;
LockMsgPair.ClearResp(); LockMsgPair.ClearResp();
UnLockMsgPair.ClearResp(); UnLockMsgPair.ClearResp();
SetParamMsgPair.ClearResp(); SetParamMsgPair.ClearResp();
SettleConfirmMsgPair.ClearResp(); SettleConfirmMsgPair.ClearResp();
} }
} }

@ -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;
} }
} }

@ -2,6 +2,10 @@
public class SetParam public class SetParam
{ {
/// <summary>
/// 车vin
/// </summary>
public string CarNo { get; set; }
/// <summary> /// <summary>
/// 车辆累计放电量 /// 车辆累计放电量
/// </summary> /// </summary>
@ -66,4 +70,4 @@ public class SetParam
/// 14 待结算电费电量 /// 14 待结算电费电量
/// </summary> /// </summary>
public double ElectricityToBeSettled { get; set; } public double ElectricityToBeSettled { get; set; }
} }

Loading…
Cancel
Save