| package com.ld.igds.protocol.bhzn.grainv1.server; | 
|   | 
| import com.ld.igds.protocol.bhzn.grainv1.msg.AnalysisService; | 
| import com.ld.igds.protocol.bhzn.grainv1.msg.builder.ReMessageBuilder; | 
| import com.ld.igds.protocol.bhzn.grainv1.msg.message.IoMessage; | 
| import com.ld.igds.util.BytesUtil; | 
| import com.ld.io.api.IoMsgConsumer; | 
| import com.ld.io.api.IoSession; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
|   | 
| /** | 
|  * | 
|  */ | 
| @Slf4j | 
| @Service | 
| public class BhznGrainV1MessageConsumer implements IoMsgConsumer { | 
|   | 
|   | 
|     @Autowired | 
|     private AnalysisService analysisService; | 
|   | 
|     /** | 
|      * 处理消息 | 
|      * | 
|      * @param ioSession | 
|      * @param bytes | 
|      */ | 
|     @Override | 
|     public void consume(IoSession ioSession, byte[] bytes) { | 
|         if (null == bytes) { | 
|             log.error("Reply bytes is null"); | 
|             return; | 
|         } | 
|   | 
|         //添加信息心跳标记 | 
|         BhznGrainV1ServerUtils.addHeartBeat(ioSession); | 
|   | 
|         //默认设置主通讯服务 | 
|         BhznGrainV1ServerUtils.addSession(ioSession); | 
|   | 
|         try { | 
|             String hexStr = BytesUtil.bytesToString(bytes); | 
|             log.info("主机返回报文------->>平台:" + hexStr); | 
|             hexStr = hexStr.substring(BhznGrainV1ServerUtils.MSG_START.length()); | 
|   | 
|             IoMessage ioMessage = ReMessageBuilder.getInstance().buildMessage(hexStr); | 
|             ioMessage.setIp(ioSession.getAddress()); | 
|             ioMessage.setPort(ioSession.getPort()); | 
|   | 
|             analysisService.analysis(ioSession.getBusinessKey(), ioMessage); | 
|         } catch (Exception e) { | 
|             log.error(e.getMessage(), e); | 
|         } | 
|     } | 
| } |