/** * Thêm mới ảnh model * * @param modelForm * @return */ @RequestMapping(value = "/addimage", method = RequestMethod.POST) @ResponseBody public Response addImage(@ModelAttribute ModelForm modelForm) { List<String> images = new ArrayList<>(); Response resp; if (modelForm.getImage() != null && modelForm.getImage().getSize() > 0) { resp = imageService.upload(modelForm.getImage(), ImageType.MODEL, modelForm.getId()); if (resp == null || !resp.isSuccess()) { return new Response(false, resp.getMessage()); } images.add((String) resp.getData()); } else if (modelForm.getImageUrl() != null && !modelForm.getImageUrl().trim().equals("")) { resp = imageService.download(modelForm.getImageUrl(), ImageType.MODEL, modelForm.getId()); if (resp == null || !resp.isSuccess()) { return new Response(false, resp.getMessage()); } images.add((String) resp.getData()); } else { return new Response(false, "Bạn phải chọn ảnh để thêm"); } try { String data = (String) resp.getData(); // String url = imageService.getUrl(data).getUrl(); ArrayList<String> url = new ArrayList<String>(); List<String> get = imageService.get(ImageType.MODEL, modelForm.getId()); for (String imgs : get) { url.add(imageService.getUrl(imgs).thumbnail(100, 100, "outbound").getUrl()); } return new Response(true, "Đã thêm ảnh thành công", url); } 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); }