fei
6 天以前 1868fe69485d0d904bba24f2672a52a626ccf9f2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java
@@ -56,7 +56,7 @@
    @Autowired
    private IArchiveRecordsService iArchiveRecordsService;
    // 用于生成当天导出序号的方法
    private String generateDailySequence(String date) {
        // 使用synchronized确保线程安全
@@ -116,7 +116,7 @@
    /**
     * 将Excel指定子sheet转换为PDF并下载
     * @param response 响应对象
@@ -129,22 +129,22 @@
        // 设置响应头
        response.setContentType(MediaType.APPLICATION_PDF_VALUE);
        response.setHeader("Content-Disposition", "attachment; filename=sheet.pdf");
        try {
            // 使用Aspose.Cells读取Excel文件
            com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(excelPath);
            // 获取指定名称的子sheet
            com.aspose.cells.Worksheet sheet = wb.getWorksheets().get(sheetName);
            // 如果需要获取索引方式的子sheet,可以使用以下代码
            // com.aspose.cells.Worksheet sheet = wb.getWorksheets().get(0); // 获取第一个sheet
            // 创建一个新的Workbook,只包含指定的sheet
            com.aspose.cells.Workbook newWorkbook = new com.aspose.cells.Workbook();
            newWorkbook.getWorksheets().clear();
            newWorkbook.getWorksheets().addCopy(sheet.getName());
            // 将Excel转换为PDF字节数组
            java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
            newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF);
@@ -160,7 +160,7 @@
            throw e;
        }
    }
    /**
     * 将Excel所有子sheet转换为PDF并打包下载
     * @param response 响应对象
@@ -172,33 +172,33 @@
        // 设置响应头
        response.setContentType("application/zip");
        response.setHeader("Content-Disposition", "attachment; filename=all_sheets.zip");
        try (ServletOutputStream os = response.getOutputStream();
             ZipOutputStream zos = new ZipOutputStream(os)) {
            // 使用Aspose.Cells读取Excel文件
            com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(excelPath);
            // 获取所有sheet
            com.aspose.cells.WorksheetCollection sheets = wb.getWorksheets();
            // 遍历所有sheet
            for (int i = 0; i < sheets.getCount(); i++) {
                com.aspose.cells.Worksheet sheet = sheets.get(i);
                String sheetName = sheet.getName();
                // 创建一个新的Workbook,只包含当前sheet
                com.aspose.cells.Workbook newWorkbook = new com.aspose.cells.Workbook();
                newWorkbook.getWorksheets().clear();
                newWorkbook.getWorksheets().addCopy(sheet.getName());
                // 创建临时字节输出流
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                // 将新的Workbook保存为PDF到临时流
                newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF);
                byte[] pdfBytes = baos.toByteArray();
                // 获取PDF总页数
                // 将PDF添加到ZIP文件
@@ -206,10 +206,10 @@
                zos.putNextEntry(entry);
                zos.write(pdfBytes);
                zos.closeEntry();
                System.out.println("Excel子sheet \"" + sheetName + "\" 转换为PDF成功");
            }
            System.out.println("Excel所有子sheet转换为PDF并打包成功");
        } catch (Exception e) {
            e.printStackTrace();
@@ -266,47 +266,47 @@
        }
        String inpath= "案卷封面.xls";
        long old = System.currentTimeMillis();
        // 设置响应头
        response.setContentType("application/pdf");
        response.setHeader("Content-Disposition", "attachment; filename=import_template.pdf");
        try {
            // 读取Excel文件
            com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(inpath);
            // 获取需要导出的sheet(索引从0开始)
            int targetSheetIndex = 1;
            com.aspose.cells.Worksheet targetSheet = wb.getWorksheets().get(targetSheetIndex);
            targetSheet.autoFitRows(true);
            System.out.println("当前sheet名称:" + targetSheet.getName());
            System.out.println("当前sheet索引:" + targetSheet.getIndex());
            // 隐藏所有其他工作表
            for (int i = 0; i < wb.getWorksheets().getCount(); i++) {
                if (i != targetSheetIndex) {
                    wb.getWorksheets().get(i).setVisible(false);
                }
            }
            // 设置活动工作表为目标工作表
            wb.getWorksheets().setActiveSheetIndex(targetSheetIndex);
            // 创建PDF保存选项
            com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions();
            // 设置页面类型为A4
            // 确保所有列在一页上
            pdfSaveOptions.setAllColumnsInOnePagePerSheet(true);
            // 设置打印页面类型为默认
            pdfSaveOptions.setCompliance(PdfCompliance.PDF_A_1_B); // 设置 PDF 兼容性标准
            // 直接将原始工作簿保存为PDF(只包含可见的工作表)
            wb.save(response.getOutputStream(), pdfSaveOptions);
            long now = System.currentTimeMillis();
            System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒");
        } catch (Exception e) {
@@ -314,7 +314,7 @@
            // 打印详细错误信息
            System.err.println("转换失败:" + e.getMessage());
            e.printStackTrace(System.err);
            // 返回错误信息
            response.reset();
            response.setContentType("text/plain;charset=utf-8");
@@ -416,7 +416,7 @@
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
            String formattedDate = date.format(formatter);
            System.out.println(formattedDate);
            // 生成当天导出序号
            String sequence = generateDailySequence(formattedDate);
            String fna = "GH" + formattedDate + sequence + "/";
@@ -528,24 +528,107 @@
                    }
                }
                //09-备考表.pdf
//                pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), ids[i]);
//                // 2. 压缩PDF到ZIP文件
//                // 添加PDF文件到ZIP
//                ZipEntry zipEntry4 = new ZipEntry(fna + adir +"/"+pdf09Path);
//                zos.putNextEntry(zipEntry4);
//
//                // 读取PDF文件内容并写入ZIP
//                try (FileInputStream fis = new FileInputStream(pdf09Path)) {
//                    byte[] buffer = new byte[1024];
//                    int len;
//                    while ((len = fis.read(buffer)) > 0) {
//                        zos.write(buffer, 0, len);
//                    }
//                }
                //09-备考表.pdf
                String pdf09Path = "09-备考表.pdf";
                //  pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), id);
                //拿到相关数据
                List<DocumentMaterialFileStyle> dmfs = documentMaterialsService.findFileStyleInfo(Math.toIntExact(ids[i]));
                LocalDate currentDate = LocalDate.now();
                String cdt = currentDate.getYear()+"年"+currentDate.getMonthValue()+"月"+currentDate.getDayOfMonth()+"日";
                pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), ids[i]);
                // 2. 压缩PDF到ZIP文件
                // 添加PDF文件到ZIP
                ZipEntry zipEntry4 = new ZipEntry(fna + adir +"/"+pdf09Path);
                zos.putNextEntry(zipEntry4);
                // 读取PDF文件内容并写入ZIP
                try (FileInputStream fis = new FileInputStream(pdf09Path)) {
                    byte[] buffer = new byte[1024];
                    int len;
                    while ((len = fis.read(buffer)) > 0) {
                        zos.write(buffer, 0, len);
                HashMap<String, Object> hs = new HashMap<String, Object>();
                int allPages = 0;
                int texPages = 0;
                int picPages = 0;
                int patPages = 0;
                if(!dmfs.isEmpty())
                {
                    for(DocumentMaterialFileStyle documentMaterialFileStyle:dmfs)
                    {
                        if(documentMaterialFileStyle.getFileStyle().equals("文字材料"))
                            texPages = documentMaterialFileStyle.getCnt();
                        if(documentMaterialFileStyle.getFileStyle().equals("图样材料"))
                            patPages = documentMaterialFileStyle.getCnt();
                        if(documentMaterialFileStyle.getFileStyle().equals("照片材料"))
                            picPages = documentMaterialFileStyle.getCnt();
                    }
                }
                allPages = texPages + picPages + patPages;
                hs.put("pages", allPages);
                hs.put("patPages", patPages);
                hs.put("picPages", picPages);
                hs.put("texPages", texPages);
                hs.put("volumeNumber", aIV.getRecordId());
                hs.put("time", cdt);
                if (!getLicense()) {
                    System.out.println("没有相关证书!");
                }
                try {
                    // 获取 Word 模板所在路径
                    String filepath = "09-备考表.docx";
                    // 通过 XWPFTemplate 编译文件并渲染数据到模板中
                    XWPFTemplate template = XWPFTemplate.compile(filepath).render(hs
                    );
                    String renderedDocPath = "rendered_output.docx";
                    File renderedFile = new File(renderedDocPath);
                    try {
                        // 将完成数据渲染的文档写出
                        template.writeAndClose(new FileOutputStream(renderedFile));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    com.aspose.words.Document doc = new com.aspose.words.Document("rendered_output.docx");
                    // 创建临时字节输出流
                    ByteArrayOutputStream baobk = new ByteArrayOutputStream();
                    // 将Word文档转换为PDF字节数组
                    doc.save(baobk, com.aspose.words.SaveFormat.PDF);//ȫ��֧��DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF �໥ת��
                   ZipEntry zipEntry4 = new ZipEntry(fna + adir +"/"+pdf09Path);
                zos.putNextEntry(zipEntry4);
                    baobk.writeTo(zos);
                } catch (Exception e) {
                    e.printStackTrace();
                }
             //   com.aspose.words.Document doc = new com.aspose.words.Document("09-备考表.docx");
                //excel 卷内封面导出zip
                ZipEntry entryiv = new ZipEntry(fna + adir +"/"+"案卷封面" + ".xls");
@@ -867,23 +950,30 @@
            String cdt = currentDate.getYear()+"年"+currentDate.getMonthValue()+"月"+currentDate.getDayOfMonth()+"日";
            HashMap<String, Object> hs = new HashMap<String, Object>();
            if(dmfs.isEmpty())
            int allPages = 0;
            int texPages = 0;
            int picPages = 0;
            int patPages = 0;
            if(!dmfs.isEmpty())
            {
                //全部数据值为0
                hs.put("pages", 0);
                hs.put("volumeNumber", aIV.getRecordId());
                hs.put("time", cdt);
                for(DocumentMaterialFileStyle documentMaterialFileStyle:dmfs)
                {
                    if(documentMaterialFileStyle.getFileStyle().equals("文字材料"))
                        texPages = documentMaterialFileStyle.getCnt();
                    if(documentMaterialFileStyle.getFileStyle().equals("图样材料"))
                        patPages = documentMaterialFileStyle.getCnt();
                    if(documentMaterialFileStyle.getFileStyle().equals("照片材料"))
                        picPages = documentMaterialFileStyle.getCnt();
                }
            }
            else {
                int pcc = dmfs.size()<=1?0: dmfs.get(1).getCnt();
                int oth = dmfs.size()<=2?0: dmfs.get(2).getCnt();
                int allCnt = dmfs.get(0).getCnt() + pcc + oth;
                hs.put("pages", allCnt);
                hs.put("volumeNumber", aIV.getRecordId());
                hs.put("time", cdt);
            allPages = texPages + picPages + patPages;
            hs.put("pages", allPages);
            hs.put("patPages", patPages);
            hs.put("picPages", picPages);
            hs.put("texPages", texPages);
            hs.put("volumeNumber", aIV.getRecordId());
            hs.put("time", cdt);
            }
            if (!getLicense()) {
                System.out.println("没有相关证书!");
            }
@@ -1169,25 +1259,26 @@
                    res = false;
                }
                //得到文件名frontCompWithZore(4, dc.get)+
                String fname = frontCompWithZore(4, dc.getFileNumber().intValue())+"-"+dc.getTitle()+"-"+frontCompWithZore(4,dc.getPageNumber().intValue())+"."
                        +dc.getUrl().split("\\.")[1];
                if(dc.getStage().equals("01-申请材料"))
                    zos.putNextEntry(new ZipEntry("01-申请材料/"+fname));
                else if(dc.getStage().equals("02-办案过程材料"))
                    zos.putNextEntry(new ZipEntry("02-办案过程材料/"+fname));
                else if(dc.getStage().equals("03-结论性文件"))
                    zos.putNextEntry(new ZipEntry("03-结论性文件/"+fname));
                else if(dc.getStage().equals("04-其他材料")) {
                    zos.putNextEntry(new ZipEntry("04-其他材料/" + fname));
                String fname = "";
                if(dc.getFileNumber()!=null&&dc.getPageNumber()!=null) {
                    fname = frontCompWithZore(4, dc.getFileNumber().intValue()) + "-" + dc.getTitle() + "-" + frontCompWithZore(4, dc.getPageNumber().intValue()) + "."
                            + dc.getUrl().split("\\.")[1];
                    if (dc.getStage().equals("01-申请材料"))
                        zos.putNextEntry(new ZipEntry("01-申请材料/" + fname));
                    else if (dc.getStage().equals("02-办案过程材料"))
                        zos.putNextEntry(new ZipEntry("02-办案过程材料/" + fname));
                    else if (dc.getStage().equals("03-结论性文件"))
                        zos.putNextEntry(new ZipEntry("03-结论性文件/" + fname));
                    else if (dc.getStage().equals("04-其他材料")) {
                        zos.putNextEntry(new ZipEntry("04-其他材料/" + fname));
                    } else if (dc.getStage().equals("05-档案变更材料"))
                        zos.putNextEntry(new ZipEntry("05-档案变更材料/" + fname));
                    else if (dc.getStage().equals("06-业务数据"))
                        zos.putNextEntry(new ZipEntry("06-业务数据/" + fname));
                    else
                        zos.putNextEntry(new ZipEntry(fname));
                }
                else if(dc.getStage().equals("05-档案变更材料"))
                    zos.putNextEntry(new ZipEntry("05-档案变更材料/"+fname));
                else if(dc.getStage().equals("06-业务数据"))
                    zos.putNextEntry(new ZipEntry("06-业务数据/"+fname));
                else
                    zos.putNextEntry(new ZipEntry(fname));
                int len;
                FileInputStream in = new FileInputStream(tempFile);