コード例 #1
0
 @SuppressWarnings("unchecked")
 public void processDateAndSclassID(Date date, String sclassID, boolean updateRanking) {
   logger.info("开始更新足球赛程赛果, date:{}, sclassID:{}", new String[] {DateUtil.format(date), sclassID});
   long startmillis = System.currentTimeMillis();
   try {
     String param = "";
     if (null != date) {
       param = "date=" + DateUtil.format("yyyy-MM-dd", date);
     }
     if (null != sclassID) {
       Sclass sclass = Sclass.findSclass(Integer.parseInt(sclassID));
       if (null == sclass) {
         return;
       }
       param = "sclassID=" + sclassID;
     }
     String data = httpUtil.getResponse(url, HttpUtil.GET, HttpUtil.UTF8, param);
     if (StringUtil.isEmpty(data)) {
       logger.info("更新足球赛程赛果时获取数据为空");
       return;
     }
     Document doc = DocumentHelper.parseText(data);
     List<Element> matches = doc.getRootElement().elements("match");
     for (Element match : matches) {
       doProcess(match, updateRanking);
     }
   } catch (Exception e) {
     logger.error("更新足球赛程赛果出错, date:" + DateUtil.format(date) + ",sclassID:" + sclassID, e);
   }
   long endmillis = System.currentTimeMillis();
   logger.info(
       "更新足球赛程赛果结束, date:{},sclassID:{},共用时 {}",
       new String[] {DateUtil.format(date), sclassID, String.valueOf((endmillis - startmillis))});
 }
コード例 #2
0
  @SuppressWarnings("unchecked")
  public Set<String> updateScheduleById(String scheduleId, Set<String> set) {
    try {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      logger.info("根据id更新赛事,id=" + scheduleId);
      if (StringUtils.isBlank(scheduleId)) {
        return set;
      }
      String param = "id=" + scheduleId;
      String data = httpUtil.getResponse(scheduleByIdUrl, HttpUtil.GET, HttpUtil.UTF8, param);
      if (StringUtils.isBlank(data)) {
        logger.info("根据id更新赛事,获取数据为空,id=" + scheduleId);
        return set;
      }
      Document doc = DocumentHelper.parseText(data);
      List<Element> matches = doc.getRootElement().elements("match");

      Schedule schedule = Schedule.findById(Integer.parseInt(scheduleId), false);
      Date matchTime = schedule.getMatchTime(); // 比赛时间
      if (matches == null || matches.size() == 0) { // 删除赛事
        boolean zqEventEmpty = CommonUtil.isZqEventEmpty(schedule);
        if (schedule != null && zqEventEmpty) {
          schedule.remove();
          logger.info("足球赛事删除,id=" + scheduleId);
          if (matchTime != null) {
            set.add(sdf.format(matchTime));
          }
          return set;
        }
      } else if (matches.size() == 1) { // 更新赛事
        Element match = matches.get(0);
        doProcess(match, true);
        if (matchTime != null) { // 之前的比赛时间
          set.add(sdf.format(matchTime));
        }
        String d = match.elementTextTrim("d"); // 现在的比赛时间
        Date time = DateUtil.parse("yyyy/MM/dd HH:mm:ss", d);
        if (time != null) {
          set.add(sdf.format(time));
        }
        return set;
      }
    } catch (Exception e) {
      logger.error("根据id更新赛事发生异常,id=" + scheduleId, e);
    }
    return set;
  }