Example #1
0
 private static List<Product> getProductListByCategory(
     List<Product> productList, Category category) {
   List<Product> products = new ArrayList<>();
   for (Product product : productList) {
     if (product.getCategory().toString().equals(category.toString())) {
       products.add(product);
     }
   }
   return products;
 }
Example #2
0
 public static void exportProducts(
     String fileName,
     List<Product> productList,
     Map<Type, List<Category>> typeMap,
     List<Procurement> procurementList) {
   logger.info("Export product to excel");
   ExcelGenerator generator = new ExcelGenerator(fileName);
   List<String[]> headerList = new ArrayList<>();
   List<String> sheetNames = new ArrayList<>();
   for (Type type : typeMap.keySet()) {
     sheetNames.add(type.getType());
     headerList.add(new String[] {"名字", "描述", "大类", "小类", "采购价", "系数", "销售价", "单位"});
   }
   List<List<String[]>> contents = new ArrayList<>();
   for (Type type : typeMap.keySet()) {
     List<Category> categoryList = typeMap.get(type);
     List<String[]> content = new ArrayList<>();
     for (Category category : categoryList) {
       List<Product> subProductList = getProductListByCategory(productList, category);
       for (Product product : subProductList) {
         Procurement procurement = getProcurement(procurementList, product.getId());
         double procprice = product.getPrice();
         double procindex = 1.0;
         if (procurement != null) {
           procprice = procurement.getProcprice();
           procindex = procurement.getProcindex();
         }
         content.add(
             new String[] {
               product.getName(),
               product.getDescription(),
               product.getType().getType(),
               product.getCategory().getCategory(),
               String.valueOf(procprice),
               String.valueOf(procindex),
               product.getPrice().toString(),
               product.getUnit()
             });
       }
     }
     contents.add(content);
   }
   try {
     generator.generate(sheetNames, headerList, contents);
   } catch (IOException e) {
     e.printStackTrace();
     return;
   }
 }