@ResponseBody
  @RequestMapping("/getInfosByParams")
  public List<DemandSupplyVO> getByParam(
      String type, String order, String field, String categoryId) {
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("type", type);
    paramMap.put("field", field);
    paramMap.put("sortOrder", order);
    // 得到所有供需信息
    List<DemandSupplyInfo> infos = demandSupplyInfoService.getByParams(paramMap);

    // convert
    List<DemandSupplyVO> tmps = new ArrayList<DemandSupplyVO>();
    for (DemandSupplyInfo info : infos) {
      tmps.add(convertVO(info));
    }
    List<DemandSupplyVO> vos = new ArrayList<DemandSupplyVO>();
    if (StringUtils.isNoneBlank(categoryId)) {
      // exclude
      if (vos.size() > 0) {
        for (DemandSupplyVO vo : tmps) {
          Product product = productService.getById(vo.getProductId());
          if (StringUtils.equals(product.getCategory().getId(), categoryId)) {
            vos.add(vo);
          }
        }
      }

    } else {
      vos.addAll(tmps);
    }
    return vos;
  }
  @ResponseBody
  @RequestMapping("/getByQueryParams")
  public List<DemandSupplyVO> getByQueryParams(@ModelAttribute DSQueryForm form) {
    // 如果产品类别为空,字段全部在一个对象里统一封装处理,否则做对比过滤
    Map<String, Object> queryMap = new HashMap<String, Object>();
    queryMap.put("type", form.getType());
    queryMap.put("timeSearch", form.getTimeSearch());
    queryMap.put("priceSearch", form.getPriceSearch());
    queryMap.put("attentionSearch", form.getAttentionSearch());
    // 得到所有供需信息
    List<DemandSupplyInfo> infos = demandSupplyInfoService.getByQueryParams(queryMap);

    // convert
    List<DemandSupplyVO> tmps = new ArrayList<DemandSupplyVO>();
    for (DemandSupplyInfo info : infos) {
      tmps.add(convertVO(info));
    }
    List<DemandSupplyVO> vos = new ArrayList<DemandSupplyVO>();
    String categoryId = form.getCategoryId();
    if (StringUtils.isNoneBlank(categoryId)) {
      // exclude
      if (vos.size() > 0) {
        for (DemandSupplyVO vo : tmps) {
          Product product = productService.getById(vo.getProductId());
          if (StringUtils.equals(product.getCategory().getId(), categoryId)) {
            vos.add(vo);
          }
        }
      }

    } else {
      vos.addAll(tmps);
    }
    return vos;
  }
  private DemandSupplyVO convertVO(DemandSupplyInfo info) {
    DemandSupplyVO vo = new DemandSupplyVO();
    User user = userService.getById(info.getId());
    User currentUser = PermissionContext.getUser();
    if (user != null) {
      vo.setUsername(user.getUsername());
    } else {
      vo.setUsername("未知");
    }
    vo.setId(info.getId());
    vo.setAmount(info.getAmount());
    vo.setPrice(info.getPrice());
    vo.setCreatedAt(info.getCreatedAt());
    vo.setStartDate(info.getStartDate());
    vo.setEndDate(info.getEndDate());
    vo.setDsType(info.getDsType());
    vo.setMemo(info.getMemo());
    vo.setAddress(info.getAddress());
    vo.setPraiseCnt(info.getPraiseCnt());
    String productId = info.getProduct().getId();
    vo.setProductId(productId);

    Product product = productService.getById(productId);
    vo.setProductName(product.getCname());
    int row = praiseInfoService.getCnt(info.getId(), currentUser.getId());
    if (row != 0) {
      PraiseType rType = praiseInfoService.getTypeByUserId(currentUser.getId(), info.getId());
      vo.setView(rType == PraiseType.addPraise);
    } else {
      vo.setView(false);
    }

    String imgs = product.getImgs();
    if (StringUtils.isNoneBlank(imgs)) {
      List<String> productImgs = new ArrayList<String>();
      String[] array = StringUtils.split(imgs, ",");
      for (String img : array) {
        productImgs.add(GlobalValue.QINIU_HOST + img);
      }
      vo.setProductImgs(productImgs);
      vo.setImg(productImgs.get(0));
    }
    return vo;
  }