private void synStock() throws Exception {
    // 店铺同步比例
    double synrate = 1;
    Log.info(username, "开始同步商品库存");

    StringBuffer updateItemsXML = new StringBuffer();

    String sql =
        "select orgid from ecs_tradecontactorgcontrast with(nolock) where tradecontactid="
            + tradecontactid;
    int orgid = this.getDao().intSelect(sql);

    sql = "update ecs_stockconfig set errflag=0,errmsg='' where orgid=" + orgid;
    this.getDao().execute(sql);

    sql = "update ecs_stockconfigsku set errflag=0,errmsg='' where orgid=" + orgid;
    this.getDao().execute(sql);
    // 店铺同步比例表
    sql = "select synrate from ecs_shopglobalconfig where shopOrgId=" + orgid;
    String temp = this.getDao().strSelect(sql);
    if (!"".equals(temp)) synrate = Float.parseFloat(temp);
    int n = 0;

    for (int k = 0; k < 10; ) {
      try {
        sql = "select * from ecs_stockconfig with(nolock) where orgid=" + orgid;
        Vector vtstockconfig = this.getDao().multiRowSelect(sql);
        for (int i = 0; i < vtstockconfig.size(); i++) {
          try {
            Hashtable htstockconfig = (Hashtable) vtstockconfig.get(i);

            ECS_StockConfig stockconfig = new ECS_StockConfig();
            stockconfig.getMapData(htstockconfig);

            String itemid = stockconfig.getItemid();
            Log.info("商品ID:" + stockconfig.getItemid() + " 货号:" + stockconfig.getItemcode());

            if (stockconfig.getIsneedsyn() == 0) {
              Log.info(username, "配置不需要同步库存,货号:" + stockconfig.getItemcode());
              continue; // 不需要同步
            }

            sql =
                "select * from ecs_stockconfigsku with(nolock) where orgid="
                    + orgid
                    + " and itemid='"
                    + stockconfig.getItemid()
                    + "'";

            Vector vtstockconfigsku = this.getDao().multiRowSelect(sql);

            for (int j = 0; j < vtstockconfigsku.size(); j++) {
              try {
                Hashtable htstockconfigsku = (Hashtable) vtstockconfigsku.get(j);

                ECS_StockConfigSku stockconfigsku = new ECS_StockConfigSku();
                stockconfigsku.getMapData(htstockconfigsku);

                Log.info(
                    username,
                    "SKU:" + stockconfigsku.getSku() + " 原库存:" + stockconfigsku.getStockcount());

                boolean ismulti = false;
                boolean isfind = true;

                sql =
                    "select count(*) from barcode with(nolock) where custombc='"
                        + stockconfigsku.getSku()
                        + "'";
                if (this.getDao().intSelect(sql) == 0) {
                  sql =
                      "select count(*) from MultiSKURef where refcustomercode='"
                          + stockconfigsku.getSku()
                          + "'";
                  if (this.getDao().intSelect(sql) == 0) {
                    Log.warn(
                        username,
                        "找不到SKU【"
                            + stockconfigsku.getSku()
                            + "】对应的条码,商品标题:"
                            + stockconfig.getTitle());

                    stockconfigsku.setErrflag(1);
                    stockconfigsku.setErrmsg("找不到SKU【" + stockconfigsku.getSku() + "】对应的条码");
                    this.getDao().updateByKeys(stockconfigsku, "orgid,itemid,skuid");

                    stockconfig.setErrflag(1);
                    stockconfig.setErrmsg("找不到SKU【" + stockconfigsku.getSku() + "】对应的条码");
                    this.getDao().updateByKeys(stockconfig, "orgid,itemid");

                    isfind = false;
                    continue;
                  } else ismulti = true;
                }

                int qty = 0;

                if (isfind) {
                  if (ismulti) {
                    int minqty = 1000000;
                    sql =
                        "select customercode,qty from MultiSKURef where refcustomercode='"
                            + stockconfigsku.getSku()
                            + "'";
                    Vector multiskulist = this.getDao().multiRowSelect(sql);
                    for (Iterator itmulti = multiskulist.iterator(); itmulti.hasNext(); ) {
                      Hashtable skuref = (Hashtable) itmulti.next();
                      String customercode = skuref.get("customercode").toString();
                      double skurefqty = Double.valueOf(skuref.get("qty").toString()).doubleValue();
                      qty =
                          StockManager.getTradeContactUseableStock(
                              this.getDao().getConnection(),
                              Integer.valueOf(tradecontactid).intValue(),
                              customercode);

                      qty = (Double.valueOf(Math.ceil(qty / skurefqty))).intValue();

                      if (qty < minqty) {
                        minqty = qty;
                      }
                    }

                    qty = minqty;
                  } else {
                    qty =
                        StockManager.getTradeContactUseableStock(
                            this.getDao().getConnection(),
                            Integer.valueOf(tradecontactid).intValue(),
                            stockconfigsku.getSku());
                  }

                  if (qty < 0) qty = 0;
                }

                int addstockqty = 0;
                if (Math.abs(stockconfig.getAddstockqty()) < 1)
                  addstockqty =
                      Double.valueOf(Math.floor(qty * stockconfig.getAddstockqty())).intValue();
                else addstockqty = Double.valueOf(stockconfig.getAddstockqty()).intValue();
                // 如果可用库存加上需增加的库存小于等于警戒库存,则将库存同步为0
                if ((qty + addstockqty) <= stockconfig.getAlarmqty()) {
                  qty = 0;
                } else {
                  qty = qty + addstockqty;
                }

                Log.info("old qty: " + qty);
                qty = Double.valueOf(Math.floor(qty * synrate)).intValue();
                Log.info("new qty: " + qty);
                // 更新库存开始
                StockUtils.UpdateSkuStock(
                    this.getDao(),
                    orgid,
                    url,
                    app_id,
                    secret,
                    session,
                    stockconfigsku.getSku(),
                    qty,
                    stockconfig,
                    stockconfigsku);

              } catch (Exception ex) {
                if (this.getConnection() != null && !this.getConnection().getAutoCommit())
                  this.getConnection().rollback();

                if (this.getExtconnection() != null && !this.getExtconnection().getAutoCommit())
                  this.getExtconnection().rollback();
                Log.error(jobName, ex.getMessage());
              }
            }

            k = 0;
          } catch (Exception ex) {
            if (this.getConnection() != null && !this.getConnection().getAutoCommit())
              this.getConnection().rollback();

            if (this.getExtconnection() != null && !this.getExtconnection().getAutoCommit())
              this.getExtconnection().rollback();
            Log.error(jobName, ex.getMessage());
          }
        }
        break;

      } catch (Exception e) {
        if (++k >= 10) throw e;
        if (this.getConnection() != null && !this.getConnection().getAutoCommit())
          this.getConnection().rollback();

        if (this.getExtconnection() != null && !this.getExtconnection().getAutoCommit())
          this.getExtconnection().rollback();
        Log.warn(jobName + ", 远程连接失败[" + k + "], 10秒后自动重试. " + Log.getErrorMessage(e));

        Thread.sleep(10000L);
      }
    }
  }
