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(); } }
private void delivery(Connection conn) throws Exception { String sql = "select a.sheetid,b.tid, upper(ltrim(rtrim(b.companycode))) companycode," + "upper(ltrim(rtrim(b.outsid))) outsid from it_upnote a with(nolock), ns_delivery b with(nolock)" + "where a.sheettype=3 and a.sheetid=b.sheetid and a.receiver='" + Params.tradecontactid + "' and b.iswait=0"; Vector vdeliveryorder = SQLHelper.multiRowSelect(conn, sql); Log.info("本次要处理的订单发货条数为: " + vdeliveryorder.size()); for (int i = 0; i < vdeliveryorder.size(); i++) { Hashtable hto = (Hashtable) vdeliveryorder.get(i); String sheetid = hto.get("sheetid").toString(); String orderid = hto.get("tid").toString(); String post_company = hto.get("companycode").toString(); String post_no = hto.get("outsid").toString(); // 如果物流公司为空则忽略处理 if (post_company.trim().equals("")) { Log.warn(jobname, "快递公司为空!订单号:" + orderid + ""); continue; } String postcompanyid = getCompanyID(post_company); if (postcompanyid.equals("")) { // 如果物流公司为空则忽略处理 if (post_company.trim().equals("")) { Log.warn(jobname, "快递公司未配置!快递公司:" + post_company + " 订单号:" + orderid + ""); continue; } } Map<String, String> params = new HashMap<String, String>(); // 系统级参数设置 params.put("app_id", Params.app_id); params.put("format", Params.format); params.put("method", "kdt.logistics.online.confirm"); params.put("sign_method", "MD5"); params.put("v", Params.ver); params.put("timestamp", Formatter.format(new Date(), Formatter.DATE_TIME_FORMAT)); params.put("tid", orderid); params.put("is_no_express", "0"); params.put("out_stype", postcompanyid); params.put("out_sid", post_no); String responseOrderListData = Utils.sendByPost(params, Params.AppSecret, Params.url); Log.info("result: " + responseOrderListData); // {"status":{"code":10006,"msg":"\u5fc5\u8981\u53c2\u6570\u7f3a\u5931"},"result":null} JSONObject responseDelivery = new JSONObject(responseOrderListData); if (!responseDelivery.isNull("error_response")) { String errdesc = responseDelivery.getJSONObject("error_response").getString("msg"); if ("\u65e0\u6548\u7684\u8ba2\u5355\u53f7".equals(errdesc)) { Log.info(jobname + " 订单号不存在: " + orderid); } else { Log.warn( "订单发货失败,订单号:[" + orderid + "],快递公司:[" + post_company + "],快递单号:[" + post_no + "] 错误信息:" + errdesc); continue; } } try { conn.setAutoCommit(false); sql = "insert into IT_UpNoteBak(Owner,SheetID,SheetType,Sender,Receiver,Notetime,HandleTime,Flag) " + " select Owner , SheetID , SheetType , Sender , Receiver , Notetime , getdate() , 1 from IT_UpNote " + " where SheetID = '" + sheetid + "' and SheetType = 3"; SQLHelper.executeSQL(conn, sql); sql = "delete from IT_UpNote where SheetID='" + sheetid + "' and sheettype=3"; SQLHelper.executeSQL(conn, sql); conn.commit(); conn.setAutoCommit(true); } catch (SQLException sqle) { if (!conn.getAutoCommit()) try { conn.rollback(); } catch (Exception e1) { } try { conn.setAutoCommit(true); } catch (Exception e1) { } throw new JSQLException(sql, sqle); } Log.info( jobname, "处理订单【" + orderid + "】发货成功,快递公司【" + post_company + "】,快递单号【" + post_no + "】"); } }
// 修改订单备注 private void modifiRemark(Connection conn) throws Exception { String sql = "select sheetid,sender from it_upnote where sheettype=5 and flag=0 and receiver='" + Params.tradecontactid + "'"; Vector modifiReList = SQLHelper.multiRowSelect(conn, sql); if (modifiReList.size() == 0) return; for (int i = 0; i < modifiReList.size(); i++) { try { Hashtable item = (Hashtable) modifiReList.get(i); String sheetid = item.get("sheetid").toString(); String sender = item.get("sender").toString(); String[] remarks = sender.split(":"); // 订单号 String tid = remarks[0]; // 备注 String remark = remarks[1]; Map<String, String> params = new HashMap<String, String>(); // 系统级参数设置 params.put("appKey", Params.app_id); params.put("sessionKey", Params.token); params.put("format", Params.format); params.put("method", "yhd.order.merchant.remark.update"); params.put("ver", Params.ver); params.put("timestamp", Formatter.format(new Date(), Formatter.DATE_TIME_FORMAT)); params.put("orderCode", tid); params.put("remark", remark); String response = Utils.sendByPost(params, Params.AppSecret, Params.url); // Log.info("修改备注: "+response); JSONObject responseCount = new JSONObject(response); if (0 == (responseCount.getJSONObject("response").getInt("errorCount"))) { try { conn.setAutoCommit(false); sql = "insert into IT_UpNoteBak(Owner,SheetID,SheetType,Sender,Receiver,Notetime,HandleTime,Flag) " + " select Owner , SheetID , SheetType , Sender , Receiver , Notetime , getdate() , 1 from IT_UpNote " + " where SheetID = '" + sheetid + "' and SheetType = 5"; SQLHelper.executeSQL(conn, sql); sql = "delete from IT_UpNote where SheetID='" + sheetid + "' and sheettype=5"; SQLHelper.executeSQL(conn, sql); conn.commit(); conn.setAutoCommit(true); Log.info(jobname, "处理订单【" + tid + "】 sheetid【" + sheetid + "】 修改备注成功"); } catch (Exception ex) { if (!conn.getAutoCommit()) { try { conn.rollback(); } catch (Exception el) { } } try { conn.setAutoCommit(true); } catch (Exception es) { } throw new Exception("事务回滚失败!"); } } else { Log.info(jobname, "处理订单【" + tid + "】 sheetid【" + sheetid + "】 修改备注失败"); } } catch (Exception ex) { Log.error(jobname, ex.getMessage()); } } Log.info(jobname + ",修改订单备注完成"); }
public void getRefund(Connection conn) throws Exception { String resultText = ""; for (int k = 0; k < 5; ) { try { // 获取到退货订单号 String apiMethod = "suning.custom.batchrejectedOrd.query"; HashMap<String, String> reqMap = new HashMap<String, String>(); reqMap.put( "startTime", Formatter.format( new Date(System.currentTimeMillis() - daymillis), Formatter.DATE_TIME_FORMAT)); reqMap.put("endTime", Formatter.format(new Date(), Formatter.DATE_TIME_FORMAT)); HashMap<String, String> map = new HashMap<String, String>(); map.put("appSecret", Params.appsecret); map.put("appMethod", apiMethod); map.put("format", Params.format); map.put("versionNo", "v1.2"); map.put("appKey", Params.appKey); // 发送请求 String responseText = CommHelper.doRequest(map, Params.url); Log.info("退换货数据: " + responseText); // 把返回的数据转成json对象 JSONObject responseObj = new JSONObject(responseText).getJSONObject("sn_responseContent"); // 错误对象 if (responseText.indexOf("sn_error") != -1) { // 发生错误 String operCode = responseObj.getJSONObject("sn_error").getString("error_code"); if (!"".equals(operCode)) { Log.error("苏宁获取退货订单", "获取退货订单失败,operCode:" + operCode); } return; } JSONArray ReturnCodeList = responseObj.getJSONObject("sn_body").getJSONArray("batchQueryRejectedOrd"); for (int i = 0; i < ReturnCodeList.length(); i++) { try { String orderCode = ReturnCodeList.getJSONObject(i).getString("orderCode"); Order o = new Order(); OrderUtils.createRefundOrder( "生成苏宁退换货接口订单", conn, Params.tradecontactid, o, Params.url, Params.appKey, Params.appsecret, Params.format); } catch (Exception ex) { if (conn != null && !conn.getAutoCommit()) { conn.rollback(); } Log.error(jobName, ex.getMessage()); continue; } } 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); } } }
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); } } }
// 检查取消订单 4 取消 private void checkCancleOrders() throws Exception { int pageIndex = 1; boolean hasNextPage = true; for (int k = 0; k < 10; ) { try { int n = 1; while (hasNextPage) { Date enddate = new Date(); Date startdate = new Date(new Date().getTime() - daymillis); // 方法名 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); // sn_error if (!"success".equals(responseObj.getString("result"))) { // 发生错误 String operCode = responseObj.getJSONObject("sn_error").getString("error_code"); if ("biz.handler.data-get:no-result".equals(operCode)) { // 没有结果 Log.info("没有可用的订单!"); } else { Log.warn("取订单出错了,错误码: " + operCode); } break; } JSONObject orderInfos = responseObj.getJSONObject("info"); // 总页数 String orderTotal = String.valueOf(orderInfos.getString("counts")); int orderTotaltemp = Integer.parseInt(orderTotal); int pageTotalTemp = orderTotaltemp < Integer.parseInt(pageSize) ? 1 : orderTotaltemp / Integer.parseInt(pageSize) == 0 ? Integer.parseInt(pageSize) : orderTotaltemp / Integer.parseInt(pageSize) + 1; 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); int returnOrderCount = 0; // 订单编号 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.getShipping_status() + "付款状态: " + o.getPay_status()); if (o != null) { if ("4".equals(o.getPay_status())) { // 正常订单 Log.info("订单号: " + o.getOrder_sn()); // 如果是等待发货订单,创建接口订单成功,减少其它店的库存 try { OrderUtils.createInterOrder( this.getDao().getConnection(), o, tradecontactid, username); } catch (SQLException sqle) { throw new JException("生成退货订单出错!" + sqle.getMessage()); } } } } // 判断是否有下一页 if ("".equals(pageTotal) || pageTotal == null) pageTotal = "0"; if (pageIndex >= Integer.parseInt(pageTotal)) hasNextPage = false; else pageIndex++; n++; } break; } catch (Exception e) { e.printStackTrace(); if (++k >= 10) throw e; if (this.getDao() != null && !this.getDao().getConnection().getAutoCommit()) { this.getDao().rollback(); } Log.warn(jobName + " ,远程连接失败[" + k + "], 10秒后自动重试. " + Log.getErrorMessage(e)); Thread.sleep(10000L); } } Log.info("本次取ecshop退货订单任务处理完毕!"); }
/** 检查未入待发货订单 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); } } }
// 家装订单发货 private void jzSend( String post_no, String orderid, String post_company, Connection conn, String sheetid) { try { TaobaoClient client = new DefaultTaobaoClient(Params.url, Params.appkey, Params.appsecret); WlbOrderJzwithinsConsignRequest req = new WlbOrderJzwithinsConsignRequest(); req.setTid(TranTid(orderid)); JSONObject obj = new JSONObject(); obj.put("mail_no ", post_no); obj.put("zy_company ", post_company); req.setTmsPartner(obj.toString()); JSONArray arr = new JSONArray(Params.jzParams); WlbOrderJzwithinsConsignResponse rsp; for (int i = 0; i < arr.length(); i++) { req.setInsPartner(arr.get(i).toString()); rsp = client.execute(req, Params.authcode); String sql; if (rsp.isSuccess()) { try { conn.setAutoCommit(false); sql = "insert into IT_UpNoteBak(Owner,SheetID,SheetType,Sender,Receiver,Notetime,HandleTime,Flag) " + " select Owner , SheetID , SheetType , Sender , Receiver , Notetime , getdate() , 1 from IT_UpNote " + " where SheetID = '" + sheetid + "' and SheetType = 3"; SQLHelper.executeSQL(conn, sql); sql = "delete from IT_UpNote where SheetID='" + sheetid + "' and sheettype=3"; SQLHelper.executeSQL(conn, sql); conn.commit(); conn.setAutoCommit(true); } catch (SQLException sqle) { if (!conn.getAutoCommit()) try { conn.rollback(); } catch (Exception e1) { } try { conn.setAutoCommit(true); } catch (Exception e1) { } // throw new JSQLException(sql, sqle); } Log.info( username, "处理订单【" + orderid + "】发货成功,快递公司【" + post_company + "】,快递单号【" + post_no + "】", null); Log.info(username, "家装发货参数: " + arr.get(i).toString(), null); break; } else { Log.info(username, "家装订单发货失败,错误信息: " + rsp.getResultInfo(), null); continue; } } } catch (ApiException e) { Log.error( username, "处理订单【" + orderid + "】发货失败,快递公司【" + post_company + "】,快递单号【" + post_no + "】,错误信息:" + e.getMessage(), null); } catch (Exception e) { Log.error(username, "同步发货状态出错了, 错误信息: " + e.getMessage(), null); } }
public void run() { Log.info(jobname, "启动[" + jobname + "]模块"); do { Connection conn = null; try { conn = PoolHelper.getInstance().getConnection(Params.dbname); List infsheetlist = JwUtil.getintfsheetlist(conn, 900000, 100); Order order = null; for (Iterator it = infsheetlist.iterator(); it.hasNext(); ) { try { Hashtable ht = (Hashtable) it.next(); Integer serialID = (Integer) ht.get("SerialID"); String operData = (String) ht.get("OperData"); String sql = "SELECT * from Inf_downNotebak where operdata='" + operData + "' AND SheetType='900000' AND result='success' and opertype='100'"; Vector duplicateNum = SQLHelper.multiRowSelect(conn, sql); if (duplicateNum != null && duplicateNum.size() > 0) { conn.setAutoCommit(false); JwUtil.delBackUpIntsheetData(conn, serialID); conn.commit(); conn.setAutoCommit(true); Log.info("此单已发送,删除重复的单成功,订单号: " + order.getOrderCode()); continue; } sql = "select a.custompursheetid orderCode,a.custompursheetid orderDetailCode,a.tax " + "orderTax,convert(varchar,a.notifydate,20) createDate,convert(varchar,a.notifydate,20) " + "updateDate,convert(varchar,a.notifydate,20) payTime,a.postfee postPrice,a.CustomsOrderNo " + "invoiceName,a.note buyerMessage,a.payfee amountReceivable,a.payfee actualPayment," + "a.linkman name, a.tele mobilePhone,a.address,isnull(a.zipcode,'000000') zip,b.notifyqty num," + "b.title,b.price, b.price*b.notifyqty payment,b.price*b.notifyqty totalPrice," + "c.custombc skuID ,rtrim(c.outerSkuId) outerSkuId,a.customsbarcode hgBarcode " + "from outstock0 a with(nolock),outstockitem0 b with(nolock),barcode c with(nolock) where a.sheetid=b.sheetid and b.barcodeid=c.barcodeid and a.sheetid='" + operData + "'"; Vector sqlresult = SQLHelper.multiRowSelect(conn, sql); if (sqlresult.size() == 0) { conn.setAutoCommit(false); JwUtil.backUpIntsheetData(conn, serialID); conn.commit(); conn.setAutoCommit(true); Log.info("同步订单失败,订单已经处理或不存在,订单号: " + order.getOrderCode()); continue; } order = new Order(); ReceiveInfo receiveInfo = new ReceiveInfo(); int i = 0; detail det = null; for (Iterator t = sqlresult.iterator(); t.hasNext(); ) { Hashtable htTemp = (Hashtable) t.next(); if (i == 0) { order.getMapData(htTemp); receiveInfo.getMapData(htTemp); String address = receiveInfo.getAddress(); if (address.indexOf(" ") > 0) { String[] add = address.split(" "); // 设置地址明细 if (add.length < 3) { System.out.println(operData + " 地址不符合要求"); } if (add.length == 4) { receiveInfo.setProvince(add[0]); receiveInfo.setCity(add[1]); receiveInfo.setDistrict(add[2]); receiveInfo.setAddress(add[3]); } else if (add.length == 5) { receiveInfo.setProvince(add[0]); receiveInfo.setCity(add[1]); receiveInfo.setDistrict(add[2]); receiveInfo.setAddress(add[4].trim()); } else { receiveInfo.setProvince(add[0]); receiveInfo.setCity(add[1]); receiveInfo.setDistrict(add[2]); } } String mobilePhone = receiveInfo.getMobilePhone(); mobilePhone = mobilePhone.replaceAll(" +", " "); if (mobilePhone.indexOf(" ") > 0) { String[] contacts = mobilePhone.split(" "); receiveInfo.setMobilephone(contacts[0]); if (contacts[1].length() == 11) // 如果是手机号码就设置,如果是身份证就不设置了 receiveInfo.setPhone(contacts[1]); } else if (mobilePhone.indexOf("/") > 0) { String[] contacts = mobilePhone.split("/"); if (contacts.length == 2) { receiveInfo.setMobilephone(contacts[0]); if (contacts[1].length() == 11) // 如果是手机号码就设置,如果是身份证就不设置了 receiveInfo.setPhone(contacts[1]); } } else { receiveInfo.setMobilephone(mobilePhone); } } det = new detail(); det.getMapData(htTemp); order.getDetail().getRelationData().add(det); i++; } // Log.info("address: "+receiveInfo.getAddress()); order.setReceiver(receiveInfo.toJSONObject()); String temp = order.toJSONObject().replaceAll("\"\\{", "\\{"); temp = temp.replaceAll("\",\"detail\"", ",\"detail\""); // Log.info("temp: "+temp); String bizData1 = "{\"saleOrderList\":[" + temp + "]}"; String sign = JwUtil.makeSign(bizData1); Map requestParams = JwUtil.makeRequestParams(bizData1, service, Params.appkey, Params.format, sign); String result = CommHelper.sendRequest(Params.url, requestParams, ""); Log.info("result: " + result); JSONObject re = new JSONObject(result); if (re.getBoolean("isSuccess")) { conn.setAutoCommit(false); JwUtil.backUpIntsheetData(conn, serialID); conn.commit(); conn.setAutoCommit(true); Log.info("同步订单成功,订单号: " + order.getOrderCode()); } else if (re.getString("body").contains("推送订单错误,可能已存在")) { conn.setAutoCommit(false); JwUtil.delBackUpIntsheetData(conn, serialID); conn.commit(); conn.setAutoCommit(true); Log.info("删除重复的单成功,订单号: " + order.getOrderCode()); } else { Log.error(jobname, "sheetid: " + operData + " " + re.getString("body")); } } catch (Exception e) { Log.error(jobname, e.getMessage()); if (conn != null && !conn.getAutoCommit()) conn.rollback(); continue; } } } catch (Exception e) { try { if (conn != null && !conn.getAutoCommit()) conn.rollback(); } catch (Exception e1) { Log.error(jobname, "回滚事务失败"); } Log.error("105", jobname, Log.getErrorMessage(e)); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { Log.error(jobname, "关闭数据库连接失败"); } } System.gc(); long startwaittime = System.currentTimeMillis(); while (System.currentTimeMillis() - startwaittime < (long) (Params.waittime * 1000)) try { sleep(1000L); } catch (Exception e) { Log.warn(jobname, "系统不支持休眠操作, 作业将严重影响机器性能"); } } while (true); }