赞
踩
- /**
- * 导出-- 查看筛选条件下:查看当前活动抽奖名单
- * @param request
- * @param response
- * @throws Exception
- */
- @RequestMapping("/download_lottery_list")
- public synchronized void download_lottery_list(@RequestParam(required = false) Integer id,
- @RequestParam(required = false) String stationNo,
- @RequestParam(required = false) Integer isWin,
- HttpServletRequest request,
- HttpServletResponse response){
- HSSFWorkbook workbook = new HSSFWorkbook();
- String token = request.getParameter("REQUEST_USER_TOKEN");
- try {
- HSSFSheet sheet = workbook.createSheet("抽奖名单1");
- Wrapper<ActivityLottery> wrapper = new EntityWrapper<ActivityLottery>();
- wrapper.eq("activity_id",id);
- if(!StringUtils.isEmpty(stationNo)){
- wrapper.like("station_no",stationNo);
- }
- if(isWin!=null){
- wrapper.eq("is_win",isWin);
- }
- wrapper.orderBy("scan_time",false);
- //String :openId ;
- Map<String , ActivityUser> mapActivityUser = activityUserService.getActivityUserMap();
- //String :stationNo ;
- Map<String , ActivityStation> mapActivityStation = activityStationService.getActivityStationMap();
- List<ActivityLottery> activityLotteries = activityLotteryService.selectList(wrapper);
- if(StringUtils.isEmpty(token)) activityLotteries = new ArrayList<ActivityLottery>();
- if(!activityLotteries.isEmpty()){
- List<ActivityLotteryVo> activityLotteryVos = BeanUtil.copyListProperties(activityLotteries,ActivityLotteryVo::new);
- String fileName = "抽奖名单" + ".xls";//设置要导出的文件的名字
- String[] headers = { "是否中奖", "抽奖时间", "站主姓名", "站点编号", "站点地址","站主电话", "抽奖人姓名","手机号码","邮寄地址"};
- //headers表示excel表中第一行的表头
- HSSFRow row = sheet.createRow(0);
- //在excel表中添加表头
- for(int i=0;i<headers.length;i++){
- HSSFCell cell = row.createCell(i);
- HSSFRichTextString text = new HSSFRichTextString(headers[i]);
- cell.setCellValue(text);
- }
- int index = 2;//记录额外创建的sheet数量
- //在表中存放查询到的数据放入对应的列
- for(int i=0;i<activityLotteryVos.size();i++){
- HSSFRow row1 = sheet.createRow((i + 1) - ((index-2) * 50000));
- if ((i + 1) % 50000 == 0) {
- sheet = workbook.createSheet("抽奖名单" + index);
- row = sheet.createRow(0);
- //在excel表中添加表头
- for(int j=0;j<headers.length;j++){
- HSSFCell cell = row.createCell(j);
- HSSFRichTextString text = new HSSFRichTextString(headers[j]);
- cell.setCellValue(text);
- }
- index++;
- }
- ActivityUser activityUser = mapActivityUser.get(activityLotteryVos.get(i).getOpenId());
- ActivityStation activityStation = mapActivityStation.get(activityLotteryVos.get(i).getStationNo());
- if(activityUser!=null){
- activityLotteryVos.get(i).setName(activityUser.getName());
- activityLotteryVos.get(i).setUserAddress(activityUser.getAddress());
- activityLotteryVos.get(i).setPhone(activityUser.getPhone());
- }
- if(activityStation!=null){
- activityLotteryVos.get(i).setOwner(activityStation.getOwner());
- activityLotteryVos.get(i).setStationAddress(activityStation.getAddress());
- activityLotteryVos.get(i).setStationPhone(activityStation.getStationPhone());
- }
- row1.createCell(0).setCellValue(activityLotteryVos.get(i).getIsWin()==0?"否":"是");
- row1.createCell(1).setCellValue(DateUtils.formatTimesTampDate(activityLotteryVos.get(i).getScanTime()));
- row1.createCell(2).setCellValue(activityLotteryVos.get(i).getOwner());
- row1.createCell(3).setCellValue(activityLotteryVos.get(i).getStationNo());
- row1.createCell(4).setCellValue(activityLotteryVos.get(i).getStationAddress());
- row1.createCell(5).setCellValue(activityLotteryVos.get(i).getStationPhone());
- row1.createCell(6).setCellValue(activityLotteryVos.get(i).getName());
- row1.createCell(7).setCellValue(activityLotteryVos.get(i).getPhone());
- row1.createCell(8).setCellValue(activityLotteryVos.get(i).getUserAddress());
- }
- response.setContentType("application/octet-stream");
- fileName = URLEncoder.encode(fileName, "UTF-8");
- response.setHeader("Content-disposition", "attachment;filename=" + fileName);
- response.flushBuffer();
- workbook.write(response.getOutputStream());
- }else{
- Result result = new Result();
- try {
- result.setType(TypeEnum.FAIL.getCode());
- result.setTrue(false);
- result.setMessage("无权限");
- result.setCode(TypeEnum.noauthStatus.getCode());
- response.setStatus(403);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/json; charset=utf-8");
- response.getWriter().print(JSONObject.toJSONString(result));
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。