using AutoMapper; using Entity.DbModel.Station; using Entity.Dto.Resp; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; using Repository.Station; using Service.Charger.Client; namespace Service.Station; [Scope("SingleInstance")] public class BinInfoService : BaseServices { private readonly BinInfoRepository _binInfoRepository; public BinInfoService(BinInfoRepository binInfoRepository) { _binInfoRepository = binInfoRepository; } /// /// 获取仓位数据 /// /// 仓位数据列表 public List 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.ChargerNo); if (chargerClient != null) { binInfoResp.power = chargerClient.RealTimeChargePower; binInfoResp.ChargeConnectFlag = chargerClient.Connected; binInfoResp.ChargingTime = chargerClient.UploadTelemetryData.ChargingTime; binInfoResp.EstimatedRemainingTime = chargerClient.UploadTelemetryData.EstimatedRemainingTime; if (chargerClient.BatteryPackTotalElectricity != null) binInfoResp.OnceElectricCharge = chargerClient.BatteryPackTotalElectricity.OnceElectricCharge; binInfoResp.BmsNeedVoltage = chargerClient.UploadTelemetryData.BmsNeedVoltage; binInfoResp.BmsNeedCurrent = chargerClient.UploadTelemetryData.BmsNeedCurrent; if (chargerClient.BatteryPackData != null) binInfoResp.TotalCurrent = chargerClient.BatteryPackData.TotalCurrent; if (chargerClient.BatteryPackDataVoltage != null) binInfoResp.CellTemperatureMax = chargerClient.BatteryPackDataVoltage.CellTemperatureMax; if (chargerClient.BatteryPackDataVoltage != null) binInfoResp.CellTemperatureMin = chargerClient.BatteryPackDataVoltage.CellTemperatureMin; binInfoResp.ChargingStartTime = chargerClient.ChargingStartTime; binInfoResp.ChargingStopTime = chargerClient.ChargingStopTime; binInfoResp.IsAuthed = chargerClient.IsAuthed; } } return binInfoList; } /// /// 禁用仓位 /// /// /// 修改结果 public bool UpdateStatus(int id) { return _binInfoRepository.UpdateStatus(id); } }