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.1 KiB

using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using Newtonsoft.Json;
using Repository.Station;
using Service.Cloud.Client;
using Service.Cloud.Common;
using Service.Cloud.Msg.Cloud.Req;
using Service.Cloud.Msg.Host.Resp;
namespace Service.Cloud.Handler;
[Scope("InstancePerDependency")]
public class BatteryOperatingModelHandler: IBaseHandler
{
private readonly BatteryOpModelRepository _batteryOpModelRepository;
private readonly BatteryOpModelDetailRepository _batteryOpModelDetailRepository;
public BatteryOperatingModelHandler(BatteryOpModelRepository batteryOpModelRepository,
BatteryOpModelDetailRepository batteryOpModelDetailRepository)
{
_batteryOpModelRepository = batteryOpModelRepository;
_batteryOpModelDetailRepository = batteryOpModelDetailRepository;
}
public bool CanHandle(string cmd)
{
return CloudConst.setOpModel == cmd;
}
public void Handle(string t)
{
BatteryOperatingModel? req = JsonConvert.DeserializeObject<BatteryOperatingModel>(t);
if (req != null)
{
BatteryOpModel batteryOpModel = new BatteryOpModel()
{
ModelId = req.oid,
CreatedTime = req.ut
};
_batteryOpModelRepository.Insert(batteryOpModel);
if (req.seg is {Count: > 0})
{
List<BatteryOpModelDetail> list = new();
foreach (var d in req.seg)
{
list.Add(new BatteryOpModelDetail()
{
ModelId = req.oid,
BatteryType = d.btc,
BatteryCount = d.bc,
StartTime = d.st,
EndTime = d.et
});
}
_batteryOpModelDetailRepository.Insert(list);
}
BatteryOperatingModelResp resp = new BatteryOperatingModelResp();
CloudClientMgr.CloudClient?.Publish(resp);
}
}
}