1.查询并返回结果list集合
private List<TbTaxOrder> tbTaxOrderList = null;
@RestController @RequestMapping("/core/order") public class TbTaxOrderController { public static final Logger LOGGER = Logger.getLogger("TbTaxOrderController"); @Autowired private ITbTaxOrderService tbTaxOrderService; @Autowired private ITbTaxOilStationService stationService; private List<TbTaxOrder> tbTaxOrderList = null; /** * 根据取票方式和取票状态查询 * @param params * @return */ @RequestMapping(value = "/getByMethodAndStatus", method = RequestMethod.POST) public ResponseVO getByReceiveMethodAndOrderStatus(@RequestBody Map<String, Object> params) { try{ String receiveMethod = (String) params.get("receiveMethod"); String orderStatus = (String) params.get("orderStatus"); String stationStaffId = (String) params.get("stationStaffId"); if(StringUtil.isNotEmpty(orderStatus)){ String[] list = orderStatus.split(","); params.put("list",list); } if (StringUtil.isEmpty(receiveMethod) || StringUtil.isEmpty(stationStaffId)) { return ResultUtil.error("receiveMethod || stationStaffId 为空"); } tbTaxOrderList = tbTaxOrderService.getByReceiveMethodAndOrderStatus(params); return ResultUtil.success(tbTaxOrderList); }catch (Exception e){ e.printStackTrace(); if(e instanceof TaxException){ return ResultUtil.error(e.getMessage()); } return ResultUtil.error(); } } /** * 导出开票记录到excel * @return */ @RequestMapping(value = "/DownLoadExcel", method = RequestMethod.POST) public ResponseVO DownLoadExcel() { try{ //格式化时间 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //1、创建工作簿 Workbook wb = new XSSFWorkbook(); //1.1、设置表格的格式----居中 CellStyle cs = wb.createCellStyle(); // cs.setAlignment(HorizontalAlignment.CENTER); //2.1、创建工作表 Sheet sheet = wb.createSheet("Excel download"); //2.2、合并单元格 // sheet.addMergedRegion(new CellRangeAddress(4, 8, 5, 9)); //3.1、创建行----表头行 Row row = sheet.createRow(0); //4、创建格 Cell cell = row.createCell(0); cell.setCellValue("油卡号"); cell.setCellStyle(cs); cell = row.createCell(1); cell.setCellValue("油卡手机号"); cell.setCellStyle(cs); cell = row.createCell(2); cell.setCellValue("开票金额"); cell.setCellStyle(cs); cell = row.createCell(3); cell.setCellValue("截止时间"); cell.setCellStyle(cs); cell = row.createCell(4); cell.setCellValue("公司名称"); cell.setCellStyle(cs); cell = row.createCell(5); cell.setCellValue("开票申请时间"); cell.setCellStyle(cs); cell = row.createCell(6); cell.setCellValue("取票状态"); cell.setCellStyle(cs); cell = row.createCell(7); cell.setCellValue("取票方式"); cell.setCellStyle(cs); //5、写入实体数据 if(null != tbTaxOrderList && tbTaxOrderList.size() > 0){ for (int i = 0; i < tbTaxOrderList.size(); i++) { //3.2、创建行----内容行 row = sheet.createRow(i+1); TbTaxOrder order = (TbTaxOrder)tbTaxOrderList.get(i); //第几行第几格 第一行第一格为“code” row.createCell(0).setCellValue(order.getCardCode()); row.createCell(1).setCellValue(order.getBindPhone()); if(null != order.getBillAmount()){ row.createCell(2).setCellValue(order.getBillAmount().toString()); }else{ row.createCell(2).setCellValue(""); } if(null != order.getEndDate()){ String endDate = formatter.format(order.getEndDate()); row.createCell(3).setCellValue(endDate); }else{ row.createCell(3).setCellValue(order.getEndDate()); } row.createCell(4).setCellValue(order.getCompany()); String insertDate = formatter.format(order.getInsertDate()); row.createCell(5).setCellValue(insertDate); if("1".toString().equals(order.getReceiveMethod())){ row.createCell(6).setCellValue("未办理"); }else if("2".toString().equals(order.getReceiveMethod())){ row.createCell(6).setCellValue("开票中"); }else if("3".toString().equals(order.getReceiveMethod())){ row.createCell(6).setCellValue("开票完成"); }else if("4".toString().equals(order.getReceiveMethod())){ row.createCell(6).setCellValue("开票请求驳回"); }else { row.createCell(6).setCellValue("已邮寄 或 已自提"); } if("1".toString().equals(order.getReceiveMethod())){ row.createCell(7).setCellValue("默认不选择"); }else if("12".toString().equals(order.getReceiveMethod())){ row.createCell(7).setCellValue("场站自取"); }else{ row.createCell(7).setCellValue("邮寄"); } } //6、将文件储存到指定位置 try { FileOutputStream fout = new FileOutputStream("D:\\" + new Date().getTime() + ".xlsx"); wb.write(fout); fout.close(); return ResultUtil.success("导出完成"); } catch (IOException e) { e.printStackTrace(); return ResultUtil.error("导出失败"); } }else{ return ResultUtil.error("tbTaxOrderList 不能为空"); } }catch (Exception e){ e.printStackTrace(); if(e instanceof TaxException){ return ResultUtil.error(e.getMessage()); } return ResultUtil.error(); } } }