@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"; }
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; }