/**
   * TODO 暂没有用上
   *
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ModelAndView productJSONData(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    Integer productId = RequestUtil.getInteger(request, "productId");
    Product product = productManager.getById(productId);
    Integer storeId = ConfigUtil.getInstance().getStore().getStoreId();
    ProductStat productStat = productStatManager.getProductStat(storeId, product.getId());
    // TODO 是否只检查已激活的Sku信息
    List<ProductSku> productSkuList = productSkuManager.findActiveProductSkusByProductId(productId);

    JSONObject jsonProduct = new JSONObject();
    jsonProduct.put("productId", product.getProductId());
    jsonProduct.put("productName", product.getProductName());
    jsonProduct.put("productCode", product.getProductCode());
    jsonProduct.put("availabilityRule", product.getAvailabilityRule());
    Map<String, Object> jsonProductStat = new HashMap<String, Object>();
    jsonProductStat.put("buyCount", productStat.getBuyCount());
    jsonProductStat.put("averageRate", productStat.getAverageRate());
    jsonProductStat.put("reviewCount", productStat.getReviewCount());
    jsonProduct.put("productStat", jsonProductStat);
    List<Map<String, Object>> jsonProductSkus = new ArrayList<Map<String, Object>>();
    for (ProductSku productSku : productSkuList) {
      Map<String, Object> jsonProductSku = new HashMap<String, Object>();
      jsonProductSku.put("productSkuId", productSku.getProductSkuId());
      jsonProductSku.put("productSkuCode", productSku.getProductSkuCode());
      // 相应的价格等
      Inventory inventory = inventoryService.getInventoryBySku(productSku.getId());
      Map<String, Object> jsonInventory = new HashMap<String, Object>();
      jsonInventory.put("productSkuId", inventory.getProductSkuId());
      jsonInventory.put("quantityOnHand", inventory.getQuantityOnHand());
      jsonInventory.put("allocatedQuantity", inventory.getAllocatedQuantity());
      jsonInventory.put("availableQuantity", inventory.getAvailableQuantity());
      jsonProductSku.put("inventory", jsonInventory);
      jsonProductSkus.add(jsonProductSku);
      if (productSku.getId().intValue() == product.getDefaultProductSkuId().intValue()) {
        jsonProduct.put("defaultProductSku", jsonProductSku);
      }
    }
    jsonProduct.put("productSkus", jsonProductSkus);
    PrintWriter out = response.getWriter();
    out.println(jsonProduct.toString());
    return null;
  }
  private JSONObject skuToJson(
      ProductSku productSku, Map<SkuOption, SkuOptionValue> skuOptionAndValues) {
    ConfigUtil configUtil = ConfigUtil.getInstance();
    JSONObject jsonProductSku = new JSONObject();
    jsonProductSku.put("productSkuId", productSku.getProductSkuId());
    jsonProductSku.put("productSkuCode", productSku.getProductSkuCode());
    jsonProductSku.put("image", productSku.getImage());
    jsonProductSku.put(
        "weight",
        productSku.getWeight() == null
            ? null
            : productSku.getWeight().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
    // 相应的价格等
    jsonProductSku.put("priceViewType", productSku.getPriceViewType());
    jsonProductSku.put(
        "price", productSku.getPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
    jsonProductSku.put(
        "salePrice",
        productSku.getSalePrice() == null
            ? null
            : productSku.getSalePrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
    jsonProductSku.put(
        "discountPrice",
        productSku.getDiscountPrice() == null
            ? null
            : productSku.getDiscountPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
    jsonProductSku.put(
        "listPrice",
        productSku.getListPrice() == null
            ? null
            : productSku.getListPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
    jsonProductSku.put("discountPercent", productSku.getDiscountPercent());

    // 获取批发价
    Set<WholesalePrice> wholesalePrices = productSku.getWholesalePrices();
    List<JSONArray> jsonWholesalePrices = new ArrayList<JSONArray>();
    for (WholesalePrice wholesalePrice : wholesalePrices) {
      JSONArray jsonWholesalePrice = new JSONArray();
      jsonWholesalePrice.add(wholesalePrice.getMinQuantity());
      jsonWholesalePrice.add(
          wholesalePrice.getPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
      jsonWholesalePrices.add(jsonWholesalePrice);
    }
    jsonProductSku.put("wholesalePrices", jsonWholesalePrices);

    // 获取产品媒体productMedia
    Set<ProductMedia> productMedias = productSku.getProductMedias();
    JSONArray jsonProductMedias = new JSONArray();
    for (ProductMedia media : productMedias) {
      jsonProductMedias.add(media.getMediaUrlLarge());
    }
    jsonProductSku.put("productMedias", jsonProductMedias);

    // 获取库存信息
    if (productSku.getProduct().getAvailabilityRule().intValue()
            != CatalogConstants.PRODUCT_AVAILABILITY_ALWAYS_SELL.intValue()
        && productSku.getProduct().getAvailabilityRule().intValue()
            != CatalogConstants.PRODUCT_AVAILABILITY_NOT_IN_STOCK_SELL) {
      Inventory inventory = productSku.getInventory();
      // TODO 没有库存的全设置为0
      if (inventory == null) {
        inventory = new Inventory();
        inventory.setProductSku(productSku);
        inventory.setQuantityOnHand(0);
        inventory.setAllocatedQuantity(0);
        inventory.setReservedQuantity(0);
        inventory.setPreOrBackOrderedQty(0);
      }
      Map<String, Object> jsonInventory = new HashMap<String, Object>();
      jsonInventory.put("productSkuId", inventory.getProductSkuId());
      jsonInventory.put("quantityOnHand", inventory.getQuantityOnHand());
      jsonInventory.put("allocatedQuantity", inventory.getAllocatedQuantity());
      jsonInventory.put("availableQuantity", inventory.getAvailableQuantity());
      jsonInventory.put(
          "expectedRestockDate",
          inventory.getExpectedRestockDate() == null
              ? ""
              : DateUtil.convertDateToString(inventory.getExpectedRestockDate()));
      jsonInventory.put("preOrBackOrderedQty", inventory.getPreOrBackOrderedQty());
      jsonProductSku.put("inventory", jsonInventory);
    }
    if (skuOptionAndValues != null && skuOptionAndValues.size() > 0) {
      JSONArray jsonSkuOptions = new JSONArray();
      Set<SkuOption> skuOptions = skuOptionAndValues.keySet();
      for (SkuOption skuOption : skuOptions) {
        JSONObject jsonSkuOption = new JSONObject();
        jsonSkuOption.put("id", skuOption.getId());
        jsonSkuOption.put("vid", skuOptionAndValues.get(skuOption).getId());
        jsonSkuOptions.add(jsonSkuOption);
      }
      jsonProductSku.put("skuOptions", jsonSkuOptions);
    }
    return jsonProductSku;
  }