using Entity.Dto.Resp; 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.Charger.Server; using Service.Init; using Service.Station; namespace WebStarter.Controllers; /// /// 站外充电机管理 /// [Produces("application/json")] [ApiController] [Route("api/[controller]")] public class OutChargerController { private ChargeOrderRepository _chargeOrderRepository; private BinInfoService _binInfoService; private BinGunInfoRepository _binGunInfoRepository; public OutChargerController(ChargeOrderRepository chargeOrderRepository,BinInfoService binInfoService,BinGunInfoRepository binGunInfoRepository) { _chargeOrderRepository = chargeOrderRepository; _binInfoService = binInfoService; _binGunInfoRepository = binGunInfoRepository; } /// /// 云平台下发开始充电操作 /// /// /// [HttpPost] [Route("SendStartOutCharger")] public Result SendStartOutCharger([FromBody] PileStartChargeHttpReq httpReq) { byte.TryParse(httpReq.pn,out var chargerGunCode ); ChargerClient? chargerClient = ServerMgr.GetBySn(httpReq.ChargeNo); if (chargerClient == null) { return Result.Fail("充电机未连接"); } string chargeGunOrder = ChargerUtils.GenChargeOrderSn(); if (string.IsNullOrWhiteSpace(httpReq.con)) { httpReq.con = chargeGunOrder; } ChargerPile chargerPile = new() { ct = httpReq.ct, cp = httpReq.cp, st = httpReq.st, con = httpReq.con, cosn = chargeGunOrder, pn = httpReq.pn, }; if (chargerGunCode==1) chargerClient.ChargerPile1 = chargerPile; else chargerClient.ChargerPile2 = chargerPile; byte chargeSoc = StaticStationInfo.ChargeSoc; // 下发充电枪充电 chargerClient.SendStartOutCharger(chargerGunCode, chargeSoc, 20, 1, chargeGunOrder); // 初始化订单 _chargeOrderRepository.SaveChargeGunOrder(chargeGunOrder, httpReq.con,httpReq.ChargeNo , httpReq.pn, chargerGunCode.ToString()); return Result.Success(true); } /// /// 云端下发充电枪停止充电 /// /// /// [HttpPost] [Route("SendStopOutCharger")] public Result SendStopOutCharger([FromBody] PileStopChargeHttpReq httpReq) { byte.TryParse(httpReq.pn,out var chargerGunCode ); ChargerClient? chargerClient = ServerMgr.GetBySn(httpReq.ChargeNo); if (chargerClient == null) { return Result.Fail("充电机未连接"); } // 下发充电枪停止充电 return chargerClient.SendStopOutCharger(chargerGunCode, 0); } /// /// 给充电枪发送功率调节指令 /// /// 充电机code /// 1枪 or 2枪 /// 功率 /// [HttpGet] [Route("SendPowerRegulation/{code}/{pn}/{power}")] public Result SendPowerRegulation(string code,byte pn, float power) { if (power <=0 || power > 280) { return Result.Fail("功率值范围1到360"); } if (pn != 1 && pn != 2) { return Result.Fail("请选择1枪或者2枪"); } string _code = _binInfoService.QueryByClause(i => i.Code == code).ChargerNo; ChargerClient? chargerClient = ServerMgr.GetBySn(_code); if (chargerClient != null) { chargerClient.SendPileAdjustPower(pn,power); return Result.Success(true); } return Result.Fail("充电机未连接"); } /// /// 获取充电桩信息 /// /// [HttpGet] [Route("GetChargerPile")] public Result> GetChargerPile() { var chargerClients = ServerMgr.Dictionary; if (chargerClients.IsEmpty) { return Result>.Fail("没有充电机连接"); } var list = chargerClients.Values.Select(client => new ChargerPileResp { Sn = client.Sn, GunChargedOne = client.GunCharged[1], GunChargedTwo = client.GunCharged[2], ChargedPileOne = client.ChargedPile[1], ChargedPileTwo = client.ChargedPile[2], ChargePilePowerOne = client.ChargePilePower[1], ChargePilePowerTwo = client.ChargePilePower[2] }).ToList(); return Result>.Success(list); } }