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.

157 lines
4.8 KiB

6 months ago
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;
public OutChargerController(ChargeOrderRepository chargeOrderRepository)
{
_chargeOrderRepository = chargeOrderRepository;
}
/// <summary>
/// 云平台下发开始充电操作
/// </summary>
/// <param name="httpReq"></param>
/// <returns></returns>
[HttpPost]
[Route("SendStartOutCharger")]
public Result<bool> SendStartOutCharger([FromBody] PileStartChargeHttpReq httpReq)
{
6 months ago
string chargerCode = ChargerUtils.GetOutChargerCode(httpReq.pn);
byte chargerGunCode = ChargerUtils.GetTheGun(httpReq.pn);
ChargerClient? chargerClient = ClientMgr.GetBySn(chargerCode);
if (chargerClient == null)
{
return Result<bool>.Fail("充电机未连接");
}
6 months ago
string chargeGunOrder = ChargerUtils.GenChargeOrderSn();
if (string.IsNullOrWhiteSpace(httpReq.con))
{
6 months ago
httpReq.con = chargeGunOrder;
}
6 months ago
chargerClient.ChargerPile[chargerGunCode].ct = httpReq.ct;
chargerClient.ChargerPile[chargerGunCode].cp = httpReq.cp;
chargerClient.ChargerPile[chargerGunCode].st = httpReq.st;
chargerClient.ChargerPile[chargerGunCode].con = httpReq.con;
chargerClient.ChargerPile[chargerGunCode].cosn = chargeGunOrder;
chargerClient.ChargerPile[chargerGunCode].pn = httpReq.pn;
byte chargeSoc = StaticStationInfo.ChargeSoc;
// 下发充电枪充电
6 months ago
chargerClient.SendStartOutCharger(chargerGunCode, chargeSoc, 360, 1, chargeGunOrder);
// 初始化订单
6 months ago
_chargeOrderRepository.SaveChargeGunOrder(chargeGunOrder, httpReq.con, chargerCode, httpReq.pn,
chargerGunCode.ToString());
return Result<bool>.Success(true);
}
6 months ago
/// <summary>
/// 云端下发充电枪停止充电
/// </summary>
/// <param name="httpReq"></param>
/// <returns></returns>
[HttpPost]
[Route("SendStopOutCharger")]
public Result<bool> 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<bool>.Fail("充电机未连接");
}
// 下发充电枪停止充电
chargerClient.SendStopOutCharger(chargerGunCode, 0);
return Result<bool>.Success(true);
}
6 months ago
/// <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 > 280)
{
return Result<bool>.Fail("功率值范围1到360");
}
if (pn != 1 && pn != 2)
{
return Result<bool>.Fail("请选择1枪或者2枪");
}
ChargerClient? chargerClient = ClientMgr.GetBySn(code);
if (chargerClient != null)
{
chargerClient.SendPileAdjustPower(pn,power);
return Result<bool>.Success(true);
}
return Result<bool>.Fail("充电机未连接");
}
6 months ago
/// <summary>
/// 获取充电桩信息
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("GetChargerPile")]
public Result<List<ChargerPileResp>> GetChargerPile()
{
var chargerClients = ClientMgr.Dictionary;
if (chargerClients.IsEmpty)
{
return Result<List<ChargerPileResp>>.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<List<ChargerPileResp>>.Success(list);
}
}