#update mqtt 上位机

This commit is contained in:
2026-08-17 11:49:33 +08:00
parent c3398c6c07
commit 80bfdd134d
9 changed files with 344 additions and 288 deletions

105
.idea/workspace.xml generated
View File

@@ -6,21 +6,14 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="84ac1b15-3cfa-4375-9957-45b7b581d04e" name="Changes" comment="# commit"> <list default="true" id="84ac1b15-3cfa-4375-9957-45b7b581d04e" name="Changes" comment="# commit">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-admin/src/main/resources/application-dev.yml" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-admin/src/main/resources/application-dev.yml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-common/src/main/java/com/maibu/core/business/Device.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-common/src/main/java/com/maibu/core/business/Device.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/maibu-common/src/main/java/com/maibu/memory/DeviceSessionManager.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-common/src/main/java/com/maibu/memory/DeviceSessionManager.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-external/src/main/java/com/maibu/uav/controller/UAVController.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-external/src/main/java/com/maibu/uav/controller/UAVController.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/dto/DeviceBindDTO.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/dto/DeviceBindDTO.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-external/src/main/java/com/maibu/uav/dto/UavDeviceStateResponseDetailDTO.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-external/src/main/java/com/maibu/uav/dto/UavDeviceStateResponseDetailDTO.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/handler/CommandForwardHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/handler/CommandForwardHandler.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-external/src/main/java/com/maibu/uav/service/UAVService.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-external/src/main/java/com/maibu/uav/service/UAVService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-framework/src/main/java/com/maibu/config/SecurityConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-framework/src/main/java/com/maibu/config/SecurityConfig.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/NettyServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/NettyServer.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/handler/DeviceConnectHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/handler/DeviceConnectHandler.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/handler/DeviceConnectHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/handler/DeviceConnectHandler.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/handler/HeaderFooterDecoder.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/handler/HeaderFooterDecoder.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/service/TransferDeviceService.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/service/TransferDeviceService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/handler/HexEncoder.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-netty-server/src/main/java/com/maibu/netty/handler/HexEncoder.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/maibu-web-middleware/src/main/java/com/maibu/dto/NettySwitchDeviceDTO.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-web-middleware/src/main/java/com/maibu/dto/NettySwitchDeviceDTO.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/DeviceController.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/DeviceController.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/maibu-web-middleware/src/main/java/com/maibu/netty/handler/ClientHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-web-middleware/src/main/java/com/maibu/netty/handler/ClientHandler.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-service/maibu-iot-service/src/main/java/com/maibu/service/IDeviceService.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-service/maibu-iot-service/src/main/java/com/maibu/service/IDeviceService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-service/maibu-iot-service/src/main/java/com/maibu/service/impl/DeviceServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-service/maibu-iot-service/src/main/java/com/maibu/service/impl/DeviceServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-service/maibu-iot-service/src/main/resources/mapper/iot/DeviceMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-service/maibu-iot-service/src/main/resources/mapper/iot/DeviceMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maibu-web-middleware/src/main/java/com/maibu/common/MiddleConstant.java" beforeDir="false" afterPath="$PROJECT_DIR$/maibu-web-middleware/src/main/java/com/maibu/common/MiddleConstant.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -40,6 +33,11 @@
</option> </option>
</component> </component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="main" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
<component name="HttpClientEndpointsTabState"> <component name="HttpClientEndpointsTabState">
@@ -79,40 +77,40 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;Application.test.executor&quot;: &quot;Debug&quot;, "Application.test.executor": "Debug",
&quot;HTTP Request.MiddlePlatformApplication | #1.executor&quot;: &quot;Run&quot;, "HTTP Request.MiddlePlatformApplication | #1.executor": "Run",
&quot;HTTP Request.MiddlePlatformApplication | #2.executor&quot;: &quot;Run&quot;, "HTTP Request.MiddlePlatformApplication | #2.executor": "Run",
&quot;HTTP Request.MiddlePlatformApplication | #3.executor&quot;: &quot;Run&quot;, "HTTP Request.MiddlePlatformApplication | #3.executor": "Run",
&quot;Maven.MiddlePlatform [clean].executor&quot;: &quot;Run&quot;, "Maven.MiddlePlatform [clean].executor": "Run",
&quot;Maven.MiddlePlatform [install].executor&quot;: &quot;Run&quot;, "Maven.MiddlePlatform [install].executor": "Run",
&quot;Maven.maibu-netty-server [clean].executor&quot;: &quot;Run&quot;, "Maven.maibu-netty-server [clean].executor": "Run",
&quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;, "ModuleVcsDetector.initialDetectionPerformed": "true",
&quot;RequestMappingsPanelOrder0&quot;: &quot;0&quot;, "RequestMappingsPanelOrder0": "0",
&quot;RequestMappingsPanelOrder1&quot;: &quot;1&quot;, "RequestMappingsPanelOrder1": "1",
&quot;RequestMappingsPanelWidth0&quot;: &quot;75&quot;, "RequestMappingsPanelWidth0": "75",
&quot;RequestMappingsPanelWidth1&quot;: &quot;75&quot;, "RequestMappingsPanelWidth1": "75",
&quot;RunOnceActivity.MCP Project settings loaded&quot;: &quot;true&quot;, "RunOnceActivity.MCP Project settings loaded": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252&quot;: &quot;true&quot;, "RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;, "RunOnceActivity.git.unshallow": "true",
&quot;RunOnceActivity.typescript.service.memoryLimit.init&quot;: &quot;true&quot;, "RunOnceActivity.typescript.service.memoryLimit.init": "true",
&quot;Spring Boot.MiddlePlatformApplication.executor&quot;: &quot;Debug&quot;, "Spring Boot.MiddlePlatformApplication.executor": "Debug",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "git-widget-placeholder": "dev__control",
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;, "kotlin-language-version-configured": "true",
&quot;last_opened_file_path&quot;: &quot;/home/maibu/Test/MiddlePlatform/maibu-external/src/main/java/com/maibu/uav&quot;, "last_opened_file_path": "/home/maibu/Test/MiddlePlatform/maibu-external/src/main/java/com/maibu/uav",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;onboarding.tips.debug.path&quot;: &quot;D:/code/MiddlePlatform/maibu-service/maibu-system-service/src/main/java/com/maibu/Main.java&quot;, "onboarding.tips.debug.path": "D:/code/MiddlePlatform/maibu-service/maibu-system-service/src/main/java/com/maibu/Main.java",
&quot;settings.editor.selected.configurable&quot;: &quot;project.propVCSSupport.CommitDialog&quot;, "settings.editor.selected.configurable": "project.propVCSSupport.CommitDialog",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="RdControllerToolWindowsLayoutState" isNewUi="true"> <component name="RdControllerToolWindowsLayoutState" isNewUi="true">
<layout> <layout>
<window_info id="Bookmarks" side_tool="true" /> <window_info id="Bookmarks" side_tool="true" />
@@ -190,17 +188,6 @@
<configuration name="MiddlePlatformApplication | #3" type="HttpClient.HttpRequestRunConfigurationType" factoryName="HTTP Request" temporary="true" nameIsGenerated="true" path="$APPLICATION_CONFIG_DIR$/scratches/MiddlePlatformApplication.http" executionIdentifier="#3" index="3" runType="Run single request"> <configuration name="MiddlePlatformApplication | #3" type="HttpClient.HttpRequestRunConfigurationType" factoryName="HTTP Request" temporary="true" nameIsGenerated="true" path="$APPLICATION_CONFIG_DIR$/scratches/MiddlePlatformApplication.http" executionIdentifier="#3" index="3" runType="Run single request">
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration default="true" type="JetRunConfigurationType">
<module name="maibu-iot-service" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration default="true" type="KotlinStandaloneScriptRunConfigurationType">
<module name="maibu-iot-service" />
<option name="filePath" />
<method v="2" />
</configuration>
<configuration name="MiddlePlatformApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" temporary="true" nameIsGenerated="true"> <configuration name="MiddlePlatformApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" temporary="true" nameIsGenerated="true">
<option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources" /> <option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources" />
<module name="maibu-admin" /> <module name="maibu-admin" />
@@ -725,7 +712,7 @@
<line-breakpoint enabled="true" type="java-method"> <line-breakpoint enabled="true" type="java-method">
<url>file://$PROJECT_DIR$/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/IOTWorkOrderController.java</url> <url>file://$PROJECT_DIR$/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/IOTWorkOrderController.java</url>
<line>58</line> <line>58</line>
<properties class="com.maibu.controller.IOTWorkOrderController" method="edit"> <properties class="com.maibu.controller.IOTWorkOrderController" method="list">
<option name="EMULATED" value="true" /> <option name="EMULATED" value="true" />
<option name="WATCH_EXIT" value="false" /> <option name="WATCH_EXIT" value="false" />
</properties> </properties>

