using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; using Repository.Station; using Service.Charger.Client; namespace Service.Charger; /// /// 充电机服务 /// [Scope] public class ChargerService { public BinInfoRepository BinInfoRepository { get; set; } /// /// 启动充电 /// /// /// public Result StartChargeByBinNo(string binNo) { BinInfo? binInfo = BinInfoRepository.QueryByBinNo(binNo); if (binInfo == null) { return Result.Fail(@"充电仓不存在"); } if (string.IsNullOrWhiteSpace(binInfo.ChargerNo)) { return Result.Fail(@"充电仓未配置充电机编号"); } ChargerClient? chargerClient = ClientMgr.GetBySn(binInfo.ChargerNo); if (chargerClient == null || !chargerClient.Connected) { return Result.Fail(@"充电机未连接"); } return chargerClient.StartCharge(); } /// /// 停止充电 /// /// /// public Result StopChargeByBinNo(string binNo) { BinInfo? binInfo = BinInfoRepository.QueryByBinNo(binNo); if (binInfo == null) { return Result.Fail(@"充电仓不存在"); } if (string.IsNullOrWhiteSpace(binInfo.ChargerNo)) { return Result.Fail(@"充电仓未配置充电机编号"); } ChargerClient? chargerClient = ClientMgr.GetBySn(binInfo.ChargerNo); if (chargerClient == null || !chargerClient.Connected) { return Result.Fail(@"充电机未连接"); } chargerClient.SendRemoteStopCharging(); return Result.Success("发送停止命令成功"); } }