using COSXML.Utils; using DotNetty.Common.Utilities; using Entity.Api.Req; using Entity.Api.Resp; using Entity.Constant; using Entity.DbModel.Station; using HybirdFrameworkCore.Entity; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; using Repository.Station; using Service.Execute; using Service.Execute.Api; using Service.Execute.Model; using Service.Execute.Model.Tbox; using Service.Init; using Service.Station; namespace WebStarter.Controllers; /// /// 换电大屏 /// [ApiController] [Route("api/[controller]")] public class SwapMonitorController : ControllerBase { private readonly MonitorService _swapMonitorService; private readonly BinInfoService _binInfoService; private readonly IStringLocalizer _localizer; public readonly SwapOrderRepository _swapOrderRepository; public SwapMonitorController(MonitorService swapMonitorService, BinInfoService binInfoService,SwapOrderRepository swapOrderRepository) { _swapMonitorService = swapMonitorService; _binInfoService = binInfoService; _swapOrderRepository = swapOrderRepository; } /// /// 获取设备连接状态 目前 Tbox 云平台 plc /// /// [HttpPost("GetDeviceState")] public Result GetDeviceState() { return _swapMonitorService.GetDeviceState(); } /// /// 首页换电状态信息 /// /// [HttpPost("GetSwapMonitorData")] public async Task> GetSwapMonitorData() { var respList = _swapMonitorService.GetSwapMonitorData(); return respList; } /// /// 手动写入车辆vin码 /// /// [HttpPost("WriteVin")] public Result WriteVin([FromBody] RfidReadModel req) { if (StaticStationInfo.VehicleManually != 1) { return Result.Fail("此模式不支持手动写车辆数据,请先切换换电执行模式"); } if (StationSoftMgr.SwappingStateMachine.BeginRfidReadFlag || StationSoftMgr.SwappingStateMachine.RfidReadFlag) { return Result.Fail("目前换电进行中,请勿修改数据"); } StationSoftMgr.SwappingStateMachine.BeginRfidReadFlag = true; StationSoftMgr.SwappingStateMachine.RfidReadModel = req; return Result.Success(); } /// /// 获取模式类 /// /// [HttpPost("GetModel")] public async Task> GetModel() { return _swapMonitorService.GetModel(); } /// /// 车辆手动上锁解锁 /// /// [HttpPost("LockCar")] public async Task> LockCar(string carNo) { var success = await TBoxApi.LockCarManyTimes(carNo); return success ? Result.Success() : Result.Fail(); } /// /// 车辆手动解锁 /// /// [HttpPost("UnLockCar")] public async Task> UnLockCar(string carNo) { var success = await TBoxApi.UnLockCarManyTimes(carNo); return success ? Result.Success() : Result.Fail(); } /// /// 获取充电监控大屏 充电次数 每五分钟获取一次 /// [HttpPost("GetSwapAndChargingCount")] public async Task> SwapAndChargingCount() { return _swapMonitorService.SwapAndChargingCount(); } /// /// 设置换电模式:1:本地换电 2:远程换电 /// [HttpPost("SetSwapModel/{swapModel}")] public async Task> SetSwapModel(int swapModel) { StaticStationInfo.StationModel = swapModel; return Result.Success(); } /// /// 换电复位 /// [HttpPost("SwapReset")] public async Task> SwapReset() { StationSoftMgr.SwappingStateMachineCancel(); return Result.Success(); } /// /// 人工操作换电成功标识 /// /// [HttpGet("SwapPlcSucc")] public Result SwapPlcSucc() { return Result.Success(StationSoftMgr.SwappingStateMachine.PlcSwapFlag); } /// /// 人工操作换电成功还是失败 /// /// [HttpPost("ManualOperateSwap")] public Result ManualOperateSwap([FromBody] OperateModelReq req) { StationSoftMgr.SwappingStateMachine.OperateModel = new OperateModel() { Type = req.Type, Operator = req.Operator, Reason = req.Reason }; if (req.Type == 1) { if (!StationSoftMgr.SwappingStateMachine.PlcSwapFlag) { return Result.Fail("不满足确认换电成功条件"); } Task.Run(StationSoftMgr.SwappingStateMachineManual); } else { SwapOrder? swapOrder = StationSoftMgr.SwappingStateMachine.SwapOrder; if (swapOrder!=null) { if (req.Reason != null) { swapOrder.Remark = req.Reason; _swapOrderRepository.Update(swapOrder); } } Task.Run(StationSoftMgr.SwappingStateMachineCancel); } return Result.Success(); } /// /// 消防移仓 /// /// 入仓位选择:移仓仓位号 /// [HttpPost("FireProtectionRelocation/{entrySelect}")] public Result FireProtectionRelocation(string entrySelect) { return _binInfoService.FireProtectionRelocation(entrySelect); } /// /// 切换成 手动换电 /// [HttpPost("ManualSwapping")] public Result ManualSwapping() { StaticStationInfo.StationWay = (int)StationConstant.StationWay.Manual; return Result.Success(); } /// /// 切换成 自动换电 /// [HttpPost("AutoSwapping")] public Result AutoSwapping() { StaticStationInfo.StationWay = (int)StationConstant.StationWay.Auto; return Result.Success(); } /// /// 切换成 营业状态 /// 换电站状态: 1:营运中 2:歇业中 3:设备维护状态 4:暂停营业 /// [HttpPost("HandoverStationStatus/{status}")] public Result HandoverStationStatus(int status) { StaticStationInfo.StationStatus = status; return Result.Success(); } /// /// 获取所有连接车辆 /// [HttpGet("GetCarList")] public async Task>> GetCarList() { //兼容不能查车辆列表的,就获取当前换电车辆 if (!StaticStationInfo.TboxStateCarList) { if (StationSoftMgr.SwappingStateMachine.BoxCarInfoModel == null) { return Result>.Success(new List()); } return Result>.Success(new() { StationSoftMgr.SwappingStateMachine.BoxCarInfoModel }); } var carInfoList = await TBoxApi.GetCarInfoList(); if (carInfoList == null || carInfoList.Count <= 0) { return Result>.Success(new List()); } return Result>.Success(carInfoList.Where(i => i.CarNo.Length >= 17).ToList()); } /// /// 确认上锁成功 /// [HttpGet("ConfirmLockSucc")] public async Task> ConfirmLockSucc() { StationSoftMgr.SwappingStateMachine.ManualConfirmLockCar(); return Result.Success(); } /// /// 确认解锁成功 /// [HttpGet("ConfirmUnLockSucc")] public async Task> ConfirmUnLockSucc() { StationSoftMgr.SwappingStateMachine.ManualConfirmUnLockCar(); return Result.Success(); } /// /// 手动跳过雷达 /// [HttpGet("")] public Result>> skipTheRadar() { return Result>>.Success(_swapMonitorService.CanSelectPackBin()); } /// /// 可选仓位 /// [HttpGet("CanSelectPackBin")] public Result>> CanSelectPackBin() { return Result>>.Success(_swapMonitorService.CanSelectPackBin()); } /// /// 手动选仓 /// /// [HttpPost("SelectPackManual/{upBinId}/{inBinId}")] public Result SelectPackManual(int upBinId, int inBinId) { if (StaticStationInfo.SelectPackManually != (int)SwapConstant.AutoOrManual.Manual) { return Result.Fail("此模式不支持手动选仓,请先切换选包模式"); } if (StationSoftMgr.SwappingStateMachine.SelectPackFlag) { return Result.Fail("目前换电进行中,请勿修改数据"); } return _swapMonitorService.SelectPackManual(upBinId, inBinId); } /// /// 手动跳过雷达 /// /// [HttpGet("SkipRadarManual")] public Result SkipRadarManual() { StationSoftMgr.SwappingStateMachine!.ManualSkipRadar = true; return Result.Success(); } }