/** * 后台订单的筛选地址 * * @param orderQuery * @param response * @throws IOException */ @RequestMapping(value = "/order/search") public void searchOrder(OrderQuery orderQuery, HttpServletResponse response) throws IOException { List<OrderDetail> list = new ArrayList<OrderDetail>(); Page<Order> orderPage = tradeCenterBossClient.searchOrderByQuery(orderQuery); for (Order order : orderPage.getResult()) { OrderDetail orderDetail = new OrderDetail(); orderDetail.setUserId(order.getUserId()); orderDetail.setUserName(order.getUserName()); orderDetail.setOrderId(order.getId()); orderDetail.setOrderNo(order.getOrderNo()); orderDetail.setAccountType(order.getAccountType()); if (order.getOrderState() == OrderState.Success) { orderDetail.setEndDate( DateUtils.formatDate(order.getEndDate(), DateUtils.DateFormatType.DATE_FORMAT_STR)); } orderDetail.setStartDate( DateUtils.formatDate(order.getCreateDate(), DateUtils.DateFormatType.DATE_FORMAT_STR)); orderDetail.setInvoice(order.getInvoiceInfo().isInvoice()); orderDetail.setOrderState(order.getOrderState().toString()); orderDetail.setOrderStateDesc(order.getOrderState().serviceDesc()); Logistics logistics = tradeCenterBossClient.queryLogisticsByOrderId(order.getId()); orderDetail.setGoodToUserName(logistics.getName()); list.add(orderDetail); } new JsonResult(true) .addData("totalCount", orderPage.getTotalCount()) .addData("result", list) .toJson(response); }
private void attemptTrade( OrderResult result, IUserBalance balanceService, IStockInfo stockService, Date date, double dayLow, double dayHigh, int volume) { Order order = result.getOrder(); float quantity = order.getQuantity(); if (quantity > volume) { return; } try { if (order.getAction() == OrderAction.BUY) { if (order.getLimitPrice() < dayLow) { // price was too high to buy today return; } double orderTotal = quantity * dayLow; double accountBalance = balanceService.getBalance(order.getUserName()); if (accountBalance <= orderTotal) { quantity = (int) (accountBalance / dayLow); orderTotal = quantity * dayLow; result.setNote("Reduced quantity from " + order.getQuantity() + " to " + quantity); } if (quantity > 0 && accountBalance >= orderTotal) { try { balanceService.updateBalance(order.getUserName(), accountBalance - orderTotal); result.setCompleted(true); result.setQuantity(quantity); result.setSharePrice(dayLow); result.setDateTime(date); } catch (Exception ex) { // ignore } } else { // account balance is zero or not enough to purchase even one share result.setCancelled(true); result.setDateTime(date); result.setNote("Insufficient funds"); } } else { if (order.getLimitPrice() > dayHigh) { // price was too low to sell today return; } double orderTotal = quantity * dayHigh; double accountBalance = balanceService.getBalance(order.getUserName()); try { balanceService.updateBalance(order.getUserName(), accountBalance + orderTotal); result.setCompleted(true); result.setQuantity(quantity); result.setSharePrice(dayHigh); result.setDateTime(date); } catch (Exception ex) { // ignore } } } finally { // these apply on the first historical trade attempt (should be the same day the order was // submitted) if (!result.getCompleted() && !result.getCancelled()) { if ((order.getTimeInForce() == TimeInForce.DAY || order.getTimeInForce() == TimeInForce.FILLORKILL) && (today.after(date) || (today.equals(date) && !stockService.isWithinTradingHours()))) { // Cancel order result.setCancelled(true); result.setDateTime(date); result.setNote("Market closed"); } if (order.getTimeInForce() == TimeInForce.IMMEDIATEORCANCEL) { // Cancel order result.setCancelled(true); result.setDateTime(date); result.setNote("Unable to fill immediately"); } if (order.getTimeInForce() == TimeInForce.GOODUNTILCANCELED) { long diffInDays = (date.getTime() - order.getDateSubmitted().getTime()) / (1000 * 60 * 60 * 24); if (diffInDays > 120) { result.setCancelled(true); result.setDateTime(date); result.setNote("120 day limit reached"); } } } } }
@RequestMapping(value = "/order/export") public void exportOrder( OrderQuery orderQuery, HttpServletRequest request, HttpServletResponse response) throws IOException { List<List<Order>> orderList = tradeCenterBossClient.searchOrderListByQuery(orderQuery); String name = "订单统计"; Map<String, List> exportOrderMap = new LinkedHashMap<String, List>(); for (List<Order> orderArray : orderList) { if (orderArray == null || orderArray.size() == 0) continue; List<ExportOrder> exportOrderList = new ArrayList<ExportOrder>(); for (Order order : orderArray) { long orderId = order.getId(); Logistics logistics = order.getLogistics(); int count = 0; for (OrderItem orderItem : order.getOrderItemList()) { ExportOrder exportOrder = new ExportOrder(); Brand brand = supplierService.queryBrandById(orderItem.getBrandId()); exportOrder.setBrandName(brand == null ? "" : brand.getName()); exportOrder.setProductName(orderItem.getSkuName()); exportOrder.setProductCode(orderItem.getItemNo()); exportOrder.setNumber(String.valueOf(orderItem.getNumber())); exportOrder.setUnitPrice(Money.getMoneyString(orderItem.getUnitPrice())); exportOrder.setBackNumber(String.valueOf(orderItem.getBackNum())); exportOrder.setOrderState(orderItem.getOrderState().serviceDesc()); if (count == 0) { exportOrder.setPayBank(order.getPayBank().toDesc()); exportOrder.setCreateDate(formatDate(order.getCreateDate())); exportOrder.setSuccessDate(formatDate(tradeCenterBossClient.querySuccessDate(orderId))); exportOrder.setUserName(order.getUserName()); exportOrder.setOrderNo(String.valueOf(order.getOrderNo())); exportOrder.setOldTotalPrice(Money.getMoneyString(order.calculateOldTotalPrice())); exportOrder.setPriceMessageDetail(order.getPriceMessageDetail()); exportOrder.setTotalPrice(order.getTotalPrice()); exportOrder.setRemark(remark(order)); exportOrder.setLogisticsName(logistics.getName()); exportOrder.setLogisticsAddress( logistics.getProvince() + "," + logistics.getLocation()); exportOrder.setLogisticsPhone( getPhone(logistics.getMobile(), logistics.getTelephone())); } // 只存到最后一个订单项里, 主要用来多条订单项时合并单元格 if (count == (order.getOrderItemList().size() - 1)) { exportOrder.setItemSize(order.getOrderItemList().size()); } exportOrderList.add(exportOrder); count++; } } String sheetName = name; if (orderArray.size() > 0 && orderArray.get(0).getOrderState() == orderArray.get(orderArray.size() - 1).getOrderState()) sheetName = orderArray.get(0).getOrderState().serviceDesc(); exportOrderMap.put(sheetName, exportOrderList); } String[] headerList = new String[] { "下单时间", "完成时间", "下单人", "订单编号", "品牌", "商品名称", "商品编码", "购买数量", "购买单价", "应付总金额", "使用积分/优惠券", "实付总金额", "退货数量", "订单状态", "备注(发票、留言)", "收货人", "收货人地址", "联系电话" }; String[] fieldNameList = new String[] { "createDate", "successDate", "userName", "orderNo", "brandName", "productName", "productCode", "number", "unitPrice", "oldTotalPrice", "priceMessageDetail", "totalPrice", "backNumber", "orderState", "remark", "logisticsName", "logisticsAddress", "logisticsPhone" }; response.setHeader( "Content-Disposition", "attachment; filename=\"" + encodeFileName(request, name) + ".xls\""); response.setContentType("application/vnd.ms-excel"); ExportExcelUtil.exportExcel( exportOrderMap, headerList, fieldNameList, response.getOutputStream()); }