/* * 获取某个项目一天之类的所有订单 */ 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()); } }
/* * 获取一天之类的退款订单 */ private void getRefundBillList(Connection conn) throws Exception { long pageno = 1L; Date modified = Formatter.parseDate(lasttime, Formatter.DATE_TIME_FORMAT); for (int k = 0; k < 10; ) { try { TaobaoClient client = new DefaultTaobaoClient(Params.url, Params.appkey, Params.appsecret, "json"); TmallEaiOrderRefundMgetRequest req = new TmallEaiOrderRefundMgetRequest(); Date startdate = new Date(Formatter.parseDate(lasttime, Formatter.DATE_TIME_FORMAT).getTime() + 1000L); Date enddate = new Date( Formatter.parseDate(lasttime, Formatter.DATE_TIME_FORMAT).getTime() + daymillis); req.setStartTime(startdate); req.setEndTime(enddate); req.setPageNo(pageno); req.setPageSize(40L); req.setUseHasNext(true); TmallEaiOrderRefundMgetResponse response = client.execute(req, Params.authcode); while (true) { if (response.getRefundBillList() == null || response.getRefundBillList().size() <= 0) { if (pageno == 1) { try { // 如一天之内都取不到订单,而且当前天大于配置天,则将取订单最新时间更新为当前天的零点 if (this.dateformat .parse(Formatter.format(new Date(), Formatter.DATE_FORMAT)) .compareTo( this.dateformat.parse( Formatter.format( Formatter.parseDate( PublicUtils.getConfig(conn, lasttimeconfvalue, ""), Formatter.DATE_TIME_FORMAT), Formatter.DATE_FORMAT))) > 0) { try { String value = Formatter.format( (new Date( Formatter.parseDate( PublicUtils.getConfig(conn, lasttimeconfvalue, ""), Formatter.DATE_TIME_FORMAT) .getTime() + daymillis)), Formatter.DATE_FORMAT) + " 00:00:00"; PublicUtils.setConfig(conn, lasttimeconfvalue, value); } catch (JException je) { Log.error(jobname, je.getMessage()); } } } catch (ParseException e) { Log.error(jobname, "不可用的日期格式!" + e.getMessage()); } } break; } for (Iterator it = response.getRefundBillList().iterator(); it.hasNext(); ) { RefundBill refundbill = (RefundBill) it.next(); Log.info( refundbill.getTid() + " " + refundbill.getStatus() + " " + refundbill.getModified()); if (!RefundUtil.RefundBillisCheck( conn, String.valueOf(refundbill.getTid()), String.valueOf(refundbill.getRefundId()), refundbill.getModified())) { Trade td = OrderUtils.getFullTrade( String.valueOf(refundbill.getTid()), Params.url, Params.address, Params.appsecret, Params.authcode); RefundUtil.createRefundBill(conn, refundbill, td, Params.tradecontactid); } if (Formatter.parseDate(refundbill.getModified(), Formatter.DATE_TIME_FORMAT) .compareTo(modified) > 0) { modified = Formatter.parseDate(refundbill.getModified(), Formatter.DATE_TIME_FORMAT); } } // 判断是否下一页 if (response.getHasNext()) { pageno++; } else { break; } } if (modified.compareTo(Formatter.parseDate(lasttime, Formatter.DATE_TIME_FORMAT)) > 0) { try { String value = Formatter.format(modified, Formatter.DATE_TIME_FORMAT); PublicUtils.setConfig(conn, lasttimeconfvalue, value); } catch (JException je) { Log.error(jobname, je.getMessage()); } } // 执行成功后不再循环 break; } catch (Exception e) { if (++k >= 10) throw e; Log.warn("远程连接失败[" + k + "], 10秒后自动重试. " + Log.getErrorMessage(e)); Thread.sleep(10000L); } } }