private Pagination<UserPrize> getUserPrizePage(int offset, int limit) { Pagination<UserPrize> resp = null; List<UserPrize> iterms = new ArrayList<UserPrize>(); Pagination<Prize> page = prizeService.getPagination(offset, limit); List<String> userIds = new ArrayList<String>(); if (page != null && page.getItems() != null) { for (Prize prize : page.getItems()) { userIds.add(prize.getUserId()); } Map<String, User> map = userService.getUserMap(userIds); for (Prize prize : page.getItems()) { iterms.add(new UserPrize(prize, map.get(prize.getUserId()))); } } resp = new Pagination<UserPrize>(iterms, page.getTotalCount(), limit, offset); return resp; }
@RequestMapping(value = "/download", method = RequestMethod.GET) public void csvDownLoad( ModelMap model, HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception { if (!configService.isUserLogin(request)) { return; } Pagination<TaskHelpRE> page = friendHelperService.getTasKUserPagination(0, 50); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); StringBuffer fileName = new StringBuffer("task-help-").append(dateFormat.format(new Date())).append(".txt"); httpServletResponse.setContentType("application/octet-stream"); httpServletResponse.addHeader( "Content-Disposition", "attachment; filename=" + fileName.toString()); BufferedWriter write = null; try { write = new BufferedWriter(new OutputStreamWriter(httpServletResponse.getOutputStream())); do { List<TaskHelpRE> items = page.getItems(); writeTaskHelperREList(write, items); // get next page page = friendHelperService.getTasKUserPagination( page.getCurrentPage() * page.getPageSize(), page.getPageSize()); } while (page.getCurrentPage() < page.getPages()); } catch (IOException e) { throw e; } finally { try { if (write != null) { write.flush(); write.close(); } } catch (IOException e) { throw e; } } }