diff --git a/science-admin/src/main/java/com/yiboshi/science/rest/v1/ComProjectController.java b/science-admin/src/main/java/com/yiboshi/science/rest/v1/ComProjectController.java index 251840bc7060db183a51243bfd6179d61e205960..5c292cc61db3c2cb0eddb5c0b0060db9057a80c4 100644 --- a/science-admin/src/main/java/com/yiboshi/science/rest/v1/ComProjectController.java +++ b/science-admin/src/main/java/com/yiboshi/science/rest/v1/ComProjectController.java @@ -15,7 +15,7 @@ import com.yiboshi.science.service.ComFileService; import com.yiboshi.science.service.ComProjectService; import com.yiboshi.science.service.ComProjectTaskService; import com.yiboshi.science.service.SystemParameterService; -import com.yiboshi.science.utils.PDF; +import com.yiboshi.science.utils.PdfUtil; import com.yiboshi.science.utils.ProjectInfoToPDF; import com.yiboshi.science.utils.StringUtil; import io.swagger.annotations.Api; @@ -99,7 +99,7 @@ public class ComProjectController extends BaseController<ComProjectService, ComP @PostMapping public ResponseDataModel<byte[]> export(@PathVariable String id) { try { - return ResponseDataModel.ok(PDF.createPDF(response, "tmp-report.html", new ComProject())); + return ResponseDataModel.ok(PdfUtil.createPDF(response, "tmp-report.html", new ComProject())); } catch (Exception e) { return new ResponseDataModel(ResponseCode.SERVER_ERROR, ""); } diff --git a/science-admin/src/main/java/com/yiboshi/science/rest/v1/ComProjectTaskController.java b/science-admin/src/main/java/com/yiboshi/science/rest/v1/ComProjectTaskController.java index d63d409a2b6f298322061947ff38f81e4d7fea3c..49206e74d29c338d096c7c622b78118e73039ee7 100644 --- a/science-admin/src/main/java/com/yiboshi/science/rest/v1/ComProjectTaskController.java +++ b/science-admin/src/main/java/com/yiboshi/science/rest/v1/ComProjectTaskController.java @@ -1,39 +1,31 @@ package com.yiboshi.science.rest.v1; -import com.yiboshi.arch.base.ResponseCode; +import com.itextpdf.text.DocumentException; import com.yiboshi.arch.base.ResponseDataModel; import com.yiboshi.science.base.Pagination; import com.yiboshi.science.config.annotation.Logs; import com.yiboshi.science.config.security.SecurityUserHolder; -import com.yiboshi.science.entity.ComProject; import com.yiboshi.science.entity.ComProjectAudit; import com.yiboshi.science.entity.ComProjectTask; import com.yiboshi.science.entity.SelectListItem; import com.yiboshi.science.enumeration.CommonEnum; -import com.yiboshi.science.param.dto.ComDownloadDTO; -import com.yiboshi.science.param.dto.ComFileDTO; import com.yiboshi.science.param.dto.ComProjectTaskDTO; import com.yiboshi.science.param.dto.DataStatisticsDTO; import com.yiboshi.science.param.query.ComProjectTaskQueryVO; import com.yiboshi.science.rest.BaseController; import com.yiboshi.science.service.ComProjectTaskService; -import com.yiboshi.science.service.SystemParameterService; -import com.yiboshi.science.utils.PDF; -import com.yiboshi.science.utils.PdfUtil; import com.yiboshi.science.utils.StringUtil; +import com.yiboshi.science.utils.TaskInfoToPDFUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.apache.velocity.VelocityContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; import javax.servlet.ServletOutputStream; -import javax.validation.constraints.NotBlank; +import java.io.IOException; import java.util.ArrayList; -import java.util.Calendar; import java.util.List; /** @@ -152,25 +144,24 @@ public class ComProjectTaskController extends BaseController<ComProjectTaskServi @ApiOperation(value = "项目导出", httpMethod = "POST", notes = "项目导出") @RequestMapping("/export/{id}") @PostMapping - public ResponseDataModel<byte[]> export(@PathVariable String id) { + public void export(@PathVariable String id) throws DocumentException, IOException { try { - try (ServletOutputStream outputStream = response.getOutputStream()) { - VelocityContext context = new VelocityContext(); - Calendar calendar = Calendar.getInstance(); - int month = calendar.get(Calendar.MONTH) + 1; - int day = calendar.get(Calendar.DATE); - context.put("reportYear", 2024); - context.put("year", calendar.get(Calendar.YEAR)); - context.put("month", month >= 10 ? month : "0" + month); - context.put("day", day >= 10 ? day : "0" + day); - PdfUtil.pdfFile(context, "/template/demo.html", outputStream); - } catch (Exception e) { - e.printStackTrace(); + ComProjectTaskDTO dto=ComProjectTaskService.getTaskByProjId(id); + // 生成PDF文件字节数组 + byte[] pdfBytes = TaskInfoToPDFUtil.createContractPdf(ComProjectTaskService.getTaskByProjId(id)); + // 设置响应头 + response.setContentType("application/pdf"); + String fileName = new String((dto.getProjName() + ".pdf").getBytes("UTF-8"), "ISO-8859-1"); + response.setHeader("Content-Disposition", "attachment; filename=" + fileName); + response.setContentLength(pdfBytes.length); + // 写入响应流 + try (ServletOutputStream out = response.getOutputStream()) { + out.write(pdfBytes); + out.flush(); } - return ResponseDataModel.ok(null); -// return ResponseDataModel.ok(PDF.createPDF(response, "tmp-task.html", ComProjectTaskService.getTaskByProjId(id))); } catch (Exception e) { - return new ResponseDataModel(ResponseCode.SERVER_ERROR, ""); + response.setContentType("text/plain;charset=UTF-8"); + response.getWriter().write("导出PDF失败:" + e.getMessage()); } } diff --git a/science-admin/src/main/java/com/yiboshi/science/utils/PDF.java b/science-admin/src/main/java/com/yiboshi/science/utils/PDF.java deleted file mode 100644 index 26d56b1627cdf915465dec6b8d0f768199aa4d89..0000000000000000000000000000000000000000 --- a/science-admin/src/main/java/com/yiboshi/science/utils/PDF.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.yiboshi.science.utils; - - -import com.itextpdf.text.pdf.BaseFont; -import com.lowagie.text.DocumentException; -import freemarker.cache.ClassTemplateLoader; -import freemarker.template.Configuration; -import freemarker.template.Template; -import freemarker.template.TemplateException; -import freemarker.template.TemplateExceptionHandler; -import org.xhtmlrenderer.pdf.ITextRenderer; - -import javax.servlet.http.HttpServletResponse; -import java.io.*; -import java.util.Map; - -import static java.lang.System.in; - - -public class PDF { - - /** - * 将HTML模板转换为PDF输出流 - * @return PDF字节数组 - */ - public static byte[] createPDF(HttpServletResponse response,String temp,Object dataModel) throws IOException, TemplateException, DocumentException { - Map<String, Object> dataMap = HtmlBuilder.obj2Map(dataModel); - // 配置FreeMarker - Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); - cfg.setDefaultEncoding("utf-8"); - cfg.setClassLoaderForTemplateLoading(PDF.class.getClassLoader(), "template"); - cfg.setTemplateLoader(new ClassTemplateLoader(PDF.class.getClassLoader(), "/template")); - cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); - // 获取模板 - Template template = cfg.getTemplate(temp, "utf-8"); - // 处理模板,生成HTML内容 - StringWriter tmpText = new StringWriter(); - template.process(dataMap, tmpText); - String htmlContent = tmpText.toString(); - // 创建PDF渲染器 - ITextRenderer renderer = new ITextRenderer(); - // Java代码示例 -// renderer.getSharedContext().setDPI(1); // 提高DPI减少锯齿 - // 设置中文字体 - String simPath = ResourceFileUtil.getAbsolutePath("/fonts/simsun.ttc"); - String msyhPath = ResourceFileUtil.getAbsolutePath("/fonts/msyh.ttc"); - renderer.getFontResolver().addFont(simPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); - renderer.getFontResolver().addFont(msyhPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); - // 渲染HTML内容 - renderer.setDocumentFromString(htmlContent); - renderer.layout(); - // 创建一个ByteArrayOutputStream来保存生成的PDF - response.setContentType("application/octet-stream;charset=UTF-8"); - OutputStream outputStream = response.getOutputStream(); - // 输出PDF到字节数组 - renderer.createPDF(outputStream); - //创建存放文件内容的数组 - byte[] buff = new byte[1024]; - //所读取的内容使用n来接收 - int n; - //当没有读取完时,继续读取,循环 - while ((n = in.read(buff)) != -1) { - //将字节数组的数据全部写入到输出流中 - outputStream.write(buff, 0, n); - } - //强制将缓存区的数据进行输出 - outputStream.flush(); - //关流 - outputStream.close(); - in.close(); - // 关闭输出流 - return buff; - } - - public static boolean createPDF(String temp,Object dataModel,String outputPath) throws IOException, TemplateException, DocumentException { - Map<String, Object> dataMap = HtmlBuilder.obj2Map(dataModel); - // 配置FreeMarker - Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); - cfg.setDefaultEncoding("utf-8"); - cfg.setClassLoaderForTemplateLoading(PDF.class.getClassLoader(), "template"); - cfg.setTemplateLoader(new ClassTemplateLoader(PDF.class.getClassLoader(), "/template")); - cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); - // 获取模板 - Template template = cfg.getTemplate(temp, "utf-8"); - // 处理模板,生成HTML内容 - StringWriter tmpText = new StringWriter(); - template.process(dataMap, tmpText); - - String htmlContent = tmpText.toString(); - // 创建PDF渲染器 - ITextRenderer renderer = new ITextRenderer(); - // 设置中文字体 - String simPath = ResourceFileUtil.getAbsolutePath("/fonts/simsun.ttc"); - String msyhPath = ResourceFileUtil.getAbsolutePath("/fonts/msyh.ttc"); - renderer.getFontResolver().addFont(simPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); - renderer.getFontResolver().addFont(msyhPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); - // 渲染HTML内容 - renderer.setDocumentFromString(htmlContent); - renderer.layout(); - // 创建输出文件 - File outputFile = new File(outputPath); - // 确保父目录存在 - outputFile.getParentFile().mkdirs(); - // 创建文件输出流 - try (OutputStream outputStream = new FileOutputStream(outputFile)) { - // 输出PDF到文件 - renderer.createPDF(outputStream); - outputStream.flush(); - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } - } -} diff --git a/science-admin/src/main/java/com/yiboshi/science/utils/PdfUtil.java b/science-admin/src/main/java/com/yiboshi/science/utils/PdfUtil.java index 2ae6f93f44ce8c31d7227f4d7494a2358346e909..b1a51354739fde75e43417305d215bb966acaf27 100644 --- a/science-admin/src/main/java/com/yiboshi/science/utils/PdfUtil.java +++ b/science-admin/src/main/java/com/yiboshi/science/utils/PdfUtil.java @@ -8,15 +8,27 @@ import com.itextpdf.kernel.geom.PageSize; import com.itextpdf.kernel.pdf.PdfDocument; import com.itextpdf.kernel.pdf.PdfWriter; import com.itextpdf.layout.font.FontProvider; +import com.itextpdf.text.pdf.BaseFont; +import com.lowagie.text.DocumentException; +import freemarker.cache.ClassTemplateLoader; +import freemarker.template.Configuration; +import freemarker.template.TemplateException; +import freemarker.template.TemplateExceptionHandler; import org.apache.velocity.Template; import org.apache.velocity.app.Velocity; import org.apache.velocity.context.Context; import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; +import org.xhtmlrenderer.pdf.ITextRenderer; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.io.OutputStream; import java.io.StringWriter; import java.nio.charset.StandardCharsets; +import java.util.Map; + +import static java.lang.System.in; /** * PDF工具 @@ -67,4 +79,53 @@ public class PdfUtil { } } + public static byte[] createPDF(HttpServletResponse response, String temp, Object dataModel) throws IOException, TemplateException, DocumentException { + Map<String, Object> dataMap = HtmlBuilder.obj2Map(dataModel); + // 配置FreeMarker + Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); + cfg.setDefaultEncoding("utf-8"); + cfg.setClassLoaderForTemplateLoading(PdfUtil.class.getClassLoader(), "template"); + cfg.setTemplateLoader(new ClassTemplateLoader(PdfUtil.class.getClassLoader(), "/template")); + cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); + // 获取模板 + freemarker.template.Template template = cfg.getTemplate(temp, "utf-8"); + // 处理模板,生成HTML内容 + StringWriter tmpText = new StringWriter(); + template.process(dataMap, tmpText); + String htmlContent = tmpText.toString(); + // 创建PDF渲染器 + ITextRenderer renderer = new ITextRenderer(); + // Java代码示例 +// renderer.getSharedContext().setDPI(1); // 提高DPI减少锯齿 + // 设置中文字体 + String simPath = ResourceFileUtil.getAbsolutePath("/fonts/simsun.ttc"); + String msyhPath = ResourceFileUtil.getAbsolutePath("/fonts/msyh.ttc"); + renderer.getFontResolver().addFont(simPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); + renderer.getFontResolver().addFont(msyhPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); + // 渲染HTML内容 + renderer.setDocumentFromString(htmlContent); + renderer.layout(); + // 创建一个ByteArrayOutputStream来保存生成的PDF + response.setContentType("application/octet-stream;charset=UTF-8"); + OutputStream outputStream = response.getOutputStream(); + // 输出PDF到字节数组 + renderer.createPDF(outputStream); + //创建存放文件内容的数组 + byte[] buff = new byte[1024]; + //所读取的内容使用n来接收 + int n; + //当没有读取完时,继续读取,循环 + while ((n = in.read(buff)) != -1) { + //将字节数组的数据全部写入到输出流中 + outputStream.write(buff, 0, n); + } + //强制将缓存区的数据进行输出 + outputStream.flush(); + //关流 + outputStream.close(); + in.close(); + // 关闭输出流 + return buff; + } + } diff --git a/science-admin/src/main/java/com/yiboshi/science/utils/TaskInfoToPDFUtil.java b/science-admin/src/main/java/com/yiboshi/science/utils/TaskInfoToPDFUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..c1175a0294089fdb75a2d6088e7af5b15c1eb9e3 --- /dev/null +++ b/science-admin/src/main/java/com/yiboshi/science/utils/TaskInfoToPDFUtil.java @@ -0,0 +1,1086 @@ +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.5f); + + // 添加表格内容 + 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.setPadding(5f); + valueCell.setMinimumHeight(height); + valueCell.setVerticalAlignment(vertical); + valueCell.setHorizontalAlignment(horizontal); + 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.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); + } +} diff --git a/science-admin/src/main/java/com/yiboshi/science/utils/WordUtil.java b/science-admin/src/main/java/com/yiboshi/science/utils/WordUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..ff789156e9daff04751300bb40351f0c6256499c --- /dev/null +++ b/science-admin/src/main/java/com/yiboshi/science/utils/WordUtil.java @@ -0,0 +1,4 @@ +package com.yiboshi.science.utils; + +public class WordUtil { +} diff --git a/science-admin/src/main/resources/application.yml b/science-admin/src/main/resources/application.yml index d37dfcdac223031b1d61d8bb93a5b22f53a0ca60..eb179e193d015ba8bc9c3824851d4dc257d3e424 100644 --- a/science-admin/src/main/resources/application.yml +++ b/science-admin/src/main/resources/application.yml @@ -8,7 +8,7 @@ spring: application: name: science-admin profiles: - active: 'prod' + active: 'local' http: encoding: force: true diff --git a/science-base/src/main/java/com/yiboshi/science/base/BaseDAO.java b/science-base/src/main/java/com/yiboshi/science/base/BaseDAO.java index ede93d66b86a0e40c10fed02b9877b9d7879e1d1..e77491ebfa7193ebf653b2e61b50e2908d434021 100644 --- a/science-base/src/main/java/com/yiboshi/science/base/BaseDAO.java +++ b/science-base/src/main/java/com/yiboshi/science/base/BaseDAO.java @@ -2,6 +2,7 @@ package com.yiboshi.science.base; import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Param; @@ -13,6 +14,6 @@ import org.apache.ibatis.annotations.Param; * @version 2018-08 */ @SuppressWarnings("all") -public interface BaseDAO<V extends PaginationVO,D extends BaseDTO ,E>{ +public interface BaseDAO<V extends PaginationVO,D extends BaseDTO ,E>extends BaseMapper<E> { Page<D> getListByPage(Page<V> page, @Param("ew") Wrapper<V> queryWrapper); }