package com.cm.central.control.service.socket;

import com.cm.central.control.manager.SocketServerManager;
import com.cm.central.control.pojo.bos.SocketClientBO;
import com.cm.socket.pojo.Message;
import com.cm.socket.service.AbstractSocketService;
import io.netty.channel.ChannelHandlerContext;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: BaseService
 * @Description: service
 * @Author: WangGeng
 * @Date: 2020/7/28 2:13 下午
 * @Version: 1.0
 **/
public abstract class BaseSocketService extends AbstractSocketService {

    @Override
    public void readMessage(ChannelHandlerContext channelHandlerContext, Message readMessage) throws Exception {
        String token = readMessage.getToken();
        SocketClientBO socketClientBO = SocketServerManager.getInstance().getOnlineClientByToken(token);
        if (socketClientBO == null) {
            writeError(channelHandlerContext, "客户端未登录");
        } else {
            // 更新最后时间
            socketClientBO.setLastTime(System.currentTimeMillis());
            readMessageService(channelHandlerContext, readMessage);
        }
    }

}
