Esempio n. 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);
    }
  }
Esempio n. 2
0
 @RequestMapping(
     value = "/update",
     method = RequestMethod.POST,
     headers = "Content-Type=application/json")
 public @ResponseBody void update(@RequestBody Product product) {
   productService.update(product);
 }
Esempio n. 3
0
 @RequestMapping("/export")
 public ResponseEntity<byte[]> download() throws IOException {
   String fileName =
       String.format("菜品列表%s.xlsx", new SimpleDateFormat("yyyyMMdd").format(new Date()));
   ExcelFactory.exportProducts(
       fileName,
       productService.getAll(),
       productService.getTypeMap(),
       productService.getProcurement());
   File file = new File(fileName);
   HttpHeaders headers = new HttpHeaders();
   String cnfileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
   headers.setContentDispositionFormData("attachment", cnfileName);
   headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
   return new ResponseEntity<>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
 }
Esempio n. 4
0
 @RequestMapping(value = "/type_map", method = RequestMethod.GET)
 public @ResponseBody JSONArray getTypeMap() {
   JSONArray jsonArray = new JSONArray();
   Map<Type, List<Category>> typeMap = productService.getTypeMap();
   for (Type key : typeMap.keySet()) {
     List<Category> categoryList = typeMap.get(key);
     JSONArray categoryJsonArray = new JSONArray();
     for (Category category : categoryList) {
       JSONObject jsonObject = new JSONObject();
       jsonObject.put("key", category.getCategory());
       jsonObject.put("value", category.toString());
       categoryJsonArray.add(jsonObject);
     }
     JSONObject jsonObject = new JSONObject();
     jsonObject.put("name", key.getType());
     jsonObject.put("value", key.toString());
     jsonObject.put("list", categoryJsonArray);
     jsonArray.add(jsonObject);
   }
   return jsonArray;
 }
Esempio n. 5
0
 @RequestMapping(value = "/delete/{product_id}", method = RequestMethod.POST)
 public @ResponseBody void delete(@PathVariable("product_id") int productId) {
   productService.delete(productId);
 }
Esempio n. 6
0
 @RequestMapping(value = "/procurement/all", method = RequestMethod.GET)
 public @ResponseBody List<Procurement> getProcurement() {
   return productService.getProcurement();
 }
Esempio n. 7
0
 @RequestMapping(value = "/most_bought/{type}/wechatid/{wechatid}", method = RequestMethod.GET)
 public @ResponseBody List<Product> getMostBought(
     @PathVariable("type") String type, @PathVariable("wechatid") String wechatid) {
   return productService.getMostBought(wechatid, type);
 }
Esempio n. 8
0
 @RequestMapping(value = "/admin/category/{category}", method = RequestMethod.GET)
 public @ResponseBody List<Product> getList4Admin(@PathVariable("category") String category) {
   return productService.getList(category);
 }
Esempio n. 9
0
 @RequestMapping(value = "/category/{category}/pinyin/asc", method = RequestMethod.GET)
 public @ResponseBody List<Product> getListByPy(@PathVariable("category") String category) {
   return productService.getListSortByPinyin(category, "name", "asc");
 }
Esempio n. 10
0
 @RequestMapping(value = "/category/{category}/wechatid/{wechatid}", method = RequestMethod.GET)
 public @ResponseBody List<Product> getList(
     @PathVariable("category") String category, @PathVariable("wechatid") String wechatid) {
   //        return productService.getListByFavourites(category, wechatid);
   return productService.getList(category);
 }
Esempio n. 11
0
 @RequestMapping(value = "/save_sort", method = RequestMethod.POST)
 public @ResponseBody void saveSort(@RequestBody List<ProductOrder> productOrderList) {
   System.out.println(productOrderList);
   productService.saveProductSortOrder(productOrderList);
 }