From 9ca5b244f3465c6842ac0f6a01055c4f645e3bc3 Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Tue, 28 May 2024 19:24:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=85=E7=94=B5=E6=9C=BA=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E8=BF=9E=E6=8E=A5=E7=9A=84=E6=97=B6=E5=80=99=E8=B5=8B?= =?UTF-8?q?=E5=80=BC=E4=BB=93=E4=BD=8D=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Charger/Client/ClientMgr.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Service/Charger/Client/ClientMgr.cs b/Service/Charger/Client/ClientMgr.cs index 29b567f..0c8b078 100644 --- a/Service/Charger/Client/ClientMgr.cs +++ b/Service/Charger/Client/ClientMgr.cs @@ -69,16 +69,20 @@ public static class ClientMgr { EquipInfoRepository equipInfoRepository = AppInfo.Container.Resolve(); EquipNetInfoRepository netInfoRepository = AppInfo.Container.Resolve(); + BinInfoRepository binInfoRepository = AppInfo.Container.Resolve(); List equipInfos = equipInfoRepository.QueryListByClause(it => it.TypeCode == (int)EquipmentType.Charger); if (equipInfos.Count > 0) { Dictionary set = equipInfos.ToDictionary(it => it.Code, it => it); List equipNetInfos = netInfoRepository.QueryListByClause(it => set.Keys.Contains(it.Code)); + Dictionary binInfoMap = binInfoRepository.QueryListByClause(it => set.Keys.Contains(it.ChargerNo)) + .ToDictionary(it => it.ChargerNo, it => it); foreach (EquipNetInfo netInfo in equipNetInfos) { Task.Run(() => { - ConnClient(netInfo); + binInfoMap.TryGetValue(netInfo.Code, out var binInfo); + ConnClient(netInfo, binInfo); }); } @@ -247,14 +251,22 @@ public static class ClientMgr } } - private static void ConnClient(EquipNetInfo netInfo) + private static void ConnClient(EquipNetInfo netInfo, BinInfo? binInfo) { Log.Info($"begin to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}"); ChargerClient client = AppInfo.Container.Resolve(); + client.BinNo = binInfo.No; + client.BatteryNo = binInfo.BatteryNo; client.InitBootstrap(netInfo.NetAddr, int.Parse(netInfo.NetPort)); - client.Connect(); - client.SessionAttr(netInfo.Code, netInfo.DestAddr); + + Task.Run(() => + { + client.Connect(); + client.SessionAttr(netInfo.Code, netInfo.DestAddr); + Log.Info($"succeed to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}"); + }); + AddBySn(netInfo.Code, client); - Log.Info($"connected {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}"); + Log.Info($"begin to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}"); } } \ No newline at end of file