View File

@@ -58,8 +58,8 @@ public class NettyDevice extends Connector {
// todo 注册的时候更新 siteId // todo 注册的时候更新 siteId
private Device device; private Device device;
//todo 假如设置一个当前控制的token //todo 当前登录的账号的token 以token为控制的权限
private String currentControlToken; private String token;
@JsonIgnore @JsonIgnore
private DevicePlanTaskMapper devicePlanTaskMapper = SpringUtils.getBean(DevicePlanTaskMapper.class); private DevicePlanTaskMapper devicePlanTaskMapper = SpringUtils.getBean(DevicePlanTaskMapper.class);

View File

@@ -30,6 +30,9 @@ public class DeviceSessionManager {
// 设备ID -> 设备对象(业务实体) // 设备ID -> 设备对象(业务实体)
private final ConcurrentHashMap<String, NettyDevice> deviceMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, NettyDevice> deviceMap = new ConcurrentHashMap<>();
//当前设备的控制权在哪 登录的账号 deviceId(下位机) -> token key 唯一保证一个deviceId 只有一个控制权
private final ConcurrentHashMap<String, String> controllerMap = new ConcurrentHashMap<>();
// 设备ID -> Channel(通信通道) // 设备ID -> Channel(通信通道)
private final ConcurrentHashMap<String, Channel> channelMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, Channel> channelMap = new ConcurrentHashMap<>();
@@ -105,6 +108,64 @@ public class DeviceSessionManager {
return deviceMap.get(deviceId); return deviceMap.get(deviceId);
} }
/**
* 获取有控制权的 客户端
*/
public String getMaster(String deviceId) {
return controllerMap.get(deviceId);
}
/**
* 获取客户端当前 控制的设备
*/
public String getControl(String token) {
for (String key : controllerMap.keySet()) {
if (controllerMap.get(key).equals(token)) {
return controllerMap.get(token);
}
}
return null;
}
public void lock(String deviceId, String token) {
if (!StringUtils.isEmpty(deviceId) && !StringUtils.isEmpty(token)) {
controllerMap.put(deviceId, token);
}
}
public boolean unLock(String token) {
if (!StringUtils.isEmpty(token)) {
Iterator<String> iterator = controllerMap.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
if (controllerMap.get(key).equals(token)) {
iterator.remove();
}
}
}
return true;
}
public boolean unLock(String deviceId, String token, boolean force) {
if (!StringUtils.isEmpty(deviceId)) {
if (force) {
controllerMap.remove(deviceId);
return true;
} else {
String nowToken = controllerMap.get(deviceId);
if (!StringUtils.isEmpty(token) && nowToken.equals(token)) {
controllerMap.remove(deviceId);
return true;
}
}
}
return false;
}
// 模糊匹配 // 模糊匹配
public List<NettyDevice> getDevicesLike(String query) { public List<NettyDevice> getDevicesLike(String query) {
return deviceMap.values().stream() return deviceMap.values().stream()

View File

@@ -24,4 +24,6 @@ public class DeviceBindDTO {
private Integer type; // releaseControl 1 完全释放 2 释放控制权 可监听数据 private Integer type; // releaseControl 1 完全释放 2 释放控制权 可监听数据
private String token;
} }

View File

@@ -64,6 +64,12 @@ public class CommandForwardHandler extends SimpleChannelInboundHandler<String> {
} }
if (ConnectorType.MASTER.equals(senderNettyDevice.getDeviceType())) { if (ConnectorType.MASTER.equals(senderNettyDevice.getDeviceType())) {
//TODO 有控制权才能发
Set<Connector> connectedDevices = senderNettyDevice.getConnectedConnectors(); Set<Connector> connectedDevices = senderNettyDevice.getConnectedConnectors();
if (connectedDevices == null || connectedDevices.isEmpty()) { if (connectedDevices == null || connectedDevices.isEmpty()) {
logger.debug("发送拒绝master:{},该设备没有关联的设备", senderDeviceId); logger.debug("发送拒绝master:{},该设备没有关联的设备", senderDeviceId);

View File

@@ -115,6 +115,8 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
logger.info("{}: 设备断开 status: {}", deviceId, ConnectorStatus.DISABLED); logger.info("{}: 设备断开 status: {}", deviceId, ConnectorStatus.DISABLED);
// updateLogoutSingle(deviceId); // updateLogoutSingle(deviceId);
// todo 自动切换到其他? // todo 自动切换到其他?
sessionManager.unLock(deviceId);
} }
if (nettyDevice != null && nettyDevice.getDeviceType() == ConnectorType.SLAVE) { if (nettyDevice != null && nettyDevice.getDeviceType() == ConnectorType.SLAVE) {
nettyDevice.setOnlineStatus(0); nettyDevice.setOnlineStatus(0);
@@ -155,7 +157,7 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
} }
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { protected void channelRead0(ChannelHandlerContext ctx, String msg) {
try { try {
byte[] bytes = Hex.decodeHex(msg.toCharArray()); byte[] bytes = Hex.decodeHex(msg.toCharArray());
@@ -181,86 +183,11 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
logger.info("上位机连接 sessionId: {}", sessionId); logger.info("上位机连接 sessionId: {}", sessionId);
logger.info("上位机连接 userName: {}", userName); logger.info("上位机连接 userName: {}", userName);
logger.info("上位机连接 type: {}", parts[1]); logger.info("上位机连接 type: {}", parts[1]);
SysUser sysUser = userService.selectUserByUserName(userName);
if (sysUser != null) {
sysUserClientService.insertUserClient(sysUser.getUserId(), userName, deviceId, "", 0);
}
// 如果 当前角色存在sessionId同时和当前的穿过来不同则下发剔除指令
boolean t = false;
if (StringUtils.isEmpty(sessionId) || sysUser == null) {
t = true;
}
if (sysUser != null && !StringUtils.isEmpty(sessionId)
&& !StringUtils.isEmpty(sysUser.getSessionId())) {
if (!sysUser.getSessionId().equals(sessionId)) {
t = true;
}
}
if (t) {
// 发送已登录状态到客户端
if ("web".equals(parts[1])) {
NettyDevice device = sessionManager.getDevice(deviceId);
logger.info("web 上位机连接重连: {}", JsonUtils.toJsonString(device));
if (device != null && !StringUtils.isEmpty(device.getCurrentSlaveId())) {
logger.info("上位机连接重连: {}", deviceId);
} else {
// 判断是否账号在控制空 如果在控制设置账号为非active
List<UserClient> userClients = sysUserClientService
.selectUserClientByUserName(userName);
ConnectorStatus status = ConnectorStatus.ACTIVE;
logger.info("web 上位机连接重连2: {}", JsonUtils.toJsonString(userClients));
UserClient nowClient = null;
if (!CollectionUtils.isEmpty(userClients)) {
long count = userClients.stream().filter(
x -> x.getIsAlive() == 1 && !deviceId.equals(x.getClientName()))
.count();
if (count > 0) {
status = ConnectorStatus.RECEIVER;
}
nowClient = userClients.stream().filter(
x -> x.getIsAlive() == 1 && deviceId.equals(x.getClientName()))
.findFirst().orElse(null);
}
logger.info("web 上位机连接重连3: {}", JsonUtils.toJsonString(status));
if (!ConnectorStatus.ACTIVE.equals(status)) {
handleMasterConnect(ctx, deviceId, null, status);
} else {
logger.info("web 上位机连接重连4: {}", JsonUtils.toJsonString(nowClient));
if (nowClient != null) {
handleMasterConnect(ctx, deviceId, nowClient.getDeviceName(), status);
} else {
handleMasterConnect(ctx, deviceId, null, status);
}
} NettyDevice masterDevice = sessionManager.getDevice(sessionId);
} if (masterDevice == null) {
} else { // sessionManager.getControl(sessionId);
DeviceLoginResponseDTO responseDTO = new DeviceLoginResponseDTO(); handleMasterConnect(ctx, sessionId, null, ConnectorStatus.ACTIVE);
responseDTO.setRespond(RespondCode.have_logged_in);
ByteBuf buf = ctx.alloc().buffer();
CommandUtils.buildCommand(buf, responseDTO, CommandConstant.interaction);
ctx.channel().writeAndFlush(buf);
}
} else {
// 判断是否账号在控制空 如果在控制设置账号为非active
List<UserClient> userClients = sysUserClientService
.selectUserClientByUserName(userName);
ConnectorStatus status = ConnectorStatus.ACTIVE;
if (!CollectionUtils.isEmpty(userClients)) {
long count = userClients.stream()
.filter(x -> x.getIsAlive() == 1 && !deviceId.equals(x.getClientName()))
.count();
if (count > 0) {
status = ConnectorStatus.RECEIVER;
}
}
logger.info("上位机上线:{}", status);
// if (ConnectorStatus.ACTIVE.equals(status)) {
// //todo 设置当前控制的token
// sysUser.setSessionId(sessionId);
// userService.updateUserProfile(sysUser);
// }
handleMasterConnect(ctx, deviceId, null, status);
} }
} }
} else { } else {
@@ -428,17 +355,19 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
logger.info("12指令切换权限,c:{}", c.getConnectorId()); logger.info("12指令切换权限,c:{}", c.getConnectorId());
if (!c.getConnectorId().equals(masterId)) { if (!c.getConnectorId().equals(masterId)) {
// c.setCurrentSlaveId(null); // c.setCurrentSlaveId(null);
c.removeConnectedDevice(slaveDevice); // c.removeConnectedDevice(slaveDevice);
c.setConnectorStatus(ConnectorStatus.RECEIVER); c.setConnectorStatus(ConnectorStatus.RECEIVER);
sysUserClientService.updateAliveStatus(c.getConnectorId(), slaveId, 2); sessionManager.unLock(c.getConnectorId());
// sysUserClientService.updateAliveStatus(c.getConnectorId(), slaveId, 2);
} }
}); });
} }
logger.info("12指令解析,切换权限,slaveId:{},masterId :{}", slaveId, masterId); logger.info("12指令解析,切换权限,slaveId:{},masterId :{}", slaveId, masterId);
sessionManager.lock(slaveId, masterId);
masterDevice.setCurrentSlaveId(slaveId); masterDevice.setCurrentSlaveId(slaveId);
masterDevice.setConnectorStatus(ConnectorStatus.ACTIVE); masterDevice.setConnectorStatus(ConnectorStatus.ACTIVE);
masterDevice.addConnectedDevice(slaveDevice); masterDevice.addConnectedDevice(slaveDevice);
sysUserClientService.updateAliveStatus(masterDevice.getConnectorId(), slaveId, 1); // sysUserClientService.updateAliveStatus(masterDevice.getConnectorId(), slaveId, 1);
} else { } else {
logger.info("权限切换请求被拒绝"); logger.info("权限切换请求被拒绝");
} }
@@ -469,6 +398,74 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
} }
} }
// /**
// * 找到当前设备控制的主机 转发控制请求
// */
// private void handlePermissionRequest(DeviceRequestDTO requestDTO, byte[] bytes, ChannelHandlerContext ctx) {
// logger.info("转发控制请求 :{}", JsonUtils.toJsonString(requestDTO));
// String slaveId = requestDTO.getDeviceId();
// List<NettyDevice> controlList = sessionManager.getSlaveControl(slaveId);
// String masterId = requestDTO.getUserId() + ":" + requestDTO.getPlatform();
// logger.info("转发控制请求 controlList :{}", JsonUtils.toJsonString(controlList));
// if (!CollectionUtils.isEmpty(controlList)) {
// // 如果当前设备有控制
// logger.info("转发控制请求 发送报文");
// NettyDevice controlDevice = controlList.get(0);
// if (controlDevice != null && controlDevice.getChannel() != null && controlDevice.getChannel().isActive()) {
// controlDevice.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes));
// logger.info("转发控制请求 发送报文结束 deviceId :{}", controlDevice.getConnectorId());
// controlRequestMap.put(masterId, slaveId);
// logger.info("转发控制请求 controlRequestMap:{}", JsonUtils.toJsonString(controlRequestMap));
// }
//
// } else {
// // 判断直接给权限 还是 判断是否有该账号其他端的的控制有权限
// NettyDevice activeDevice = sessionManager.getUserControl(requestDTO.getUserId());
// boolean sendMes = true;
// if (activeDevice == null) {
// sendMes = false;
// } else {
// if (activeDevice.getConnectorId().equals(masterId)) {
// sendMes = false;
// }
// }
// if (sendMes) {
// if (activeDevice.getChannel() != null && activeDevice.getChannel().isActive()) {
// activeDevice.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes));
// logger.info("转发控制请求2 发送报文结束 deviceId :{}", activeDevice.getConnectorId());
// controlRequestMap.put(masterId, slaveId);
// logger.info("转发控制请求2 controlRequestMap:{}", JsonUtils.toJsonString(controlRequestMap));
// }
// } else {
// NettyDevice masterDevice = sessionManager.getDevice(masterId);
// if (masterDevice != null) {
// NettyDevice slaveDevice = sessionManager.getDevice(slaveId);
// masterDevice.setCurrentSlaveId(slaveId);
// masterDevice.setConnectorStatus(ConnectorStatus.ACTIVE);
// masterDevice.addConnectedDevice(slaveDevice);
//
// sysUserClientService.updateAliveStatus(masterDevice.getConnectorId(), slaveId, 1);
// if (masterDevice.getChannel() != null && masterDevice.getChannel().isActive()) {
// DeviceRequestDTO reDto = new DeviceRequestDTO();
// reDto.setPlatform(requestDTO.getPlatform());
// DeviceRespondDTO respond = new DeviceRespondDTO();
// respond.setSwitchResult(true);
// respond.setHolder("you");
// respond.setDeviceId(slaveId);
// reDto.setRespond(respond);
// ByteBuf buf = ctx.alloc().buffer();
// CommandUtils.buildCommand(buf, reDto, CommandConstant.interaction);
// String content = buf.toString(CharsetUtil.UTF_8);
// masterDevice.getChannel().writeAndFlush(buf);
// logger.info("转发控制请求设置当前控制2 发送报文:{} deviceId :{}", content, masterId);
// }
// } else {
//
// }
// }
// }
// }
/** /**
* 找到当前设备控制的主机 转发控制请求 * 找到当前设备控制的主机 转发控制请求
*/ */
@@ -476,62 +473,43 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
logger.info("转发控制请求 :{}", JsonUtils.toJsonString(requestDTO)); logger.info("转发控制请求 :{}", JsonUtils.toJsonString(requestDTO));
String slaveId = requestDTO.getDeviceId(); String slaveId = requestDTO.getDeviceId();
List<NettyDevice> controlList = sessionManager.getSlaveControl(slaveId); List<NettyDevice> controlList = sessionManager.getSlaveControl(slaveId);
String masterId = requestDTO.getUserId() + ":" + requestDTO.getPlatform(); String token = requestDTO.getToken();
// String masterId = requestDTO.getUserId() + ":" + requestDTO.getPlatform();
logger.info("转发控制请求 controlList :{}", JsonUtils.toJsonString(controlList)); logger.info("转发控制请求 controlList :{}", JsonUtils.toJsonString(controlList));
if (!CollectionUtils.isEmpty(controlList)) {
String master = sessionManager.getMaster(slaveId);
if (!StringUtils.isEmpty(master)) {
// 如果当前设备有控制 // 如果当前设备有控制
logger.info("转发控制请求 发送报文"); logger.info("转发控制请求 发送报文");
NettyDevice controlDevice = controlList.get(0); NettyDevice controlDevice = sessionManager.getDevice(master);
if (controlDevice != null && controlDevice.getChannel() != null && controlDevice.getChannel().isActive()) { if (controlDevice != null && controlDevice.getChannel() != null && controlDevice.getChannel().isActive()) {
controlDevice.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes)); controlDevice.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes));
logger.info("转发控制请求 发送报文结束 deviceId :{}", controlDevice.getConnectorId()); logger.info("转发控制请求 发送报文结束 deviceId :{}", controlDevice.getConnectorId());
controlRequestMap.put(masterId, slaveId); controlRequestMap.put(token, slaveId);
logger.info("转发控制请求 controlRequestMap:{}", JsonUtils.toJsonString(controlRequestMap)); logger.info("转发控制请求 controlRequestMap:{}", JsonUtils.toJsonString(controlRequestMap));
} }
} else { } else {
// 判断直接给权限 还是 判断是否有该账号其他端的的控制有权限 NettyDevice masterDevice = sessionManager.getDevice(token);
NettyDevice activeDevice = sessionManager.getUserControl(requestDTO.getUserId()); if (masterDevice != null) {
boolean sendMes = true; NettyDevice slaveDevice = sessionManager.getDevice(slaveId);
if (activeDevice == null) { masterDevice.setCurrentSlaveId(slaveId);
sendMes = false; masterDevice.setConnectorStatus(ConnectorStatus.ACTIVE);
} else { masterDevice.addConnectedDevice(slaveDevice);
if (activeDevice.getConnectorId().equals(masterId)) { sessionManager.lock(slaveId, token);
sendMes = false;
}
}
if (sendMes) {
if (activeDevice.getChannel() != null && activeDevice.getChannel().isActive()) {
activeDevice.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes));
logger.info("转发控制请求2 发送报文结束 deviceId :{}", activeDevice.getConnectorId());
controlRequestMap.put(masterId, slaveId);
logger.info("转发控制请求2 controlRequestMap:{}", JsonUtils.toJsonString(controlRequestMap));
}
} else {
NettyDevice masterDevice = sessionManager.getDevice(masterId);
if (masterDevice != null) {
NettyDevice slaveDevice = sessionManager.getDevice(slaveId);
masterDevice.setCurrentSlaveId(slaveId);
masterDevice.setConnectorStatus(ConnectorStatus.ACTIVE);
masterDevice.addConnectedDevice(slaveDevice);
sysUserClientService.updateAliveStatus(masterDevice.getConnectorId(), slaveId, 1);
if (masterDevice.getChannel() != null && masterDevice.getChannel().isActive()) {
DeviceRequestDTO reDto = new DeviceRequestDTO();
reDto.setPlatform(requestDTO.getPlatform());
DeviceRespondDTO respond = new DeviceRespondDTO();
respond.setSwitchResult(true);
respond.setHolder("you");
respond.setDeviceId(slaveId);
reDto.setRespond(respond);
ByteBuf buf = ctx.alloc().buffer();
CommandUtils.buildCommand(buf, reDto, CommandConstant.interaction);
String content = buf.toString(CharsetUtil.UTF_8);
masterDevice.getChannel().writeAndFlush(buf);
logger.info("转发控制请求设置当前控制2 发送报文:{} deviceId :{}", content, masterId);
}
} else {
if (masterDevice.getChannel() != null && masterDevice.getChannel().isActive()) {
DeviceRequestDTO reDto = new DeviceRequestDTO();
reDto.setPlatform(requestDTO.getPlatform());
DeviceRespondDTO respond = new DeviceRespondDTO();
respond.setSwitchResult(true);
respond.setHolder("you");
respond.setDeviceId(slaveId);
reDto.setRespond(respond);
ByteBuf buf = ctx.alloc().buffer();
CommandUtils.buildCommand(buf, reDto, CommandConstant.interaction);
String content = buf.toString(CharsetUtil.UTF_8);
masterDevice.getChannel().writeAndFlush(buf);
logger.info("转发控制请求设置当前控制2 发送报文:{} deviceId :{}", content, token);
} }
} }
} }

