@RequestMapping("discountFindById")
 @ResponseBody
 public Object findById(@RequestParam("id") int discountId) throws Exception {
   if (discountId != 0) {
     DiscountOut d = discountServiceImpl.findById(discountId);
     return d;
   }
   return null;
 }
  @RequestMapping("discountDelete")
  @ResponseBody
  public boolean doDelete(int discountId) throws Exception {

    if (discountServiceImpl.doDelete(discountId)) {
      return true;
    }
    return false;
  }
  private int findAllByPageListSize(DiscountIn inVo) throws Exception {

    PageBean<DiscountIn> pageBean = new PageBean<DiscountIn>(0, Integer.MAX_VALUE);
    pageBean.setInVo(inVo);
    List<DiscountOut> list = discountServiceImpl.findAllByPage(pageBean);
    if (list != null) {
      return list.size();
    }
    return 0;
  }
  @RequestMapping("discountInsert")
  @ResponseBody
  public boolean doInsert(DiscountIn inVo) throws Exception {

    if (discountServiceImpl.doInsert(inVo)) {
      return true;
    }

    return false;
  }
  @RequestMapping("discountUpdate")
  @ResponseBody
  public boolean doUpdate(DiscountIn inVo) throws Exception {

    System.out.println(UUID.randomUUID());

    if (discountServiceImpl.doUpdate(inVo)) {
      return true;
    }

    return false;
  }
  @RequestMapping("discountFindAllByPage")
  @ResponseBody
  public Object findAllByPage(HttpServletRequest request, DiscountIn inVo) throws Exception {
    int currentPage = Integer.parseInt(request.getParameter("page"));
    int pageSize = Integer.parseInt(request.getParameter("rows"));

    Map<String, Object> map = new HashMap<String, Object>();
    PageBean<DiscountIn> pageBean = new PageBean<DiscountIn>(currentPage, pageSize);
    pageBean.setInVo(inVo);
    map.put("total", findAllByPageListSize(inVo));
    map.put("rows", discountServiceImpl.findAllByPage(pageBean));
    System.out.println(map);
    return map;
  }
  @RequestMapping("insertDiscount")
  @ResponseBody
  public boolean insertDiscount(HttpServletRequest request, MultipartFile img) throws Exception {

    // doInsertAll

    String price = request.getParameter("price");
    String discountTypeEffect = request.getParameter("discountTypeEffect");
    String selId =
        request.getParameter("selId") == null || "".equals(request.getParameter("selId"))
            ? "0"
            : request.getParameter("selId");

    System.out.println(price + "----" + discountTypeEffect + "---" + selId);

    if (img != null) {
      String path = request.getSession().getServletContext().getRealPath("\\");
      String dirPrefix = "imgs\\discount\\";
      path += dirPrefix;
      String name = img.getOriginalFilename();
      String ext = name.substring(name.lastIndexOf("."));
      System.out.println("ext---------------" + ext);
      String fileName = KeyUtils.getImageNamePrefix() + ext;
      File file = new File(path);
      if (!file.exists()) {
        file.mkdirs();
        System.out.println(path);
      }
      file = new File(path, fileName);
      img.transferTo(file); // 保存上传的文件
      String imgUrl = dirPrefix + fileName;

      DiscountIn inVo = new DiscountIn();
      inVo.setPrice(Float.parseFloat(price));
      inVo.setImage(imgUrl);
      DiscountTypeIn tInVo = new DiscountTypeIn();
      tInVo.setDiscountTypeEffect(Integer.parseInt(discountTypeEffect));
      tInVo.setSelId(Integer.parseInt(selId));
      if (discountServiceImpl.doInsertAll(inVo, tInVo)) {
        return true;
      }
    }
    return false;
  }