From f8e91cf761cd3c95d305854f8ec736d6ebe41d07 Mon Sep 17 00:00:00 2001
From: smartwyy <645583145@qq.com>
Date: Sun, 26 May 2024 22:13:00 +0800
Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E5=8F=91=E7=94=B5=E4=BB=B7=E6=A8=A1?=
=?UTF-8?q?=E5=9E=8B=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DbModel/Station/ElecPriceModelVersion.cs | 2 +-
.../Station/ElecPriceModelVersionDetail.cs | 2 +-
Repository/BaseRepository.cs | 10 +++
.../ElecPriceModelVersionDetailRepository.cs | 13 ++++
.../ElecPriceModelVersionRepository.cs | 13 ++++
.../ChargerElectricityPriceModelHandler.cs | 66 +++++++++++++++++++
.../Cloud/Req/ChargerElectricityPriceModel.cs | 19 +++---
7 files changed, 113 insertions(+), 12 deletions(-)
create mode 100644 Repository/Station/ElecPriceModelVersionDetailRepository.cs
create mode 100644 Repository/Station/ElecPriceModelVersionRepository.cs
create mode 100644 Service/Cloud/Handler/ChargerElectricityPriceModelHandler.cs
diff --git a/Entity/DbModel/Station/ElecPriceModelVersion.cs b/Entity/DbModel/Station/ElecPriceModelVersion.cs
index 6e1ad57..49639fa 100644
--- a/Entity/DbModel/Station/ElecPriceModelVersion.cs
+++ b/Entity/DbModel/Station/ElecPriceModelVersion.cs
@@ -29,7 +29,7 @@ namespace Entity.DbModel.Station
/// Nullable:True
///
[SugarColumn(ColumnName="version")]
- public string Version {get;set;}
+ public int Version {get;set;}
///
/// Desc:生效时间;生效时间(左开右闭)
diff --git a/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs b/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs
index 3400f4c..528deff 100644
--- a/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs
+++ b/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs
@@ -29,7 +29,7 @@ namespace Entity.DbModel.Station
/// Nullable:True
///
[SugarColumn(ColumnName="version")]
- public string Version {get;set;}
+ public int Version {get;set;}
///
/// Desc:开始时间
diff --git a/Repository/BaseRepository.cs b/Repository/BaseRepository.cs
index 78023b2..a6d72de 100644
--- a/Repository/BaseRepository.cs
+++ b/Repository/BaseRepository.cs
@@ -780,6 +780,16 @@ public abstract class BaseRepository where T : class, new()
.Insertable(entity)
.ExecuteReturnIdentity();
}
+
+ ///
+ /// 写入或者更新实体数据
+ ///
+ /// 实体数据
+ ///
+ public int InsertOrUpdate(T entity)
+ {
+ return DbBaseClient.Storageable(entity).ExecuteCommand();
+ }
///
/// 写入实体数据
diff --git a/Repository/Station/ElecPriceModelVersionDetailRepository.cs b/Repository/Station/ElecPriceModelVersionDetailRepository.cs
new file mode 100644
index 0000000..d703a49
--- /dev/null
+++ b/Repository/Station/ElecPriceModelVersionDetailRepository.cs
@@ -0,0 +1,13 @@
+using Entity.DbModel.Station;
+using HybirdFrameworkCore.Autofac.Attribute;
+using SqlSugar;
+
+namespace Repository.Station;
+
+[Scope]
+public class ElecPriceModelVersionDetailRepository : BaseRepository
+{
+ public ElecPriceModelVersionDetailRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
+ {
+ }
+}
\ No newline at end of file
diff --git a/Repository/Station/ElecPriceModelVersionRepository.cs b/Repository/Station/ElecPriceModelVersionRepository.cs
new file mode 100644
index 0000000..ae06c30
--- /dev/null
+++ b/Repository/Station/ElecPriceModelVersionRepository.cs
@@ -0,0 +1,13 @@
+using Entity.DbModel.Station;
+using HybirdFrameworkCore.Autofac.Attribute;
+using SqlSugar;
+
+namespace Repository.Station;
+
+[Scope]
+public class ElecPriceModelVersionRepository : BaseRepository
+{
+ public ElecPriceModelVersionRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
+ {
+ }
+}
\ No newline at end of file
diff --git a/Service/Cloud/Handler/ChargerElectricityPriceModelHandler.cs b/Service/Cloud/Handler/ChargerElectricityPriceModelHandler.cs
new file mode 100644
index 0000000..36ab97c
--- /dev/null
+++ b/Service/Cloud/Handler/ChargerElectricityPriceModelHandler.cs
@@ -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(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,
+ StartTime = d.st,
+ EndTime = d.et
+ }).ToList();
+ _detailRepository.Insert(versionDetails);
+ }
+
+ ChargerElectricityPriceModelResp resp = new ChargerElectricityPriceModelResp();
+ CloudClientMgr.CloudClient?.Publish(resp);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Service/Cloud/Msg/Cloud/Req/ChargerElectricityPriceModel.cs b/Service/Cloud/Msg/Cloud/Req/ChargerElectricityPriceModel.cs
index d0a3341..3014add 100644
--- a/Service/Cloud/Msg/Cloud/Req/ChargerElectricityPriceModel.cs
+++ b/Service/Cloud/Msg/Cloud/Req/ChargerElectricityPriceModel.cs
@@ -1,9 +1,4 @@
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
{
@@ -17,6 +12,7 @@ namespace Service.Cloud.Msg.Cloud.Req
/// 格式”yyyy-MM-dd HH:mm:ss”
///
public string ut { get; set; }
+
///
/// 电价模型id
/// 由服务器统一进行分配
@@ -24,7 +20,7 @@ namespace Service.Cloud.Msg.Cloud.Req
public int ceid { get; set; }
- public List seg = new();
+ public List? seg { get; set; }
public string GetCmd()
{
@@ -35,20 +31,23 @@ namespace Service.Cloud.Msg.Cloud.Req
public class Seg
{
///
- /// 电价
- /// 精度 0.0001 元
- ///
+ /// 电价
+ /// 精度 0.0001 元
+ ///
public float ep { get; set; }
+
///
/// 开始时段
/// 格式”HH:mm:ss”精确到小时
///
public DateTime st { get; set; }
+
///
/// 结束时段
/// 格式“HH:mm:ss” 精确到小时
///
public DateTime et { get; set; }
+
///
/// 时段序号
/// 对应尖峰平谷序号1:尖; 2:峰; 3:平; 4:谷
@@ -56,4 +55,4 @@ namespace Service.Cloud.Msg.Cloud.Req
///
public int pr { get; set; }
}
-}
+}
\ No newline at end of file