| | |
| | | import com.estate.expert.admin.service.ReportService; |
| | | import com.estate.expert.admin.service.ReportTemplateService; |
| | | import com.estate.expert.admin.utils.WordToPdfConverter; |
| | | import com.estate.expert.admin.utils.wordtopdf.PdfUtils; |
| | | import com.estate.expert.admin.utils.wordtopdf.WordUtil; |
| | | import com.estate.expert.common.auth.IgnoreAuth; |
| | | import com.estate.expert.common.rpc.Result; |
| | | import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter; |
| | |
| | | import java.nio.file.Path; |
| | | import java.nio.file.StandardOpenOption; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Api(tags = "管理后台/统计/报告下载") |
| | | @Slf4j |
| | |
| | | } |
| | | |
| | | @Autowired |
| | | private WordToPdfConverter wordToPdfConverter; |
| | | private PdfUtils pdfUtils; |
| | | |
| | | |
| | | @ApiOperation("模糊评价报告PDF下载(新接口)- 通过Word链接转换") |
| | |
| | | public void fuzzyReportPdfNew(@ApiParam("Word文档URL") @RequestParam(value = "wordUrl") String wordUrl, |
| | | @ApiParam("文件名(可选)") @RequestParam(value = "fileName", required = false) String fileName, |
| | | HttpServletResponse response) throws Exception { |
| | | downloadPdfFromWordUrl(wordUrl, fileName, response); |
| | | |
| | | try { |
| | | wordToPdfConverter.convertUrlToPdf(wordUrl,"C:\\Users\\Admin\\Desktop\\test.pdf"); |
| | | String test = pdfUtils.test("1769239688785.docx"); |
| | | |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | |
| | | @ApiParam("报告模版ID") @RequestParam(value = "templateId") Integer templateId, |
| | | HttpServletResponse response) throws IOException { |
| | | downloadPdf(checkTaskId, templateId, response, "打分评价", false); |
| | | } |
| | | |
| | | @ApiOperation("获取报告图片列表") |
| | | @GetMapping("/getReportImages") |
| | | @ResponseBody |
| | | @IgnoreAuth |
| | | public Result<List<String>> getReportImages(@ApiParam("文件UUID") @RequestParam(value = "uuid") String uuid) { |
| | | try { |
| | | List<String> imageFiles = new ArrayList<>(); |
| | | Path imageDir = Path.of(REPORT_UPLOAD_DIR, "images").toAbsolutePath().normalize(); |
| | | |
| | | if (!Files.exists(imageDir)) { |
| | | return Result.success(imageFiles); |
| | | } |
| | | |
| | | // 查找所有匹配的图片文件 |
| | | try (var stream = Files.list(imageDir)) { |
| | | stream.filter(path -> { |
| | | String fileName = path.getFileName().toString(); |
| | | return fileName.startsWith(uuid + "_page_") && fileName.endsWith(".png"); |
| | | }) |
| | | .sorted((p1, p2) -> { |
| | | // 按页码排序 |
| | | String name1 = p1.getFileName().toString(); |
| | | String name2 = p2.getFileName().toString(); |
| | | int page1 = extractPageNumber(name1); |
| | | int page2 = extractPageNumber(name2); |
| | | return Integer.compare(page1, page2); |
| | | }) |
| | | .forEach(path -> imageFiles.add(path.getFileName().toString())); |
| | | } |
| | | |
| | | log.info("查询报告图片列表: uuid={}, 共{}张图片", uuid, imageFiles.size()); |
| | | return Result.success(imageFiles); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("查询报告图片列表失败: uuid={}", uuid, e); |
| | | return Result.error("查询图片列表失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("检查报告转换状态") |
| | |
| | | out.flush(); |
| | | |
| | | // 保存文件到服务器 |
| | | if(uuid!=null && !uuid.isEmpty()){ |
| | | saveFileToServer(docBytes, docName + ".docx",uuid); |
| | | } |
| | | // if(uuid!=null && !uuid.isEmpty()){ |
| | | // saveFileToServer(docBytes, docName + ".docx",uuid); |
| | | // } |
| | | } catch (Exception e) { |
| | | log.error("文档下载失败", e); |
| | | throw new IOException("文档下载失败: " + e.getMessage(), e); |