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.

107 lines
3.1 KiB

6 months ago
using AutoMapper;
using Entity.DbModel.Station;
using Entity.Dto.Resp;
using HybirdFrameworkCore.Entity;
6 months ago
using Microsoft.AspNetCore.Mvc;
using Repository.Station;
6 months ago
using Service.Charger;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
6 months ago
namespace WebStarter.Controllers;
/// <summary>
/// 充电机管理
/// </summary>
[Produces("application/json")]
[ApiController]
[Route("/api/[controller]")]
6 months ago
public class ChargeController : ControllerBase
{
private ChargerService _chargerService;
private BinInfoRepository _binInfoRepository;
6 months ago
6 months ago
public ChargeController(ChargerService chargerService, BinInfoRepository binInfoRepository)
6 months ago
{
_chargerService = chargerService;
_binInfoRepository = binInfoRepository;
6 months ago
}
6 months ago
/// <summary>
/// 仓位信息
/// </summary>
/// <returns>仓位信息列表</returns>
[HttpGet]
[Route("/api/ChrgMonitor/GetChargMonitorChargBinData")]
6 months ago
public Result<List<BinInfoResp>> GetChargMonitorChargBinData()
{
6 months ago
List<BinInfo> binInfos = _binInfoRepository.Query();
var configuration = new MapperConfiguration(cfg => cfg.CreateMap<BinInfo, BinInfoResp>());
var mapper = configuration.CreateMapper();
// 转换为 BinInfoResp 列表
List<BinInfoResp> binInfoList = mapper.Map<List<BinInfoResp>>(binInfos);
// 功率赋值
foreach (var binInfoResp in binInfoList)
{
ChargerClient? chargerClient = ClientMgr.GetBySn(binInfoResp.Code);
if (chargerClient != null)
{
binInfoResp.power = chargerClient.RealTimeChargePower;
}
}
return Result<List<BinInfoResp>>.Success(binInfoList);
}
6 months ago
/// <summary>
/// 仓位禁用
/// </summary>
/// <param name="data">需要禁用仓id</param>
/// <returns>仓位信息列表</returns>
[HttpGet]
[Route("/api/TBsChargingBinInfo/ChargingBinDisable{data}")]
public Result<bool> ChargingBinDisable(int data)
{
return Result<bool>.Success(_binInfoRepository.UpdateStatus(data));
}
6 months ago
/// <summary>
/// 获取仓位实时功率
/// </summary>
/// <returns>仓位实时功率列表</returns>
[HttpPost]
[Route("/api/ChrgMonitor/GetBinPowers")]
public Result<float[]> GetBinPowers()
{
float[] results = ClientMgr.Dictionary.Values
.Select(chargerClient => chargerClient.RealTimeChargePower)
.ToArray();
return Result<float[]>.Success(results);
}
6 months ago
6 months ago
/// <summary>
/// 通过仓号启动充电
/// </summary>
/// <param name="binNo">仓号</param>
/// <returns></returns>
[HttpGet]
[Route("/api/ChrgMonitor/StartChargeByBinNo/{binNo}")]
6 months ago
public Result<bool> StartChargeByBinNo(string binNo)
{
return _chargerService.StartChargeByBinNo(binNo);
}
/// <summary>
/// 通过仓号停止充电
/// </summary>
/// <param name="binNo">仓号</param>
/// <returns></returns>
[HttpGet]
[Route("/api/ChrgMonitor/StopChargeByBinNo/{binNo}")]
6 months ago
public Result<bool> StopChargeByBinNo(string binNo)
{
return _chargerService.StartChargeByBinNo(binNo);
}
}