Example #1
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);
  }
Example #2
0
 /**
  * Lấy thông tin chi tiết model theo id
  *
  * @param modelId
  * @return
  */
 @RequestMapping(value = "/getmodel", method = RequestMethod.GET)
 @ResponseBody
 public Response get(@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");
   }
   List<String> images = model.getImages();
   List<String> imgs = new ArrayList<>();
   for (String img : images) {
     imgs.add(imageService.getUrl(img).thumbnail(100, 100, "outbound").getUrl(model.getName()));
   }
   model.setImages(imgs);
   model.setProperties(modelService.getProperties(model.getId()));
   ModelSeo modelSeo = modelService.getModelSeo(id);
   if (modelSeo != null) {
     model.setModelSeo(modelSeo);
   }
   return new Response(true, "Thông tin chi tiết model", model);
 }
  /**
   * Báo cáo đã sửa xong
   *
   * @param modelLog
   * @return
   * @throws Exception
   */
  @RequestMapping(value = "/successedit", method = RequestMethod.POST)
  @ResponseBody
  public Response successedit(@RequestBody ModelLog modelLog) throws Exception {

    String idUser = viewer.getAdministrator().getId();
    try {
      modelService.submitEdit(modelLog.getModelId(), idUser, modelLog.getMessage());
    } catch (Exception e) {
      return new Response(false, e.getMessage());
    }

    return new Response(true, "Báo cáo sửa hoàn tất");
  }
 /**
  * Sửa thông tin thuộc tính model theo id
  *
  * @param propertys
  * @return
  * @throws java.lang.Exception
  */
 @RequestMapping(value = "/editproperties", method = RequestMethod.POST)
 @ResponseBody
 public Response editProperties(@RequestBody HashMap<String, String> propertys) throws Exception {
   try {
     String idModel = propertys.get("id");
     List<ModelProperty> propertysx =
         gson.fromJson(
             propertys.get("propertys"), new TypeToken<List<ModelProperty>>() {}.getType());
     modelService.updateProperties(idModel, propertysx);
     return new Response(true, "Cập nhật thành công thuộc tính");
   } catch (Exception e) {
     return new Response(false, e.getMessage());
   }
 }
 /**
  * Xóa 1 ảnh model
  *
  * @param id
  * @param imageName
  * @return
  */
 @RequestMapping(value = "/delimage", method = RequestMethod.GET)
 @ResponseBody
 public Response delImage(
     @RequestParam(value = "id", defaultValue = "") String id,
     @RequestParam(value = "name", defaultValue = "") String imageName) {
   if (imageName == null || imageName.trim().equals("")) {
     return new Response(false, "Phải chọn ảnh để xóa");
   }
   try {
     return modelService.deleteImage(id, imageName);
   } catch (Exception ex) {
     return new Response(false, ex.getMessage());
   }
 }
  /**
   * Sửa model
   *
   * @param form
   * @return
   * @throws Exception
   */
  @RequestMapping(value = "/edit", method = RequestMethod.POST)
  @ResponseBody
  public Response edit(@RequestBody ModelForm form) throws Exception {
    String id = "test";
    if (viewer != null && viewer.getAdministrator() != null) {
      id = viewer.getAdministrator().getId();
    }
    Model model = new Model();
    model.setCategoryId(form.getCategoryId());
    model.setId(form.getId());
    model.setManufacturerId(form.getManufacturerId());
    model.setEbayKeyword(form.getEbayKeyword());
    model.setName(form.getName());
    if (form.getActive() > 0) {
      model.setActive(form.getActive() == ModelForm.TRUE);
    }

    return modelService.edit(model, id);
  }
Example #7
0
  /**
   * autocomplate model
   *
   * @param keyword
   * @param cateId
   * @param manufacturerId
   * @return
   */
  @RequestMapping(value = "/searchmodel", method = RequestMethod.GET)
  @ResponseBody
  public Response searchmodel(
      @RequestParam(value = "keyword", defaultValue = "") String keyword,
      @RequestParam(value = "categoryId", defaultValue = "") String cateId,
      @RequestParam(value = "manufacturerId", defaultValue = "") String manufacturerId) {

    ModelSearch search = new ModelSearch();
    search.setKeyword(keyword);
    if (cateId != null && !"".equals(cateId.trim()) && !"0".equals(cateId.trim())) {
      search.setCategoryId(cateId);
    }
    if (manufacturerId != null
        && !"".equals(manufacturerId.trim())
        && !"0".equals(manufacturerId.trim())) {
      search.setManufacturerIds(new ArrayList<String>());
      search.getManufacturerIds().add(manufacturerId);
    }
    search.setPageIndex(0);
    search.setPageSize(100);
    DataPage<Model> dataPage = modelService.search(search);
    return new Response(true, "Danh sách model", dataPage);
  }
  /**
   * 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";
  }