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
2.0 KiB

using Entity.Constant;
using Entity.DbModel.Station;
7 months ago
using HybirdFrameworkCore.Autofac.Attribute;
using Newtonsoft.Json;
7 months ago
using Repository.Station;
using Service.Cloud.Client;
using Service.Cloud.Common;
using Service.Cloud.Msg.Cloud.Req;
7 months ago
using Service.Cloud.Msg.Host.Resp;
using Service.Init;
namespace Service.Cloud.Handler;
[Scope("InstancePerDependency")]
public class AmtBatHandler : IBaseHandler
{
7 months ago
private BinInfoRepository _binInfoRepository;
private SwapAmtOrderRepository _swapAmtOrderRepository;
7 months ago
public AmtBatHandler(BinInfoRepository binInfoRepository, SwapAmtOrderRepository swapAmtOrderRepository)
7 months ago
{
_binInfoRepository = binInfoRepository;
_swapAmtOrderRepository = swapAmtOrderRepository;
7 months ago
}
public void Handle(string t)
{
7 months ago
AmtBatRes abRes = new AmtBatRes();
AmtBat? amtBat = JsonConvert.DeserializeObject<AmtBat>(t);
abRes.result = 3;
7 months ago
if (amtBat != null)
{
int count = _swapAmtOrderRepository.GetCount(it =>
it.CarNo == amtBat.carNo && it.Status == (byte)InfoEnum.AmtOrderStatus.Success);
7 months ago
if (count > 0)
{
abRes.result = 1;
CloudClientMgr.CloudClient?.Publish(abRes);
7 months ago
}
else
{
SwapAmtOrder amtOrderInfo = new SwapAmtOrder();
amtOrderInfo.CarNo = amtBat.carNo;
amtOrderInfo.Status = (byte)InfoEnum.AmtOrderStatus.Success;
amtOrderInfo.BatteryCount = amtBat.batteryCount;
amtOrderInfo.BatteryType = amtBat.batteryTypeNo;
amtOrderInfo.AmtTime = amtBat.appointmentTime;
amtOrderInfo.ExpireTime = amtBat.appointmentTime.AddMinutes(amtBat.lockTime);
_swapAmtOrderRepository.Insert(amtOrderInfo);
CloudClientMgr.CloudClient?.Publish(abRes);
7 months ago
}
}
}
public bool CanHandle(string cmd)
{
return CloudConst.amtBat == cmd;
}
}