示例#1
0
 public static void main(String args[]) {
   Connection connection = conn();
   try {
     GetToken2 getToken2 = new GetToken2(null);
     JSONObject object = new JSONObject(PublicUtils.getConfig(connection, "美丽说Token信息2", ""));
     String result =
         Utils.sendbyget(
             Params.url,
             Params.appKey,
             Params.appsecret,
             "meilishuo.aftersales.list.get",
             object.optString("access_token"),
             new Date(),
             null,
             null,
             "",
             "",
             "",
             "");
     JSONObject object_result = new JSONObject(result);
     System.out.println(
         object_result.getJSONObject("aftersales_list_get_response").getInt("total_num"));
     JSONArray info =
         object_result.getJSONObject("aftersales_list_get_response").getJSONArray("info");
     System.out.println(info.toString());
     System.out.println(result);
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
示例#2
0
  private void getInStockItems() throws Exception {

    int pageno = 1;

    Log.info("开始取一号店仓库商品资料");
    String sql =
        "select orgid from ecs_tradecontactorgcontrast with(nolock) where tradecontactid="
            + tradecontactid;
    int orgid = this.getDao().intSelect(sql);
    for (int k = 0; k < 10; ) {
      try {

        while (true) {
          Map<String, String> productparams = new HashMap<String, String>();
          // 系统级参数设置
          productparams.put("appKey", app_key);
          productparams.put("sessionKey", token);
          productparams.put("format", format);
          productparams.put("method", "yhd.serial.products.search");
          productparams.put("ver", ver);
          productparams.put("timestamp", Formatter.format(new Date(), Formatter.DATE_TIME_FORMAT));

          productparams.put("canShow", "1");
          productparams.put("canSale", "0");
          productparams.put("curPage", String.valueOf(pageno));
          productparams.put("pageRows", "20");
          productparams.put("verifyFlg", "2");

          String responseProductData = Utils.sendByPost(productparams, app_secret, url, "");
          Log.info("取仓库商品返回数据: " + responseProductData);

          JSONObject responseproduct = new JSONObject(responseProductData);

          int totalCount = responseproduct.getJSONObject("response").getInt("totalCount");

          JSONArray productlist =
              responseproduct
                  .getJSONObject("response")
                  .getJSONObject("serialProductList")
                  .getJSONArray("serialProduct");

          for (int i = 0; i < productlist.length(); i++) {
            JSONObject product = productlist.getJSONObject(i);

            long productId = product.optLong("productId");
            String productCode = product.optString("productCode");
            String productCname = product.optString("productCname");

            Log.info("货号:" + productCode + ",产品名称:" + productCname);

            StockManager.stockConfig(
                this.getDao(),
                orgid,
                Integer.valueOf(tradecontactid),
                String.valueOf(productId),
                productCode,
                productCname,
                0);

            Map<String, String> stockparams = new HashMap<String, String>();
            // 系统级参数设置
            stockparams.put("appKey", app_key);
            stockparams.put("sessionKey", token);
            stockparams.put("format", format);
            stockparams.put("method", "yhd.serial.product.get");
            stockparams.put("ver", ver);
            stockparams.put("timestamp", Formatter.format(new Date(), Formatter.DATE_TIME_FORMAT));

            stockparams.put("productId", String.valueOf(productId));

            String responseData = Utils.sendByPost(stockparams, app_secret, url, "");
            Log.info("取仓库商品详情返回数据: " + responseData);
            JSONObject responsestock = new JSONObject(responseData);

            JSONArray childseriallist =
                responsestock
                    .getJSONObject("response")
                    .getJSONObject("serialChildProdList")
                    .getJSONArray("serialChildProd");

            for (int m = 0; m < childseriallist.length(); m++) {
              JSONObject childserial = childseriallist.optJSONObject(m);

              String sku = childserial.optString("outerId");
              long skuid = childserial.optLong("productId");

              JSONArray stocklist =
                  childserial.getJSONObject("allWareHouseStocList").getJSONArray("pmStockInfo");

              for (int j = 0; j < stocklist.length(); j++) {
                JSONObject stock = stocklist.optJSONObject(j);

                int quantity = stock.optInt("vs");
                long warehouseId = stock.optLong("warehouseId");

                StockManager.addStockConfigSku(
                    this.getDao(),
                    Integer.valueOf(tradecontactid),
                    String.valueOf(productId),
                    String.valueOf(skuid) + "-" + String.valueOf(warehouseId),
                    sku,
                    quantity);
              }
            }
          }

          // 判断是否有下一页
          if (pageno == (Double.valueOf(Math.ceil(totalCount / 20.0))).intValue()) break;

          pageno++;
        }

        break;

      } catch (Exception e) {
        if (++k >= 10) throw e;
        Log.warn(jobName + ", 远程连接失败[" + k + "], 10秒后自动重试. " + Log.getErrorMessage(e));

        Thread.sleep(10000L);
      }
    }
  }