充电机初始化连接的时候赋值仓位数据

master
smartwyy 6 months ago
parent a7c8b103a6
commit 9ca5b244f3

@ -69,16 +69,20 @@ public static class ClientMgr
{ {
EquipInfoRepository equipInfoRepository = AppInfo.Container.Resolve<EquipInfoRepository>(); EquipInfoRepository equipInfoRepository = AppInfo.Container.Resolve<EquipInfoRepository>();
EquipNetInfoRepository netInfoRepository = AppInfo.Container.Resolve<EquipNetInfoRepository>(); EquipNetInfoRepository netInfoRepository = AppInfo.Container.Resolve<EquipNetInfoRepository>();
BinInfoRepository binInfoRepository = AppInfo.Container.Resolve<BinInfoRepository>();
List<EquipInfo> equipInfos = equipInfoRepository.QueryListByClause(it => it.TypeCode == (int)EquipmentType.Charger); List<EquipInfo> equipInfos = equipInfoRepository.QueryListByClause(it => it.TypeCode == (int)EquipmentType.Charger);
if (equipInfos.Count > 0) if (equipInfos.Count > 0)
{ {
Dictionary<string, EquipInfo> set = equipInfos.ToDictionary(it => it.Code, it => it); Dictionary<string, EquipInfo> set = equipInfos.ToDictionary(it => it.Code, it => it);
List<EquipNetInfo> equipNetInfos = netInfoRepository.QueryListByClause(it => set.Keys.Contains(it.Code)); List<EquipNetInfo> equipNetInfos = netInfoRepository.QueryListByClause(it => set.Keys.Contains(it.Code));
Dictionary<string,BinInfo> binInfoMap = binInfoRepository.QueryListByClause(it => set.Keys.Contains(it.ChargerNo))
.ToDictionary(it => it.ChargerNo, it => it);
foreach (EquipNetInfo netInfo in equipNetInfos) foreach (EquipNetInfo netInfo in equipNetInfos)
{ {
Task.Run(() => 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}"); Log.Info($"begin to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}");
ChargerClient client = AppInfo.Container.Resolve<ChargerClient>(); ChargerClient client = AppInfo.Container.Resolve<ChargerClient>();
client.BinNo = binInfo.No;
client.BatteryNo = binInfo.BatteryNo;
client.InitBootstrap(netInfo.NetAddr, int.Parse(netInfo.NetPort)); 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); AddBySn(netInfo.Code, client);
Log.Info($"connected {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}"); Log.Info($"begin to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}");
} }
} }
Loading…
Cancel
Save