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.
153 lines
4.2 KiB
153 lines
4.2 KiB
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?.Connected ?? false,
|
|
CarNo = CarServerMgr.CarServer?.HeartBeatMsg?.CarNo,
|
|
ElecMsg = CarServerMgr.CarServer?.ElecMsg,
|
|
HeartBeatMsg = CarServerMgr.CarServer?.HeartBeatMsg
|
|
};
|
|
return carInfoResp;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 锁车
|
|
/// </summary>
|
|
/// <returns>发送结果</returns>
|
|
[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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 解锁
|
|
/// </summary>
|
|
/// <returns>发送结果</returns>
|
|
[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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结算
|
|
/// </summary>
|
|
/// <returns>发送结果</returns>
|
|
[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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置参数
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[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;
|
|
}
|
|
|
|
/// <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;
|
|
}
|
|
} |