You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.8 KiB
127 lines
3.8 KiB
using Common.Const;
|
|
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.Init;
|
|
|
|
namespace WebStarter.Controllers;
|
|
|
|
/// <summary>
|
|
/// 站外充电机管理
|
|
/// </summary>
|
|
[Produces("application/json")]
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class OutChargerController
|
|
{
|
|
private ChargeOrderRepository _chargeOrderRepository;
|
|
|
|
private BinInfoRepository _binInfoRepository;
|
|
|
|
public OutChargerController(ChargeOrderRepository chargeOrderRepository,BinInfoRepository binInfoRepository)
|
|
{
|
|
_chargeOrderRepository = chargeOrderRepository;
|
|
_binInfoRepository = binInfoRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 云平台下发开始充电操作
|
|
/// </summary>
|
|
/// <param name="httpReq"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("SendStartOutCharger")]
|
|
public Result<bool> SendStartOutCharger([FromBody] PileStartChargeHttpReq httpReq)
|
|
{
|
|
|
|
var chargerCode = httpReq.pn;
|
|
ChargerClient? chargerClient = ClientMgr.GetBySn(chargerCode);
|
|
|
|
if (chargerClient == null)
|
|
{
|
|
return Result<bool>.Fail("充电机未连接");
|
|
}
|
|
|
|
string chargeGunOrder = ChargerUtils.GenChargeOrderSn();
|
|
if (string.IsNullOrWhiteSpace(httpReq.con))
|
|
{
|
|
httpReq.con = chargeGunOrder;
|
|
}
|
|
|
|
chargerClient.ChargerPile.ct = httpReq.ct;
|
|
chargerClient.ChargerPile.cp = httpReq.cp;
|
|
chargerClient.ChargerPile.st = httpReq.st;
|
|
chargerClient.ChargerPile.con = httpReq.con;
|
|
chargerClient.ChargerPile.cosn = chargeGunOrder;
|
|
chargerClient.ChargerPile.pn = httpReq.pn;
|
|
|
|
byte chargeSoc = StaticStationInfo.ChargeSoc;
|
|
// 下发充电枪充电
|
|
chargerClient.SendRemoteStartCharging((byte)ChargerModeConst.OutsideTheStation, chargeSoc, 360, 1, chargeGunOrder);
|
|
|
|
_binInfoRepository.Update(i => i.ChargeStatus == 5, i => i.ChargerNo == chargerClient.Sn);
|
|
|
|
// 初始化订单
|
|
_chargeOrderRepository.SaveChargeGunOrder(chargeGunOrder, httpReq.con, chargerCode, httpReq.pn,
|
|
chargerCode);
|
|
|
|
return Result<bool>.Success(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 云端下发充电枪停止充电
|
|
/// </summary>
|
|
/// <param name="httpReq"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("SendStopOutCharger")]
|
|
public Result<bool> SendStopOutCharger([FromBody] PileStopChargeHttpReq httpReq)
|
|
{
|
|
|
|
ChargerClient? chargerClient = ClientMgr.GetBySn(httpReq.pn);
|
|
|
|
if (chargerClient == null)
|
|
{
|
|
return Result<bool>.Fail("充电机未连接");
|
|
}
|
|
|
|
// 下发充电枪停止充电
|
|
chargerClient.SendRemoteStopCharging();
|
|
|
|
_binInfoRepository.Update(i => i.ChargeStatus == 4, i => i.ChargerNo == chargerClient.Sn);
|
|
|
|
return Result<bool>.Success(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 给充电枪发送功率调节指令
|
|
/// </summary>
|
|
/// <param name="code">充电机code</param>
|
|
/// <param name="pn">1枪 or 2枪</param>
|
|
/// <param name="power">功率</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("SendPowerRegulation/{code}/{pn}/{power}")]
|
|
public Result<bool> SendPowerRegulation(string code,byte pn, float power)
|
|
{
|
|
if (power <=0 || power > 360)
|
|
{
|
|
return Result<bool>.Fail("功率值范围1到360");
|
|
}
|
|
|
|
ChargerClient? chargerClient = ClientMgr.GetBySn(code);
|
|
|
|
if (chargerClient != null)
|
|
{
|
|
chargerClient.SendPowerRegulation(power);
|
|
return Result<bool>.Success(true);
|
|
}
|
|
|
|
return Result<bool>.Fail("充电机未连接");
|
|
}
|
|
|
|
} |