View File

@@ -7,10 +7,12 @@ import com.maibu.core.domain.AjaxResult;
import com.maibu.core.domain.entity.UserClient; import com.maibu.core.domain.entity.UserClient;
import com.maibu.core.domain.model.LoginUser; import com.maibu.core.domain.model.LoginUser;
import com.maibu.core.enums.ConnectorStatus; import com.maibu.core.enums.ConnectorStatus;
import com.maibu.exception.ServiceException;
import com.maibu.mapper.DeviceMapper; import com.maibu.mapper.DeviceMapper;
import com.maibu.mapper.SysUserClientMapper; import com.maibu.mapper.SysUserClientMapper;
import com.maibu.memory.DeviceSessionManager; import com.maibu.memory.DeviceSessionManager;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@@ -20,6 +22,7 @@ import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
@@ -155,62 +158,111 @@ public class TransferDeviceService {
} }
} }
// public synchronized boolean switchDevice(DeviceBindDTO bindDTO, LoginUser user) {
// try {
// String slaveId = bindDTO.getDeviceId();
// String platform = bindDTO.getPlatform();
// String userName = user.getUsername();
// String masterId = userName + ":" + platform;
// //todo 判断是否有权限 正在控制才能切
// //todo 离线没有控制权的怎么切
// log.info("switchDevice:{}", masterId);
// NettyDevice deviceMaster = sessionManager.getDevice(masterId);
// log.info("deviceMaster:{}", deviceMaster);
// if (deviceMaster != null) {
// log.info("ConnectorStatus:{}", deviceMaster.getConnectorStatus());
// if (ConnectorStatus.RECEIVER.equals(deviceMaster.getConnectorStatus())) {
// //当前账号没有控制则可以切换为控制?
// NettyDevice activeDevice = sessionManager.getUserControl(userName);
// deviceMaster.getConnectedConnectors().clear();
// if (activeDevice == null) {
// log.info("bindConnector ACTIVE :{}", masterId);
// sessionManager.bindConnector(masterId, slaveId);
// deviceMaster.setConnectorStatus(ConnectorStatus.ACTIVE);
// deviceMaster.setCurrentSlaveId(slaveId);
// sysUserClientService.updateAliveStatus(masterId, slaveId, 1);
// } else {
// log.info("bindConnector RECEIVER :{}", masterId);
// sessionManager.bindConnector(masterId, slaveId);
// deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER);
// deviceMaster.setCurrentSlaveId(slaveId);
// sysUserClientService.updateAliveStatus(masterId, slaveId, 2);
// }
// } else {
// //从关联其他设备切换到 当前禁言 假如有控制且不是当前更新为2
// List<NettyDevice> controls = sessionManager.getSlaveControl(slaveId);
// if (CollectionUtils.isEmpty(controls)) {
// deviceMaster.getConnectedConnectors().clear();
// log.info("bindConnector 1:{}", masterId);
// sessionManager.bindConnector(masterId, slaveId);
// deviceMaster.setConnectorStatus(ConnectorStatus.ACTIVE);
// deviceMaster.setCurrentSlaveId(slaveId);
// sysUserClientService.updateAliveStatus(masterId, slaveId, 1);
// } else {
// NettyDevice controlDevice = controls.get(0);
// if (!masterId.equals(controlDevice.getConnectorId())) {
// //当前的设备有控制 的主机
// deviceMaster.getConnectedConnectors().clear();
// log.info("bindConnector RECEIVER 2:{}", masterId);
// sessionManager.bindConnector(masterId, slaveId);
// deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER);
// deviceMaster.setCurrentSlaveId(slaveId);
// sysUserClientService.updateAliveStatus(masterId, slaveId, 2);
// }
// //当前 切当前不做操作
// }
// }
// return true;
// }
// } catch (Exception e) {
// log.error("切换设备失败: {}", e.getMessage(), e);
// }
// return false;
// }
public synchronized boolean switchDevice(DeviceBindDTO bindDTO, LoginUser user) { public synchronized boolean switchDevice(DeviceBindDTO bindDTO, LoginUser user) {
try { try {
String slaveId = bindDTO.getDeviceId(); String slaveId = bindDTO.getDeviceId();
String platform = bindDTO.getPlatform(); // String platform = bindDTO.getPlatform();
String userName = user.getUsername(); // String userName = user.getUsername();
String masterId = userName + ":" + platform;
//todo 判断是否有权限 正在控制才能切 // String masterId = userName + ":" + platform;
//todo 离线没有控制权的怎么切
log.info("switchDevice:{}", masterId);
NettyDevice deviceMaster = sessionManager.getDevice(masterId); String token = bindDTO.getToken();
log.info("deviceMaster:{}", deviceMaster);
if (deviceMaster != null) { log.info("switchDevice slaveId:{},token:{}", slaveId, token);
log.info("ConnectorStatus:{}", deviceMaster.getConnectorStatus()); NettyDevice deviceMaster = sessionManager.getDevice(token);
if (ConnectorStatus.RECEIVER.equals(deviceMaster.getConnectorStatus())) { log.info("switchDevice deviceMaster:{}", deviceMaster);
//当前账号没有控制则可以切换为控制? if (deviceMaster == null) {
NettyDevice activeDevice = sessionManager.getUserControl(userName); throw new ServiceException("功能码当前账号未发送登录请求,不在线");
deviceMaster.getConnectedConnectors().clear();
if (activeDevice == null) {
log.info("bindConnector ACTIVE :{}", masterId);
sessionManager.bindConnector(masterId, slaveId);
deviceMaster.setConnectorStatus(ConnectorStatus.ACTIVE);
deviceMaster.setCurrentSlaveId(slaveId);
sysUserClientService.updateAliveStatus(masterId, slaveId, 1);
} else {
log.info("bindConnector RECEIVER :{}", masterId);
sessionManager.bindConnector(masterId, slaveId);
deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER);
deviceMaster.setCurrentSlaveId(slaveId);
sysUserClientService.updateAliveStatus(masterId, slaveId, 2);
}
} else {
//从关联其他设备切换到 当前禁言 假如有控制且不是当前更新为2
List<NettyDevice> controls = sessionManager.getSlaveControl(slaveId);
if (CollectionUtils.isEmpty(controls)) {
deviceMaster.getConnectedConnectors().clear();
log.info("bindConnector 1:{}", masterId);
sessionManager.bindConnector(masterId, slaveId);
deviceMaster.setConnectorStatus(ConnectorStatus.ACTIVE);
deviceMaster.setCurrentSlaveId(slaveId);
sysUserClientService.updateAliveStatus(masterId, slaveId, 1);
} else {
NettyDevice controlDevice = controls.get(0);
if (!masterId.equals(controlDevice.getConnectorId())) {
//当前的设备有控制 的主机
deviceMaster.getConnectedConnectors().clear();
log.info("bindConnector RECEIVER 2:{}", masterId);
sessionManager.bindConnector(masterId, slaveId);
deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER);
deviceMaster.setCurrentSlaveId(slaveId);
sysUserClientService.updateAliveStatus(masterId, slaveId, 2);
}
//当前 切当前不做操作
}
}
return true;
} }
List<NettyDevice> controls = sessionManager.getAllSlaveControl(slaveId);
if (CollectionUtils.isEmpty(controls)) {
deviceMaster.getConnectedConnectors().clear();
sessionManager.bindConnector(token, slaveId);
deviceMaster.setConnectorStatus(ConnectorStatus.ACTIVE);
deviceMaster.setCurrentSlaveId(slaveId);
sessionManager.lock(slaveId, token);
log.info("switchDevice bindConnector slaveId:{},token:{}", slaveId, token);
} else {
List<String> connectorIds = controls.stream().map(NettyDevice::getConnectorId).collect(Collectors.toList());
if (!connectorIds.contains(token)) {
//当前的设备有控制 的主机
deviceMaster.getConnectedConnectors().clear();
sessionManager.bindConnector(token, slaveId);
deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER);
deviceMaster.setCurrentSlaveId(slaveId);
log.info("switchDevice bindConnector RECEIVER :{}", token);
} else {
deviceMaster.setConnectorStatus(ConnectorStatus.ACTIVE);
deviceMaster.setCurrentSlaveId(slaveId);
sessionManager.lock(slaveId, token);
}
//当前 切当前不做操作
}
return true;
} catch (Exception e) { } catch (Exception e) {
log.error("切换设备失败: {}", e.getMessage(), e); log.error("切换设备失败: {}", e.getMessage(), e);
} }
@@ -220,51 +272,16 @@ public class TransferDeviceService {
public DeviceControlDTO remoteControl(DeviceBindDTO bindDTO, LoginUser user) { public DeviceControlDTO remoteControl(DeviceBindDTO bindDTO, LoginUser user) {
try { try {
String slaveId = bindDTO.getDeviceId(); String token = user.getToken();
String platform = bindDTO.getPlatform(); String masterToken = sessionManager.getMaster(bindDTO.getDeviceId());
String userName = user.getUsername();
String masterId = userName + ":" + platform;
DeviceControlDTO dto = new DeviceControlDTO(); DeviceControlDTO dto = new DeviceControlDTO();
NettyDevice deviceMaster = sessionManager.getDevice(masterId); if (!StringUtils.isEmpty(token) && token.equals(masterToken)) {
log.info("remoteControl deviceMaster:{}", masterId); dto.setRemoteControl(true);
dto.setOwner("you");
// //TODO 拓展当前控制不是同一个账号
// NettyDevice currentDevice = sessionManager.getCurrentControl(slaveId);
// if(currentDevice != null){
// if(currentDevice.getConnectorId().equals(masterId)){
// dto.setRemoteControl(true);
// dto.setOwner(platform);
// }else{
// dto.setRemoteControl(false);
// dto.setOwner(currentDevice.getConnectorId());
// }
// }else{
// dto.setRemoteControl(false);
// dto.setOwner(null);
// dto.setReason("occupied");
// }
if (deviceMaster != null) {
if (ConnectorStatus.ACTIVE.equals(deviceMaster.getConnectorStatus())) {
dto.setRemoteControl(true);
dto.setOwner(platform);
} else {
dto.setRemoteControl(false);
dto.setReason("occupied");
NettyDevice activeDevice = sessionManager.getUserControl(userName);
if (activeDevice != null) {
String[] l = activeDevice.getConnectorId().split(":");
dto.setOwner(l[1]);
}
}
} else { } else {
dto.setRemoteControl(false); dto.setRemoteControl(false);
dto.setReason("not exist"); dto.setReason("occupied");
NettyDevice activeDevice = sessionManager.getUserControl(userName); dto.setOwner(masterToken);
if (activeDevice != null) {
String[] l = activeDevice.getConnectorId().split(":");
dto.setOwner(l[1]);
}
} }
return dto; return dto;
} catch (Exception e) { } catch (Exception e) {
@@ -334,16 +351,15 @@ public class TransferDeviceService {
String masterId = userName + ":" + platform; String masterId = userName + ":" + platform;
Integer type = bindDTO.getType(); Integer type = bindDTO.getType();
NettyDevice deviceMaster = sessionManager.getDevice(masterId); NettyDevice deviceMaster = sessionManager.getDevice(masterId);
if (deviceMaster != null && type!=null) { if (type != null && deviceMaster != null) {
if(type == 1){ if (type == 1) {
sysUserClientService.updateAliveStatus(masterId, "", 0);
deviceMaster.setCurrentSlaveId(null); deviceMaster.setCurrentSlaveId(null);
deviceMaster.getConnectedConnectors().clear(); deviceMaster.getConnectedConnectors().clear();
} else if (type == 2) { } else if (type == 2) {
deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER); deviceMaster.setConnectorStatus(ConnectorStatus.RECEIVER);
sysUserClientService.updateAliveStatus(masterId, deviceMaster.getCurrentSlaveId(), 2);
} }
} }
sessionManager.unLock(bindDTO.getDeviceId(), bindDTO.getToken(), false);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage()); log.error(e.getMessage());
} }

View File

@@ -23,4 +23,9 @@ public class NettySwitchDeviceDTO {
*/ */
private String userId; private String userId;
/**
* 用户名
*/
private String token;
} }

View File

@@ -400,6 +400,7 @@ public class ClientHandler extends ChannelInboundHandlerAdapter {
NettySwitchDeviceDTO dto = new NettySwitchDeviceDTO(); NettySwitchDeviceDTO dto = new NettySwitchDeviceDTO();
dto.setDeviceId(nettyClient.requestDeviceId); dto.setDeviceId(nettyClient.requestDeviceId);
dto.setPlatform("web"); dto.setPlatform("web");
dto.setToken(token);
String result = httpService.doPost(postUrl, token, dto); String result = httpService.doPost(postUrl, token, dto);
ResultDTO resultDTO = JsonUtils.parseObject(result, ResultDTO.class); ResultDTO resultDTO = JsonUtils.parseObject(result, ResultDTO.class);
if (resultDTO != null && resultDTO.getData() != null) { if (resultDTO != null && resultDTO.getData() != null) {