@RequestMapping(value = "/excel", method = RequestMethod.GET)
  public void excel(HttpServletResponse response) throws Exception {
    Workbook wb = new HSSFWorkbook();
    //        CreationHelper createHelper = wb.getCreationHelper();
    Sheet sheet = wb.createSheet("new sheet");
    org.apache.poi.ss.usermodel.Row row = sheet.createRow((short) 0);
    row = sheet.createRow((short) 1);
    row.createCell(0).setCellValue("Mã");
    row.createCell(1).setCellValue("Tên");
    row.createCell(2).setCellValue("Mã Path");
    row.createCell(3).setCellValue("Tên path");
    row.createCell(4).setCellValue("Cấp danh mục");

    int i = 1;
    List<Category> listAll = categoryService.listAll();
    for (Category print : listAll) {
      if (print.getName().length() > 19) {
        i++;
        row = sheet.createRow((short) i);
        row.createCell(0).setCellValue(String.valueOf(print.getId()));
        row.createCell(1).setCellValue(String.valueOf(print.getName()));
        row.createCell(2).setCellValue(String.valueOf(print.getPath()));
        String path = "";
        for (String categoryId : print.getPath()) {
          Category get = categoryService.get(categoryId);
          path += get.getName() + " >>";
        }
        row.createCell(3).setCellValue(String.valueOf(path));
        row.createCell(4).setCellValue(String.valueOf(print.getLevel()));
      }
    }
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=Danh-sach-danh-muc.xls");
    wb.write(response.getOutputStream());
  }
 public void getAncestors(ItemSearch itemSearch, Map<String, Object> parentCategorys) {
   List<Object> cats = new ArrayList<>();
   if (itemSearch.getCategoryIds() == null || itemSearch.getCategoryIds().isEmpty()) {
     parentCategorys.put("cats", cats);
   } else {
     try {
       List<Category> ancestors = categoryService.getAncestors(itemSearch.getCategoryIds().get(0));
       for (Category cat : ancestors) {
         cats.add(categoryService.getChilds(cat.getId()));
       }
       parentCategorys.put("cats", cats);
       parentCategorys.put("ancestors", ancestors);
     } catch (Exception ex) {
     }
   }
 }
 /**
  * Thêm thuộc tính mới.
  *
  * @param categoryProperty
  * @return
  */
 @ResponseBody
 @RequestMapping(value = "/addproperty", method = RequestMethod.POST)
 public Response addProperty(@RequestBody CategoryProperty categoryProperty) {
   try {
     return categoryService.addProperty(categoryProperty);
   } catch (Exception e) {
     return new Response(false, e.getMessage());
   }
 }
 /**
  * Xóa danh mục
  *
  * @param id
  * @return
  */
 @ResponseBody
 @RequestMapping(value = "/del", method = RequestMethod.GET)
 public Response del(@RequestParam(value = "id", defaultValue = "") String id) {
   try {
     categoryService.remove(id);
   } catch (Exception e) {
     return new Response(false, e.getMessage());
   }
   return new Response(true, "Đã xóa thành công");
 }
 /**
  * Sửa thông tin giá trị thuộc tính
  *
  * @param categoryPropertyValue
  * @return
  */
 @ResponseBody
 @RequestMapping(value = "/editpropertyvalue", method = RequestMethod.POST)
 public Response editPropertyValue(@RequestBody CategoryPropertyValue categoryPropertyValue) {
   try {
     categoryService.editPropertyValue(categoryPropertyValue);
   } catch (Exception e) {
     return new Response(false, e.getMessage());
   }
   return new Response(true, "Sửa thành công");
 }
