/**
   * 将包含授权信息的Shop转换为ShopVo
   *
   * @param shop
   * @return
   */
  private ShopVo convertShopAndAuth2ShopVo(Shop shop) {
    ShopVo shopVo = null;
    if (shop == null) {
      return shopVo;
    }

    shopVo = new ShopVo();
    shopVo.setId(shop.getId());
    shopVo.setShopId(shop.getOutShopId());
    shopVo.setCatId(shop.getCatId());
    shopVo.setNick(shop.getNick());
    shopVo.setTitle(shop.getTitle());
    shopVo.setDescription(shop.getDescription());
    shopVo.setBulletin(shop.getBulletin());
    shopVo.setPicPath(shop.getPicPath());
    shopVo.setItemScore(shop.getItemScore());
    shopVo.setServiceScore(shop.getServiceScore());
    shopVo.setDeliveryScore(shop.getDeliveryScore());
    shopVo.setDeExpress(shop.getDeExpress());
    shopVo.setEnableMsg(shop.getEnableMsg());
    shopVo.setMsgTemp(shop.getMsgTemp());
    shopVo.setMsgSign(shop.getMsgSign());
    shopVo.setOutPlatformType(shop.getPlatformType().getName());
    shopVo.setOutPlatformTypeValue(
        PlatformType.valueOf(shop.getPlatformType().getName()).getValue());
    shopVo.setCreateTime(shop.getCreateTime());
    shopVo.setUpdateTime(shop.getUpdateTime());
    if (shop.getShopAuth() != null) {
      shopVo.setSessionKey(shop.getShopAuth().getSessionKey());
      shopVo.setRefreshToken(shop.getShopAuth().getRefreshToken());
    }

    return shopVo;
  }
Example #2
0
  /**
   * 动态获取评分
   *
   * @param id
   * @return
   */
  public ShopVo dynamicGetScore(Integer id) throws Exception {
    if (logger.isInfoEnabled()) {
      logger.info("动态获取评分:id = " + id);
    }
    // 获取店铺信息与店铺授权信息
    ShopVo shopVo = getShopVo(id);

    if (logger.isInfoEnabled()) {
      logger.info("从外部平台动态获取评分信息:id = " + id);
    }

    // 判断来自哪个平台
    if (StringUtils.equals(shopVo.getOutPlatformType(), PlatformType.TAO_BAO.getName())
        || StringUtils.equals(shopVo.getOutPlatformType(), PlatformType.TAO_BAO_2.getName())) {
      // 来自淘宝平台
      Map<String, Object> argsMap = new HashMap<String, Object>();
      // 设置返回字段(必须)
      argsMap.put(
          ConstantTaoBao.FIELDS,
          "sid,cid,nick,title,desc,bulletin,pic_path,created,modified,shop_score");
      // 设置卖家昵称(必须)
      argsMap.put(ConstantTaoBao.NICK, shopVo.getNick());

      if (logger.isInfoEnabled()) {
        logger.info("查询淘宝店铺信息,参数argsMap = " + argsMap);
      }

      // 创建淘宝shopApi
      TbShopApi shopApi = new TbShopApi(shopVo.getSessionKey());
      // 获取淘宝店铺信息
      ShopGetResponse response = shopApi.shopGet(argsMap);
      if (StringUtils.isNotBlank(response.getErrorCode())) {
        throw new TaoBaoApiException(
            "调用淘宝 shopApi.getShop(" + argsMap + ")出现异常," + response.getBody());
      }
      com.taobao.api.domain.Shop shop = response.getShop();
      // 设置商品描述评分
      shopVo.setItemScore(shop.getShopScore().getItemScore());
      // 设置服务态度评分
      shopVo.setServiceScore(shop.getShopScore().getServiceScore());
      // 设置发货速度评分
      shopVo.setDeliveryScore(shop.getShopScore().getDeliveryScore());

    } else if (StringUtils.equals(shopVo.getOutPlatformType(), PlatformType.JING_DONG.getName())) {
      // todo:来自京东平台
    }

    // 获取评分信息的同时将评分信息更新到本地
    Shop shop = getById(id);

    if (shop == null) {
      shop = new Shop();
    }

    shop.setBulletin(shopVo.getBulletin());
    shop.setDescription(shopVo.getDescription());
    // 设置商品描述评分
    shop.setItemScore(shopVo.getItemScore());
    // 设置服务态度评分
    shop.setServiceScore(shopVo.getServiceScore());
    // 设置发货速度评分
    shop.setDeliveryScore(shopVo.getDeliveryScore());

    if (logger.isInfoEnabled()) {
      logger.info("店铺:更新评分信息至本地," + shop);
    }
    // 将评分信息更新到本地
    generalDAO.saveOrUpdate(shop);
    return shopVo;
  }