| | |
| | | import com.fzzy.api.data.ApiCommonDevice; |
| | | import com.fzzy.api.utils.SpringUtil; |
| | | import com.fzzy.gateway.service.GatewayDeviceService; |
| | | import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils; |
| | | import com.fzzy.io.request.BaseRequest; |
| | | import com.fzzy.protocol.zldz.cmd.OnLineCommandBuilder; |
| | | import com.fzzy.protocol.zldz.data.Message; |
| | | import com.ld.io.api.InvokeResult; |
| | | import com.ld.io.api.IoSession; |
| | | import com.ld.io.api.IoSessionListener; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | log.info("++++新建连接++++-IP={},PORT={}", session.getAddress(), session.getPort()); |
| | | |
| | | // 添加自定义业务ID |
| | | session.setBusinessKey(BhznGrainV2ServerUtils.getServerKey(session.getAddress(), session.getPort())); |
| | | session.setBusinessKey(ZldzServerUtil.getServerKey(session.getAddress(), session.getPort())); |
| | | |
| | | //执行分机上线 |
| | | ApiCommonDevice commonDevice = Constant.updateCacheOnline(session.getAddress(), session.getPort()); |
| | | if (null == commonDevice.getSn()) { |
| | | log.error("------设备上线,系统中未发现当前配置-------"); |
| | | Constant.updateCacheOnline(session.getAddress(), session.getPort()); |
| | | |
| | | |
| | | try { |
| | | /***********************设备上线后主动获取配置信息******************/ |
| | | |
| | | BaseRequest request = new BaseRequest(); |
| | | request.setIp(session.getAddress()); |
| | | request.setPort(session.getPort()); |
| | | request.setCompanyId(ZldzServerUtil.DEFAULT_COMPANY); |
| | | // Step1 生成在线测试命令 |
| | | Message message = OnLineCommandBuilder.getInstance().buildMessage(request); |
| | | // 发送命令 |
| | | InvokeResult result = session.invoke(message.getByteMsg()); |
| | | //如果命令发送失败,直接踢掉连接 |
| | | if (!InvokeResult.SUCCESS.getCode().equals(result.getCode())) { |
| | | session.destroy(); |
| | | } |
| | | log.info("平台------->>分机---设备上线,自动发送设备配置信息请求命令--{}", message); |
| | | } catch (Exception e) { |
| | | log.error("平台------->>分机---设备上线,自动发送设备配置信息请求命令失败--{}", session.getAddress()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | if (null == gatewayDeviceService) { |
| | | gatewayDeviceService = SpringUtil.getBean(GatewayDeviceService.class); |
| | | |
| | | gatewayDeviceService.OfflineByCommonDevice(commonDevice); |
| | | } |
| | | gatewayDeviceService.OfflineByCommonDevice(commonDevice); |
| | | |
| | | //踢出连接 |
| | | session.destroy(); |
| | | } |
| | | } |