Beispiel #6
0
  /**
   * Lấy thông tin thuộc tính model theo id
   *
   * @param id
   * @return
   */
  @RequestMapping(value = "/getproperties", method = RequestMethod.GET)
  @ResponseBody
  public Response getProperties(@RequestParam(value = "id", defaultValue = "") String id)
      throws Exception {
    Model model = modelService.getModel(id);
    if (model == null) {
      throw new Exception("Model không tồn tại");
    }
    HashMap<String, Object> data = new HashMap<>();
    List<ModelProperty> properties = modelService.getProperties(id);
    data.put("model", model);
    data.put("properties", properties);
    data.put("categoryProperties", categoryService.getProperties(model.getCategoryId()));
    data.put(
        "categoryPropertyValues",
        categoryService.getPropertyValuesWithCategoryId(model.getCategoryId()));

    return new Response(true, "Thông tin model", data);
  }
 /**
  * Service Sửa thông tin danh mục
  *
  * @param category
  * @param categoryFrom
  * @return
  * @throws Exception
  */
 @RequestMapping(value = "/update", method = RequestMethod.POST)
 @ResponseBody
 public Response update(@RequestBody Category category) throws Exception {
   return categoryService.edit(category);
 }
 /**
  * @param category
  * @return
  * @throws Exception
  */
 @RequestMapping(value = "/add", method = RequestMethod.POST)
 @ResponseBody
 public Response add(@RequestBody Category category) throws Exception {
   return categoryService.addCategory(category);
 }
 /**
  * Xóa toàn bộ index
  *
  * @return
  * @throws Exception
  */
 @RequestMapping(value = "/unindex")
 @ResponseBody
 public Response unindex() throws Exception {
   categoryService.unindex();
   return new Response(true, "Xóa index thành công");
 }
 /**
  * Index toàn bộ category
  *
  * @throws Exception
  */
 @RequestMapping(value = "/index")
 @ResponseBody
 public Response index() throws Exception {
   categoryService.index();
   return new Response(true, "Đang xử lý index ...");
 }
  /**
   * Danh sách sản phẩm cần review
   *
   * @param modelMap
   * @param session
   * @param page
   * @return
   */
  @RequestMapping(
      value = {"/reviewitem"},
      method = RequestMethod.GET)
  public String reviewList(
      ModelMap modelMap,
      HttpSession session,
      @RequestParam(value = "page", defaultValue = "0") int page) {

    ItemSearch itemSearch = new ItemSearch();
    itemSearch.setStatus(4);
    List<String> cateIds = new ArrayList<>();
    List<String> shopCateIds = new ArrayList<>();
    List<String> manufIds = new ArrayList<>();
    List<String> modelIds = new ArrayList<>();
    if (itemSearch.getCategoryIds() == null) {
      itemSearch.setCategoryIds(new ArrayList<String>());
    }
    itemSearch.setSource(ItemSource.SELLER);
    long createTime = 1388509200 * 1000L;
    itemSearch.setCreateTimeFrom(createTime);
    itemSearch.setCreateTimeTo(System.currentTimeMillis());
    if (session.getAttribute("itemSearch") != null && page != 0) {
      itemSearch = (ItemSearch) session.getAttribute("itemSearch");
    } else {
      session.setAttribute("itemSearch", itemSearch);
    }
    Map<String, Object> parentCategorys = new HashMap<>();
    getAncestors(itemSearch, parentCategorys);

    if (page > 0) {
      itemSearch.setPageIndex(page - 1);
    } else {
      itemSearch.setPageIndex(0);
    }
    itemSearch.setPageSize(50);

    DataPage<Item> itemPage = itemService.searchMongo(itemSearch);
    for (Item item : itemPage.getData()) {
      if (item.getCategoryId() != null
          && !item.getCategoryId().equals("")
          && !cateIds.contains(item.getCategoryId())) {
        cateIds.add(item.getCategoryId());
      }
      if (item.getShopCategoryId() != null
          && !item.getShopCategoryId().equals("")
          && !shopCateIds.contains(item.getShopCategoryId())) {
        shopCateIds.add(item.getShopCategoryId());
      }
      if (item.getManufacturerId() != null
          && !item.getManufacturerId().equals("")
          && !manufIds.contains(item.getManufacturerId())) {
        manufIds.add(item.getManufacturerId());
      }
      if (item.getModelId() != null
          && !item.getModelId().equals("")
          && !modelIds.contains(item.getModelId())) {
        modelIds.add(item.getModelId());
      }
    }
    for (Item item : itemPage.getData()) {
      List<String> images = new ArrayList<>();
      if (item != null && item.getImages() != null && !item.getImages().isEmpty()) {
        for (String img : item.getImages()) {
          images.add(
              imageService.getUrl(img).thumbnail(200, 200, "outbound").getUrl(item.getName()));
        }
        item.setImages(images);
      }
      if (item.getSellerName() == null || item.getSellerName().equals("")) {
        try {
          User seller = userService.get(item.getSellerId());
          item.setSellerName(seller.getEmail());
        } catch (Exception ex) {
        }
      }
    }
    List<City> cities = cityService.list();
    modelMap.put("itemSearch", itemSearch);
    modelMap.put("itemPage", itemPage);
    modelMap.put("cities", cities);
    modelMap.put("itemCates", categoryService.getCategories(cateIds));
    modelMap.put("itemShopCates", shopCategoryService.get(shopCateIds));
    modelMap.put("itemManuf", manufacturerService.getManufacturers(manufIds));
    modelMap.put("itemModels", modelService.getModels(modelIds));
    modelMap.put(
        "clientScript",
        "category = "
            + gson.toJson(categoryService.getChilds(null))
            + ",cities="
            + gson.toJson(cities)
            + ";reviewitem.init({parentCategorys:"
            + gson.toJson(parentCategorys)
            + ", categoryId:'"
            + (itemSearch.getCategoryIds().isEmpty() ? "" : itemSearch.getCategoryIds().get(0))
            + "'});");
    return "cp.item.review";
  }
  /**
   * Tìm kiếm tất cả sản phẩm
   *
   * @param itemSearch
   * @param session
   * @param modelMap
   * @return
   */
  @RequestMapping(
      value = {"/reviewitem"},
      method = RequestMethod.POST)
  public String reviewSearch(
      @ModelAttribute("itemSearch") ItemSearch itemSearch, HttpSession session, ModelMap modelMap) {
    Map<String, Object> parentCategorys = new HashMap<>();
    List<String> cateIds = new ArrayList<>();
    List<String> shopCateIds = new ArrayList<>();
    List<String> manufIds = new ArrayList<>();
    List<String> modelIds = new ArrayList<>();

    itemSearch.setPageIndex(0);
    itemSearch.setPageSize(50);
    if (itemSearch.getCategoryId() != null && !itemSearch.getCategoryId().equals("")) {
      itemSearch.setCategoryIds(new ArrayList<String>());
      itemSearch.getCategoryIds().add(itemSearch.getCategoryId());
    }
    getAncestors(itemSearch, parentCategorys);
    session.setAttribute("itemSearch", itemSearch);
    DataPage<Item> itemPage = itemService.searchMongo(itemSearch);
    for (Item item : itemPage.getData()) {
      if (item.getCategoryId() != null
          && !item.getCategoryId().equals("")
          && !cateIds.contains(item.getCategoryId())) {
        cateIds.add(item.getCategoryId());
      }
      if (item.getShopCategoryId() != null
          && !item.getShopCategoryId().equals("")
          && !shopCateIds.contains(item.getShopCategoryId())) {
        shopCateIds.add(item.getShopCategoryId());
      }
      if (item.getManufacturerId() != null
          && !item.getManufacturerId().equals("")
          && !manufIds.contains(item.getManufacturerId())) {
        manufIds.add(item.getManufacturerId());
      }
      if (item.getModelId() != null
          && !item.getModelId().equals("")
          && !modelIds.contains(item.getModelId())) {
        modelIds.add(item.getModelId());
      }
    }
    for (Item item : itemPage.getData()) {
      List<String> images = new ArrayList<>();
      if (item != null && item.getImages() != null && !item.getImages().isEmpty()) {
        for (String img : item.getImages()) {
          images.add(
              imageService.getUrl(img).thumbnail(200, 200, "outbound").getUrl(item.getName()));
        }
        item.setImages(images);
      }
      if (item.getSellerName() == null || item.getSellerName().equals("")) {
        try {
          User seller = userService.get(item.getSellerId());
          item.setSellerName(seller.getEmail());
        } catch (Exception ex) {
        }
      }
    }
    if (itemSearch.getCategoryIds() == null) {
      itemSearch.setCategoryIds(new ArrayList<String>());
    }
    List<City> cities = cityService.list();
    modelMap.put("itemSearch", itemSearch);
    modelMap.put("itemPage", itemPage);
    modelMap.put("cities", cities);
    modelMap.put("itemCates", categoryService.getCategories(cateIds));
    modelMap.put("itemShopCates", shopCategoryService.get(shopCateIds));
    modelMap.put("itemManuf", manufacturerService.getManufacturers(manufIds));
    modelMap.put("itemModels", modelService.getModels(modelIds));
    modelMap.put(
        "clientScript",
        "category = "
            + gson.toJson(categoryService.getChilds(null))
            + ",cities="
            + gson.toJson(cities)
            + ";reviewitem.init({parentCategorys:"
            + gson.toJson(parentCategorys)
            + ", categoryId:'"
            + (itemSearch.getCategoryIds().isEmpty() ? "" : itemSearch.getCategoryIds().get(0))
            + "'});");
    return "cp.item.review";
  }