using log4net; using Microsoft.AspNetCore.Mvc; using Service.Api.Resp; using Service.TBox.Server; using Service.TBox.Service; using WebStarter.Dto.Resp; namespace WebStarter.Controllers; /// /// 车辆管理 /// [ApiController] [Route("[controller]")] public class TBoxController : ControllerBase { private static readonly ILog Log = LogManager.GetLogger(typeof(TBoxController)); /// /// 连接车辆 /// /// vin码 /// [HttpGet("connect/{carNo}")] public bool Connect(string carNo) { Log.Info($"Connect {carNo}"); TBoxServerMgr.Server.StartSendVin(carNo); return TBoxServerMgr.Server != null && TBoxServerMgr.Server.BatteryNo()!=null; } /// /// 加锁 /// /// vin码 /// "0:未解锁未上锁 1:解锁成功 2:上锁成功 3:无效数据 其他状态无效" [HttpGet("lock/{carNo}")] public bool Lock(string carNo) { Log.Info($"Lock {carNo}"); TBoxServerMgr.Server?.StartSendLock(1); return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus==2; } /// /// 解锁 /// /// vin码 /// 发送状态 [HttpGet("unLock/{carNo}")] public bool UnLock(string carNo) { Log.Info($"UnLock {carNo}"); TBoxServerMgr.Server?.StartSendLock(2); if (TBoxService.GetHnYQCarInfo(carNo).CarInfo.CarVin != carNo) { Connect(carNo); } return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus ==1; } /// /// 获取车辆信息 /// /// [HttpGet("getCarInfo/{carNo}")] public CarInfoResp GetCarInfo(string carNo) { Log.Info($"getCarInfo {carNo}"); return TBoxService.GetHnYQCarInfo(carNo); } /// /// 断开连接 /// /// vin码 /// 发送状态 [HttpGet("disConnect/{carNo}")] public bool DisConnect(string carNo) { Log.Info($"DisConnect {carNo}"); TBoxServerMgr.Server?.StartSendLock(0); return TBoxServerMgr.Server != null && !TBoxServerMgr.Server.Connected; } /// /// Reset /// /// vin码 /// [HttpGet("reset")] public bool Reset() { Log.Info($"Reset "); TBoxServerMgr.Server?.Reset(); return true; } }