|
|
|
|
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]
|
|
|
|
|
public class ChargerElectricityPriceModelHandler : IBaseHandler
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private ElecPriceModelVersionRepository _versionRepository;
|
|
|
|
|
private ElecPriceModelVersionDetailRepository _detailRepository;
|
|
|
|
|
|
|
|
|
|
public ChargerElectricityPriceModelHandler(ElecPriceModelVersionRepository elecPriceModelVersionRepository,
|
|
|
|
|
ElecPriceModelVersionDetailRepository elecPriceModelVersionDetailRepository)
|
|
|
|
|
{
|
|
|
|
|
this._versionRepository = elecPriceModelVersionRepository;
|
|
|
|
|
this._detailRepository = elecPriceModelVersionDetailRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanHandle(string cmd)
|
|
|
|
|
{
|
|
|
|
|
return CloudConst.setChargePrice == cmd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Handle(string t)
|
|
|
|
|
{
|
|
|
|
|
ChargerElectricityPriceModel? priceModel = JsonConvert.DeserializeObject<ChargerElectricityPriceModel>(t);
|
|
|
|
|
if (priceModel != null)
|
|
|
|
|
{
|
|
|
|
|
ElecPriceModelVersion version = _versionRepository.QueryByClause(d => d.Version == priceModel.ceid);
|
|
|
|
|
if (version == null)
|
|
|
|
|
{
|
|
|
|
|
version = new ElecPriceModelVersion
|
|
|
|
|
{
|
|
|
|
|
Version = priceModel.ceid
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
version.StartTime = DateTime.Now;
|
|
|
|
|
version.EndTime = DateTime.Now.AddYears(10);
|
|
|
|
|
_versionRepository.InsertOrUpdate(version);
|
|
|
|
|
|
|
|
|
|
List<Seg>? segs = priceModel.seg;
|
|
|
|
|
if (segs is { Count: > 0 })
|
|
|
|
|
{
|
|
|
|
|
List<ElecPriceModelVersionDetail> versionDetails = segs.Select(d => new ElecPriceModelVersionDetail()
|
|
|
|
|
{
|
|
|
|
|
Version = version.Version,
|
|
|
|
|
Price = (int)d.ep * 10000,
|
|
|
|
|
Type = d.pr,
|
|
|
|
|
StartTime = d.st,
|
|
|
|
|
EndTime = d.et
|
|
|
|
|
}).ToList();
|
|
|
|
|
_detailRepository.Insert(versionDetails);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChargerElectricityPriceModelResp resp = new ChargerElectricityPriceModelResp();
|
|
|
|
|
CloudClientMgr.CloudClient?.Publish(resp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|