• wangxl's avatar
    1 · d320d334
    wangxl authored
    d320d334
TaskInfoToPDFUtil.java 62.5 KB
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
package com.yiboshi.science.utils;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import com.yiboshi.science.param.dto.*;

import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static com.yiboshi.science.utils.ProjectInfoToPDF.getCurrentOperatingSystem;

public class TaskInfoToPDFUtil {

    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    static SimpleDateFormat sdfM = new SimpleDateFormat("yyyy年MM月");

    /**
     * 生成项目合同书PDF
     *
     * @param dto 项目任务信息
     * @return PDF文件字节数组
     */
    public static byte[] createContractPdf(ComProjectTaskDTO dto) throws DocumentException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Document document = new Document(PageSize.A4, 54f, 54f, 72f, 72f);

        try {
            // 宋体
            BaseFont sfChinese = loadChineseFont("simsun.ttc");
            // 仿宋
            BaseFont fsChinese = loadChineseFont("simfang.ttf");

            PdfWriter writer = PdfWriter.getInstance(document, baos);

            // 添加添加页码水印事件处理器
            writer.setPageEvent(new WatermarkPageEvent("", fsChinese));
            document.open();

            // 首页
            firstPageInfo(document, dto, sfChinese, fsChinese);

            // 填写说明
            fillInInstructions(document, sfChinese, fsChinese);

            // 项目基本信息
            baseProjectInfo(document, dto, sfChinese, fsChinese);

            // 项目组成员
            projectMemberInfo(document, dto, sfChinese, fsChinese);

            // 项目主要实施内容和目标
            projectTargetInfo(document, dto, sfChinese, fsChinese);

            // 项目经费预算表
            projectBudgetInfo(document, dto, sfChinese, fsChinese);

            // 设备费—购置设备预算明细表
            projectDeviceInfo(document, dto, sfChinese, fsChinese);

            // 设备费—试制设备预算明细表
            projectManufactureInfo(document, dto, sfChinese, fsChinese);

            // 项目承担单位研究资金支出预算明细表
            projectUnitPaymentInfo(document, dto, sfChinese, fsChinese);

            // 项目实施阶段及任务
            projectStageGoalsInfo(document, dto, sfChinese, fsChinese);

            //项目课题设置
            projectSubInfo(document, dto, sfChinese, fsChinese);

        } finally {
            if (document != null && document.isOpen()) {
                document.close();
            }
        }

