@RequestMapping( value = { "/mi/shop/view/json/{id}", "/mi/shop/add/view/json/{id}", "/mi/shop/update/view/json/{id}" }, method = {RequestMethod.GET}) @ResponseBody public Object getMiViewJson(HttpServletRequest request, @PathVariable String id) { Map<String, Object> resultMap = new HashMap<String, Object>(); try { ShopModel shop = shopService.get(id); if (shop != null) { // PermissionQueryModel pqm = new PermissionQueryModel(); // pqm.setTargetPage(PageUtil.BEGIN_PAGE); // pqm.setPageSize(PageUtil.MAX_PAGE_SIZE); // pqm.setShopId(id); // List<PermissionModel> permissions = permissionService // .strictList(pqm); shop.setPreViewUrl( aossService.addImgParams( shop.getPreViewUrl(), Constants.ALIYUN_OSS_IMAGE_PARAMS_TYPE_HEAD_IMG)); resultMap.put("shop", shop); // resultMap.put("relations", permissions); } } catch (Exception e) { resultMap.put("shop", null); LOG.error(LoginUtil.SEARCH_DISPLAY + permissionObjectName + "详细信息出错!", e); } return resultMap; }
@RequestMapping( value = "/shop/view/preView/{id}", method = {RequestMethod.GET}) public void toViewPreView( HttpServletRequest request, HttpServletResponse response, @PathVariable String id) throws IOException { ShopModel shop = shopService.get(id); shop.setPreViewUrl( aossService.addImgParams(shop.getPreViewUrl(), Constants.ALIYUN_OSS_IMAGE_WATER_MARK)); response.sendRedirect(shop.getPreViewUrl()); }
@RequestMapping( value = "/shop/search/-{searchKeyword}-", method = {RequestMethod.GET}) public String toSearch(HttpServletRequest request, @PathVariable String searchKeyword) { ShopQueryModel command = new ShopQueryModel(); command.setTargetPage(PageUtil.BEGIN_PAGE); command.setPageSize(PageUtil.DEFAULT_PAGE_SIZE); command.setSearchKeyword(searchKeyword); List<ShopModel> list = shopService.strictList(command); for (ShopModel shop : list) { shop.setPreViewUrl( aossService.addImgParams( shop.getPreViewUrl(), Constants.ALIYUN_OSS_IMAGE_PARAMS_TYPE_NORMAL_PRE_IMG)); } int total = shopService.strictCount(command); request.setAttribute("results", list); request.setAttribute("total", total); return "ui/shop/search"; }
@RequestMapping( value = "/shop/search/json/{searchKeyword}-{targetPage}-{pageSize}", method = {RequestMethod.GET}) @ResponseBody public Object toSearchJson( HttpServletRequest request, @PathVariable String searchKeyword, @PathVariable Integer targetPage, @PathVariable Integer pageSize) { ShopQueryModel command = new ShopQueryModel(); command.setTargetPage(targetPage); command.setPageSize(pageSize); command.setSearchKeyword(searchKeyword); List<ShopModel> list = shopService.strictList(command); for (ShopModel shop : list) { shop.setPreViewUrl( aossService.addImgParams( shop.getPreViewUrl(), Constants.ALIYUN_OSS_IMAGE_PARAMS_TYPE_NORMAL_PRE_IMG)); } Map<String, Object> result = ResultMapUtil.getResultMap(); result.put("results", list); return result; }
@RequestMapping( value = "/shop/view/{id}", method = {RequestMethod.GET}) public String toView(HttpServletRequest request, @PathVariable String id) { ShopModel shop = shopService.get(id); shop.setPreViewUrl( aossService.addImgParams( shop.getPreViewUrl(), Constants.ALIYUN_OSS_IMAGE_PARAMS_TYPE_BANNER)); ProductQueryModel pqm = new ProductQueryModel(); pqm.setTargetPage(PageUtil.BEGIN_PAGE); pqm.setPageSize(PageUtil.MAX_PAGE_SIZE); pqm.setShopId(id); List<ProductModel> list = productService.strictList(pqm); for (ProductModel product : list) { product.setPreViewUrl( aossService.addImgParams( product.getPreViewUrl(), Constants.ALIYUN_OSS_IMAGE_PARAMS_TYPE_NORMAL_PRE_IMG)); } shop.setProducts(list); request.setAttribute("shop", shop); return "ui/shop/view"; }
private Object saveOrUpdateUser( HttpServletRequest request, ShopModel shop, String newPermissionIds) { Map<String, Object> resultMap = null; String actionName; if (StringUtils.isBlank(shop.getId())) { actionName = LoginUtil.ADD_DISPLAY; shop.setCreaterId(LoginUtil.getCurrentUserId(request)); } else { actionName = LoginUtil.UPDATE_DISPLAY; } shop.setEditorId(LoginUtil.getCurrentUserId(request)); shop.setPreViewUrl(aossService.clearImgParams(shop.getPreViewUrl())); try { shopService.saveOrUpdate(shop); resultMap = ResultMapUtil.getResultMap(actionName + permissionObjectName + "成功!"); } catch (ConstraintViolationException e) { Set<ConstraintViolation<?>> constraintViolations = e.getConstraintViolations(); Iterator<ConstraintViolation<?>> iter = constraintViolations.iterator(); while (iter.hasNext()) { ConstraintViolation<?> cv = iter.next(); resultMap = ResultMapUtil.getResultMap(cv.getMessage(), cv.getPropertyPath().toString()); break; } if (resultMap == null) { resultMap = ResultMapUtil.getResultMap(actionName + permissionObjectName + "失败!", false); } LOG.error(actionName + permissionObjectName + "失败!", e); } catch (DataIntegrityViolationException e) { LOG.error(actionName + permissionObjectName + "失败!", e); resultMap = ResultMapUtil.getResultMap("name", permissionObjectName + "名重复!"); } catch (Exception e) { LOG.error(actionName + permissionObjectName + "失败!", e); resultMap = ResultMapUtil.getResultMap(actionName + permissionObjectName + "失败!", false); } return resultMap; }