コード例 #1
0
 /**
  * 已加入投放的宝贝
  *
  * @param userId
  * @param activityId
  * @param pageNum
  * @param pageSize
  * @return
  */
 public Page<PosterRecommendPublishItem> paginatePublishAddedItems(
     Long userId, Long activityId, int pageNum, int pageSize) {
   List<PosterRecommendPublishItem> publishItems =
       posterRecommendPublishItemDAO.paginateByUserIdAndActivityId(
           userId, activityId, "add_time desc", (pageNum - 1) * pageSize, pageSize);
   int count = posterRecommendPublishItemDAO.countByUserIdAndActivityId(userId, activityId);
   if (CollectionUtils.isNotEmpty(publishItems)) {
     return Page.create(count, pageNum, pageSize, publishItems);
   } else {
     return Page.create(
         count, pageNum, pageSize, Lists.<PosterRecommendPublishItem>newArrayList());
   }
 }
コード例 #2
0
  /**
   * 查询可供选择加入投放的宝贝
   *
   * @param userId
   * @param activityId
   * @param onSale
   * @param query
   * @param sellerCids
   * @param pageNum
   * @param pageSize
   * @return
   * @throws TaobaoAccessControlException
   * @throws TaobaoEnhancedApiException
   * @throws TaobaoSessionExpiredException
   */
  @NotNull
  public Page<PublishItem> paginateItems(
      Long userId,
      Long activityId,
      boolean onSale,
      String query,
      List<Long> sellerCids,
      int pageNum,
      int pageSize)
      throws TaobaoAccessControlException, TaobaoEnhancedApiException,
          TaobaoSessionExpiredException {

    Page<Item> itemPage;
    List<PublishItem> returnPublishItems = Lists.newArrayList();

    // 从淘宝 api 获取商品
    if (onSale) {
      itemPage =
          taobaoApiShopService.paginateOnSaleItems(
              userId,
              query,
              ITEM_FIELDS,
              sellerCids,
              pageNum,
              pageSize,
              true,
              null,
              "modified:asc");

    } else {
      itemPage =
          taobaoApiShopService.paginateInventoryItems(
              userId,
              query,
              ITEM_FIELDS,
              Lists.newArrayList(BANNER_FOR_SHELVED),
              sellerCids,
              pageNum,
              pageSize,
              true,
              "modified:asc");
    }

    List<Item> taobaoItems = itemPage.getItems();

    if (CollectionUtils.isEmpty(taobaoItems)) {
      return Page.create(
          itemPage.getTotalSize(), pageNum, pageSize, Lists.<PublishItem>newArrayList());
    }

    Map<Long, PosterRecommendPublishItem> indexMap = Maps.newHashMap();

    if (null != activityId) {
      // 获取已经加入投放的宝贝并且设置是否加入投放的标志位
      List<PosterRecommendPublishItem> posterRecommendPublishItems =
          posterRecommendPublishItemDAO.selectByUserIdAndActivityId(userId, activityId);

      indexMap =
          Maps.uniqueIndex(
              posterRecommendPublishItems,
              new Function<PosterRecommendPublishItem, Long>() {
                @Nullable
                @Override
                public Long apply(@Nullable PosterRecommendPublishItem input) {
                  return input.getItemNumIid();
                }
              });
    }

    for (Item item : taobaoItems) {
      PublishItem publishItem = new PublishItem();
      publishItem.setItem(item);

      if (indexMap.keySet().contains(item.getNumIid())) {
        publishItem.setPublishItemStatus(indexMap.get(item.getNumIid()).getStatus());
      } else {
        publishItem.setPublishItemStatus(PUBLISH_ITEM_STATUS_NOT_IN_DB);
      }
      returnPublishItems.add(publishItem);
    }
    return Page.create(itemPage.getTotalSize(), pageNum, pageSize, returnPublishItems);
  }