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.

60 lines
1.7 KiB

using Entity.Constant;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using Newtonsoft.Json;
using Repository.Station;
using Service.Cloud.Common;
using Service.Cloud.Msg.Cloud.Req;
using Service.Cloud.Msg.Host.Resp;
using Service.Init;
namespace Service.Cloud.Handler;
[Scope("InstancePerDependency")]
public class AmtBatHandler : IBaseHandler
{
private BinInfoRepository _binInfoRepository;
private SwapAmtOrderRepository _swapAmtOrderRepository;
public AmtBatHandler(BinInfoRepository binInfoRepository, SwapAmtOrderRepository swapAmtOrderRepository)
{
_binInfoRepository = binInfoRepository;
_swapAmtOrderRepository = swapAmtOrderRepository;
}
public void Handle(string t)
{
AmtBatRes abRes = new AmtBatRes();
abRes.rs = 3;
AmtBat? amtBat = JsonConvert.DeserializeObject<AmtBat>(t);
if (amtBat != null)
{
int count = _swapAmtOrderRepository.GetCount(it =>
it.CarNo == amtBat.cn && it.Status == (byte)InfoEnum.AmtOrderStatus.Success);
if (count > 0)
{
abRes.rs = 1;
}
else
{
SwapAmtOrder amtOrderInfo = new SwapAmtOrder()
{
Sn = StaticStationInfo.StationNo,
CarNo = amtBat.cn,
BatteryCount = amtBat.bm,
BatteryType = amtBat.bn,
AmtTime = amtBat.at,
ExpireTime = amtBat.at.AddMinutes(amtBat.am)
};
}
}
}
public bool CanHandle(string cmd)
{
return CloudConst.amtBat == cmd;
}
}