// 更新比赛缓存数据 private void updateMatchCacheData() { Date now = new Date(); long nowtime = now.getTime(); long resultminute = (nowtime - lastUpdateTime) / (1000 * 60); if (resultminute < 1) return; // 每次更新时间不得小于1分钟 RedisListSimple<Match> matchInfo = new RedisListSimple<Match>("matchmanager_server", Match.class); List<Match> matchlist = matchInfo.getAll(); // 获取所有列表数据 for (Match match : matchlist) { // 更新内存数据 matchMap.put(match.getConfId(), match); } }
/** * 大厅比赛列表信息获取 * * @param logicRequest */ @RPCReponse(EventDefinition.EVENT_GET_CMATCH) public ResultVo e_championships(LogicRequest args) { ResultVo resultvo = null; // 返回值 List<ChampionshipsVo> resultList = new ArrayList<ChampionshipsVo>(); try { // 1. 读取用户数据 MatchOp packet = ObjectBeanUtil.JACKSON.readValue(args.getData(), MatchOp.class); Long fbid = packet.getFbid(); int gt = packet.getGt(); // 一级分类 int mt = packet.getMt(); // 比赛类型 int ml = packet.getMl(); // 比赛等级 Map<Integer, Integer> emptyMatch = new HashMap<Integer, Integer>(); // 空比赛<类型ID,count> // 更新缓存数据 updateMatchCacheData(); // 从缓存获取比赛列表信息 for (Entry<Integer, Match> entry : matchMap.entrySet()) { Match match = entry.getValue(); // 如果为定时赛开放登记时间不到不显示 Date beginTime = match.getBt(); if (beginTime != null && System.currentTimeMillis() < beginTime.getTime()) continue; if (match.getIsOn() == false) continue; if (gt != match.getGt()) continue; if (mt != 0 && match.getMt() != mt) continue; if (ml != 0 && match.getMl() != ml) continue; // if(match.getEt() > 0) continue; // 设置显示空桌 if (match.getSt() == Match.MATCH_STATUS_OPEN) { if (emptyMatch.containsKey(match.getConfId())) emptyMatch.put(match.getConfId(), emptyMatch.get(match.getConfId()) + 1); else emptyMatch.put(match.getConfId(), 1); if (emptyMatch.get(match.getConfId()) > match.getEt()) // 超过预留空座不添加到集合 continue; } if (match.getSpt() != null && match.getSpt().getTime() <= System.currentTimeMillis() && Match.MATCH_STATUS_DOING != match.getSt() && Match.MATCH_STATUS_OVER != match.getSt()) match.setSt(Match.MATCH_STATUS_ENDREGISTER); // 报名截止 // 状态筛选 boolean it = isJoinMatch(match.getConfId(), fbid); if (packet.getSt() > -1) { if (packet.getSt() == 11) { // 已登记 if (it != true || match.getSt() == Match.MATCH_STATUS_OVER) // 未登记和已结束 continue; } else if (packet.getSt() != match.getSt()) { continue; } } String pattern = "yyyy-MM-dd HH:mm"; String spt = match.getSpt() != null ? (new SimpleDateFormat(pattern)).format(match.getSpt()) : ""; String stt = match.getStt() != null ? (new SimpleDateFormat(pattern)).format(match.getStt()) : ""; double aa = match.getMnc() * add(match.getMa(), -match.getFwc(), -match.getRc()); if (isToday(match.getSpt())) spt = "今天 " + String.copyValueOf(spt.toCharArray(), 11, 5); if (isToday(match.getStt())) stt = "今天 " + String.copyValueOf(stt.toCharArray(), 11, 5); // 计算比赛开始时间,(秒) long now = System.currentTimeMillis(); // 报名截止时间 int lst = Integer.parseInt(String.valueOf((match.getSpt().getTime() - now) / 1000)); // 分钟 // 是否为密码房间 boolean ispwd = !"".equals(match.getPwd()); ChampionshipsVo mvo = new ChampionshipsVo( match.getMi(), match.getMn(), match.getSp(), match.getMa(), match.getSt(), match.getMc(), match.getMnc(), match.getMt(), match.getMl(), String.valueOf(match.getMc()), spt, stt, aa, lst, ispwd, match.getJfc(), match.getFwc(), match.getRc()); mvo.setMatchServerId(match.getMatchServerId()); // 我的参赛状态 mvo.setIt(it ? 1 : 0); // 奖品图片路径 mvo.setPin(match.getToprcfg()); mvo.setSv(match.getConfId()); // 是否为坐满就玩 if (match.getUct() == 0) mvo.setGs(1); // Logger.info("cv:"+mvo); resultList.add(mvo); } } catch (Exception e) { // LOGGER.error("大厅比赛列表信息获取 error !!!",e); e.printStackTrace(); resultvo = new ResultVo("championships", /*Definition.UNKNOW_CODE*/ 29999L); } resultvo = new ResultVo("championships", Definition.SUCCESS_CODE, resultList); return resultvo; }