        return baos.toByteArray();
    }

    private static void firstPageInfo(Document document, ComProjectTaskDTO dto, BaseFont bfChinese, BaseFont fsChinese) throws DocumentException {
        Font normalFont = new Font(bfChinese, 16, Font.NORMAL);

        // 添加附件编号
        Paragraph attachment = new Paragraph("附件4", normalFont);
        attachment.setAlignment(Element.ALIGN_LEFT);
        document.add(attachment);
        document.add(new Paragraph("\n"));

        // 从DTO获取项目编号
        Paragraph projectNoPara = new Paragraph("项目编号:" + dto.getProjNo(), normalFont);
        projectNoPara.setAlignment(Element.ALIGN_LEFT);
        document.add(projectNoPara);
        document.add(new Paragraph("\n\n\n\n\n\n"));

        // 添加标题
        Font titleFont = new Font(bfChinese, 22, Font.BOLD);
        Paragraph title = new Paragraph("省级临床医学中心科研项目合同书", titleFont);
        title.setAlignment(Element.ALIGN_CENTER);
        document.add(title);
        document.add(new Paragraph("\n\n\n\n\n\n"));

        Font labelFont = new Font(fsChinese, 15, Font.NORMAL);
        // 创建表格
        PdfPTable table = new PdfPTable(5);
        table.setWidths(new float[]{70f, 15f, 15f, 50f, 210f});
        table.isLockedWidth();
        // 添加表格内容
        addTablePageCell(table, "项目名称:", null, dto.getProjName(), 4, labelFont);
        addTablePageCell(table, "项目下达单位(甲方):", 4, dto.getAppUnitName(), null, labelFont);
        addTablePageCell(table, "项目承担单位(乙方):", 4, dto.getAppUnitName(), null, labelFont);
        addTablePageCell(table, "项目负责人:", 2, dto.getAppPersonName(), 3, labelFont);
        addTablePageCell(table, "项目起止年限:", 3, sdf.format(dto.getStartDate()) + " 至 " + sdf.format(dto.getEndDate()), 2, labelFont);
        document.add(table);
    }

    private static void fillInInstructions(Document document, BaseFont bfChinese, BaseFont fsChinese) throws DocumentException {
        document.newPage();
        Paragraph instructionTitle = new Paragraph("填写说明", new Font(fsChinese, 16, Font.BOLD));
        instructionTitle.setAlignment(Element.ALIGN_CENTER);
        document.add(instructionTitle);
        // 添加填写说明内容
        String[] instructions = {
                "一、本合同由甲、乙两方共同签订。甲方系指省卫生健康委;乙方系指省级临床医学中心依托单位。",
                "二、本合同所列内容应实事求是填写,表达要明确、严谨。对填写不符合要求的合同书,或填报内容出现虚报夸大、不切实际的,甲方将退回项目承担单位修改。",
                "三、合同书规定的项目考核指标应根据省级临床医学中心科研项目建设要求,遵循明确、量化、可考核的原则,其中技术指标应明确项目完成时达到的关键技术参数及预期可以形成的发明专利、标准、新技术、新产品、新装置、论文、专著等的数量;经济指标应明确项目完成时产生的产值、销售收入、利税、技术及产品应用所形成的市场规模、效益等。",
                "五、项目实施阶段及任务要根据省级临床医学中心科研项目建设实施内容、主要任务和目标合理安排。各阶段的任务目标是项目年度(中期检查(评估)和安排项目结转经费的依据。",
                "六、项目自筹经费指项目承担单位自行筹措,在项目执行期能够落实的非政府财政经费。原则上自筹经费以项目起始时间后项目单位自筹投入的资金进行核算。",
                "七、“科技报告类型”,包括项目验收前撰写的全面描述研究过程和技术内容的最终科技报告、项目年度或中期检查时撰写的描述本年度研究过程和进展的年度技术进展报告以及在项目实施过程中撰写的包含科研活动细节及基础数据的专题科技报告。科技报告“公开类别及时限”分为公开或延期公开,内容需要发表论文、申请专利、出版专著或涉及技术诀窍的,可标注为延期公开需要发表论文的,延期公开时限原则上在2年(含2年)以内;需要申请专利、出版专著的,延期公开时限原则上在3年(含3年)以内;涉及技术诀窍的,延期公开时限原则上在5年(含5年)以内(涉密项目科技报告按照有关规定管理)",
                "八、省财政资金支出的预算计划应按照国家及省相关规定执行。重大、重点项目的预算计划应吸纳经费评审时提出的调整意见。",
        };
        Font contentFont = new Font(bfChinese, 16, Font.NORMAL);
        for (String instruction : instructions) {
            Paragraph para = new Paragraph(instruction, contentFont);
            para.setAlignment(Element.ALIGN_LEFT);
            para.setFirstLineIndent(28f); // 设置首行缩进
            para.setLeading(30f); // 设置行间距
            document.add(para);
        }
    }

    private static void baseProjectInfo(Document document, ComProjectTaskDTO dto, BaseFont bfChinese, BaseFont fsChinese) throws DocumentException {
        document.newPage();
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        Font normalFont = new Font(bfChinese, 10.5f, Font.NORMAL);

        // 添加项目内容章节
        addSection(document, "一、项目基本情况", titleFont);

        // 创建表格
        PdfPTable table = new PdfPTable(8);
        table.setWidths(new float[]{80f, 80f, 30f, 60f, 60f, 80f, 30f, 100f});
        table.setWidthPercentage(100);
        // 设置表格默认边框宽度
//      table.getDefaultCell().setBorderWidth(0.1f);
        table.setSplitLate(false);          // 避免拆分时边框异
        table.isInline();

        // 添加表格内容
        addValueCell(table, "单位名称:", null, dto.getAppUnitName(), 7, normalFont, null, null, null);

        addValueCell(table, "注册单位类型", null, "医疗机构", 4, normalFont, null, null, null);
        addValueCell(table, "组织机构代码/统一社会信用代码", 2, dto.getOrganizationCode(), null, normalFont, null, null, null);

        addValueCell(table, "通讯地址", null, dto.getUnitAddress(), 7, normalFont, null, null, null);

        addValueCell(table, "注册所在地", null, dto.getRegisteredAddress(), 2, normalFont, null, null, null);
        addValueCell(table, "邮编", null, dto.getPostCode(), null, normalFont, null, null, null);
        addValueCell(table, "法定代表人", null, dto.getLegalPerson(), 2, normalFont, null, null, null);

        addCell(table, "职工总数 " + dto.getWorkCount() + " (人)", 2, null, normalFont, null, null, null);
        addCell(table, "其中专科以上人员 " + dto.getSpecializedPersonnel() + " (人)", 4, null, normalFont, null, null, null);
        addCell(table, "研究开发人员 " + dto.getResearchPersonnel() + " (人)", 2, null, normalFont, null, null, null);

        addValueCell(table, "开户银行", null, dto.getDepositBank(), 4, normalFont, null, null, null);
        addValueCell(table, "银行账号", null, dto.getBankAccount(), 2, normalFont, null, null, null);

        addValueCell(table, "开户银行地址", null, dto.getDepositBankAddress(), 4, normalFont, null, null, null);
        addValueCell(table, "银行联行号", null, dto.getInterbankNumber(), 2, normalFont, null, null, null);
        document.add(table);


        // 添加项目内容章节
        addSection(document, "二、项目基本情况", titleFont);
        // 创建表格
        PdfPTable projTable = new PdfPTable(10);
        projTable.setWidths(new float[]{40f, 80f, 60f, 90f, 20f, 20f, 100f, 80f, 20f, 60f});
        projTable.setWidthPercentage(100);
        // 设置表格默认边框宽度
        projTable.getDefaultCell().setBorderWidth(0.5f);

        addValueCell(projTable, "项目编号:", 2, dto.getProjNo(), 8, normalFont, null, null, null);

        addValueCell(projTable, "项目名称", 2, dto.getProjName(), 8, normalFont, null, null, null);

        addValueCell(projTable, "所属我省重点领域", 2, dto.getKeyAreas(), 8, normalFont, null, null, null);

        addValueCell(projTable, "项目开始时间", 2, sdf.format(dto.getStartDate()), 2, normalFont, null, null, null);
        addValueCell(projTable, "项目结束时间", 3, sdf.format(dto.getEndDate()), 3, normalFont, null, null, null);

        addValueCell(projTable, "项目负责人", 2, dto.getAppUnitName(), 2, normalFont, null, null, null);
        addValueCell(projTable, "联系电话", 3, dto.getMobile(), 3, normalFont, null, null, null);

        addValueCell(projTable, "项目联系人姓名", 2, dto.getLinkName(), 2, normalFont, null, null, null);
        addValueCell(projTable, "联系人电话", 3, dto.getLinkMobile(), 3, normalFont, null, null, null);

        addValueCell(projTable, "传真", 2, dto.getLinkFax(), 2, normalFont, null, null, null);
        addValueCell(projTable, "电子邮箱", 3, dto.getLinkEmail(), 3, normalFont, null, null, null);

        addValueCell(projTable, "项目总经费(万元)", 2, Objects.nonNull(dto.getTotalFunding()) ? dto.getTotalFunding().toString() : "", 2, normalFont, null, null, null);
        addValueCell(projTable, "财政经费(万元)", 2, Objects.nonNull(dto.getGovFunding()) ? dto.getGovFunding().toString() : "", null, normalFont, null, null, null);
        addValueCell(projTable, "自筹经费(万元)", null, Objects.nonNull(dto.getSelfFunding()) ? dto.getSelfFunding().toString() : "", 2, normalFont, null, null, null);

        addValueCell(projTable, "是否科技报告:", 2, dto.getIsTechnologyReport().equals(1) ? "是" : "否", 8, normalFont, null, null, null);

        addValueCell(projTable, "科技报告类型:", 2, "", 8, normalFont, null, null, null);

        addCell(projTable, "项目主要参与单位及分工", 10, null, normalFont, null, null, null);

        addCell(projTable, "序号", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(projTable, "单位名称", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(projTable, "单位地址", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(projTable, "组织机构代码/统一社会信用代码", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(projTable, "分 工", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(projTable, "签字", null, null, normalFont, null, null, Element.ALIGN_CENTER);

        for (int i = dto.getCooperativeUnits() != null ? dto.getCooperativeUnits().size() : 0; i < 2; i++) {
            if (dto.getCooperativeUnits() == null) {
                List<ComProjectCooperativeUnitsDTO> list = new ArrayList<>();
                dto.setCooperativeUnits(list);
            }
            dto.getCooperativeUnits().add(new ComProjectCooperativeUnitsDTO());
        }
        for (int i = 0; i < dto.getCooperativeUnits().size(); i++) {
            addCell(projTable, String.valueOf(i + 1), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(projTable, dto.getCooperativeUnits().get(i).getUnitName(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(projTable, dto.getCooperativeUnits().get(i).getUnitAddress(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(projTable, dto.getCooperativeUnits().get(i).getOrganizationCode(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(projTable, dto.getCooperativeUnits().get(i).getProjectWork(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(projTable, "", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        }
        document.add(projTable);

    }

    private static void projectMemberInfo(Document document, ComProjectTaskDTO dto, BaseFont bfChinese, BaseFont fsChinese) throws DocumentException {
        // 添加横向页面
        document.setPageSize(PageSize.A4.rotate());
        document.newPage();
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        Font normalFont = new Font(bfChinese, 10.5f, Font.NORMAL);

        // 添加项目内容章节
        addSection(document, "三、项目人员情况", titleFont);

        // 创建表格
        PdfPTable table = new PdfPTable(16);
        table.setWidths(new float[]{35f, 45f, 20f, 30f, 15f, 15f, 50f, 15f, 15f, 30f, 50f, 30f, 15f, 35f, 5f, 30f});
        table.setWidthPercentage(100);
        // 设置表格默认边框宽度
        table.getDefaultCell().setBorderWidth(0.5f);

        PdfPCell titleCell = new PdfPCell(new Phrase("项目负责人", new Font(bfChinese, 10.5f, Font.BOLD)));
        titleCell.setRowspan(5);
        titleCell.setColspan(2);// 合并6行
        titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        titleCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        titleCell.setMinimumHeight(25.5f); // 调整高度以适应内容
        table.addCell(titleCell);

        // 添加表格内容
        addValueCell(table, "姓名", 3, dto.getAppPersonName(), 3, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "性别", 2, dto.getSex(), 2, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "出生日期", 2, Objects.nonNull(dto.getBirthday()) ? sdf.format(dto.getBirthday()) : "", 2, normalFont, null, null, Element.ALIGN_CENTER);

        addValueCell(table, "证件类型", 3, "身份证", 3, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "证件号码", 2, dto.getCertId(), 2, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "民族", 2, dto.getNationName(), 2, normalFont, null, null, Element.ALIGN_CENTER);

        addValueCell(table, "职称", 3, dto.getTitleName(), 3, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "从事专业", 2, dto.getSpecName(), 2, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "项目分工", 2, dto.getProjWork(), 2, normalFont, null, null, Element.ALIGN_CENTER);

        addValueCell(table, "学位", 3, dto.getDegreeName(), 3, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "职务", 2, dto.getDutyName(), 2, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "传真", 2, dto.getFax(), 2, normalFont, null, null, Element.ALIGN_CENTER);

        addValueCell(table, "手机", 3, dto.getMobile(), 3, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "联系电话", 2, dto.getTelephone(), 2, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "电子邮箱", 2, dto.getEmail(), 2, normalFont, null, null, Element.ALIGN_CENTER);

        PdfPCell cell = new PdfPCell(new Phrase("项目负责人", new Font(bfChinese, 10.5f, Font.BOLD)));
        cell.setColspan(16);// 合并6行
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setMinimumHeight(25.5f); // 调整高度以适应内容
        table.addCell(cell);

        addCell(table, "姓名", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "出生日期", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "性别", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "职称", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "学位", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "工作单位", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "电话", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "电子邮箱", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "证件号码", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "项目分工", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "每年工作时间(月)", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "签字", null, null, normalFont, null, null, Element.ALIGN_CENTER);

        if (dto.getMembers() == null || dto.getMembers().size() < 4) {
            for (int i = dto.getMembers() != null ? dto.getMembers().size() : 0; i < 4; i++) {
                if (dto.getMembers() == null) {
                    List<ComProjectMembersDTO> list = new ArrayList<>();
                    dto.setMembers(list);
                }
                dto.getMembers().add(new ComProjectMembersDTO());
            }
        }
        for (int i = 0; i < dto.getMembers().size(); i++) {
            ComProjectMembersDTO e = dto.getMembers().get(i);
            addCell(table, e.getName(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, Objects.nonNull(e.getBirthday()) ? sdf.format(e.getBirthday()) : "", null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getSex(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getTitleName(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getDegreeName(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getWorkUnit(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getMobile(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getEmail(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getCertId(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getProjWork(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, Objects.nonNull(e.getForMonths()) ? e.getForMonths().toString() : "", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, "", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        }

        addValueCell(table, "项目组人数", 2, Objects.nonNull(dto.getMemCount()) ? dto.getMemCount().toString() : "0" + "人", null, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "高级", null, Objects.nonNull(dto.getMemHighCount()) ? dto.getMemHighCount().toString() : "0" + "人", 2, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "中级", null, Objects.nonNull(dto.getMemMiddleCount()) ? dto.getMemMiddleCount().toString() : "0" + "人", 2, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "初级", null, Objects.nonNull(dto.getMemLowCount()) ? dto.getMemLowCount().toString() : "0" + "人", null, normalFont, null, null, Element.ALIGN_CENTER);
        addValueCell(table, "其他", 2, 0 + "人", null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "--", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        document.add(table);
    }

    private static void projectTargetInfo(Document document, ComProjectTaskDTO dto, BaseFont bfChinese, BaseFont fsChinese) throws DocumentException {
        // 添加横向页面
        document.setPageSize(PageSize.A4);
        document.newPage();

        Font titleFont = new Font(bfChinese, 14f, Font.BOLD);
        Font normalFont = new Font(bfChinese, 14f, Font.NORMAL);

        // 添加项目内容章节
        addSection(document, "四、项目主要实施内容和目标", titleFont);

        // 创建表格
        PdfPTable table = new PdfPTable(1);
        table.setWidths(new float[]{100f});
        table.setWidthPercentage(100);
        // 设置表格默认边框宽度
        table.getDefaultCell().setBorderWidth(0.5f);

        addCell(table, "项目实施目标", null, null, titleFont, null, null, null);
        addTableContentCell(table, "", dto.getResearchContent(), null, normalFont, 200f);

        addCell(table, "项目考核指标", null, null, titleFont, null, null, null);
        addTableContentCell(table, "1、主要技术指标:", dto.getTechnologyTarget(), null, normalFont, 200f);

        addTableContentCell(table, "2、主要经济指标:", dto.getEconomyTarget(), null, normalFont, 200f);

        addTableContentCell(table, "3、项目实施中形成的示范基地、中试线、生产线及其规模等:", dto.getAchievementTarget(), null, normalFont, 200f);

        addTableContentCell(table, "4、科技报告考核指标", dto.getTechnologyReportsTarget(), null, normalFont, 200f);

        addTableContentCell(table, "5、其他应考核的指标:", dto.getOtherTarget(), null, normalFont, 200f);

        document.add(table);
    }

    private static void projectBudgetInfo(Document document, ComProjectTaskDTO dto, BaseFont bfChinese, BaseFont fsChinese) throws DocumentException {
        // 添加横向页面
        document.setPageSize(PageSize.A4);
        document.newPage();

        Font titleFont = new Font(bfChinese, 14f, Font.BOLD);
        Font normalFont = new Font(bfChinese, 14f, Font.NORMAL);

        // 添加项目内容章节
        addSection(document, "五、项目经费预算表", titleFont);

        Paragraph section = new Paragraph("金额单位:万元(保留两位小数)", new Font(bfChinese, 10.5f, Font.NORMAL));
        section.setSpacingBefore(15);
        section.setSpacingAfter(10);
        section.setAlignment(Element.ALIGN_RIGHT);
        document.add(section);

        // 创建表格
        PdfPTable table = new PdfPTable(8);
        table.setWidths(new float[]{160f, 80f, 20f, 80f, 20f, 80f, 20f, 80f});
        table.setWidthPercentage(100);
        // 设置表格默认边框宽度
        table.getDefaultCell().setBorderWidth(0.5f);

        addCell(table, "预算科目", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "总预算数", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "财政资金", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "自筹资金", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "备注", 2, null, normalFont, null, null, Element.ALIGN_CENTER);

        if (dto.getBudget() == null || dto.getBudget().size() < 23) {
            for (int i = dto.getBudget() != null ? dto.getBudget().size() : 0; i < 23; i++) {
                if (dto.getBudget() == null) {
                    List<ComProjectBudgetDTO> list = new ArrayList<>();
                    dto.setBudget(list);
                }
                dto.getBudget().add(new ComProjectBudgetDTO());
            }
        }
        for (int i = 0; i < dto.getBudget().size(); i++) {
            ComProjectBudgetDTO e = dto.getBudget().get(i);
            addCell(table, e.getBudgetName(), null, null, normalFont, null, null, null);
            addCell(table, e.getTotalBudget(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getApplyFunds(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getSelfFunds(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getTotalBudget(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        }

        addCell(table, "三、分年度用款计划", 8, null, titleFont, null, null, null);

        addCell(table, "年度", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "第一年", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "第二年", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "第三年", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "合计", null, null, normalFont, null, null, Element.ALIGN_CENTER);

        if (dto.getFundPlan() == null || dto.getFundPlan().size() < 3) {
            for (int i = dto.getFundPlan() != null ? dto.getFundPlan().size() : 0; i < 3; i++) {
                if (dto.getFundPlan() == null) {
                    List<ComProjectFundPlanDTO> list = new ArrayList<>();
                    dto.setFundPlan(list);
                }
                dto.getFundPlan().add(new ComProjectFundPlanDTO());
            }
        }
        for (int i = 0; i < dto.getFundPlan().size(); i++) {
            ComProjectFundPlanDTO e = dto.getFundPlan().get(i);
            addCell(table, e.getFundName(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getYearValue1(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getYearValue2(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getYearValue3(), 2, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getTotalAmount(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
        }
        document.add(table);
    }

    private static void projectDeviceInfo(Document document, ComProjectTaskDTO dto, BaseFont bfChinese, BaseFont fsChinese) throws DocumentException {
        // 添加横向页面
        document.setPageSize(PageSize.A4.rotate());
        document.newPage();

        Font titleFont = new Font(bfChinese, 14f, Font.BOLD);
        Font normalFont = new Font(bfChinese, 10.5f, Font.NORMAL);

        // 添加标题
        addSection(document, "设备费—购置设备预算明细表", titleFont);

        // 添加单位说明
        Paragraph unitDesc = new Paragraph("单位:万元(保留两位小数)", normalFont);
        unitDesc.setAlignment(Element.ALIGN_RIGHT);
        unitDesc.setSpacingAfter(10f);
        document.add(unitDesc);

        // 创建表格
        PdfPTable table = new PdfPTable(15);
        float[] columnWidths = {25f, 60f, 50f, 40f, 30f, 40f, 40f, 40f, 40f, 40f, 40f, 40f, 40f, 60f, 60f};
        table.setWidths(columnWidths);
        table.setWidthPercentage(100);

        addCell(table, "序号", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "设备名称", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "功能和技术指标", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "单价(万元/台套)", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "数量(台套)", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "金额", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "资金来源", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "购置单位", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "存放单位(地点)", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "购置设备类型", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "主要生产厂家及国别", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "规格型号", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "拟开放共享范围", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "购置必要性及对项目研究的作用和用途", null, 2, normalFont, null, null, Element.ALIGN_CENTER);

        addCell(table, "财政\n" + "资金", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "自筹\n" + "资金", null, null, normalFont, null, null, Element.ALIGN_CENTER);

        if (dto.getDeviceList() == null || dto.getDeviceList().size() < 2) {
            for (int i = dto.getDeviceList() != null ? dto.getDeviceList().size() : 0; i < 2; i++) {
                if (dto.getDeviceList() == null) {
                    List<ComProjectEquipmentDTO> list = new ArrayList<>();
                    dto.setDeviceList(list);
                }
                dto.getDeviceList().add(new ComProjectEquipmentDTO());
            }
        }

        int fiftyUpNumber = 0;
        int fiftyDownNumber = 0;
        int totalNumber = 0;

        BigDecimal fiftyUpAmount = new BigDecimal(0.0);
        BigDecimal fiftyDownAmount = new BigDecimal(0);
        BigDecimal totalAmount = new BigDecimal(0);

        for (int i = 0; i < dto.getDeviceList().size(); i++) {
            ComProjectEquipmentDTO e = dto.getDeviceList().get(i);
            if (Objects.nonNull(e.getQuantity()) && Objects.nonNull(e.getUnitPrice())) {
                int result = e.getUnitPrice().compareTo(new BigDecimal(5));
                if (result >= 0) {
                    fiftyUpNumber += e.getQuantity();
                    fiftyUpAmount = fiftyUpAmount.add(e.getUnitPrice().multiply(new BigDecimal(e.getQuantity())));
                } else {
                    fiftyDownNumber += e.getQuantity();
                    fiftyDownAmount = fiftyDownAmount.add(e.getUnitPrice().multiply(new BigDecimal(e.getQuantity())));
                }
                totalNumber += e.getQuantity();
                totalAmount = totalAmount.add(e.getUnitPrice().multiply(new BigDecimal(e.getQuantity())));
            }

            addCell(table, i + 1, null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getName(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getFunctionTarget(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getUnitPrice(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getQuantity(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getTotalBudget(), null, null, normalFont, null, null, Element.ALIGN_CENTER);

            addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);

            addCell(table, e.getBuyUnit(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getStorageLocation(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getEquipmentType(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getManufacturer(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getSpecificationType(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getSharedScope(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getUseFrom(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
        }
        addCell(table, "单价5万元以上购置设备合计", 3, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyUpNumber, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyUpAmount, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);

        addCell(table, "单价5万元以下购置设备合计", 3, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyDownNumber, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyDownAmount, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);

        addCell(table, "累  计", 3, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, totalNumber, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, totalAmount, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, '/', null, null, normalFont, null, null, Element.ALIGN_CENTER);

        document.add(table);
    }

    private static void projectManufactureInfo(Document document, ComProjectTaskDTO dto, BaseFont bfChinese, BaseFont fsChinese) throws DocumentException {
        // 添加横向页面
        document.setPageSize(PageSize.A4.rotate());
        document.newPage();

        Font titleFont = new Font(bfChinese, 14f, Font.BOLD);
        Font normalFont = new Font(bfChinese, 10.5f, Font.NORMAL);

        // 添加标题
        addSection(document, "设备费—试制设备预算明细表", titleFont);

        // 添加单位说明
        Paragraph unitDesc = new Paragraph("单位:万元(保留两位小数)", normalFont);
        unitDesc.setAlignment(Element.ALIGN_RIGHT);
        unitDesc.setSpacingAfter(10f);
        document.add(unitDesc);

        // 创建表格
        PdfPTable table = new PdfPTable(10);
        float[] columnWidths = {25f, 60f, 60f, 40f, 25f, 40f, 40f, 40f, 40f, 40f};
        table.setWidths(columnWidths);
        table.setWidthPercentage(100);

        addCell(table, "序号", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "设备名称", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "功能和技术指标", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "单价(万元/台套)", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "数量(台套)", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "金额", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "资金来源", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "试制单位", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "安置单位", null, 2, normalFont, null, null, Element.ALIGN_CENTER);

        addCell(table, "财政\n" + "资金", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "自筹\n" + "资金", null, null, normalFont, null, null, Element.ALIGN_CENTER);

        if (dto.getManufactureList() == null || dto.getManufactureList().size() < 2) {
            for (int i = dto.getManufactureList() != null ? dto.getManufactureList().size() : 0; i < 2; i++) {
                if (dto.getManufactureList() == null) {
                    List<ComProjectManufactureDTO> list = new ArrayList<>();
                    dto.setManufactureList(list);
                }
                dto.getManufactureList().add(new ComProjectManufactureDTO());
            }
        }

        int fiftyUpNumber = 0;
        BigDecimal fiftyUpAmount = new BigDecimal(0.0);
        BigDecimal fiftyUpGovFun = new BigDecimal(0.0);
        BigDecimal fiftyUpSelfFun = new BigDecimal(0.0);

        int fiftyDownNumber = 0;
        BigDecimal fiftyDownAmount = new BigDecimal(0.0);
        BigDecimal fiftyDownGovFun = new BigDecimal(0.0);
        BigDecimal fiftyDownSelfFun = new BigDecimal(0.0);

        int totalNumber = 0;
        BigDecimal totalAmount = new BigDecimal(0.0);
        BigDecimal totalGovFun = new BigDecimal(0.0);
        BigDecimal totalSelfFun = new BigDecimal(0.0);

        for (int i = 0; i < dto.getManufactureList().size(); i++) {
            ComProjectManufactureDTO e = dto.getManufactureList().get(i);
            if (Objects.nonNull(e.getUnitPrice())) {
                int result = e.getUnitPrice().compareTo(new BigDecimal(5));
                if (result >= 0) {
                    if (Objects.nonNull(e.getQuantity())) {
                        fiftyUpNumber += e.getQuantity();
                        fiftyUpAmount = fiftyUpAmount.add(e.getUnitPrice().multiply(new BigDecimal(e.getQuantity())));
                    }
                    if (Objects.nonNull(e.getFundAmount())) {
                        fiftyUpGovFun = fiftyUpGovFun.add(e.getFundAmount());
                    }
                    if (Objects.nonNull(e.getSelfAmount())) {
                        fiftyUpSelfFun = fiftyUpSelfFun.add(e.getSelfAmount());
                    }
                } else {
                    if (Objects.nonNull(e.getQuantity())) {
                        fiftyDownNumber += e.getQuantity();
                        fiftyDownAmount = fiftyDownAmount.add(e.getUnitPrice().multiply(new BigDecimal(e.getQuantity())));
                    }
                    if (Objects.nonNull(e.getFundAmount())) {
                        fiftyDownGovFun = fiftyDownGovFun.add(e.getFundAmount());
                    }
                    if (Objects.nonNull(e.getSelfAmount())) {
                        fiftyDownSelfFun = fiftyDownSelfFun.add(e.getSelfAmount());
                    }
                }
                if (Objects.nonNull(e.getQuantity())) {
                    totalNumber += e.getQuantity();
                    totalAmount = totalAmount.add(e.getUnitPrice().multiply(new BigDecimal(e.getQuantity())));
                }
                if (Objects.nonNull(e.getFundAmount())) {
                    totalGovFun = totalGovFun.add(e.getFundAmount());
                }
                if (Objects.nonNull(e.getSelfAmount())) {
                    totalSelfFun = totalSelfFun.add(e.getSelfAmount());
                }
            }
            addCell(table, i + 1, null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getName(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getFunctionTarget(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getUnitPrice(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getQuantity(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getTotalBudget(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getFundAmount(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getSelfAmount(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getManufactureUnit(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getStorageUnit(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
        }
        addCell(table, "单价5万元以上购置设备合计", 3, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyUpNumber, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyUpAmount, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyUpGovFun, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyUpSelfFun, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);

        addCell(table, "单价5万元以下购置设备合计", 3, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyDownNumber, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyDownAmount, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyDownGovFun, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, fiftyDownSelfFun, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);


        addCell(table, "累  计", 3, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, totalNumber, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, totalAmount, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, totalGovFun, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, totalSelfFun, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "/", null, null, normalFont, null, null, Element.ALIGN_CENTER);

        document.add(table);
    }

    private static void projectUnitPaymentInfo(Document document, ComProjectTaskDTO dto, BaseFont bfChinese, BaseFont fsChinese) throws DocumentException {
        // 添加横向页面
        document.setPageSize(PageSize.A4.rotate());
        document.newPage();

        Font titleFont = new Font(bfChinese, 14f, Font.BOLD);
        Font normalFont = new Font(bfChinese, 10.5f, Font.NORMAL);

        // 添加标题
        addSection(document, "项目承担单位研究资金支出预算明细表", titleFont);

        // 添加单位说明
        Paragraph unitDesc = new Paragraph("金额单位:万元", normalFont);
        unitDesc.setAlignment(Element.ALIGN_RIGHT);
        unitDesc.setSpacingAfter(10f);
        document.add(unitDesc);

        // 创建表格
        PdfPTable table = new PdfPTable(10);
        float[] columnWidths = {25f, 60f, 60f, 40f, 25f, 40f, 40f, 40f, 40f, 60f};
        table.setWidths(columnWidths);
        table.setWidthPercentage(100);

        addCell(table, "序号", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "单位名称", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "统一社会信用代码", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "单位类型", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "任务分工", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "研究任务负责人", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "合计", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "省级财政资金", 2, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "其他来源资金", null, 2, normalFont, null, null, Element.ALIGN_CENTER);


        addCell(table, "小计", null, null, normalFont, null, null, null);
        addCell(table, "其中:间接\n" + "费用", null, null, normalFont, null, null, null);

        if (dto.getUnitPayment() == null || dto.getUnitPayment().size() < 2) {
            for (int i = dto.getUnitPayment() != null ? dto.getUnitPayment().size() : 0; i < 2; i++) {
                if (dto.getUnitPayment() == null) {
                    List<ComProjectUnitPaymentDTO> list = new ArrayList<>();
                    dto.setUnitPayment(list);
                }
                dto.getUnitPayment().add(new ComProjectUnitPaymentDTO());
            }
        }

        BigDecimal totalAmount = new BigDecimal(0.0);
        BigDecimal totalFundAmount = new BigDecimal(0.0);
        BigDecimal totalIndirectFee = new BigDecimal(0.0);
        BigDecimal totalSelfAmount = new BigDecimal(0.0);

        for (int i = 0; i < dto.getUnitPayment().size(); i++) {
            ComProjectUnitPaymentDTO e = dto.getUnitPayment().get(i);
            if (Objects.nonNull(e.getTotalAmount())) {
                totalAmount = totalAmount.add(e.getTotalAmount());
            }
            if (Objects.nonNull(e.getFundAmount())) {
                totalFundAmount = totalFundAmount.add(e.getFundAmount());
            }
            if (Objects.nonNull(e.getIndirectFee())) {
                totalIndirectFee = totalIndirectFee.add(e.getIndirectFee());
            }
            if (Objects.nonNull(e.getSelfAmount())) {
                totalSelfAmount = totalSelfAmount.add(e.getSelfAmount());
            }
            addCell(table, i + 1, null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getUnitName(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getSocialCode(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getRoleName(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getTaskDivision(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getTaskLeader(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getTotalAmount(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getFundAmount(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getIndirectFee(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getSelfAmount(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
        }
        addCell(table, "累  计", 6, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, totalAmount, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, totalFundAmount, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, totalIndirectFee, null, null, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, totalSelfAmount, null, null, normalFont, null, null, Element.ALIGN_CENTER);

        document.add(table);
    }

    private static void projectStageGoalsInfo(Document document, ComProjectTaskDTO dto, BaseFont bfChinese, BaseFont fsChinese) throws DocumentException {
        document.setPageSize(PageSize.A4);
        document.newPage();

        Font titleFont = new Font(bfChinese, 14f, Font.BOLD);
        Font normalFont = new Font(bfChinese, 10.5f, Font.NORMAL);

        // 添加标题
        addSection(document, "六、项目实施阶段及任务", titleFont);
        // 创建表格
        PdfPTable table = new PdfPTable(3);
        table.setWidths(new float[]{30f, 150f, 320f});
        table.setWidthPercentage(100);

        // 添加表头
        addCell(table, "序号", null, null, normalFont, 30f, Element.ALIGN_CENTER, Element.ALIGN_CENTER);
        addCell(table, "时间", null, null, normalFont, 30f, Element.ALIGN_CENTER, Element.ALIGN_CENTER);
        addCell(table, "计划完成内容和关键节点目标", null, null, normalFont, 30f, Element.ALIGN_CENTER, Element.ALIGN_CENTER);

        if (dto.getStageGoals() == null || dto.getStageGoals().size() < 3) {
            for (int i = dto.getStageGoals() != null ? dto.getStageGoals().size() : 0; i < 3; i++) {
                if (dto.getStageGoals() == null) {
                    List<ComProjectStageGoalDTO> list = new ArrayList<>();
                    dto.setStageGoals(list);
                }
                dto.getStageGoals().add(new ComProjectStageGoalDTO());
            }
        }
        for (int i = 0; i < dto.getStageGoals().size(); i++) {
            ComProjectStageGoalDTO e = dto.getStageGoals().get(i);
            addCell(table, String.valueOf(i), null, null, normalFont, 120f, Element.ALIGN_CENTER, Element.ALIGN_CENTER);
            Paragraph timePara = new Paragraph();
            timePara.add(new Chunk("第" + numberTo(i + 1) + "阶段\n", normalFont));
            if (Objects.nonNull(e.getStartTime()) && Objects.nonNull(e.getEndTime()))
                timePara.add(new Chunk(sdfM.format(e.getStartTime()) + " 至 " + sdfM.format(e.getEndTime()), normalFont));
            else
                timePara.add(new Chunk("__年__月 至 __年__月", normalFont));
            timePara.setAlignment(Element.ALIGN_CENTER);

            PdfPCell timeCell = new PdfPCell(timePara);
            timeCell.setMinimumHeight(120f);
            timeCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            timeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(timeCell);

            addCell(table, e.getTarget(), null, null, normalFont, 120f, Element.ALIGN_CENTER, Element.ALIGN_CENTER);
        }
        document.add(table);
    }

    private static void projectSubInfo(Document document, ComProjectTaskDTO dto, BaseFont bfChinese, BaseFont fsChinese) throws DocumentException {

        Font titleFont = new Font(bfChinese, 14f, Font.BOLD);
        Font normalFont = new Font(bfChinese, 10.5f, Font.NORMAL);

        // 添加标题
        addSection(document, "七、项目课题设置", titleFont);

        // 创建表格
        PdfPTable table = new PdfPTable(7);
        float[] columnWidths = {25f, 60f, 60f, 40f, 25f, 40f, 40f};
        table.setWidths(columnWidths);
        table.setWidthPercentage(100);

        addCell(table, "序号", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "课题名称", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "承担单位", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "课题负责人", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "课题预算总经费", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "其中:省科技经费", null, 2, normalFont, null, null, Element.ALIGN_CENTER);
        addCell(table, "自筹经费", null, 2, normalFont, null, null, Element.ALIGN_CENTER);

        if (dto.getProjectSubList() == null || dto.getProjectSubList().size() < 3) {
            for (int i = dto.getProjectSubList() != null ? dto.getProjectSubList().size() : 0; i < 3; i++) {
                if (dto.getProjectSubList() == null) {
                    List<ComProjectSubDTO> list = new ArrayList<>();
                    dto.setProjectSubList(list);
                }
                dto.getProjectSubList().add(new ComProjectSubDTO());
            }
        }
        for (int i = 0; i < dto.getProjectSubList().size(); i++) {
            ComProjectSubDTO e = dto.getProjectSubList().get(i);
            addCell(table, i + 1, null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getProjName(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getUndertakingUnit(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getDirector(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getTotalBudget(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getGovBudget(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
            addCell(table, e.getSelfBudget(), null, null, normalFont, null, null, Element.ALIGN_CENTER);
        }
        document.add(table);
    }

    private static String numberTo(int number) {
        char[] cs = "零一二三四五六七八九".toCharArray();
        String temp = "";
        while (number > 0) {
            temp += cs[number % 10];
            number /= 10;
        }
        return temp;

    }

    /**
     * 水印页面事件
     */
    private static class WatermarkPageEvent extends PdfPageEventHelper {
        private String watermarkText;
        private BaseFont baseFont;

        public WatermarkPageEvent(String watermarkText, BaseFont baseFont) {
            this.watermarkText = watermarkText;
            this.baseFont = baseFont;
        }

        @Override
        public void onEndPage(PdfWriter writer, Document document) {
            try {
                PdfContentByte canvas = writer.getDirectContentUnder();
                Rectangle pageSize = document.getPageSize();
                float width = pageSize.getWidth();
                float height = pageSize.getHeight();

                // 设置水印字体
                canvas.saveState();
                canvas.beginText();
                canvas.setFontAndSize(baseFont, 30);  // 减小字体大小
                canvas.setGrayFill(0.9f);

                // 计算水印间距
                float xStep = width / 2;  // 水平间距
                float yStep = height / 3;  // 垂直间距

                // 在页面上添加多个水印
                for (float y = yStep / 2; y < height; y += yStep) {
                    for (float x = xStep / 2; x < width; x += xStep) {
                        canvas.showTextAligned(Element.ALIGN_CENTER,
                                watermarkText,
                                x,
                                y,
                                45);
                    }
                }

                canvas.endText();
                canvas.restoreState();

                // 添加页码
                PdfContentByte canvasOver = writer.getDirectContent();
                canvasOver.saveState();
                canvasOver.beginText();
                canvasOver.setFontAndSize(baseFont, 12);  // 设置页码字体大小
                canvasOver.setColorFill(BaseColor.BLACK);

                // 页码文本
                String text = String.format("- %d -", writer.getPageNumber());

                // 在页面底部居中添加页码
                canvasOver.showTextAligned(Element.ALIGN_CENTER,
                        text,
                        width / 2,    // 页面中心
                        15,          // 距离底部15单位,降低页码位置
                        0);          // 不旋转

                canvasOver.endText();
                canvasOver.restoreState();

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private static void addTablePageCell(PdfPTable table, String label, Integer labelColspan, String value, Integer valueColspan, Font font) {
        PdfPCell labelCell = new PdfPCell(new Phrase(label, font));
        // 设置标签单元格样式
        labelCell.setMinimumHeight(36f); // 增加行高
        labelCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        labelCell.setHorizontalAlignment(Element.ALIGN_LEFT); // 改为左对齐
        if (Objects.nonNull(labelColspan))
            labelCell.setColspan(labelColspan);
        labelCell.setBorder(Rectangle.NO_BORDER);
        table.addCell(labelCell);

        PdfPCell valueCell = new PdfPCell(new Phrase(value != null ? value : "", font));
        valueCell.setPadding(5f);
        valueCell.setMinimumHeight(36f); // 增加行高
        valueCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        valueCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        if (Objects.nonNull(valueColspan))
            valueCell.setColspan(valueColspan);
        // 只保留下边框
        valueCell.setBorder(Rectangle.BOTTOM);
        table.addCell(valueCell);
    }

    private static void addValueCell(PdfPTable table, String label, Integer labelColspan, String value, Integer valueColspan, Font font, Float height, Integer vertical, Integer horizontal) {
        addCell(table, label, labelColspan, null, font, height, vertical, horizontal);
        addCell(table, value, valueColspan, null, font, height, vertical, horizontal);
    }

    private static void addCell(PdfPTable table, Object value, Integer valueColspan, Integer valueRowspan, Font font, Float height, Integer vertical, Integer horizontal) {
        if (Objects.isNull(height))
            height = 25.5f;
        if (Objects.isNull(vertical))
            vertical = Element.ALIGN_MIDDLE;
        if (Objects.isNull(horizontal))
            horizontal = Element.ALIGN_LEFT;
        PdfPCell valueCell = new PdfPCell(new Phrase(value != null ? value.toString() : "", font));
        if (Objects.nonNull(valueRowspan))
            valueCell.setRowspan(valueRowspan);
        if (Objects.nonNull(valueColspan))
            valueCell.setColspan(valueColspan);
        valueCell.setCellEvent(new UniformBorderEvent());
        valueCell.setPadding(5f);
        valueCell.setMinimumHeight(height);
        valueCell.setVerticalAlignment(vertical);
        valueCell.setHorizontalAlignment(horizontal);// 设置边框宽度
        valueCell.setBorderColor(new BaseColor(0, 0, 0));
//      valueCell.setBorderWidth(0.5f); // 设置边框宽度
        table.addCell(valueCell);
    }

    private static void addTableContentCell(PdfPTable table, String label, String value, Integer valueColspan, Font font, Float height) {
        if (Objects.isNull(height))
            height = 25.5f;
        Paragraph para = new Paragraph(label + (label.equals("") ? "" : "\n") + value, font);
        para.setAlignment(Element.ALIGN_LEFT);
        para.setLeading(24f); // 设置行间距
        PdfPCell valueCell = new PdfPCell(para);
        valueCell.setMinimumHeight(height);
        valueCell.setVerticalAlignment(Element.ALIGN_TOP);
        valueCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        valueCell.setCellEvent(new UniformBorderEvent());
//      valueCell.setBorderWidth(0.5f); // 设置边框宽度
        if (Objects.nonNull(valueColspan))
            valueCell.setColspan(valueColspan);
        table.addCell(valueCell);
    }

    private static BaseFont loadChineseFont(String fontName) {
        try {
            if ("linux".equals(getCurrentOperatingSystem())) {
                if (fontName.toLowerCase().endsWith(".ttc"))
                    return BaseFont.createFont("/usr/share/fonts/" + fontName + ",0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                else
                    return BaseFont.createFont("/usr/share/fonts/" + fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            } else {
                if (fontName.toLowerCase().endsWith(".ttc"))
                    return BaseFont.createFont("c:/Windows/Fonts/" + fontName + ",0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                else
                    return BaseFont.createFont("c:/Windows/Fonts/" + fontName, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            }
        } catch (Exception e) {
            throw new RuntimeException("加载字体文件失败,请确保系统中存在字体文件 " + fontName + ":" + e.getMessage(), e);
        }
    }

    private static void addSection(Document document, String title, Font font) throws DocumentException {
        Paragraph section = new Paragraph(title, font);
        section.setSpacingBefore(15);
        section.setSpacingAfter(10);
        document.add(section);
    }
}