| | |
| | | return R.fail("未查询到用户"); |
| | | } |
| | | |
| | | @ApiOperation(value = "excel导出-活动签到居民志愿者") |
| | | @PostMapping("regist/export/new") |
| | | public R activityExportRegistNew(@RequestBody ComActActRegistVO comActActRegistVO) { |
| | | String name = "活动签到导出数据.xlsx"; |
| | | String ftpUrl = "/mnt/data/web/excel/"; |
| | | R r = communityService.getRegistLists(comActActRegistVO); |
| | | if (R.isOk(r)) { |
| | | List<ComActActRegistExcelNewVO> excelVOS = |
| | | JSONArray.parseArray(JSONArray.toJSONString(r.getData()), ComActActRegistExcelNewVO.class); |
| | | try { |
| | | SFTPUtil sftp = new SFTPUtil(userName, password, host, port); |
| | | sftp.login(); |
| | | boolean existDir = sftp.isExistDir(ftpUrl + name); |
| | | if (!existDir) { |
| | | String property = System.getProperty("user.dir"); |
| | | String fileName = property + File.separator + name; |
| | | // 这里 需要指定写用哪个class去写 |
| | | ExcelWriter excelWriter = null; |
| | | InputStream inputStream = null; |
| | | try { |
| | | excelWriter = EasyExcel.write(fileName, ComActActRegistExcelNewVO.class) |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
| | | .registerWriteHandler(new CustomSheetWriteHandler()).build(); |
| | | WriteSheet writeSheet = EasyExcel.writerSheet("活动签到导出数据").build(); |
| | | excelWriter.write(excelVOS, writeSheet); |
| | | excelWriter.finish(); |
| | | File file = new File(fileName); |
| | | inputStream = new FileInputStream(file); |
| | | sftp.uploadMore(ftpUrl, name, inputStream); |
| | | sftp.logout(); |
| | | inputStream.close(); |
| | | String absolutePath = file.getAbsolutePath(); |
| | | boolean delete = file.delete(); |
| | | log.info("删除excel【{}】结果【{}】", absolutePath, delete); |
| | | } finally { |
| | | // 千万别忘记finish 会帮忙关闭流 |
| | | if (inputStream != null) { |
| | | inputStream.close(); |
| | | } |
| | | if (excelWriter != null) { |
| | | excelWriter.finish(); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(excelUrl + name); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("文件传输失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | return R.fail("未查询到用户"); |
| | | } |
| | | |
| | | @ApiOperation(value = "社区活动数据统计", response = ComActActivityStatisticsVO.class) |
| | | @GetMapping("statistics") |
| | | public R activityStatistics(@RequestParam("activityId") Long activityId){ |