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.

68 lines
2.8 KiB

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<BinInfo>
{
private readonly BinInfoRepository _binInfoRepository;
public BinInfoService(BinInfoRepository binInfoRepository)
{
_binInfoRepository = binInfoRepository;
}
/// <summary>
/// 获取仓位数据
/// </summary>
/// <returns>仓位数据列表</returns>
public List<BinInfoResp> GetChargMonitorChargBinData()
{
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.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;
}
}
return binInfoList;
}
/// <summary>
/// 禁用仓位
/// </summary>
/// <param name="id"></param>
/// <returns>修改结果</returns>
public bool UpdateStatus(int id)
{
return _binInfoRepository.UpdateStatus(id);
}
}