public static void exportOrders( String fileName, List<Order> orderList, List<String> orderStatusList) { logger.info("Export Orders to excel"); ExcelGenerator generator = new ExcelGenerator(fileName); List<String[]> headerList = new ArrayList<>(); List<String> sheetNames = new ArrayList<>(); for (String status : orderStatusList) { sheetNames.add(status); headerList.add(new String[] {"用户名", "订单时间", "配送时间", "门店信息", "收货人", "联系方式", "状态"}); } List<List<String[]>> contents = new ArrayList<>(); for (String status : orderStatusList) { List<String[]> content = new ArrayList<>(); List<Order> subOrderList = getOrderListByStatus(orderList, status); for (Order order : subOrderList) { content.add( new String[] { order.getUserId(), order.getOrderTs(), order.getDeliveryTs(), order.getBuyerInfo(), order.getConsignee(), order.getConsigneeContact(), order.getStatus() }); } contents.add(content); } try { generator.generate(sheetNames, headerList, contents); } catch (IOException e) { e.printStackTrace(); return; } }
private static List<Order> getOrderListByStatus(List<Order> orderList, String status) { List<Order> subOrderList = new ArrayList<>(); for (Order order : orderList) { if (order.getStatus().equals(status)) { subOrderList.add(order); } } return subOrderList; }