示例#1
0
  public List<KeywordType> getAllKeyword(List<Long> adgroupIds) {
    if (logger.isDebugEnabled()) {
      logger.debug("推广单元总数: " + adgroupIds.size());
    }

    try {
      KeywordService keywordService = commonService.getService(KeywordService.class);

      List<KeywordType> keywordTypeList = new ArrayList<>();
      GetKeywordIdByAdgroupIdRequest kwIdRequest = new GetKeywordIdByAdgroupIdRequest();
      kwIdRequest.setAdgroupIds(adgroupIds);
      GetKeywordIdByAdgroupIdResponse response =
          keywordService.getKeywordIdByAdgroupId(kwIdRequest);
      if (response == null) {
        Thread.sleep(3000);
        response = keywordService.getKeywordIdByAdgroupId(kwIdRequest);
      }
      List<GroupKeywordId> groupKeywordIds = response.getGroupKeywordIds();
      List<Long> kwIds = new ArrayList<>(groupKeywordIds.size() << 1);

      for (GroupKeywordId gkId : groupKeywordIds) {
        kwIds.addAll(gkId.getKeywordIds());
      }

      GetKeywordByKeywordIdRequest getKeywordByKeywordIdRequest =
          new GetKeywordByKeywordIdRequest();
      getKeywordByKeywordIdRequest.setKeywordIds(kwIds);

      GetKeywordByKeywordIdResponse response1 =
          keywordService.getKeywordByKeywordId(getKeywordByKeywordIdRequest);
      if (response1 == null) {
        Thread.sleep(3000);
        response1 = keywordService.getKeywordByKeywordId(getKeywordByKeywordIdRequest);
      }

      if (logger.isDebugEnabled()) {
        logger.debug("当前请求得到的关键词总数: " + response1.getKeywordTypes().size());
      }

      keywordTypeList.addAll(response1.getKeywordTypes());

      if (keywordTypeList.size() == 0) {
        return Collections.emptyList();
      }

      return keywordTypeList;
    } catch (final Exception e) {
      e.printStackTrace();
    }

    return Collections.emptyList();
  }
示例#2
0
  /**
   * 计划包含最大1000个单元
   *
   * @param campaignIds
   * @return
   */
  public List<AdgroupType> getAllAdGroup(List<Long> campaignIds) {
    try {
      AdgroupService adgroupService = commonService.getService(AdgroupService.class);

      List<Long> subList = new ArrayList<>(20);
      List<AdgroupType> adgroupTypes = new ArrayList<>();
      for (int i = 1; i <= campaignIds.size(); i++) {
        Long camId = campaignIds.get(i - 1);
        subList.add(camId);

        if (i % 20 == 0) {
          GetAdgroupByCampaignIdRequest getAdgroupByCampaignIdRequest =
              new GetAdgroupByCampaignIdRequest();
          getAdgroupByCampaignIdRequest.setCampaignIds(subList);
          GetAdgroupByCampaignIdResponse response =
              adgroupService.getAdgroupByCampaignId(getAdgroupByCampaignIdRequest);

          if (response == null) {
            Thread.sleep(5000);

            response = adgroupService.getAdgroupByCampaignId(getAdgroupByCampaignIdRequest);
            if (response == null) {
              subList.clear();
              continue;
            }
          }

          for (CampaignAdgroup campaignAdgroup : response.getCampaignAdgroups()) {
            adgroupTypes.addAll(campaignAdgroup.getAdgroupTypes());
          }
          subList.clear();
        }
      }

      if (!subList.isEmpty()) {
        GetAdgroupByCampaignIdRequest getAdgroupByCampaignIdRequest =
            new GetAdgroupByCampaignIdRequest();
        getAdgroupByCampaignIdRequest.setCampaignIds(subList);
        GetAdgroupByCampaignIdResponse response =
            adgroupService.getAdgroupByCampaignId(getAdgroupByCampaignIdRequest);

        if (response == null) {
          Thread.sleep(5000);

          response = adgroupService.getAdgroupByCampaignId(getAdgroupByCampaignIdRequest);
          if (response == null) {
            subList.clear();
          }
        }

        for (CampaignAdgroup campaignAdgroup : response.getCampaignAdgroups()) {
          adgroupTypes.addAll(campaignAdgroup.getAdgroupTypes());
        }
      }

      return adgroupTypes;
    } catch (final Exception e) {
      e.printStackTrace();
    }

    return Collections.emptyList();
  }