示例#1
0
  @RequestMapping(value = "/upload", method = RequestMethod.POST)
  public @ResponseBody void uploadProduct(
      @RequestParam(value = "pic", required = false) MultipartFile pic,
      @RequestParam(value = "id", required = false) Integer id,
      @RequestParam("name") String name,
      @RequestParam("description") String description,
      @RequestParam("type") String type,
      @RequestParam("category") String category,
      @RequestParam("price") double price,
      @RequestParam("unit") String unit,
      HttpServletResponse response) {
    if (type == null
        || name == null
        || pic == null
        || description == null
        || category == null
        || price == 0
        || unit == null) {
      response.setStatus(HttpStatus.NOT_ACCEPTABLE.value());
      return;
    }
    Product product;
    if (id != null) {
      product = productService.getById(id);
    } else {
      product = new Product();
    }
    product.setName(name);
    product.setDescription(description);
    product.setType(Type.valueOf(type));
    product.setCategory(Category.valueOf(category));
    product.setPrice(price);
    product.setUnit(unit);
    // for Linux
    String dstFilePath =
        "/" + PathUtil.getWebInfPath() + "/product_images/" + product.generatePicurlHash() + ".jpg";
    // for Windows
    //        String dstFilePath = PathUtil.getWebInfPath() + "/product_images/" +
    // product.generatePicurlHash() + ".jpg";
    System.out.println("dstFilePath =" + dstFilePath);
    if (pic != null) {
      product.setPicurl("product_images/" + product.generatePicurlHash() + ".jpg");

      File picFile = new File(dstFilePath);

      try {
        pic.transferTo(picFile);
      } catch (IllegalStateException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    product.setDataChangeLastTime(new Timestamp(System.currentTimeMillis()));
    if (id != null) {
      productService.update(product);
    } else {
      productService.save(product);
    }
  }
示例#2
0
  /**
   * Group search API for the new filter type search and sort criteria
   *
   * @author DiepLe
   * @param searchAndSortCriteria
   * @return
   */
  @RequestMapping(value = "/search", method = RequestMethod.POST)
  @ResponseBody
  public ApiResponse<Object> getGroupSummaryByNewFilterTypeSearchAndSortCriteria(
      @RequestBody SearchAndSortCriteria searchAndSortCriteria) {

    final ApiResponse<Object> apiResponse = new ApiResponse<>();
    List<PermissionGroupSummaryDTO> permissionGroupSummaryDTO = null;
    Long totalRecords = null;
    PermissionGroupSummariesDTO summaries = null;

    try {
      permissionGroupSummaryDTO =
          groupService.getGroupSummaryByNewSearchAndSortCriteria(searchAndSortCriteria);
      totalRecords = groupService.getTotalCountForSearchAndSortCriteria(searchAndSortCriteria);
      summaries = new PermissionGroupSummariesDTO();
      summaries.setGroupList(permissionGroupSummaryDTO);
      summaries.setTotalRecords(totalRecords);
    } catch (IllegalStateException e) {
      e.printStackTrace();
      apiResponse.setStatus("failure");
      apiResponse.setData(null);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1069");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1069", new Object[] {e.getMessage()}, LocaleContextHolder.getLocale()));
      return apiResponse;
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
      apiResponse.setStatus("failure");
      apiResponse.setData(null);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1070");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1070", new Object[] {e.getMessage()}, LocaleContextHolder.getLocale()));
      return apiResponse;
    } catch (Exception e) {
      throw new LucasRuntimeException(LucasRuntimeException.INTERNAL_ERROR, e);
    }

    apiResponse.setData(summaries);

    return apiResponse;
  }
示例#3
0
 @RequestMapping("/upfile")
 @ResponseBody
 public String upfile(
     @RequestParam("desc") String desc, @RequestParam("file") MultipartFile file) {
   try {
     if (!file.isEmpty()) {
       logger.info("{}上传中", desc);
       file.transferTo(new File("d:/fileupload/" + file.getOriginalFilename()));
       return "上传成功";
     }
   } catch (IllegalStateException e) {
     logger.error("非法状态错误");
     e.printStackTrace();
   } catch (IOException e) {
     logger.error("文件I/O错误");
     e.printStackTrace();
   }
   return "上传失败";
 }