From 900d7646a19635925ad5017828a0bc967d325241 Mon Sep 17 00:00:00 2001 From: xjl <2595686544@qq.com> Date: Tue, 20 Aug 2024 09:05:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=91=E5=B9=B3=E5=8F=B0=E4=B8=8B=E5=8F=91?= =?UTF-8?q?=E5=B0=96=E5=B3=B0=E5=B9=B3=E8=B0=B7=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DbModel/Station/ElecPriceModelVersion.cs | 19 +++-- Service/Cloud/Client/CloudClientMgr.cs | 40 ++++----- .../Handler/ElectricityPriceModelHandler.cs | 83 +++++++++++++++++++ Service/Cloud/Msg/Cloud/Req/SetStaPrice.cs | 48 +++++++---- Service/Cloud/Msg/Host/Resp/SetStaPriceRes.cs | 64 +++++++------- WebStarter/db/xjl0725.sql | 6 +- 6 files changed, 187 insertions(+), 73 deletions(-) create mode 100644 Service/Cloud/Handler/ElectricityPriceModelHandler.cs diff --git a/Entity/DbModel/Station/ElecPriceModelVersion.cs b/Entity/DbModel/Station/ElecPriceModelVersion.cs index f823d10..671ba49 100644 --- a/Entity/DbModel/Station/ElecPriceModelVersion.cs +++ b/Entity/DbModel/Station/ElecPriceModelVersion.cs @@ -31,12 +31,19 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName="version")] public int Version {get;set;} - /// - /// Desc:生效时间;生效时间(左开右闭) - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="start_time")] + /// + /// Desc:云平台版本号;版本号,唯一 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ceid")] + public string Ceid { get; set; } + /// + /// Desc:生效时间;生效时间(左开右闭) + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName="start_time")] public DateTime? StartTime {get;set;} /// diff --git a/Service/Cloud/Client/CloudClientMgr.cs b/Service/Cloud/Client/CloudClientMgr.cs index 8d6b436..5f418a5 100644 --- a/Service/Cloud/Client/CloudClientMgr.cs +++ b/Service/Cloud/Client/CloudClientMgr.cs @@ -214,43 +214,43 @@ public class CloudClientMgr if (CloudClient.Connected) { - if (StationConstant.StationModel.Remote == BaseEnumExtensions.GetEnumByCode( - StaticStationInfo.StationModel)) - { - CloudApi.SendStateLog(); - } + //if (StationConstant.StationModel.Remote == BaseEnumExtensions.GetEnumByCode( + //StaticStationInfo.StationModel)) + //{ + // CloudApi.SendStateLog(); + //} TaskHostStatusReported(); - TaskAirConditioningData(); + //TaskAirConditioningData(); - TaskTemperatureHumidityData(); + //TaskTemperatureHumidityData(); - TaskPowerTotal(); + //TaskPowerTotal(); - TaskStaChargingTota(); + //TaskStaChargingTota(); - TaskMeterEnergyKwh(); + //TaskMeterEnergyKwh(); - TaskMeterDayEnergyVal(); + //TaskMeterDayEnergyVal(); - TaskStaHourEnergyVal(); + //TaskStaHourEnergyVal(); - TaskStaDayEnergyVal(); + //TaskStaDayEnergyVal(); - TaskStaDayOpeEnergyVal(); + //TaskStaDayOpeEnergyVal(); - //TaskStaHourAmountVal(); + ////TaskStaHourAmountVal(); - SendRealTimeFaultInfo(); + //SendRealTimeFaultInfo(); - SendStartLogMessage(); + //SendStartLogMessage(); - SendBatteryTotal(); + //SendBatteryTotal(); - SendChargingTotalDis(); + //SendChargingTotalDis(); } Thread.Sleep(1000); } @@ -717,7 +717,7 @@ public class CloudClientMgr } /// - /// 换电站分时用电统计信息 + /// 换电站分时用电统计信息(站控不计价,这一帧不要) /// private static void TaskStaHourAmountVal() { diff --git a/Service/Cloud/Handler/ElectricityPriceModelHandler.cs b/Service/Cloud/Handler/ElectricityPriceModelHandler.cs new file mode 100644 index 0000000..55c2b9b --- /dev/null +++ b/Service/Cloud/Handler/ElectricityPriceModelHandler.cs @@ -0,0 +1,83 @@ +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 ElectricityPriceModelHandler : IBaseHandler +{ + + private ElecPriceModelVersionRepository _versionRepository; + private ElecPriceModelVersionDetailRepository _detailRepository; + + public ElectricityPriceModelHandler(ElecPriceModelVersionRepository elecPriceModelVersionRepository, + ElecPriceModelVersionDetailRepository elecPriceModelVersionDetailRepository) + { + this._versionRepository = elecPriceModelVersionRepository; + this._detailRepository = elecPriceModelVersionDetailRepository; + } + + //两个电价帧用这个,另一个不用 + public bool CanHandle(string cmd) + { + return CloudConst.setStaPrice == cmd; + } + + public void Handle(string t) + { + SetStaPrice? priceModel = JsonConvert.DeserializeObject(t); + if (priceModel != null) + { + if (priceModel.priceTemp.Count>0) + { + ElecPriceModelVersion version = _versionRepository.QueryByClause(d => d.Ceid == priceModel.priceTemp[0].ceid); + + if (version == null) + { + var version01 = _versionRepository.QueryListByClause(d => d.Ceid != null, 1, "desc"); + + version = new ElecPriceModelVersion + { + Version = version01 == null ? 1:version01[0].Version + 1, + Ceid = priceModel.priceTemp[0].ceid, + }; + } + version.StartTime = DateTime.Now; + version.EndTime = DateTime.Now.AddYears(10); + _versionRepository.InsertOrUpdate(version); + + List? segs = priceModel.priceTemp; + 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(); + //先删除同模型ID的数据 + _detailRepository.Delete(u=>u.Version== version.Version); + _detailRepository.Insert(versionDetails); + } + } + + + + SetStaPriceRes resp = new SetStaPriceRes(); + CloudClientMgr.CloudClient?.Publish(resp); + } + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Cloud/Req/SetStaPrice.cs b/Service/Cloud/Msg/Cloud/Req/SetStaPrice.cs index b0cf041..a563eb2 100644 --- a/Service/Cloud/Msg/Cloud/Req/SetStaPrice.cs +++ b/Service/Cloud/Msg/Cloud/Req/SetStaPrice.cs @@ -12,36 +12,50 @@ namespace Service.Cloud.Msg.Cloud.Req /// public class SetStaPrice : ICmd { - /// - /// 计费模型ID - /// 唯一的计费 id,由服务器统一进行分配 - /// - public int eid { get; set; } /// /// 更新时间 - /// 格 式 ” yyyy-MM-ddHH:mm:ss” + /// 格式”yyyy-MM-dd HH:mm:ss” /// public string ut { get; set; } + + public List? priceTemp { get; set; } + + public string GetCmd() + { + return CloudConst.setStaPrice; + } + + } + public class PriceTemp + { + /// + /// 电价模型id + /// 由服务器统一进行分配 + /// + public string ceid { get; set; } + /// + /// 电价 + /// 精度 0.0001 元 + /// + public float ep { get; set; } + /// /// 开始时段 /// 格式”HH:mm:ss”精确到小时 /// - public string st { get; set; } + public DateTime st { get; set; } + /// /// 结束时段 /// 格式“HH:mm:ss” 精确到小时 /// - public string et { get; set; } + public DateTime et { get; set; } + /// - /// 换电服务单价 - /// 0.001 + /// 时段序号 + /// 对应尖峰平谷序号1:尖; 2:峰; 3:平; 4:谷 + /// /// - public double pr { get; set; } - - public string GetCmd() - { - return CloudConst.setStaPrice; - } - + public int pr { get; set; } } } diff --git a/Service/Cloud/Msg/Host/Resp/SetStaPriceRes.cs b/Service/Cloud/Msg/Host/Resp/SetStaPriceRes.cs index 5819b47..046b51c 100644 --- a/Service/Cloud/Msg/Host/Resp/SetStaPriceRes.cs +++ b/Service/Cloud/Msg/Host/Resp/SetStaPriceRes.cs @@ -13,36 +13,42 @@ namespace Service.Cloud.Msg.Host.Resp public class SetStaPriceRes : ICmd { /// - /// 更新时间 - /// 格式”yyyy-MM-dd HH:mm:ss” + /// 应答结果 + /// 0:成功 1:失败 + /// /// - public string ut { get; set; } - /// - /// 电价模型 id - /// 由服务器统一进行分配 - /// - public int ceid { get; set; } - /// - /// 电价 - /// 精度 0.0001 元 - /// - public float ep { get; set; } - /// - /// 开始时段 - /// 格式”HH:mm:ss”精确到小时 - /// - public string st { get; set; } - /// - /// 结束时段 - /// 格式“HH:mm:ss” 精确到小时 - /// - public string et { get; set; } - /// - /// 时段序号 - /// 对应尖峰平谷序号1:尖; 2:峰; 3:平; 4:谷 - /// - /// - public int pr { get; set; } + public int re { get; set; } + ///// + ///// 更新时间 + ///// 格式”yyyy-MM-dd HH:mm:ss” + ///// + //public string ut { get; set; } + ///// + ///// 电价模型 id + ///// 由服务器统一进行分配 + ///// + //public int ceid { get; set; } + ///// + ///// 电价 + ///// 精度 0.0001 元 + ///// + //public float ep { get; set; } + ///// + ///// 开始时段 + ///// 格式”HH:mm:ss”精确到小时 + ///// + //public string st { get; set; } + ///// + ///// 结束时段 + ///// 格式“HH:mm:ss” 精确到小时 + ///// + //public string et { get; set; } + ///// + ///// 时段序号 + ///// 对应尖峰平谷序号1:尖; 2:峰; 3:平; 4:谷 + ///// + ///// + //public int pr { get; set; } public string GetCmd() { diff --git a/WebStarter/db/xjl0725.sql b/WebStarter/db/xjl0725.sql index 46cab2b..146f83a 100644 --- a/WebStarter/db/xjl0725.sql +++ b/WebStarter/db/xjl0725.sql @@ -2,4 +2,8 @@ ALTER TABLE equip_alarm_record ADD COLUMN upload_status INT DEFAULT 0 COMMENT '上报状态 0:未上传 1:已上传'; ALTER TABLE equip_alarm_process_record -ADD COLUMN upload_status INT DEFAULT 0 COMMENT '上报状态 0:未上传 1:已上传'; \ No newline at end of file +ADD COLUMN upload_status INT DEFAULT 0 COMMENT '上报状态 0:未上传 1:已上传'; + + +ALTER TABLE elec_price_model_version +ADD COLUMN ceid VARCHAR(50) COMMENT '云平台模型ID'; \ No newline at end of file