|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|