@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; }
@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; }
/** * 根据编号预览 * * @param model * @param id * @return */ @RequestMapping("/preview") public String DsFinish(Model model, String id) { DemandSupplyInfo info = demandSupplyInfoService.getById(id); DemandSupplyVO vo = convertVO(info); model.addAttribute("vo", vo); List<FeedBack> list = new ArrayList<FeedBack>(); list = feedBackService.getByDemondInfoId(id); model.addAttribute("list", list); // 根据用户编号查询 String userId = info.getUserId(); if (StringUtils.isNoneBlank(userId)) { // 判断此消息其关注否 PraiseType attention = praiseInfoService.getTypeByUserId(userId, id); if (attention != null) { if (attention.equals(PraiseType.addPraise)) { model.addAttribute("att", attention); } } List<DemandSupplyInfo> ListThree = demandSupplyInfoService.getThreeByUserId(userId, id); if (ListThree != null && !ListThree.isEmpty()) { List<DemandSupplyVO> voThree = new ArrayList<DemandSupplyVO>(); for (DemandSupplyInfo vt : ListThree) { voThree.add(convertVO(vt)); } model.addAttribute("voThree", voThree); // for each convertVO // exclude first value object // order top 3 // top 4 } } return "DsFinish"; }
/** 默认情况下的查询,只根据供求类型进行查询 */ @RequestMapping("/getInfosByType") public String getByType(String type, Model model) { try { List<DemandSupplyInfo> infos = demandSupplyInfoService.getAllByType(type); List<DemandSupplyVO> vos = new ArrayList<DemandSupplyVO>(); for (DemandSupplyInfo info : infos) { vos.add(convertVO(info)); } model.addAttribute("vos", vos); } catch (Exception e) { logger.error(e.getMessage()); e.printStackTrace(); } return "/goods/infos"; }
@RequestMapping("/attention") public String getAttention(Model model) { try { User currentUser = PermissionContext.getUser(); List<DemandSupplyInfo> all = demandSupplyInfoService.getAllByUserId(currentUser.getId()); List<DemandSupplyVO> vos = new ArrayList<DemandSupplyVO>(); for (DemandSupplyInfo alls : all) { vos.add(convertVO(alls)); } model.addAttribute("vos", vos); } catch (Exception e) { logger.error(e.getMessage()); e.printStackTrace(); } return "/attention"; }