using HybirdFrameworkCore.Entity; using Microsoft.AspNetCore.Mvc; using Repository.Station; using Service.Charger.Client; using Service.Charger.Common; using Service.Charger.Msg.Http.Req; using Service.Init; namespace WebStarter.Controllers; /// /// 站外充电机管理 /// [Produces("application/json")] [ApiController] [Route("api/[controller]")] public class OutChargerController { private ChargeOrderRepository _chargeOrderRepository; public OutChargerController(ChargeOrderRepository chargeOrderRepository) { _chargeOrderRepository = chargeOrderRepository; } /// /// 云平台下发开始充电操作 /// /// /// [HttpPost] [Route("SendStartOutCharger")] public Result SendStartOutCharger([FromBody] PileStartChargeHttpReq httpReq) { string chargerCode = ChargerUtils.GetOutChargerCode(httpReq.pn); byte chargerGunCode = ChargerUtils.GetTheGun(httpReq.pn); ChargerClient? chargerClient = ClientMgr.GetBySn(chargerCode); if (chargerClient == null) { return Result.Fail("充电机未连接"); } if (string.IsNullOrWhiteSpace(httpReq.con)) { httpReq.con = ChargerUtils.GenChargeOrderSn(); } byte chargeSoc = StaticStationInfo.ChargeSoc; // 下发充电枪充电 chargerClient.SendStartOutCharger(chargerGunCode, chargeSoc, 360, 1, httpReq.con); // 初始化订单 _chargeOrderRepository.SaveChargeGunOrder(httpReq.con, chargerCode, httpReq.pn, chargerGunCode.ToString()); return Result.Success(true); } /// /// 云端下发充电枪停止充电 /// /// /// [HttpPost] [Route("SendStopOutCharger")] public Result SendStopOutCharger([FromBody] PileStopChargeHttpReq httpReq) { string chargerCode = ChargerUtils.GetOutChargerCode(httpReq.pn); byte chargerGunCode = ChargerUtils.GetTheGun(httpReq.pn); ChargerClient? chargerClient = ClientMgr.GetBySn(chargerCode); if (chargerClient == null) { return Result.Fail("充电机未连接"); } // 下发充电枪停止充电 chargerClient.SendStopOutCharger(chargerGunCode, 0); return Result.Success(true); } }