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.

72 lines
2.0 KiB

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