using Entity.Api.Req; using Entity.Api.Resp; using Entity.DbModel.Station; using HybirdFrameworkCore.Entity; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; using Service.Charger.Msg.Host.Req; using Service.Charger.Server; using Service.Station; namespace WebStarter.Controllers; /// /// 充电大屏 /// [ApiController] [Route("api/[controller]")] public class ChargeMonitorController { private readonly BinInfoService _binInfoService; private readonly MonitorService _monitorService; private readonly IStringLocalizer _localizer; public ChargeMonitorController(IStringLocalizer localizer,BinInfoService binInfoService, MonitorService monitorService) { _localizer = localizer; _binInfoService = binInfoService; _monitorService = monitorService; } /// /// 仓位预约 /// /// 仓位 /// /// /// [HttpPost("BinInfoMakeAnAppointment/{binNo}/{amtLock}")] public async Task> BinInfoMakeAnAppointment(string binNo, int amtLock) { BinInfo binInfo = await _binInfoService.QueryByClauseAsync(u => u.No == binNo); if (binInfo == null) throw new Exception("充电仓不存在"); binInfo.AmtLock = amtLock; bool result = await _binInfoService.UpdateAsync(binInfo); if (result) return Result.Success(result); else return Result.Fail(result); } /// /// 修改仓位电池编码 /// /// /// /// /// [HttpPost("UpdateBatteryNo/{binNo}/{batteryNo}")] public async Task> UpdateBatteryNo(string binNo, string batteryNo) { BinInfo binInfo = await _binInfoService.QueryByClauseAsync(u => u.No == binNo); if (binInfo == null) throw new Exception("充电仓不存在"); BinInfo binInfoBatteryNo = await _binInfoService.QueryByClauseAsync(u => u.BatteryNo == batteryNo); if (binInfoBatteryNo != null) { throw new Exception("已存在相同电池编码"); } binInfo.BatteryNo = batteryNo; bool result = await _binInfoService.UpdateAsync(binInfo); if (result) return Result.Success(result); else return Result.Fail(result); } /// /// 充电仓查询:条件:仓位编号 仓位名称 /// [HttpPost("ChargePositionQuery")] public async Task>> ChargePositionQuery( [FromBody] ChargePositionQueryReq chargePositionQueryReq) { PageResult respList = await _binInfoService.ChargePositionQuery(chargePositionQueryReq); if (respList.Rows!=null) { foreach (var resp in respList.Rows) { resp.Name = _localizer[resp.Name]; } } return Result>.Success(respList); } /// /// 充电仓 0:禁用 1:启用 /// /// 仓位编号 /// 仓位状态:0-禁用、1-启用 /// /// [HttpPost("SetChargingBinStatus/{binNo}/{status}")] public async Task> ChargingBinDisable(string binNo, int status) { BinInfo binInfo = await _binInfoService.QueryByClauseAsync(u => u.No == binNo); if (binInfo == null) throw new Exception("充电仓不存在"); binInfo.Status = status; bool result = await _binInfoService.UpdateAsync(binInfo); if (result) return Result.Success(result); else return Result.Fail(result); } /// /// 电池移仓 /// /// 取仓号 /// 放仓号 /// [HttpGet("BatteryRelocation")] public async Task> BatteryRelocation(ushort removeBinNo, ushort putBinNo) { Result res = Result.Fail(); try { res = _monitorService.BatteryRelocation(removeBinNo, putBinNo, 1); } catch (Exception e) { Result.Fail(); } return res; } /// /// 移仓时下拉项 仓位电池状态 /// [HttpGet("GetChargeBinOption")] public Result> GetChargeBinOption() { Result> respList = _monitorService.GetChargeBinOption(); if (respList.Data!=null) { foreach (var resp in respList.Data) { resp.Name = _localizer[resp.Name]; } } return respList; } }