From 7b47ffad9833190aadf2a372e209da5f5ef2e9d5 Mon Sep 17 00:00:00 2001 From: rszn <645583145@qq.com> Date: Tue, 9 Jul 2024 13:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E6=B1=A0=E4=BF=A1=E6=81=AF=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Cloud/Client/CloudClient.cs | 9 +++ Service/Cloud/Client/CloudClientMgr.cs | 87 ++++++++++++-------- Service/Cloud/Common/CloudConst.cs | 15 ++-- Service/Cloud/Msg/Cloud/Resp/BatDataInfo.cs | 81 ------------------- Service/Cloud/Msg/Host/Req/BatDataInfo.cs | 26 ++++-- Service/Cloud/Msg/Host/Req/SingleBatInfo.cs | 84 +++++++++++++++++++ WebStarter/appsettings.dev.json | 90 ++++++++++++++------- WebStarter/appsettings.prod.json | 5 +- 8 files changed, 241 insertions(+), 156 deletions(-) delete mode 100644 Service/Cloud/Msg/Cloud/Resp/BatDataInfo.cs create mode 100644 Service/Cloud/Msg/Host/Req/SingleBatInfo.cs diff --git a/Service/Cloud/Client/CloudClient.cs b/Service/Cloud/Client/CloudClient.cs index 41bc8b4..a77e76a 100644 --- a/Service/Cloud/Client/CloudClient.cs +++ b/Service/Cloud/Client/CloudClient.cs @@ -76,6 +76,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR /// /// public MsgPair CarAuth { get; set; } = new(); + public MsgPair BatData { get; set; } = new(); public MsgPair ChannelStatus { get; set; } = new(); public MsgPair AirConditioning { get; set; } = new(); public MsgPair ChargeRecord { get; set; } = new(); @@ -404,6 +405,14 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR return CarAuth.GetResp(timeSpan); } + public BatDataInfoRes? SendBatDataInfo(BatDataInfo batDataInfo, + TimeSpan? timeSpan = null) + { + this.BatData.Req = batDataInfo; + this.Publish(batDataInfo); + return BatData.GetResp(timeSpan); + } + /// /// 换电站通道状态上报 /// diff --git a/Service/Cloud/Client/CloudClientMgr.cs b/Service/Cloud/Client/CloudClientMgr.cs index dcd873b..68201e1 100644 --- a/Service/Cloud/Client/CloudClientMgr.cs +++ b/Service/Cloud/Client/CloudClientMgr.cs @@ -19,6 +19,7 @@ public class CloudClientMgr public static CloudClient? CloudClient { get; set; } private static DateTime _dateTime = DateTime.Now.AddSeconds(-30); + public static void Init() { CloudClient = AppInfo.Container.Resolve(); @@ -53,45 +54,65 @@ public class CloudClientMgr { BinInfo? binInfo = binInfoRepository.QueryByClause(it => it.ChargerNo == data.ChargerNo); ChargeDevDataInfo req = new ChargeDevDataInfo(); - req.sn = StaticStationInfo.StationNo; - req.en = StaticStationInfo.StationNo + data.ChargerNo; - req.sd = "A"+int.Parse(binInfo.No); - req.mtp = StaticStationInfo.ChargePower; - req.mcr = 1; - req.hb = binInfo?.Exists??0; - req.el = 0; - req.cno = int.Parse(binInfo.No); - req.cs = binInfo.ChargeStatus??0; - req.fs = 0; - req.@as = 0; - //fc = data., - //st = data., - req.ct = data.ChargingTime; - //ssoc = data., - req.csoc = data.CurrentSoc; - //ssoe = data., - //csoe = data., - req.cvot = data.BmsChargingVoltage; - req.ccur = data.BmsChargingCurrent; - req.nvot = data.BmsNeedVoltage; - req.ncur = data.BmsNeedCurrent; - req.lsv = data.SingleBatteryMinVoltage; - req.hsv = data.SingleBatteryMaxVoltage; - req.lst = data.MinBatteryTemp; - req.hst = data.MaxBatteryTemp; - req.ws = 0xFF; - req.it = 0xFF; - req.ot = 0xFF; - req.bt = DateTime.Now; - - + req.sn = StaticStationInfo.StationNo; + req.en = StaticStationInfo.StationNo + data.ChargerNo; + req.sd = "A" + int.Parse(binInfo.No); + req.mtp = StaticStationInfo.ChargePower; + req.mcr = 1; + req.hb = binInfo?.Exists ?? 0; + req.el = 0; + req.cno = int.Parse(binInfo.No); + req.cs = binInfo.ChargeStatus ?? 0; + req.fs = 0; + req.@as = 0; + //fc = data., + //st = data., + req.ct = data.ChargingTime; + //ssoc = data., + req.csoc = data.CurrentSoc; + //ssoe = data., + //csoe = data., + req.cvot = data.BmsChargingVoltage; + req.ccur = data.BmsChargingCurrent; + req.nvot = data.BmsNeedVoltage; + req.ncur = data.BmsNeedCurrent; + req.lsv = data.SingleBatteryMinVoltage; + req.hsv = data.SingleBatteryMaxVoltage; + req.lst = data.MinBatteryTemp; + req.hst = data.MaxBatteryTemp; + req.ws = 0xFF; + req.it = 0xFF; + req.ot = 0xFF; + req.bt = DateTime.Now; + + if ((DateTime.Now - _dateTime).TotalSeconds <= 30) { return; } _dateTime = DateTime.Now; - CloudClient?.SendChargeDevDataInfo(req); + CloudClient?.SendChargeDevDataInfo(req); + } + } + } + catch (Exception e) + { + Log.Info("error", e); + } + }); + + redisHelper?.GetSubscriber().Subscribe("BatteryInfoUploadTask", (channel, value) => + { + try + { + Log.Info($"receive BatteryInfoUploadTask={value}"); + if (value.HasValue) + { + BatDataInfo? data = JsonConvert.DeserializeObject(value.ToString()); + if (data != null) + { + CloudClient?.SendBatDataInfo(data); } } } diff --git a/Service/Cloud/Common/CloudConst.cs b/Service/Cloud/Common/CloudConst.cs index df8530b..b573cdb 100644 --- a/Service/Cloud/Common/CloudConst.cs +++ b/Service/Cloud/Common/CloudConst.cs @@ -59,24 +59,25 @@ public class CloudConst public static readonly string eqmStateEndLogInfoRes = "eqmStateEndLogInfoRes"; public static readonly string chargeDevDataInfo = "chargeDevDataInfo"; public static readonly string chargeDevDataInfoRes = "chargeDevDataInfoRes"; - + public static readonly string batDataInfo = "batDataInfo"; + /// /// 站外 /// public static readonly string pileStartCharge = "pileStartCharge"; public static readonly string pileStartChargeRes = "pileStartChargeRes"; - + public static readonly string pileStopCharge = "pileStopCharge"; public static readonly string pileRealtimeRes = "pileRealtimeRes"; - + public static readonly string pileEndCharge = "pileEndCharge"; public static readonly string pileEndChargeRes = "pileEndChargeRes"; - - + + public static readonly string pileChargeRealtime = "pileChargeRealtime"; public static readonly string pileChargeRealtimeRes = "pileChargeRealtimeRes"; - + public static readonly string pileRealtime = "pileRealtime"; #endregion -} \ No newline at end of file +} diff --git a/Service/Cloud/Msg/Cloud/Resp/BatDataInfo.cs b/Service/Cloud/Msg/Cloud/Resp/BatDataInfo.cs deleted file mode 100644 index 074355a..0000000 --- a/Service/Cloud/Msg/Cloud/Resp/BatDataInfo.cs +++ /dev/null @@ -1,81 +0,0 @@ -namespace Service.Cloud.Msg.Cloud.Resp; - -/// -/// 4.2.11.1 换电站电池包数据信息 -/// -public class BatDataInfo -{ - /// - /// 场站编码 换电站唯一码 - /// - public string sn { get; set; } - /// - /// 换电站电池包总 数量 - /// - public int batn { get; set; } - /// - /// 电池序列号 - /// - public string bn { get; set; } - /// - /// 充电架 ID 按电池架的编号 A1,A2… - /// - public string sd { get; set; } - /// - /// 所在充电机序号 从 1 开始递增 - /// - public int cno { get; set; } - /// - /// 是否在充电 0:未知 1:正在充电 2:未电池 - /// - public int hc { get; set; } - /// - /// 电接头连接状态 0:未知 1:已经连接 2:未连接 - /// - public int el { get; set; } - /// - /// 剩余能量 单位 0.1 kwh - /// - public float soe { get; set; } - /// - /// 当前 SOC 0-100 单位 0.1 ,没有充电填 0 - /// - public float soc { get; set; } - /// - /// 当前 SOH 0-100 单位 0.1 ,没有充电填 0 - /// - public float soh { get; set; } - /// - /// 最低单体电压 单位 0.01V - /// - public float lsv { get; set; } - /// - /// 最高单体电压 单位 0.01V - /// - public float hsv { get; set; } - /// - /// 最低单体温度 单位 0.1℃ - /// - public float lst { get; set; } - /// - /// 最高单体温度 单位 0.1℃ - /// - public float hst { get; set; } - /// - /// 单体电池号 从 1 开始递增 - /// - public int sl { get; set; } - /// - /// 单体电压 每一节电芯的单体电压 单位 0.1V ,如果没有该节电芯的数据,填65535.0 无效值 - /// - public float sv { get; set; } - /// - /// 单体温度 每一节电芯的单体温度 单位 0.1℃ ,如果没有该节电芯的数据,填65535.0 无效值 - /// - public float st { get; set; } - /// - /// 更新时间 格式 ”yyyy-MM-dd HH:mm:ss ” - /// - public DateTime bt { get; set; } - -} \ No newline at end of file diff --git a/Service/Cloud/Msg/Host/Req/BatDataInfo.cs b/Service/Cloud/Msg/Host/Req/BatDataInfo.cs index de51bc8..0a91b8f 100644 --- a/Service/Cloud/Msg/Host/Req/BatDataInfo.cs +++ b/Service/Cloud/Msg/Host/Req/BatDataInfo.cs @@ -1,16 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Service.Cloud.Common; namespace Service.Cloud.Msg.Host.Req { /// /// 4.2.11.1 换电站电池包数据信息 /// - public class BatDataInfo + public class BatDataInfo : ICmd { + /// + /// 场站编码 换电站唯一码 + /// + public string sn { get; set; } + /// + /// 换电站电池包总 数量 + /// + public int batn { get; set; } + + /// + /// 电池信息 + /// + public List datainfo { get; set; } + + public string GetCmd() + { + return CloudConst.batDataInfo; + } } } diff --git a/Service/Cloud/Msg/Host/Req/SingleBatInfo.cs b/Service/Cloud/Msg/Host/Req/SingleBatInfo.cs new file mode 100644 index 0000000..602eed3 --- /dev/null +++ b/Service/Cloud/Msg/Host/Req/SingleBatInfo.cs @@ -0,0 +1,84 @@ +namespace Service.Cloud.Msg.Host.Req; + +public class SingleBatInfo +{ + /// + /// 电池序列号 + /// + public string bn { get; set; } + + /// + /// 充电架 ID 按电池架的编号 A1,A2… + /// + public string sd { get; set; } + + /// + /// 所在充电机序号 从 1 开始递增 + /// + public int cno { get; set; } + + /// + /// 是否在充电 0:未知 1:正在充电 2:未电池 + /// + public int hc { get; set; } + + /// + /// 电接头连接状态 0:未知 1:已经连接 2:未连接 + /// + public int el { get; set; } + + /// + /// 剩余能量 单位 0.1 kwh + /// + public float soe { get; set; } + + /// + /// 当前 SOC 0-100 单位 0.1 ,没有充电填 0 + /// + public float soc { get; set; } + + /// + /// 当前 SOH 0-100 单位 0.1 ,没有充电填 0 + /// + public float soh { get; set; } + + /// + /// 最低单体电压 单位 0.01V + /// + public float lsv { get; set; } + + /// + /// 最高单体电压 单位 0.01V + /// + public float hsv { get; set; } + + /// + /// 最低单体温度 单位 0.1℃ + /// + public float lst { get; set; } + + /// + /// 最高单体温度 单位 0.1℃ + /// + public float hst { get; set; } + + /// + /// 单体电池号 从 1 开始递增 + /// + public int sl { get; set; } + + /// + /// 单体电压 每一节电芯的单体电压 单位 0.1V ,如果没有该节电芯的数据,填65535.0 无效值 + /// + public float sv { get; set; } + + /// + /// 单体温度 每一节电芯的单体温度 单位 0.1℃ ,如果没有该节电芯的数据,填65535.0 无效值 + /// + public float st { get; set; } + + /// + /// 更新时间 格式 ”yyyy-MM-dd HH:mm:ss ” + /// + public DateTime bt { get; set; } +} diff --git a/WebStarter/appsettings.dev.json b/WebStarter/appsettings.dev.json index 060d827..3137138 100644 --- a/WebStarter/appsettings.dev.json +++ b/WebStarter/appsettings.dev.json @@ -23,12 +23,18 @@ "AllowedHosts": "*", ",": null, "Cryptogram": { - "StrongPassword": "false", // 是否开启密码强度验证 - "PasswordStrengthValidation": "(?=^.{6,16}$)(?=.*\\d)(?=.*\\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\\n).*$", // 密码强度验证正则表达式,必须须包含大小写字母、数字和特殊字符的组合,长度在6-16之间 - "PasswordStrengthValidationMsg": "密码必须包含大小写字母、数字和特殊字符的组合,长度在6-16之间", // 密码强度验证消息提示 - "CryptoType": "SM2", // 密码加密算法:MD5、SM2、SM4 - "PublicKey": "0484C7466D950E120E5ECE5DD85D0C90EAA85081A3A2BD7C57AE6DC822EFCCBD66620C67B0103FC8DD280E36C3B282977B722AAEC3C56518EDCEBAFB72C5A05312", // 公钥 - "PrivateKey": "8EDB615B1D48B8BE188FC0F18EC08A41DF50EA731FA28BF409E6552809E3A111" // 私钥 + "StrongPassword": "false", + // 是否开启密码强度验证 + "PasswordStrengthValidation": "(?=^.{6,16}$)(?=.*\\d)(?=.*\\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\\n).*$", + // 密码强度验证正则表达式,必须须包含大小写字母、数字和特殊字符的组合,长度在6-16之间 + "PasswordStrengthValidationMsg": "密码必须包含大小写字母、数字和特殊字符的组合,长度在6-16之间", + // 密码强度验证消息提示 + "CryptoType": "SM2", + // 密码加密算法:MD5、SM2、SM4 + "PublicKey": "0484C7466D950E120E5ECE5DD85D0C90EAA85081A3A2BD7C57AE6DC822EFCCBD66620C67B0103FC8DD280E36C3B282977B722AAEC3C56518EDCEBAFB72C5A05312", + // 公钥 + "PrivateKey": "8EDB615B1D48B8BE188FC0F18EC08A41DF50EA731FA28BF409E6552809E3A111" + // 私钥 }, //Login "TokenOptions": { @@ -38,34 +44,62 @@ "Issuer": "jwtIssuer" }, "Upload": { - "Path": "Upload/{yyyy}/{MM}/{dd}", // 文件上传目录 - "MaxSize": 20480, // 文件最大限制KB:1024*20 - "ContentType": [ "image/jpg", "image/png", "image/jpeg", "image/gif", "image/bmp", "text/plain", "application/pdf", "application/msword", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "video/mp4" ], - "EnableMd5": false // 启用文件MDF5验证-防止重复上传 + "Path": "Upload/{yyyy}/{MM}/{dd}", + // 文件上传目录 + "MaxSize": 20480, + // 文件最大限制KB:1024*20 + "ContentType": [ + "image/jpg", + "image/png", + "image/jpeg", + "image/gif", + "image/bmp", + "text/plain", + "application/pdf", + "application/msword", + "application/vnd.ms-excel", + "application/vnd.ms-powerpoint", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "video/mp4" + ], + "EnableMd5": false + // 启用文件MDF5验证-防止重复上传 }, //SysLogin "JWTSettings": { - "ValidateIssuerSigningKey": true, // 是否验证密钥,bool 类型,默认true - "IssuerSigningKey": "3c1cbc3f546eda35168c3aa3cb91780fbe703f0996c6d123ea96dc85c70bbc0a", // 密钥,string 类型,必须是复杂密钥,长度大于16 - "ValidateIssuer": true, // 是否验证签发方,bool 类型,默认true - "ValidIssuer": "Admin.NET", // 签发方,string 类型 - "ValidateAudience": true, // 是否验证签收方,bool 类型,默认true - "ValidAudience": "Admin.NET", // 签收方,string 类型 - "ValidateLifetime": true, // 是否验证过期时间,bool 类型,默认true,建议true + "ValidateIssuerSigningKey": true, + // 是否验证密钥,bool 类型,默认true + "IssuerSigningKey": "3c1cbc3f546eda35168c3aa3cb91780fbe703f0996c6d123ea96dc85c70bbc0a", + // 密钥,string 类型,必须是复杂密钥,长度大于16 + "ValidateIssuer": true, + // 是否验证签发方,bool 类型,默认true + "ValidIssuer": "Admin.NET", + // 签发方,string 类型 + "ValidateAudience": true, + // 是否验证签收方,bool 类型,默认true + "ValidAudience": "Admin.NET", + // 签收方,string 类型 + "ValidateLifetime": true, + // 是否验证过期时间,bool 类型,默认true,建议true //"ExpiredTime": 20, // 过期时间,long 类型,单位分钟,默认20分钟,最大支持 13 年 - "ClockSkew": 5, // 过期时间容错值,long 类型,单位秒,默认5秒 - "Algorithm": "HS256", // 加密算法,string 类型,默认 HS256 - "RequireExpirationTime": true // 验证过期时间,设置 false 将永不过期 + "ClockSkew": 5, + // 过期时间容错值,long 类型,单位秒,默认5秒 + "Algorithm": "HS256", + // 加密算法,string 类型,默认 HS256 + "RequireExpirationTime": true + // 验证过期时间,设置 false 将永不过期 }, - - "SnowId": { - "WorkerId": 1, // 机器码 全局唯一 - "WorkerIdBitLength": 6, // 机器码位长 默认值6,取值范围 [1, 19] - "SeqBitLength": 6, // 序列数位长 默认值6,取值范围 [3, 21](建议不小于4,值越大性能越高、Id位数也更长) - "WorkerPrefix": "adminnet_" // 缓存前缀 + "WorkerId": 1, + // 机器码 全局唯一 + "WorkerIdBitLength": 6, + // 机器码位长 默认值6,取值范围 [1, 19] + "SeqBitLength": 6, + // 序列数位长 默认值6,取值范围 [3, 21](建议不小于4,值越大性能越高、Id位数也更长) + "WorkerPrefix": "adminnet_" + // 缓存前缀 }, - "HttpContextRequest": { "Scheme": "" }, @@ -88,7 +122,7 @@ "task": { "enable": false }, - "Log": { + "Log": { "Src": "D:\\RiderProjects\\hn_back_charger\\WebStarter\\bin\\Debug\\net6.0\\logs", "Dest": "D:\\zip", "Days": 7 diff --git a/WebStarter/appsettings.prod.json b/WebStarter/appsettings.prod.json index ecbc6b0..01c13f3 100644 --- a/WebStarter/appsettings.prod.json +++ b/WebStarter/appsettings.prod.json @@ -122,7 +122,10 @@ "task": { "enable": true }, - "Log": { + "Task": { + "Disabled": "ChargeOrderUploadTask" + }, + "Log": { "Src": "D:\\RiderProjects\\hn_back_charger\\WebStarter\\bin\\Debug\\net6.0\\logs", "Dest": "D:\\zip", "Days": 7