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) { SetChargePrice? priceModel = JsonConvert.DeserializeObject(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? segs = priceModel.seg; if (segs is { Count: > 0 }) { List 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); } SetChargePriceRes resp = new SetChargePriceRes(); CloudClientMgr.CloudClient?.Publish(resp); } } }