下发电价模型处理

master
smartwyy 6 months ago
parent 9e19414383
commit f8e91cf761

@ -29,7 +29,7 @@ namespace Entity.DbModel.Station
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="version")] [SugarColumn(ColumnName="version")]
public string Version {get;set;} public int Version {get;set;}
/// <summary> /// <summary>
/// Desc:生效时间;生效时间(左开右闭) /// Desc:生效时间;生效时间(左开右闭)

@ -29,7 +29,7 @@ namespace Entity.DbModel.Station
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="version")] [SugarColumn(ColumnName="version")]
public string Version {get;set;} public int Version {get;set;}
/// <summary> /// <summary>
/// Desc:开始时间 /// Desc:开始时间

@ -781,6 +781,16 @@ public abstract class BaseRepository<T> where T : class, new()
.ExecuteReturnIdentity(); .ExecuteReturnIdentity();
} }
/// <summary>
/// 写入或者更新实体数据
/// </summary>
/// <param name="entity">实体数据</param>
/// <returns></returns>
public int InsertOrUpdate(T entity)
{
return DbBaseClient.Storageable(entity).ExecuteCommand();
}
/// <summary> /// <summary>
/// 写入实体数据 /// 写入实体数据
/// </summary> /// </summary>

@ -0,0 +1,13 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar;
namespace Repository.Station;
[Scope]
public class ElecPriceModelVersionDetailRepository : BaseRepository<ElecPriceModelVersionDetail>
{
public ElecPriceModelVersionDetailRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
}

@ -0,0 +1,13 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar;
namespace Repository.Station;
[Scope]
public class ElecPriceModelVersionRepository : BaseRepository<ElecPriceModelVersion>
{
public ElecPriceModelVersionRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
}

@ -0,0 +1,66 @@
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);
}
}
}

@ -1,9 +1,4 @@
using Service.Cloud.Common; using Service.Cloud.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Service.Cloud.Msg.Cloud.Req namespace Service.Cloud.Msg.Cloud.Req
{ {
@ -17,6 +12,7 @@ namespace Service.Cloud.Msg.Cloud.Req
/// 格式”yyyy-MM-dd HH:mm:ss” /// 格式”yyyy-MM-dd HH:mm:ss”
/// </summary> /// </summary>
public string ut { get; set; } public string ut { get; set; }
/// <summary> /// <summary>
/// 电价模型id /// 电价模型id
/// 由服务器统一进行分配 /// 由服务器统一进行分配
@ -24,7 +20,7 @@ namespace Service.Cloud.Msg.Cloud.Req
public int ceid { get; set; } public int ceid { get; set; }
public List<Seg> seg = new(); public List<Seg>? seg { get; set; }
public string GetCmd() public string GetCmd()
{ {
@ -39,16 +35,19 @@ namespace Service.Cloud.Msg.Cloud.Req
/// 精度 0.0001 元 /// 精度 0.0001 元
/// </summary> /// </summary>
public float ep { get; set; } public float ep { get; set; }
/// <summary> /// <summary>
/// 开始时段 /// 开始时段
/// 格式”HH:mm:ss”精确到小时 /// 格式”HH:mm:ss”精确到小时
/// </summary> /// </summary>
public DateTime st { get; set; } public DateTime st { get; set; }
/// <summary> /// <summary>
/// 结束时段 /// 结束时段
/// 格式“HH:mm:ss” 精确到小时 /// 格式“HH:mm:ss” 精确到小时
/// </summary> /// </summary>
public DateTime et { get; set; } public DateTime et { get; set; }
/// <summary> /// <summary>
/// 时段序号 /// 时段序号
/// 对应尖峰平谷序号1:尖; 2:峰; 3:平; 4 /// 对应尖峰平谷序号1:尖; 2:峰; 3:平; 4

Loading…
Cancel
Save