1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| @GetMapping("/export") @SystemLog(businessName = "导出评论数据") @ApiOperation(value = "导出评论数据", notes = "导出评论数据") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页号", dataType = "int", paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "int", paramType = "query"), @ApiImplicitParam(name = "keywords", value = "搜索关键字", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "type", value = "评论类型", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "status", value = "审核状态", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "articleId", value = "文章ID", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "string", paramType = "query") }) public void exportComment(Integer pageNum, Integer pageSize, @Valid CommentListDto commentListDto, HttpServletResponse response) { try { ResponseResult result = adminCommentService.exportComment(pageNum, pageSize, commentListDto); if (result.getCode() != 200 || result.getData() == null) { throw new RuntimeException("获取导出数据失败"); } @SuppressWarnings("unchecked") List<CommentExportVo> exportData = (List<CommentExportVo>) result.getData(); if (exportData.isEmpty()) { throw new RuntimeException("没有可导出的数据"); } String fileName = "评论数据_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); ExcelExportUtil.exportExcel(response, exportData, CommentExportVo.class, fileName, "评论数据"); } catch (Exception e) { e.printStackTrace(); if (!response.isCommitted()) { try { response.reset(); response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); ResponseResult result = ResponseResult.errorResult( AppHttpCodeEnum.SYSTEM_ERROR.getCode(), "导出失败: " + e.getMessage() ); WebUtils.renderString(response, JSON.toJSONString(result)); } catch (Exception ex) { ex.printStackTrace(); } } } }
|