Recently wrote a business, use some of the more useful tools to record.
List <RobotCard> robotCardList = null; IF (. BizRouteEnum.ROUTE_1.getRouteCode () the equals (param.getExportModel ())) {// conditional derived. 1, or a given data lead RobotCard robotCardParam = BeanUtil.toBean (map, RobotCard.class); robotCardList = this.searchList (robotCardParam); } the else { List <Long> IDS = param.getIds (); RobotAssert.notNull (IDS, "select the data to be exported."); robotCardList = the this. selectBatchIds (IDS); } RobotAssert.notNull (robotCardList, "no valid data."); the ArrayList <the Map <String, Object >> = new new rows the ArrayList <> (); robotCardList.forEach (RC -> { the Map <String, Object> a LinkedHashMap new new COL = <> (); col.put ( "No", rc.getId ().toString()); col.put ( "amount", rc.getCardAmount()); col.put("密码", rc.getPayPasswd()); rows.add(col); }); ExcelWriter excelWriter = ExcelUtil.getWriter(); excelWriter.setColumnWidth(0, 30); excelWriter.write(rows); ByteArrayOutputStream baos = new ByteArrayOutputStream(); excelWriter.flush(baos); excelWriter.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(bos, Charset.defaultCharset()); //添加xls try { jodd.io.ZipUtil.addToZip(zos, baos.toByteArray(), "制卡数据.xls", "制卡数据"); } catch (Exception e1) { LOGGER.error ( "failed file compression.", E1); } robotCardList.forEach (Card -> { // produce two-dimensional code QrConfig config = new new QrConfig (300, 300); config.setCharset (Charset.forName ( "UTF -8 ")); String CardID = card.getId () toString ();. byte [] = Data QrCodeUtil.generatePng (CardID, config); // compressing the try { jodd.io.ZipUtil.addToZip (ZOS, Data, cardId.concat (CommonConstant.PNG), CardID); } the catch (Exception E) { LOGGER.error ( "file compression failure.", E); } }); the try { zos.finish (); zos.close () ; } the catch (Exception E) { LOGGER.error ( "compressed stream failed to close.", e); } // upload ByteArrayInputStream in = new ByteArrayInputStream (bos.toByteArray ( )); String url = oSSClientUtil.putObjectForInputStream( OssConstant.PAYMENT_TEMP.concat(DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)).concat(CommonConstant.PNG), in);