コード例 #1
0
  public Map<String, Account> loadSourceFromDatabase(
      IUserConfiguration configuration, String getDataSql) throws IOException {
    Map<String, Account> accounts = bingUtils.loadAccounts((IBingUserConfiguration) configuration);

    LOGGER.info("Load data from database");
    final long[] rowsCount = {0};
    jdbcTemplate.query(
        getDataSql,
        (rs, rowNum) -> {
          long searchEngineId = rs.getLong(AdwordsConstants.SEARCH_ENGINE_ID);
          if (1 == searchEngineId) {
            String accountId = rs.getString(AdwordsConstants.SEARCH_ENGINE_ACCOUNT_ID);
            long campaignId = rs.getLong(AdwordsConstants.SEARCH_ENGINE_CAMPAIGN_ID);
            long adGroupId = rs.getLong(AdwordsConstants.SEARCH_ENGINE_AD_GROUP_ID);
            long keywordId = rs.getLong(AdwordsConstants.SEARCH_ENGINE_KEYWORD_ID);
            String keywordName = rs.getString("keyword_name");
            registerSourceKeyword(
                accounts, accountId, campaignId, adGroupId, keywordId, keywordName);
            rowsCount[0]++;
          }
          return null;
        });
    LOGGER.info("Rows count: {}", rowsCount[0]);

    return accounts;
  }
コード例 #2
0
  public Map<String, Account> loadSourceFromCsv(IUserConfiguration configuration)
      throws IOException {
    Map<String, Account> accounts = bingUtils.loadAccounts((IBingUserConfiguration) configuration);

    csvService.loadSourceFromCsv(
        configuration,
        Arrays.asList(
            AdwordsConstants.SEARCH_ENGINE_ID,
            AdwordsConstants.SEARCH_ENGINE_ACCOUNT_ID,
            AdwordsConstants.SEARCH_ENGINE_CAMPAIGN_ID,
            AdwordsConstants.SEARCH_ENGINE_AD_GROUP_ID,
            AdwordsConstants.SEARCH_ENGINE_KEYWORD_ID,
            AdwordsConstants.SEARCH_ENGINE_KEYWORD_NAME,
            AdwordsConstants.CLICKS,
            AdwordsConstants.COST,
            AdwordsConstants.ORDERS,
            AdwordsConstants.GP_USD),
        dataRow -> {
          long searchEngineId =
              AdwordsUtils.getLongValue(dataRow.apply(AdwordsConstants.SEARCH_ENGINE_ID));
          if (2 == searchEngineId) {
            String accountId = dataRow.apply(AdwordsConstants.SEARCH_ENGINE_ACCOUNT_ID);
            long campaignId =
                AdwordsUtils.getLongValue(
                    dataRow.apply(AdwordsConstants.SEARCH_ENGINE_CAMPAIGN_ID));
            long adGroupId =
                AdwordsUtils.getLongValue(
                    dataRow.apply(AdwordsConstants.SEARCH_ENGINE_AD_GROUP_ID));
            long keywordId =
                AdwordsUtils.getLongValue(dataRow.apply(AdwordsConstants.SEARCH_ENGINE_KEYWORD_ID));
            String keywordName = dataRow.apply(AdwordsConstants.SEARCH_ENGINE_KEYWORD_NAME);

            Criterion keyword =
                registerSourceKeyword(
                    accounts, accountId, campaignId, adGroupId, keywordId, keywordName);

            if (keyword != null) {
              CommonMetrics metrics = new CommonMetrics();
              metrics.setClicks(getLongValue(dataRow.apply(CLICKS)));
              metrics.setOrders(getLongValue(dataRow.apply(ORDERS)));
              metrics.setCost(AdwordsUtils.getDoubleValue(dataRow.apply(COST)));
              metrics.setGrossProfit(
                  metrics.getClicks() > 0
                      ? AdwordsUtils.getDoubleValue(dataRow.apply(AdwordsConstants.GP_USD))
                          / metrics.getClicks()
                      : 0);
              keyword.setMetrics(metrics);
            }
          }
        });
    return accounts;
  }