|
|
|
@ -9,18 +9,18 @@ using Service.Cloud.Msg.Host.Resp;
|
|
|
|
|
|
|
|
|
|
namespace Service.Cloud.Handler;
|
|
|
|
|
|
|
|
|
|
[Scope]
|
|
|
|
|
[Scope("InstancePerDependency")]
|
|
|
|
|
public class ChargerElectricityPriceModelHandler : IBaseHandler
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private ElecPriceModelVersionRepository _versionRepository;
|
|
|
|
|
private ElecPriceModelVersionDetailRepository _detailRepository;
|
|
|
|
|
private ElecPriceModelVersionRepository _versionRepository{ get; set; }
|
|
|
|
|
private ElecPriceModelVersionDetailRepository _detailRepository{ get; set; }
|
|
|
|
|
|
|
|
|
|
public ChargerElectricityPriceModelHandler(ElecPriceModelVersionRepository elecPriceModelVersionRepository,
|
|
|
|
|
ElecPriceModelVersionDetailRepository elecPriceModelVersionDetailRepository)
|
|
|
|
|
{
|
|
|
|
|
this._versionRepository = elecPriceModelVersionRepository;
|
|
|
|
|
this._detailRepository = elecPriceModelVersionDetailRepository;
|
|
|
|
|
_versionRepository = elecPriceModelVersionRepository;
|
|
|
|
|
_detailRepository = elecPriceModelVersionDetailRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanHandle(string cmd)
|
|
|
|
@ -33,36 +33,38 @@ public class ChargerElectricityPriceModelHandler : IBaseHandler
|
|
|
|
|
SetChargePrice? priceModel = JsonConvert.DeserializeObject<SetChargePrice>(t);
|
|
|
|
|
if (priceModel != null)
|
|
|
|
|
{
|
|
|
|
|
ElecPriceModelVersion version = _versionRepository.QueryByClause(d => d.Version == priceModel.ceid);
|
|
|
|
|
|
|
|
|
|
ElecPriceModelVersion version = _versionRepository.QueryByClause(d => d.Version == priceModel.electricityId);
|
|
|
|
|
|
|
|
|
|
if (version == null)
|
|
|
|
|
{
|
|
|
|
|
version = new ElecPriceModelVersion
|
|
|
|
|
{
|
|
|
|
|
Version = priceModel.ceid
|
|
|
|
|
Version = priceModel.electricityId,
|
|
|
|
|
Ceid = priceModel.electricityId.ToString()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
version.StartTime = DateTime.Now;
|
|
|
|
|
version.EndTime = DateTime.Now.AddYears(10);
|
|
|
|
|
_versionRepository.InsertOrUpdate(version);
|
|
|
|
|
|
|
|
|
|
List<Seg>? segs = priceModel.seg;
|
|
|
|
|
List<Seg>? segs = priceModel.timeList;
|
|
|
|
|
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
|
|
|
|
|
Price = d.price,
|
|
|
|
|
Type = d.type,
|
|
|
|
|
StartHour = d.startTime.Hour,
|
|
|
|
|
StartMinute = d.startTime.Minute,
|
|
|
|
|
StartSecond = d.startTime.Second,
|
|
|
|
|
EndHour = d.endTime.Hour,
|
|
|
|
|
EndMinute = d.endTime.Minute,
|
|
|
|
|
EndSecond = d.endTime.Second
|
|
|
|
|
}).ToList();
|
|
|
|
|
_detailRepository.Insert(versionDetails);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetChargePriceRes resp = new SetChargePriceRes();
|
|
|
|
|
CloudClientMgr.CloudClient?.Publish(resp);
|
|
|
|
|
}
|
|
|
|
|