Exemple #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);
      }
    }
  }
  public void run() {
    Properties proper = StringUtil.getStringProperties(this.getExecuteobj().getParams());
    tid = proper.getProperty("tid");
    tradecontactid = proper.getProperty("tradecontactid");
    url = proper.getProperty("url");
    appkey = proper.getProperty("appkey");
    appsecret = proper.getProperty("appsecret");
    authcode = proper.getProperty("authcode");
    sellernick = proper.getProperty("sellernick");
    try {
      updateJobFlag(1);
      String sql = "select isnull(value,0) from config where name='等待付款订单是否进系统'";
      if ("1".equals(this.getDao().strSelect(sql))) ;
      waitbuyerpayisin = true;

      TaobaoClient client = new DefaultTaobaoClient(url, appkey, appsecret, "xml");
      TradeGetRequest req = new TradeGetRequest();
      req.setFields("tid,modified,status,orders.outer_sku_id,orders.num");
      req.setTid(Long.parseLong(tid));
      TradeGetResponse response = client.execute(req, authcode);

      if (response.getTrade() == null) {
        return;
      }

      Trade td = response.getTrade();

      if (td.getStatus().equals("WAIT_SELLER_SEND_GOODS")) {

        if (!OrderManager.isCheck(
            "检查淘宝订单", this.getDao().getConnection(), String.valueOf(td.getTid()))) {
          if (!OrderManager.TidLastModifyIntfExists(
              "检查淘宝订单",
              this.getDao().getConnection(),
              String.valueOf(td.getTid()),
              td.getModified())) {
            OrderUtils.createInterOrder(
                this.getDao().getConnection(), td, Params.tradecontactid, Params.username, true);
            for (Iterator ito = td.getOrders().iterator(); ito.hasNext(); ) {
              Order o = (Order) ito.next();
              String sku = o.getOuterSkuId();

              StockManager.deleteWaitPayStock(
                  jobName,
                  this.getDao().getConnection(),
                  Params.tradecontactid,
                  String.valueOf(td.getTid()),
                  sku);
              StockManager.addSynReduceStore(
                  jobName,
                  this.getDao().getConnection(),
                  Params.tradecontactid,
                  td.getStatus(),
                  String.valueOf(td.getTid()),
                  sku,
                  -o.getNum(),
                  false);
            }
          }
        }

        // 等待买家付款时记录锁定库存
      } else if (td.getStatus().equals("WAIT_BUYER_PAY")
          || td.getStatus().equals("TRADE_NO_CREATE_PAY")) {
        if (waitbuyerpayisin) {
          if (!OrderManager.TidLastModifyIntfExists(
              "检查淘宝订单",
              this.getDao().getConnection(),
              String.valueOf(td.getTid()),
              td.getModified())) {
            OrderUtils.createInterOrder(
                this.getDao().getConnection(), td, Params.tradecontactid, Params.username, false);
          }
        }
        for (Iterator ito = td.getOrders().iterator(); ito.hasNext(); ) {
          Order o = (Order) ito.next();
          String sku = o.getOuterSkuId();
          StockManager.addWaitPayStock(
              jobName,
              this.getDao().getConnection(),
              Params.tradecontactid,
              String.valueOf(td.getTid()),
              sku,
              o.getNum());
          StockManager.addSynReduceStore(
              jobName,
              this.getDao().getConnection(),
              Params.tradecontactid,
              td.getStatus(),
              String.valueOf(td.getTid()),
              sku,
              -o.getNum(),
              false);
        }

        // 付款以后用户退款成功,交易自动关闭
        // 释放库存,数量为负数
      } else if (td.getStatus().equals("TRADE_CLOSED")) {
        OrderManager.CancelOrderByCID(
            jobName, this.getDao().getConnection(), String.valueOf(td.getTid()));
        for (Iterator ito = td.getOrders().iterator(); ito.hasNext(); ) {
          Order o = (Order) ito.next();
          String sku = o.getOuterSkuId();
          StockManager.deleteWaitPayStock(
              jobName,
              this.getDao().getConnection(),
              Params.tradecontactid,
              String.valueOf(td.getTid()),
              sku);
          // StockManager.addSynReduceStore(jobName, this.getDao().getConnection(),
          // Params.tradecontactid, td.getStatus(),String.valueOf(td.getTid()),sku,
          // o.getNum(),false);
        }

        // 付款以前,卖家或买家主动关闭交易
        // 释放等待买家付款时锁定的库存
      } else if (td.getStatus().equals("TRADE_CLOSED_BY_TAOBAO")) {

        if (waitbuyerpayisin) {

          if (!OrderManager.TidLastModifyIntfExists(
              "检查淘宝订单",
              this.getDao().getConnection(),
              String.valueOf(td.getTid()),
              td.getModified())) {
            OrderUtils.createInterOrder(
                this.getDao().getConnection(), td, Params.tradecontactid, Params.username, false);
          }
        }

        for (Iterator ito = td.getOrders().iterator(); ito.hasNext(); ) {
          Order o = (Order) ito.next();
          String sku = o.getOuterSkuId();

          StockManager.deleteWaitPayStock(
              jobName,
              this.getDao().getConnection(),
              Params.tradecontactid,
              String.valueOf(td.getTid()),
              sku);

          if (StockManager.WaitPayStockExists(
              jobName,
              this.getDao().getConnection(),
              Params.tradecontactid,
              String.valueOf(td.getTid()),
              sku)) // 有获取到等待买家付款状态时才加库存
          {

            StockManager.addSynReduceStore(
                jobName,
                this.getDao().getConnection(),
                Params.tradecontactid,
                td.getStatus(),
                String.valueOf(td.getTid()),
                sku,
                o.getNum(),
                false);
          }
        }

      } else if (td.getStatus().equals("TRADE_FINISHED")) {

        for (Iterator ito = td.getOrders().iterator(); ito.hasNext(); ) {
          Order o = (Order) ito.next();
          String sku = o.getOuterSkuId();

          StockManager.deleteWaitPayStock(
              jobName,
              this.getDao().getConnection(),
              Params.tradecontactid,
              String.valueOf(td.getTid()),
              sku);

          // 更新结束时间

          OrderUtils.updateFinishedStatus(
              this.getDao().getConnection(), Params.tradecontactid, td.getTid(), td.getEndTime());
        }
      }

      // if(Params.isc)
      // {
      // 处理退货
      for (Iterator oit = td.getOrders().iterator(); oit.hasNext(); ) {
        Order o = (Order) oit.next();
        // Log.info("订单号:"+String.valueOf(td.getTid())+" 退货ID:"+String.valueOf(o.getRefundId()));
        if (o.getRefundId() > 0) {
          OrderUtils.getRefund(
              jobName,
              this.getDao().getConnection(),
              Params.url,
              Params.appkey,
              Params.appsecret,
              Params.authcode,
              Params.tradecontactid,
              td,
              o,
              String.valueOf(td.getTid()),
              o.getRefundId());
        }
      }

      updateJobFlag(0);
      Log.info(
          jobName,
          "执行作业成功 ["
              + this.getExecuteobj().getActivetimes()
              + "] ["
              + this.getExecuteobj().getNotes()
              + "] 下次处理时间: "
              + this.datetimeformat.format(this.getExecuteobj().getNextactive()));

    } catch (Exception e) {
      try {

        if (this.getDao().getConnection() != null
            && !this.getDao().getConnection().getAutoCommit()) {
          this.getDao().getConnection().rollback();
          this.getDao().getConnection().setAutoCommit(true);
        }

      } catch (Exception e1) {
        Log.error(jobName, "回滚事务失败");
        Log.error(jobName, e1.getMessage());
      }

      try {
        if (this.getExecuteobj().getSkip() == 1) {
          UpdateTimerJob();
        } else UpdateTimerJob(Log.getErrorMessage(e));
      } catch (Exception ex) {
        Log.error(jobName, "更新任务信息失败");
        Log.error(jobName, ex.getMessage());
      }
      Log.error(jobName, "错误信息:" + Log.getErrorMessage(e));

      Log.error(
          jobName,
          "执行作业失败 ["
              + this.getExecuteobj().getActivetimes()
              + "] ["
              + this.getExecuteobj().getNotes()
              + "] \r\n  "
              + Log.getErrorMessage(e));
    } finally {

      try {
        updateJobFlag(0);
      } catch (Exception e) {
        Log.error(jobName, e.getMessage());
        Log.error(jobName, "更新处理标志失败");
        TimerRunner.modifiedErrVect(this.getExecuteobj().getId());
      }

      try {
        if (this.getDao().getConnection() != null) {
          this.getDao().getConnection().setAutoCommit(true);
          this.getDao().getConnection().close();
        }

      } catch (Exception e) {
        Log.error(jobName, "关闭数据库连接失败");
      }
    }
  }
  /** 检查未入待发货订单 orderStatus=10 等待发货 这里检查一天时间的未入订单 */
  public void checkWaitStockOutOrders() throws Exception {
    Log.info(jobName + "任务开始!");
    Connection conn = this.getDao().getConnection();
    int pageIndex = 1;
    boolean hasNextPage = true;

    for (int k = 0; k < 5; ) {
      try {

        while (hasNextPage) {
          Date startdate = new Date(new Date().getTime() - daymillis);
          Date enddate = new Date();
          // 方法名
          String apimethod = "search_order_list";
          HashMap<String, Object> reqMap = new HashMap<String, Object>();
          reqMap.put("last_modify_st_time", startdate.getTime() / 1000L);
          reqMap.put("last_modify_en_time", enddate.getTime() / 1000L);
          reqMap.put("pages", String.valueOf(pageIndex));
          reqMap.put("counts", pageSize);
          reqMap.put("return_data", "json");
          reqMap.put("act", apimethod);
          reqMap.put("api_version", "1.0");
          // 发送请求

          Log.info("第" + pageIndex + "页");
          String responseText = CommHelper.doRequest(reqMap, url);
          Log.info("返回数据为: " + responseText);
          // 把返回的数据转成json对象
          JSONObject responseObj = new JSONObject(responseText.replaceAll(":null", ":\"\""));
          // 错误对象
          if (!"success".equals(responseObj.getString("result"))) { // 发生错误
            String operCode = responseObj.getJSONObject("sn_error").getString("error_code");
            if (operCode.indexOf("no-result") != -1) { // 没有数据直接退出方法体
              Log.error("获取ecshop订单列表", "获取订单列表失败,操作码:" + operCode);
              return;
            }
            hasNextPage = false;
            break;
          }

          JSONObject orderInfos = responseObj.getJSONObject("info");
          String orderTotal = String.valueOf(orderInfos.getString("counts"));
          int orderTotaltemp = Integer.parseInt(orderTotal);
          int pageTotalTemp =
              Double.valueOf(Math.ceil(orderTotaltemp / Double.parseDouble(Params.pageSize)))
                  .intValue();
          String pageTotal = String.valueOf(pageTotalTemp);

          Log.info("总订单数为: " + orderTotal);
          Log.info("总页数为: " + pageTotal);
          if (orderTotal == null || orderTotal.equals("") || orderTotal.equals("0")) {
            break;
          }
          // 订单元素
          JSONArray ordersList = orderInfos.getJSONArray("data_info");
          for (int i = 0; i < ordersList.length(); i++) { // 某个订单
            JSONObject orderInfo = ordersList.getJSONObject(i);
            // 订单编号
            String orderCode = (String) orderInfo.get("order_sn");
            if (orderInfo.isNull("shop_info")) continue;
            // 订单商品集合
            JSONArray items = orderInfo.getJSONArray("shop_info");
            // 构造一个订单对象
            Order o = new Order();
            o.setObjValue(o, orderInfo);
            o.setFieldValue(o, "shop_info", items);
            Log.info(
                "订单号: "
                    + o.getOrder_sn()
                    + ", 发货状态: "
                    + o.getShipping_status()
                    + "付款状态: "
                    + o.getPay_status());
            if (o != null) {
              if ("0".equals(o.getShipping_status()) && "2".equals(o.getPay_status())) { // 正常订单
                Log.info("检查到一条订单:" + orderCode);
                // 如果是等待发货订单,创建接口订单成功,减少其它店的库存
                if (!OrderManager.isCheck(jobName, conn, orderCode)) {
                  if (!OrderManager.TidLastModifyIntfExists(
                      jobName, conn, orderCode, new Date(o.getAdd_time() * 1000L))) {
                    try {
                      OrderUtils.createInterOrder(conn, o, tradecontactid, username);
                      for (Iterator ito = o.getShop_info().getRelationData().iterator();
                          ito.hasNext(); ) {
                        OrderItem item = (OrderItem) ito.next();
                        String sku = item.getProduct_sn();
                        StockManager.deleteWaitPayStock(
                            jobName, conn, tradecontactid, orderCode, sku);
                        long qty = (long) item.getGoods_number();
                        // 在ecs_rationconfig表中存在机构添加一条库存同步记录(不包括自己)
                        StockManager.addSynReduceStore(
                            jobName, conn, tradecontactid, "未发货", o.getOrder_sn(), sku, qty, false);
                      }

                    } catch (SQLException sqle) {
                      throw new JException("生成接口订单出错!" + sqle.getMessage());
                    }
                  }
                } // 订单状态 10待发货,20已发货,21部分发货,30交易成功 ,40交易关闭
              }
            }
          }
          // 判断是否有下一页
          if ("".equals(pageTotal) || pageTotal == null) pageTotal = "0";
          if (pageIndex >= Integer.parseInt(pageTotal)) hasNextPage = false;
          else pageIndex++;

          break;
        }
        Log.info(jobName + "执行完毕!");
        break;
      } catch (Exception e) {
        if (++k >= 5) throw e;
        if (conn != null && !conn.getAutoCommit()) {
          conn.rollback();
        }
        Log.warn(jobName + " ,远程连接失败[" + k + "], 10秒后自动重试. " + Log.getErrorMessage(e));
        Thread.sleep(10000L);
      }
    }
  }
