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