| package com.ld.igds.protocol.bhzn.grainv2.server; | 
|   | 
| import com.ld.igds.common.CoreSerService; | 
| import com.ld.io.api.IoSession; | 
| import com.ld.io.api.IoSessionListener; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
|   | 
| /** | 
|  * | 
|  */ | 
| @Slf4j | 
| @Service | 
| public class BhznGrainV2SessionListener implements IoSessionListener { | 
|   | 
|     @Autowired | 
|     private CoreSerService coreSerService; | 
|   | 
|     /** | 
|      * 设备创建在线,需要注意当前使用主机模式,主机上线默认所有相同SN配置的分机全部上线 | 
|      * | 
|      * @param session | 
|      */ | 
|     @Override | 
|     public void onCreate(IoSession session) { | 
|   | 
| //        //添加到内存 | 
| //        BhznGrainV2ServerUtils.addSession(session); | 
|   | 
|         log.info("++++新建连接++++-IP={},PORT={}", session.getAddress(), session.getPort()); | 
|   | 
|         // 添加自定义业务ID | 
|         session.setBusinessKey(BhznGrainV2ServerUtils.getServerKey(session.getAddress(), session.getPort())); | 
|   | 
|         //项目采用无线主机模式,直接获取默认设备 | 
|        // DeviceSer deviceSer = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), BhznGrainV1ServerUtils.DEFAULT_MAC_ID); | 
|   | 
|         //if (null == deviceSer) return; | 
|   | 
|         //coreSerService.onlineBySn(session.getAddress(), session.getPort(), deviceSer.getSn(), Constant.YN_Y); | 
|         //更新缓存 | 
|        // coreSerService.refreshCache(deviceSer.getCompanyId()); | 
|     } | 
|   | 
|     /** | 
|      * 注意,当前采用主机模式,主机离线所有相同SN配置的分机全部离线 | 
|      * | 
|      * @param session | 
|      */ | 
|     @Override | 
|     public void onDestroy(IoSession session) { | 
|         log.info("----连接断开-----IP={},PORT={}", session.getAddress(), session.getPort()); | 
|   | 
| //        //项目采用无线主机模式,直接获取默认设备 | 
| //        DeviceSer deviceSer = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), BhznGrainV1ServerUtils.DEFAULT_MAC_ID); | 
| // | 
| //        if (null == deviceSer) return; | 
|   | 
|         //由于设备掉线后自动调整 | 
| //        coreSerService.onlineBySn(session.getAddress(), session.getPort(), deviceSer.getSn(), Constant.YN_N); | 
| //        //更新缓存 | 
| //        coreSerService.refreshCache(deviceSer.getCompanyId()); | 
|     } | 
| } |