Exemple #5
0
  /*
   * 获取某个项目一天之类的所有订单
   */
  public static void getBusinessOrderList(
      String modulename,
      Connection conn,
      Hashtable htwsinfo,
      String grouponid,
      Date starttime,
      Date endtime)
      throws JException {
    OMFactory soapFactory = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = soapFactory.createOMNamespace(htwsinfo.get("namespace").toString(), "");
    OMElement soapResponse = soapFactory.createOMElement("groupon", omNs);
    DisneyRequestBean requestBean = new DisneyRequestBean();
    String s = (new StringBuilder(String.valueOf(System.currentTimeMillis()))).toString();
    requestBean.setRequest_time(s);
    requestBean.setSign(
        MD5Util.MD5Encode(
            (new StringBuilder(grouponid))
                .append(s)
                .append(htwsinfo.get("key").toString())
                .toString()));
    requestBean.setGrouponid(grouponid);
    requestBean.setLimit(htwsinfo.get("limit").toString());
    requestBean.setTotal(htwsinfo.get("total").toString());

    requestBean.setStartTime(String.valueOf(starttime.getTime())); // 增加一秒
    requestBean.setEndTime(String.valueOf(endtime.getTime())); // 增加一天
    soapResponse.addChild(ObjBodyWriter.convertBeanToXml(requestBean, "request"));
    Options options = new Options();
    options.setTo(new EndpointReference(htwsinfo.get("wsurl").toString()));
    options.setAction("getBusinessProjectList");
    options.setProperty("__CHUNKED__", Boolean.valueOf(false));
    ServiceClient sender = null;
    try {
      sender = new ServiceClient();
      sender.setOptions(options);
      OMElement result = sender.sendReceive(soapResponse);

      Document doc = DOMHelper.newDocument(result.toString(), htwsinfo.get("encoding").toString());
      Element urlset = doc.getDocumentElement();
      NodeList orderinfonodes = urlset.getElementsByTagName("order_info");
      if (orderinfonodes.getLength() > 0) {
        for (int i = 0; i < orderinfonodes.getLength(); i++) {

          Element orderinfoelement = (Element) orderinfonodes.item(i);
          Order o = OrderUtils.getOrder(orderinfoelement);
          String orderid = o.getOrderId();
          String status = o.getStatus();
          String sku = o.getSKU();
          long qty = Long.valueOf(o.getBuyNum());
          Date updatetime = Formatter.parseDate(o.getPaymentTime(), Formatter.DATE_TIME_FORMAT);

          /*
           *1、如果状态为等待卖家发货则生成接口订单
           *2、删除等待买家付款时的锁定库存
           */
          Log.info(o.getOrderId() + " " + o.getStatus() + " " + o.getPaymentTime());
          if (status.equals("1")) {
            // 即使取订单时不需要判断订单是否存在,每天检查订单时需检查订单是否已经存在
            if (htwsinfo.get("style").toString().equals("0")) {
              try {
                createInterOrder(
                    conn,
                    htwsinfo.get("tradecontactid").toString(),
                    htwsinfo.get("username").toString(),
                    o);
                StockManager.deleteWaitPayStock(
                    modulename, conn, htwsinfo.get("tradecontactid").toString(), orderid, sku);
              } catch (SQLException sqle) {
                throw new JException("生成接口订单出错!" + sqle.getMessage());
              }
            } else {
              if (!OrderManager.TidExists("检查团宝未入订单", conn, String.valueOf(o.getOrderId()))) {
                if (OrderManager.TidIntfExists("检查团宝未入订单", conn, String.valueOf(o.getOrderId()))) {
                  Log.info(
                      "接口中存在,客户订单中不存在:"
                          + o.getOrderId()
                          + " "
                          + o.getStatus()
                          + " "
                          + o.getPaymentTime());
                } else {
                  Log.info(
                      "接口中不存在,客户订单中不存在:"
                          + o.getOrderId()
                          + " "
                          + o.getStatus()
                          + " "
                          + o.getPaymentTime());
                }
                try {
                  createInterOrder(
                      conn,
                      htwsinfo.get("tradecontactid").toString(),
                      htwsinfo.get("username").toString(),
                      o);
                  StockManager.deleteWaitPayStock(
                      modulename, conn, htwsinfo.get("tradecontactid").toString(), orderid, sku);
                } catch (SQLException sqle) {
                  throw new JException("生成接口订单出错!" + sqle.getMessage());
                }
              }
            }
          }
          // 等待买家付款时记录锁定库存
          else if (status.equals("0")) {
            StockManager.addWaitPayStock(
                modulename, conn, htwsinfo.get("tradecontactid").toString(), orderid, sku, qty);
            StockManager.addSynReduceStore(
                modulename,
                conn,
                htwsinfo.get("tradecontactid").toString(),
                status,
                orderid,
                sku,
                -qty,
                false);
            // 付款以后用户退款成功,交易自动关闭
            // 释放库存,数量为正数
          } else if (status.equals("6")) {
            StockManager.addSynReduceStore(
                modulename,
                conn,
                htwsinfo.get("tradecontactid").toString(),
                status,
                orderid,
                sku,
                qty,
                false);
            // 付款以前,卖家或买家主动关闭交易
            // 释放等待买家付款时锁定的库存
          } else if (status.equals("4")) {
            StockManager.deleteWaitPayStock(
                modulename, conn, htwsinfo.get("tradecontactid").toString(), orderid, sku);
            StockManager.addSynReduceStore(
                modulename,
                conn,
                htwsinfo.get("tradecontactid").toString(),
                status,
                orderid,
                sku,
                qty,
                false);
          }

          // 更新同步订单最新时间
          if (updatetime.compareTo(
                  Formatter.parseDate(
                      PublicUtils.getConfig(conn, htwsinfo.get("lasttimeconfvalue").toString(), ""),
                      Formatter.DATE_TIME_FORMAT))
              > 0)
            PublicUtils.setConfig(
                conn,
                htwsinfo.get("lasttimeconfvalue").toString(),
                Formatter.format(updatetime, Formatter.DATE_TIME_FORMAT));
        }
      } else {
        try {
          // 如该段时间之内都取不到订单,而且当前天大于配置天,则将取订单最新时间更新为当前天的零点
          if (dateformat
                  .parse(Formatter.format(new Date(), Formatter.DATE_FORMAT))
                  .compareTo(
                      dateformat.parse(
                          Formatter.format(
                              Formatter.parseDate(
                                  PublicUtils.getConfig(
                                      conn, htwsinfo.get("lasttimeconfvalue").toString(), ""),
                                  Formatter.DATE_TIME_FORMAT),
                              Formatter.DATE_FORMAT)))
              > 0) {

            PublicUtils.setConfig(
                conn,
                htwsinfo.get("lasttimeconfvalue").toString(),
                Formatter.format(
                        (new Date(
                            Formatter.parseDate(
                                        PublicUtils.getConfig(
                                            conn, htwsinfo.get("lasttimeconfvalue").toString(), ""),
                                        Formatter.DATE_TIME_FORMAT)
                                    .getTime()
                                + daymillis)),
                        Formatter.DATE_FORMAT)
                    + " 00:00:00");
          }
        } catch (ParseException e) {
          throw new JException("不可用的日期格式!" + e.getMessage());
        }
      }

    } catch (JException ja) {
      Log.error(modulename, ja.getMessage());
    } catch (AxisFault af) {
      throw new JException("访问远程服务出错!" + af.getMessage());
    } catch (Exception e) {
      throw new JException("解析XML出错!" + e.getMessage());
    }
  }