/**
   * 邀请好友列表
   *
   * @param args
   * @return
   */
  @RPCReponse("e_invitation_list")
  public ResultVo invitationlist(LogicRequest args) {
    ResultVo vo = null;
    Long uid = null;
    try {
      FlashLoginOp op = ObjectBeanUtil.JACKSON.readValue(args.getData(), FlashLoginOp.class);
      if (op != null) {
        uid = op.getFbid();
      }

      if (uid == null || uid <= 0) {
        vo = new ResultVo(Definition.GET_INVITATIONS_LIST, Definition.ARG_CODE);
        return vo;
      }

      List<Invitations> relations = LobbyUserHelper.getInvitationUser(uid.toString());
      vo = new ResultVo(Definition.GET_INVITATIONS_LIST, Definition.SUCCESS_CODE, relations);

    } catch (Exception e) {
      vo = new ResultVo(Definition.GET_INVITATIONS_LIST, Definition.UNKNOW_CODE);
    }
    return vo;
  }
  @Override
  @RPCReponse("e_getoffrooms")
  public ResultVo getOffRooms(LogicRequest args) {
    // TODO 自动生成的方法存根
    ResultVo vo = null;
    Long fbid = null;
    try {
      FlashLoginOp op = ObjectBeanUtil.JACKSON.readValue(args.getData(), FlashLoginOp.class);
      if (op != null) {
        fbid = op.getFbid();
        List<UserInRoom> resultList = new ArrayList<UserInRoom>();
        List<UserInRoom> userInRoomList =
            LocalCache.USER_IN_ROOM.get(String.valueOf(op.getFbid())); // 普通房间
        if (userInRoomList != null) {
          UserInRoom inRoom = null;
          Rooms room = null;
          for (int i = 0; i < userInRoomList.size(); i++) {
            inRoom = userInRoomList.get(i);
            if (inRoom.getIsSit() == 1 || inRoom.getIsSit() == 2) {
              room = LocalCache.getRoom(inRoom.getRid());
              if (room != null) {
                inRoom.setGt(room.getGt());
                // 强制更新
                userInRoomList.set(i, inRoom);
              }
              resultList.add(inRoom);
            }
          }
        }
        // 技术债务, 比赛房间断线重连
        RedisMapMap<Integer /*playerId*/, UserInRoom> roomMapCache =
            new RedisMapMap<Integer /*playerId*/, UserInRoom>(
                "matchroom", Integer.class, UserInRoom.class);
        RedisMapSimple<Integer /*roomId*/, UserInRoom> roommap = roomMapCache.get(op.getFbid());
        if (null != roommap) {
          for (UserInRoom inRoom : roommap.values()) {
            resultList.add(inRoom);
          }
        }

        //				List<UserInRoom> matchUserInRoomList =
        // LocalMatchCache.MATCH_USER_IN_ROOM.get(String.valueOf(op.getFbid()));// 比赛房间
        //				if (matchUserInRoomList != null) {
        //					UserInRoom inRoom = null;
        //					for (int i = 0; i < matchUserInRoomList.size(); i++) {
        //						inRoom = matchUserInRoomList.get(i);
        //						if (inRoom.getIsSit() == 1 || inRoom.getIsSit() == 2) {
        //							Match match = LocalMatchCache.MATCHS.get(inRoom.getMi());
        //							if (match != null) {
        //								MatchUser mu = match.getUsers().get(op.getFbid());
        //								if (mu != null && mu.getRanking() == 0) {// 没有淘汰
        //									resultList.add(inRoom);
        //								}
        //							}
        //						}
        //					}
        //				}
        // 成功
        vo = new ResultVo(Definition.GETOFFROOMS, Definition.SUCCESS_CODE, resultList);
      } else {
        vo = new ResultVo(Definition.GETOFFROOMS, Definition.ARG_CODE, null);
        // Logger.error("deal with getoffroom arg error!!!");
      }
    } catch (Exception e) {
      vo = new ResultVo(Definition.GETOFFROOMS, Definition.UNKNOW_CODE, null);
      // Logger.error("deal with getoffroom error  !!!",e);
    }

    return vo;
  }
  @Override
  @RPCReponse("e_login")
  public LoginVo login(LogicRequest args) {
    // ConcurrentHashMap<Long, PlayerInfoInSupremeRoom> inRoomQueue =
    // CarCache.PLAYER_INFO_IN_SUPREMEROOM;
    // System.out.println(inRoomQueue);
    FlashLoginOp rpcMap = null;
    try {
      rpcMap = ObjectBeanUtil.JACKSON.readValue(args.getData(), FlashLoginOp.class);
    } catch (IOException e) {
      LOGGER.warn("", e);
    }
    // Users uf = usersDao.get(rpcMap.getFbid());

    /*
     * UserFundInfoVo users = LocalCache.USER_FUNDS.get(rpcMap.getFbid());
     * if (users == null) {// 从本地调试或手机端登录的账,这里进入系统缓存 String imgurl = "";
     *
     * imgurl = LobbyUserHelper.getFigureurl(rpcMap.getFbid(), null);
     *
     * UserFund userFund = LobbyUserHelper.getUserFund(rpcMap.getFbid());//
     * userFundDao.get(rpcMap.getFbid()); if (userFund != null) {
     * userFund.setImgurl(imgurl); users =
     * LobbyUserHelper.saveUserInfoToCache(userFund, false);
     *
     * } }
     */
    String userNick = null;
    RedisLogin redis = SpringUtils.getBean(RedisLogin.class);
    String uname = redis.hget(USER_INFO_CECHED_PRDFIX + rpcMap.getFbid(), "name");

    if (uname == null) userNick = "joker";
    else userNick = uname;

    List<TodayMatchs> matchs = null; // MatchService.getTodayMatchs();// 今日大赛
    // 返回值
    /**
     * String cmd, long code, int isn, int isg, double gchips, long sessionid, String name, int lds,
     * double ldcs, double ldms, List<TodayMatchs> matchs
     */
    LoginVo vo =
        new LoginVo(
            Definition.LOGIN,
            Definition.SUCCESS_CODE,
            LobbyUserHelper.isLoginNewUser(rpcMap.getFbid()),
            userNick,
            matchs);
    String key = "";
    boolean isenablerk =
        true; // OptionUtils.convertToBoolean(OptionUtils.getDefaultOption("option.api.appkey.reload.enable",
    // "true"));
    if (isenablerk) { // 重连的时候需要重置sign
      key = UUID.randomUUID().toString();
      // LobbyUserHelper.updateUserSign(fbId, key);
    }
    vo.setKey(key);

    // 获取用户sessionid
    String sessionId = args.getSession();
    // 获取用户所在的映射服务器
    String targetMapping = redis.hget(RedisKeys.KEY_LOGIN_MAPPING, sessionId);

    if (null == targetMapping) // 没有登陆
    {
      String proxyId = LogicPropertyUtil.getString("proxy.id", "proxy1");
      String keyProxyMap = String.format(RedisKeys.KEY_LOGIN_PROXY, proxyId);
      // 保存映射
      redis.hset(
          RedisKeys.KEY_LOGIN_MAPPING,
          sessionId,
          String.format("%s@%s", proxyId, args.getChannelId()));
      redis.hset(keyProxyMap, args.getSession(), args.getChannelId());

    } else // 已经登陆
    {

      boolean isPlayGame = LobbyUserHelper.isPlay(Long.valueOf(sessionId)); // TODO
      // 是否在游戏当中

      String[] mappingInfo = targetMapping.split("@");

      String targetRouter = mappingInfo[0];
      String targetChannelId = mappingInfo[1];
      if (isPlayGame) // 正在玩游戏
      {
        // TODO 通知当前通信的客户端下线
        vo = new LoginVo(Definition.LOGIN, Definition.REPEAT_CODE);
        return vo;

      } else {
        LoginVo event = new LoginVo(Definition.OTHERPLAYLOGIN, Definition.REPEAT_CODE);

        // 踢出前一个正在操作的对象
        ProxyResponse response = new ProxyResponse();
        response.setChannelId(targetChannelId);
        response.setSession(sessionId);
        response.setReponse(event);
        response.setIsRoute(1);
        response.setProxy(targetRouter);
        Event responseEvent =
            io.nadron.client.event.Events.dataInEvent(ProxyResponseBuilder.build(response));
        LogicChannelUtil.writeObjectToChannel(responseEvent);
        // 保存映射关系
        String proxyId = LogicPropertyUtil.getString("proxy.id");
        String keyProxyMap = String.format(RedisKeys.KEY_LOGIN_PROXY, proxyId);
        // 保存映射
        redis.hset(
            RedisKeys.KEY_LOGIN_MAPPING,
            sessionId,
            String.format("%s@%s", proxyId, args.getChannelId()));
        redis.hset(keyProxyMap, args.getSession(), args.getChannelId());
      }
      LobbyUserHelper.deleteAllUserInRoom(sessionId);
    }
    LobbyUserHelper.sendJewelBoxMoneyFromData(sessionId);

    // 发送公告
    Notices n = LobbyMsgHelper.getLastNotice();
    if (n != null && System.currentTimeMillis() < n.getEndTime().getTime()) {
      MsgSendVo msgvo =
          new MsgSendVo(
              Definition.NOTICES,
              n.getContent(),
              DateUtils.dateToString(
                  new Date(n.getOperatedTime().getTime()), DateUtils.PATTERN_YMDHMS));
      // 发送
      LogicChannelUtil.sendToTargets(msgvo, Lists.newArrayList(sessionId));
    }
    //
    return vo;
  }