public String addItems(Order order) throws Exception { LOGGER.info("Adding items to order: " + order.getOrderId()); Order corder = getOrder(order.getOrderId()); for (OrderItem orderItem : order.getItems()) { LOGGER.info("Adding item: " + orderItem.getItem().getItemId()); Item item = _warehouse.getItem(orderItem.getItem().getItemId()); if (item == null) { throw new RuntimeException("Item " + orderItem.getItem().getItemId() + " not found!"); } else { orderItem.setItem(item); corder.getItems().add(orderItem); } } LOGGER.info("Order after adding items: " + corder); return SUCCESS; }
@Override public OrderAck submitOrder(Order order) { // Create an order ack return new OrderAck() .setOrderId(order.getOrderId()) .setAccepted(true) .setStatus("Order Accepted"); }
private void saveOrder(Order orderToSave) { valueList.put("_id", currentOrder.getOrderId()); for (EditText fieldToSave : editFields) { if (fieldToSave.getText() != null) { valueList.put(fieldToSave.getTag().toString(), fieldToSave.getText().toString()); } } orderToSave.setOrderValues(valueList); if (orderToSave.save()) { Toast toast = Toast.makeText( MainActivity.appContext, "Order " + orderToSave.getOrderId() + " saved", Toast.LENGTH_LONG); toast.show(); } }
/** * @param session * @param restaurantId * @return */ private Order buildAndRegister(HttpSession session, String restaurantId) { Order order = orderRepository.create(); Restaurant restaurant = restaurantRepository.findByRestaurantId(restaurantId); order.setRestaurantId(restaurantId); order.setRestaurant(restaurant); order = orderRepository.save(order); session.setAttribute("orderid", order.getOrderId()); session.removeAttribute("completedorderid"); return order; }
@Override public void run() { System.out.println("Checking Credit for Order Id->" + order.getOrderId()); try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } Random random = new Random(); int rNum = random.nextInt(2); boolean creditAvail = (rNum == 0) ? true : false; System.out.println("Credit Available ->" + creditAvail); order.setCreditCheck(creditAvail); }
public void orderTest() { Customer customer = customerDAO.getCustomerById(3); List<Commodity> commodityList = commoDAO.getCommoditiesByIdString("2;3;4"); List<OrderCommodityRel> relationLsit = CommodityListTools.commoToRel(commodityList); Order order = new Order(customer, relationLsit, 100); Map<Integer, Integer> map = new HashMap<Integer, Integer>(); map.put(2, 2); map.put(3, 4); map.put(4, 4); order.setBuyNum(map); Date date = new Date(); order.setOrderTime(new Timestamp(date.getTime())); orderDAO.createOrder(order); System.out.println(order.getOrderId()); }
@Override public OrderAck submitOrder(Order order) { // Create an order ack OrderAck orderAck = new OrderAck().setOrderId(order.getOrderId()); // Check the inventory try { Item orderItem = _inventory.lookupItem(order.getItemId()); // Check quantity on hand and generate the ack if (orderItem.getQuantity() >= order.getQuantity()) { orderAck.setAccepted(true).setStatus("Order Accepted"); // $NON-NLS-1$ } else { orderAck.setAccepted(false).setStatus("Insufficient Quantity"); // $NON-NLS-1$ } } catch (ItemNotFoundException infEx) { orderAck.setAccepted(false).setStatus("Item Not Available"); // $NON-NLS-1$ } return orderAck; }
public void paymentTest() { Payment payment = new Payment(); // 取出订单 Order order = orderDAO.getOrderById(8); // 取出订单顾客 Customer customer = order.getCustomer(); // 取出操作员 Worker worker = workerDAO.getWorkerById(7); // 取出银行卡 Bankcard bankcard = customer.getBankcardList().get(0); payment.setPayCustomer(customer); System.out.println("OrderId:" + order.getOrderId()); payment.setPayOrder(order); System.out.println(bankcard); payment.setPayCard(bankcard); payment.setPayPrice(order.getOrderPrice()); payment.setPayType(1); payment.setWorker(worker); paymentDAO.createPayment(payment); }
/* * 转入一个订单到接口表 */ public static void createInterOrder( Connection conn, String tradecontactid, String username, Order o) throws SQLException, JException { String sheetid = ""; int haspostFee; String sql = "declare @Err int ; declare @NewSheetID char(16); execute @Err = TL_GetNewSheetID 1105, @NewSheetID output;select @NewSheetID;"; try { conn.setAutoCommit(false); sheetid = SQLHelper.strSelect(conn, sql); if (sheetid.trim().equals("")) throw new JSQLException(sql, "取接口单号出错!"); // 加入到通知表 sql = "insert into it_downnote(Owner , sheetid , sheettype , sender , receiver , notetime , handletime) values('yongjun','" + sheetid + "',1 , '" + tradecontactid + "' , 'yongjun' , getdate() , null) "; SQLHelper.executeSQL(conn, sql); if (Float.valueOf(o.getPostage()).compareTo(Float.valueOf("0.0")) > 0) haspostFee = 1; else haspostFee = 0; // 加入到单据表 sql = "insert into ns_customerorder(CustomerOrderId,SheetID,Owner,tid,OrderSheetID,sellernick," + " created ,payment,status,buyermemo,tradememo,paytime,totalfee,postfee," + " buyernick,receivername,receiverstate,receivercity,receiverdistrict," + " receiveraddress,receiverzip,receivermobile,receiverphone,buyeremail,haspostFee," + " price,num,title,tradefrom,TradeContactID) " + " values(" + "'" + sheetid + "','" + sheetid + "','yongjun','" + o.getOrderId() + "','','" + username + "'," + "'" + o.getCreatTime() + "','" + String.valueOf( Float.valueOf(o.getMoney()) * Float.valueOf(o.getBuyNum()) + Float.valueOf(o.getPostage())) + "'," + "'" + o.getStatus() + "','" + o.getRemarks() + "','" + o.getRemarks() + "','" + o.getPaymentTime() + "','" + String.valueOf(Float.valueOf(o.getMoney()) * Float.valueOf(o.getBuyNum())) + "','" + o.getPostage() + "','" + o.getbuyerNick() + "'" + ",'" + o.getReceiverName() + "','" + o.getProvince() + "', '" + o.getCity() + "','','" + o.getAddress() + "', " + "'" + o.getZipCode() + "','" + o.getMobilePhone() + "','" + o.getMobilePhone() + "'," + "'" + o.getEmail() + "','" + String.valueOf(haspostFee) + "'," + "'" + o.getMoney() + "','" + o.getBuyNum() + "', '" + username + "','GROUPON','" + tradecontactid + "')"; SQLHelper.executeSQL(conn, sql); sql = "insert into ns_orderitem(CustomerOrderId,orderItemId,SheetID," + " sellernick,buyernick,created,outerskuid,totalfee,payment," + " status,owner,num,price,skuid) values( " + "'" + sheetid + "','" + sheetid + "_" + o.getOrderId() + "','" + sheetid + "'," + "'" + username + "', '" + o.getbuyerNick() + "' ,'" + o.getCreatTime() + "', " + "'" + o.getSKU() + "' , '" + String.valueOf(Float.valueOf(o.getMoney()) * Float.valueOf(o.getBuyNum())) + "','" + String.valueOf( Float.valueOf(o.getMoney()) * Float.valueOf(o.getBuyNum()) + Float.valueOf(o.getPostage())) + "' , " + "'" + o.getStatus() + "','yongjun'," + "" + o.getBuyNum() + ",'" + o.getMoney() + "','" + o.getSKU() + "')"; SQLHelper.executeSQL(conn, sql); conn.commit(); conn.setAutoCommit(true); Log.info("生成订单【" + o.getOrderId() + "】接口数据成功,接口单号【" + sheetid + "】"); } catch (JSQLException e1) { if (!conn.getAutoCommit()) try { conn.rollback(); } catch (Exception e2) { } try { conn.setAutoCommit(true); } catch (Exception e3) { } throw new JException("生成订单【" + o.getOrderId() + "】接口数据失败!" + e1.getMessage()); } }
/* * 获取某个项目一天之类的所有订单 */ 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()); } }