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.

72 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("InstancePerDependency")]
public class ChargerElectricityPriceModelHandler : IBaseHandler
{
private ElecPriceModelVersionRepository _versionRepository{ get; set; }
private ElecPriceModelVersionDetailRepository _detailRepository{ get; set; }
public ChargerElectricityPriceModelHandler(ElecPriceModelVersionRepository elecPriceModelVersionRepository,
ElecPriceModelVersionDetailRepository elecPriceModelVersionDetailRepository)
{
_versionRepository = elecPriceModelVersionRepository;
_detailRepository = elecPriceModelVersionDetailRepository;
}
public bool CanHandle(string cmd)
{
return CloudConst.setChargePrice == cmd;
}
public void Handle(string t)
{
SetChargePrice? priceModel = JsonConvert.DeserializeObject<SetChargePrice>(t);
if (priceModel != null)
{
ElecPriceModelVersion version = _versionRepository.QueryByClause(d => d.Version == priceModel.electricityId);
if (version == null)
{
version = new ElecPriceModelVersion
{
Version = priceModel.electricityId,
Ceid = priceModel.electricityId.ToString()
};
}
version.StartTime = DateTime.Now;
version.EndTime = DateTime.Now.AddYears(10);
_versionRepository.InsertOrUpdate(version);
List<Seg>? segs = priceModel.timeList;
if (segs is { Count: > 0 })
{
List<ElecPriceModelVersionDetail> versionDetails = segs.Select(d => new ElecPriceModelVersionDetail()
{
Version = version.Version,
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);
}
}
}