From 50d25c269904dfed25fce4f78609e430fd0e577a Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Thu, 23 May 2024 17:32:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=91=E5=B9=B3=E5=8F=B0=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/DbModel/Station/AmtOrderInfo.cs | 167 ++++++++++++++++++ Entity/DbModel/Station/BinInfo.cs | 29 +-- Entity/DbModel/Station/ChargeOrder.cs | 66 ++++++- .../ModbusTcpMaster/ModbusTcpMaster.cs | 55 +++++- .../Session/ModbusSession.cs | 2 +- Repository/Station/AmtOrderInfoRepository.cs | 13 ++ Service/Cloud/Common/CloudConst.cs | 2 +- Service/Cloud/Handler/AmtBatHandler.cs | 42 ++++- Service/Cloud/Msg/Cloud/Req/AmtBat.cs | 18 ++ ...erBasicInformation.cs => SetStBaseInfo.cs} | 2 +- Service/Cloud/Msg/Host/Resp/AmtBatRes.cs | 3 + ...rviceableStateResp.cs => SetServiceRes.cs} | 2 +- ...InformationResp.cs => SetStBaseInfoRes.cs} | 2 +- Service/EquipmentInit.cs | 6 +- Service/Init/StaticStationInfo.cs | 1 - Service/System/SysConfigService.cs | 1 + 16 files changed, 385 insertions(+), 26 deletions(-) create mode 100644 Entity/DbModel/Station/AmtOrderInfo.cs create mode 100644 Repository/Station/AmtOrderInfoRepository.cs rename Service/Cloud/Msg/Cloud/Req/{DeliverBasicInformation.cs => SetStBaseInfo.cs} (98%) rename Service/Cloud/Msg/Host/Resp/{ServiceableStateResp.cs => SetServiceRes.cs} (93%) rename Service/Cloud/Msg/Host/Resp/{DeliverBasicInformationResp.cs => SetStBaseInfoRes.cs} (92%) diff --git a/Entity/DbModel/Station/AmtOrderInfo.cs b/Entity/DbModel/Station/AmtOrderInfo.cs new file mode 100644 index 0000000..7efa3f4 --- /dev/null +++ b/Entity/DbModel/Station/AmtOrderInfo.cs @@ -0,0 +1,167 @@ +using SqlSugar; + +namespace Entity.DbModel.Station +{ + /// + ///预约订单表 + /// + [SugarTable("amt_order_info")] + public partial class AmtOrderInfo + { + public AmtOrderInfo() + { + } + + /// + /// Desc:主键 + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")] + public long Id { get; set; } + + /// + /// Desc:换电站编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "sn")] + public string Sn { get; set; } + + /// + /// Desc:车辆编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "car_no")] + public string CarNo { get; set; } + + /// + /// Desc:预约单号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "order_no")] + public string? OrderNo { get; set; } + + /// + /// Desc:车辆vim码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "vin")] + public string Vin { get; set; } + + /// + /// Desc:预约电池类型编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "battery_type")] + public string BatteryType { get; set; } + + /// + /// Desc:预约电池编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "battery_nos")] + public string BatteryNos { get; set; } + + /// + /// Desc:预约数量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "batnum")] + public int? Batnum { get; set; } + + /// + /// Desc:预约电池锁仓仓号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "bin_nos")] + public string BinNos { get; set; } + + /// + /// Desc:预约时间 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "start_time")] + public DateTime? StartTime { get; set; } + + /// + /// Desc:预约到期时间 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "end_time")] + public DateTime? EndTime { get; set; } + + /// + /// Desc:预约单状态:1:预约成功;2:预约取消;3:预约失败;4:换电完成;5:换电失败;6:换电中;7:预约过期 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "status")] + public byte? Status { get; set; } + + /// + /// Desc:取消时间 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "cancel_time")] + public DateTime? CancelTime { get; set; } + + /// + /// Desc:换电完成时间 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "swap_finish_time")] + public DateTime? SwapFinishTime { get; set; } + + /// + /// Desc:换电订单编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "swap_order_no")] + public string SwapOrderNo { get; set; } + + /// + /// Desc:创建人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_by")] + public string CreatedBy { get; set; } + + /// + /// Desc:创建时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + /// + /// Desc:更新人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_by")] + public string UpdatedBy { get; set; } + + /// + /// Desc:更新时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } + } +} \ No newline at end of file diff --git a/Entity/DbModel/Station/BinInfo.cs b/Entity/DbModel/Station/BinInfo.cs index 1217335..9409db5 100644 --- a/Entity/DbModel/Station/BinInfo.cs +++ b/Entity/DbModel/Station/BinInfo.cs @@ -47,6 +47,14 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName="name")] public string Name {get;set;} + /// + /// Desc:在位状态:0-不在位;1-在位;2-无效 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName="exists")] + public int? Exists {get;set;} + /// /// Desc:电池编号 /// Default: @@ -183,6 +191,14 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName="updated_by")] public string UpdatedBy {get;set;} + /// + /// Desc:最后结束充电时间 结束充电后更新 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName="last_charge_finish_time")] + public DateTime? LastChargeFinishTime {get;set;} + /// /// Desc:更新时间 /// Default:CURRENT_TIMESTAMP @@ -191,18 +207,5 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName="updated_time")] public DateTime? UpdatedTime {get;set;} - /// - /// 电池是否在为 - /// 0:不在位 1:在位 2:无效 - /// - - [SugarColumn(ColumnName="exists")] - public int? Exists { get; set; } - /// - /// 最后结束充电的时间 - /// - [SugarColumn(ColumnName="last_charge_finish_time")] - public DateTime? LastChargeFinishTime { get; set; } - } } diff --git a/Entity/DbModel/Station/ChargeOrder.cs b/Entity/DbModel/Station/ChargeOrder.cs index 5d7a8e4..8f40726 100644 --- a/Entity/DbModel/Station/ChargeOrder.cs +++ b/Entity/DbModel/Station/ChargeOrder.cs @@ -63,6 +63,22 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName="charger_gun_no")] public string ChargerGunNo {get;set;} + /// + /// Desc:0:站内充电 1:站外充电 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName="charge_mode")] + public int? ChargeMode {get;set;} + + /// + /// Desc:1:站控启动 2:本地启动 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName="start_mode")] + public int? StartMode {get;set;} + /// /// Desc:充电开始时间 /// Default: @@ -101,7 +117,7 @@ namespace Entity.DbModel.Station /// Nullable:True /// [SugarColumn(ColumnName="charge_time_count")] - public string ChargeTimeCount {get;set;} + public int? ChargeTimeCount {get;set;} /// /// Desc:充电电量 @@ -111,6 +127,14 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName="elec_count")] public decimal? ElecCount {get;set;} + /// + /// Desc:交流电表量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName="ac_elec_count")] + public decimal? AcElecCount {get;set;} + /// /// Desc:充电开始交流表电量 /// Default: @@ -183,6 +207,38 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName="valley_elec_count")] public decimal? ValleyElecCount {get;set;} + /// + /// Desc:尖时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName="ac_sharp_elec_count")] + public decimal? AcSharpElecCount {get;set;} + + /// + /// Desc:峰时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName="ac_peak_elec_count")] + public decimal? AcPeakElecCount {get;set;} + + /// + /// Desc:平时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName="ac_flat_elec_count")] + public decimal? AcFlatElecCount {get;set;} + + /// + /// Desc:谷时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName="ac_valley_elec_count")] + public decimal? AcValleyElecCount {get;set;} + /// /// Desc:电价版本号 /// Default: @@ -239,5 +295,13 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName="updated_time")] public DateTime? UpdatedTime {get;set;} + /// + /// Desc:云平台充电订单 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName="cloud_sn")] + public string CloudSn {get;set;} + } } diff --git a/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs b/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs index 380d03d..94b59ed 100644 --- a/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs +++ b/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs @@ -112,15 +112,66 @@ public class ModbusTcpMaster return null; } - public byte[]? BatchRead(int registerNo, int length) + public byte[]? BatchReadHolderRegister(int registerNo, int length) { OperateResult result = ModbusTcpNet.Read("x=3;" + registerNo, (ushort)length); if (result.IsSuccess) return result.Content; return null; - } + public byte[]? BatchReadInputRegister(int registerNo, int length) + { + OperateResult result = ModbusTcpNet.Read("x=4;" + registerNo, (ushort)length); + if (result.IsSuccess) return result.Content; + + return null; + } + + /// + /// 读取线圈,需要指定起始地址,如果富文本地址不指定,默认使用的功能码是 0x01
+ /// To read the coil, you need to specify the start address. If the rich text address is not specified, the default function code is 0x01. + ///
+ /// 起始地址,格式为"1234" + /// 带有成功标志的bool对象 + public OperateResult ReadCoil(string address) => ModbusTcpNet.ReadBool(address); + + /// + /// 批量的读取线圈,需要指定起始地址,读取长度,如果富文本地址不指定,默认使用的功能码是 0x01
+ /// For batch reading coils, you need to specify the start address and read length. If the rich text address is not specified, the default function code is 0x01. + ///
+ /// 起始地址,格式为"1234" + /// 读取长度 + /// 带有成功标志的bool数组对象 + public OperateResult ReadCoil(string address, ushort length) + { + return ModbusTcpNet.ReadBool(address, length); + } + + /// + /// 读取输入线圈,需要指定起始地址,如果富文本地址不指定,默认使用的功能码是 0x02
+ /// To read the input coil, you need to specify the start address. If the rich text address is not specified, the default function code is 0x02. + ///
+ /// 起始地址,格式为"1234" + /// 带有成功标志的bool对象 + public OperateResult ReadDiscrete(string address) + { + return ModbusTcpNet.ReadDiscrete(address); + } + + /// + /// 批量的读取输入点,需要指定起始地址,读取长度,如果富文本地址不指定,默认使用的功能码是 0x02
+ /// To read input points in batches, you need to specify the start address and read length. If the rich text address is not specified, the default function code is 0x02 + ///
+ /// 起始地址,格式为"1234" + /// 读取长度 + /// 带有成功标志的bool数组对象 + public OperateResult ReadDiscrete(string address, ushort length) + { + return ModbusTcpNet.ReadDiscrete(address, length); + } + + public bool WriteValue(ModbusProperty property) { var value = property.Value; diff --git a/HybirdFrameworkDriver/Session/ModbusSession.cs b/HybirdFrameworkDriver/Session/ModbusSession.cs index 627c1b1..da750de 100644 --- a/HybirdFrameworkDriver/Session/ModbusSession.cs +++ b/HybirdFrameworkDriver/Session/ModbusSession.cs @@ -30,6 +30,6 @@ public class ModbusSession public byte[]? Read(int registerNo, int length) { - return ModbusTcpMaster.BatchRead(registerNo, length); + return ModbusTcpMaster.BatchReadHolderRegister(registerNo, length); } } \ No newline at end of file diff --git a/Repository/Station/AmtOrderInfoRepository.cs b/Repository/Station/AmtOrderInfoRepository.cs new file mode 100644 index 0000000..4478473 --- /dev/null +++ b/Repository/Station/AmtOrderInfoRepository.cs @@ -0,0 +1,13 @@ +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using SqlSugar; + +namespace Repository.Station; + +[Scope("SingleInstance")] +public class AmtOrderInfoRepository : BaseRepository +{ + public AmtOrderInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) + { + } +} \ No newline at end of file diff --git a/Service/Cloud/Common/CloudConst.cs b/Service/Cloud/Common/CloudConst.cs index d336670..e5e7a93 100644 --- a/Service/Cloud/Common/CloudConst.cs +++ b/Service/Cloud/Common/CloudConst.cs @@ -18,9 +18,9 @@ public class CloudConst public static readonly string setStBaseInfo = "setStBaseInfo"; public static readonly string setStBaseInfoRes = "setStBaseInfoRes"; public static readonly string devList = "devList"; - public static readonly string setServiceRes = "setServiceRes"; public static readonly string devListRep = "devListRep"; public static readonly string setService = "setService"; + public static readonly string setServiceRes = "setServiceRes"; public static readonly string setOpTime = "setOpTime"; public static readonly string setOpTimeRes = "setOpTimeRes"; public static readonly string setOpModel = "setOpModel"; diff --git a/Service/Cloud/Handler/AmtBatHandler.cs b/Service/Cloud/Handler/AmtBatHandler.cs index 64cd936..1aa47dd 100644 --- a/Service/Cloud/Handler/AmtBatHandler.cs +++ b/Service/Cloud/Handler/AmtBatHandler.cs @@ -1,16 +1,56 @@ -using HybirdFrameworkCore.Autofac.Attribute; +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; using Newtonsoft.Json; +using Repository.Station; using Service.Cloud.Common; using Service.Cloud.Msg.Cloud.Req; +using Service.Cloud.Msg.Host.Resp; +using Service.Execute.Enum; +using Service.Init; namespace Service.Cloud.Handler; [Scope("InstancePerDependency")] public class AmtBatHandler : IBaseHandler { + private BinInfoRepository _binInfoRepository; + private AmtOrderInfoRepository _amtOrderInfoRepository; + + public AmtBatHandler(BinInfoRepository binInfoRepository, AmtOrderInfoRepository amtOrderInfoRepository) + { + _binInfoRepository = binInfoRepository; + _amtOrderInfoRepository = amtOrderInfoRepository; + } + public void Handle(string t) { + AmtBatRes abRes = new AmtBatRes(); + abRes.rs = 3; AmtBat? amtBat = JsonConvert.DeserializeObject(t); + if (amtBat != null) + { + int count = _amtOrderInfoRepository.GetCount(it => + it.CarNo == amtBat.cn && it.Status == (byte)InfoEnum.AmtOrderStatus.Success); + + if (count > 0) + { + abRes.rs = 1; + } + else + { + AmtOrderInfo amtOrderInfo = new AmtOrderInfo() + { + Sn = StaticStationInfo.StationNo, + CarNo = amtBat.cn, + Batnum = amtBat.bm, + BatteryType = amtBat.bn, + StartTime = amtBat.at, + EndTime = amtBat.at.AddMinutes(amtBat.am) + }; + + } + + } } public bool CanHandle(string cmd) diff --git a/Service/Cloud/Msg/Cloud/Req/AmtBat.cs b/Service/Cloud/Msg/Cloud/Req/AmtBat.cs index c2ecf59..c73fc3e 100644 --- a/Service/Cloud/Msg/Cloud/Req/AmtBat.cs +++ b/Service/Cloud/Msg/Cloud/Req/AmtBat.cs @@ -4,11 +4,29 @@ namespace Service.Cloud.Msg.Cloud.Req; public class AmtBat : ICmd { + /// + /// station no + /// public string sn { get; set; } + /// + /// car no + /// public string cn { get; set; } + /// + /// 电池型号编号 + /// public string bn { get; set; } + /// + /// battery count + /// public int bm { get; set; } + /// + /// 预约时间 + /// public DateTime at { get; set; } + /// + /// 锁定时长 单位:分钟 + /// public int am { get; set; } public string GetCmd() { diff --git a/Service/Cloud/Msg/Cloud/Req/DeliverBasicInformation.cs b/Service/Cloud/Msg/Cloud/Req/SetStBaseInfo.cs similarity index 98% rename from Service/Cloud/Msg/Cloud/Req/DeliverBasicInformation.cs rename to Service/Cloud/Msg/Cloud/Req/SetStBaseInfo.cs index ed61ef7..f096642 100644 --- a/Service/Cloud/Msg/Cloud/Req/DeliverBasicInformation.cs +++ b/Service/Cloud/Msg/Cloud/Req/SetStBaseInfo.cs @@ -10,7 +10,7 @@ namespace Service.Cloud.Msg.Cloud.Req /// /// 3.2.3.1 后台服务器下发换电站的基础信息 /// - public class DeliverBasicInformation + public class SetStBaseInfo { /// /// 电站编码 diff --git a/Service/Cloud/Msg/Host/Resp/AmtBatRes.cs b/Service/Cloud/Msg/Host/Resp/AmtBatRes.cs index 19ed67a..64e3673 100644 --- a/Service/Cloud/Msg/Host/Resp/AmtBatRes.cs +++ b/Service/Cloud/Msg/Host/Resp/AmtBatRes.cs @@ -4,6 +4,9 @@ namespace Service.Cloud.Msg.Host.Resp; public class AmtBatRes : ICmd { + /// + /// 1:预约电池失败; 2:换电站无电池可预约; 3:预约成功; + /// public int rs { get; set; } public string GetCmd() diff --git a/Service/Cloud/Msg/Host/Resp/ServiceableStateResp.cs b/Service/Cloud/Msg/Host/Resp/SetServiceRes.cs similarity index 93% rename from Service/Cloud/Msg/Host/Resp/ServiceableStateResp.cs rename to Service/Cloud/Msg/Host/Resp/SetServiceRes.cs index f9f6923..a6671a8 100644 --- a/Service/Cloud/Msg/Host/Resp/ServiceableStateResp.cs +++ b/Service/Cloud/Msg/Host/Resp/SetServiceRes.cs @@ -10,7 +10,7 @@ namespace Service.Cloud.Msg.Host.Resp /// /// 3.2.5.2 换电站应答后台服务器下发换电站的可服务状态设置 /// - public class ServiceableStateResp + public class SetServiceRes { /// /// 应答结果 diff --git a/Service/Cloud/Msg/Host/Resp/DeliverBasicInformationResp.cs b/Service/Cloud/Msg/Host/Resp/SetStBaseInfoRes.cs similarity index 92% rename from Service/Cloud/Msg/Host/Resp/DeliverBasicInformationResp.cs rename to Service/Cloud/Msg/Host/Resp/SetStBaseInfoRes.cs index 34fa3f5..e29738e 100644 --- a/Service/Cloud/Msg/Host/Resp/DeliverBasicInformationResp.cs +++ b/Service/Cloud/Msg/Host/Resp/SetStBaseInfoRes.cs @@ -10,7 +10,7 @@ namespace Service.Cloud.Msg.Host.Resp /// /// 3.2.3.2 换电站应答后台服务器下发换电站的基础信息 /// - public class DeliverBasicInformationResp + public class SetStBaseInfoRes { /// /// 应答结果 diff --git a/Service/EquipmentInit.cs b/Service/EquipmentInit.cs index 23ebe9d..70acec7 100644 --- a/Service/EquipmentInit.cs +++ b/Service/EquipmentInit.cs @@ -81,13 +81,13 @@ namespace Service PlcStaticInfo.PlcInfos.TryGetValue(sn, out PlcInfo plcInfo); if (plcInfo != null) { - var bytes01 = master.BatchRead(1, 115); + var bytes01 = master.BatchReadHolderRegister(1, 115); if (bytes01 != null) { ModbusDecoder.Decode(bytes01, plcInfo.hostToPlc); } - var bytes02 = master.BatchRead(201, 222); + var bytes02 = master.BatchReadHolderRegister(201, 222); if (bytes02 != null) { ModbusDecoder.Decode(bytes02, plcInfo.plcToHost); @@ -129,7 +129,7 @@ namespace Service #endregion } - var bytes03 = master.BatchRead(701, 10); + var bytes03 = master.BatchReadHolderRegister(701, 10); if (bytes03 != null) { ModbusDecoder.Decode(bytes03, plcInfo.plcFault); diff --git a/Service/Init/StaticStationInfo.cs b/Service/Init/StaticStationInfo.cs index d06fec7..51a89ca 100644 --- a/Service/Init/StaticStationInfo.cs +++ b/Service/Init/StaticStationInfo.cs @@ -1,5 +1,4 @@ using Autofac; -using Entity.Constant; using HybirdFrameworkCore.Autofac; using Service.Station; using Service.System; diff --git a/Service/System/SysConfigService.cs b/Service/System/SysConfigService.cs index 598491c..21efcbe 100644 --- a/Service/System/SysConfigService.cs +++ b/Service/System/SysConfigService.cs @@ -204,6 +204,7 @@ namespace Service.System string newValue = Convert.ToString(value); Dictionary.AddOrUpdate(key, newValue, (s, s1) => newValue); + redisHelper.SetKeyValueStr(key, newValue); SysConfig sysConfig = _sysConfigRep.QueryByClause(i => i.GroupCode == keys[0] && i.Code == keys[1]); if (sysConfig == null)