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.

70 lines
2.5 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]
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,
StartHour = d.st.Hour,
StartMinute = d.st.Minute,
StartSecond = d.st.Second,
EndHour = d.et.Hour,
EndMinute = d.et.Minute,
EndSecond = d.et.Second
}).ToList();
_detailRepository.Insert(versionDetails);
}
ChargerElectricityPriceModelResp resp = new ChargerElectricityPriceModelResp();
CloudClientMgr.CloudClient?.Publish(resp);
}
}
}