Commit 09c0845d authored by 徐俊's avatar 徐俊
parents fb5a7d88 d320d334
...@@ -156,6 +156,7 @@ public class ComProjectTaskController extends BaseController<ComProjectTaskServi ...@@ -156,6 +156,7 @@ public class ComProjectTaskController extends BaseController<ComProjectTaskServi
// WordUtils.getHtmlContent(dto, "C:\\Users\\kylin\\Desktop\\导出Pdf\\output.docx"); // WordUtils.getHtmlContent(dto, "C:\\Users\\kylin\\Desktop\\导出Pdf\\output.docx");
// 生成PDF文件字节数组 // 生成PDF文件字节数组
// byte[] pdfBytes = TaskInfoToPDFUtil.createContractPdf(dto);
byte[] pdfBytes = TaskToPDF.createContractPdf(dto); byte[] pdfBytes = TaskToPDF.createContractPdf(dto);
// 设置响应头 // 设置响应头
response.setContentType("application/pdf"); response.setContentType("application/pdf");
......
...@@ -145,7 +145,7 @@ public class ComExpertSpecServiceImpl extends BaseServiceImpl<ComExpertSpecDAO, ...@@ -145,7 +145,7 @@ public class ComExpertSpecServiceImpl extends BaseServiceImpl<ComExpertSpecDAO,
List<ComProjectGroupDetailDTO> finalMembers1 = members; List<ComProjectGroupDetailDTO> finalMembers1 = members;
list.forEach((e) -> { list.forEach((e) -> {
boolean isDisabled = false; boolean isDisabled = false;
String description = e.getSex() + "/" + AgeUtil.getResidentAge(e.getBirthday()) + "岁/" + e.getWorkUnit(); String description = e.getTreeCode() + "/"+e.getSex() + "/" + AgeUtil.getResidentAge(e.getBirthday()) + "岁/" + e.getWorkUnit();
isDisabled = units.contains(e.getUnitId()); isDisabled = units.contains(e.getUnitId());
// 检查专家的证件号是否在 members 列表中 // 检查专家的证件号是否在 members 列表中
if (!isDisabled) if (!isDisabled)
......
...@@ -1041,9 +1041,9 @@ public class TaskInfoToPDFUtil { ...@@ -1041,9 +1041,9 @@ public class TaskInfoToPDFUtil {
valueCell.setPadding(5f); valueCell.setPadding(5f);
valueCell.setMinimumHeight(height); valueCell.setMinimumHeight(height);
valueCell.setVerticalAlignment(vertical); valueCell.setVerticalAlignment(vertical);
valueCell.setHorizontalAlignment(horizontal); valueCell.setHorizontalAlignment(horizontal);// 设置边框宽度
valueCell.setBorderWidth(0.1f); // 设置边框宽度
valueCell.setBorderColor(new BaseColor(0, 0, 0)); valueCell.setBorderColor(new BaseColor(0, 0, 0));
// valueCell.setBorderWidth(0.5f); // 设置边框宽度
table.addCell(valueCell); table.addCell(valueCell);
} }
...@@ -1057,7 +1057,8 @@ public class TaskInfoToPDFUtil { ...@@ -1057,7 +1057,8 @@ public class TaskInfoToPDFUtil {
valueCell.setMinimumHeight(height); valueCell.setMinimumHeight(height);
valueCell.setVerticalAlignment(Element.ALIGN_TOP); valueCell.setVerticalAlignment(Element.ALIGN_TOP);
valueCell.setHorizontalAlignment(Element.ALIGN_LEFT); valueCell.setHorizontalAlignment(Element.ALIGN_LEFT);
valueCell.setBorderWidth(0.5f); // 设置边框宽度 valueCell.setCellEvent(new UniformBorderEvent());
// valueCell.setBorderWidth(0.5f); // 设置边框宽度
if (Objects.nonNull(valueColspan)) if (Objects.nonNull(valueColspan))
valueCell.setColspan(valueColspan); valueCell.setColspan(valueColspan);
table.addCell(valueCell); table.addCell(valueCell);
......
package com.yiboshi.science.utils; package com.yiboshi.science.utils;
import com.itextpdf.kernel.colors.DeviceRgb; import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.layout.borders.Border;
import com.itextpdf.layout.borders.SolidBorder; import com.itextpdf.layout.borders.SolidBorder;
import com.itextpdf.layout.element.AreaBreak;
import com.itextpdf.layout.element.Cell; import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table; import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.properties.TextAlignment; import com.itextpdf.layout.properties.*;
import com.itextpdf.layout.element.Paragraph; import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.properties.UnitValue;
import com.itextpdf.kernel.pdf.PdfDocument; import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter; import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document; import com.itextpdf.layout.Document;
import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import com.yiboshi.science.param.dto.*; import com.yiboshi.science.param.dto.*;
import com.itextpdf.kernel.font.PdfFont; import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory; import com.itextpdf.kernel.font.PdfFontFactory;
...@@ -30,6 +32,9 @@ public class TaskToPDF { ...@@ -30,6 +32,9 @@ public class TaskToPDF {
static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
static SimpleDateFormat sdfM = new SimpleDateFormat("yyyy年MM月"); static SimpleDateFormat sdfM = new SimpleDateFormat("yyyy年MM月");
static float borderWidth = 1f;
static Border unitedBorder = new SolidBorder(new DeviceRgb(0, 0, 0), borderWidth);
private static PdfFont createFont(String fontName) { private static PdfFont createFont(String fontName) {
try { try {
if ("linux".equals(getCurrentOperatingSystem())) { if ("linux".equals(getCurrentOperatingSystem())) {
...@@ -54,11 +59,12 @@ public class TaskToPDF { ...@@ -54,11 +59,12 @@ public class TaskToPDF {
* @param dto 项目任务信息 * @param dto 项目任务信息
* @return PDF文件字节数组 * @return PDF文件字节数组
*/ */
public static byte[] createContractPdf(ComProjectTaskDTO dto) { public static byte[] createContractPdf1(ComProjectTaskDTO dto) {
try { try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(baos)); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(baos));
Document document = new Document(pdfDoc); Document document = new Document(pdfDoc);
document.setMargins(72f, 54f, 72f, 54f);
// 添加中文字体支持 // 添加中文字体支持
// 宋体 // 宋体
PdfFont sfChinese = createFont("simsun.ttc"); PdfFont sfChinese = createFont("simsun.ttc");
...@@ -76,7 +82,7 @@ public class TaskToPDF { ...@@ -76,7 +82,7 @@ public class TaskToPDF {
cell.setBorder(new SolidBorder(new DeviceRgb(0, 0, 0), 0.5f)); cell.setBorder(new SolidBorder(new DeviceRgb(0, 0, 0), 0.5f));
cell.setTextAlignment(TextAlignment.CENTER); cell.setTextAlignment(TextAlignment.CENTER);
// 使用中文测试文本 // 使用中文测试文本
cell.add(new Paragraph("单元格 " + (i+1) + "-" + (j+1)).setFont(sfChinese)); cell.add(new Paragraph("单元格 " + (i + 1) + "-" + (j + 1)).setFont(sfChinese));
table.addCell(cell); table.addCell(cell);
} }
} }
...@@ -90,4 +96,251 @@ public class TaskToPDF { ...@@ -90,4 +96,251 @@ public class TaskToPDF {
return null; return null;
} }
} }
/**
* 生成项目合同书PDF
*
* @param dto 项目任务信息
* @return PDF文件字节数组
*/
public static byte[] createContractPdf(ComProjectTaskDTO dto) throws DocumentException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(baos));
Document document = new Document(pdfDoc);
try {
// 设置页边距 (左, 右, 上, 下)
document.setMargins(72f, 54f, 72f, 54f);
// 宋体
PdfFont sfChinese = createFont("simsun.ttc");
// 仿宋
PdfFont fsChinese = createFont("simfang.ttf");
// 首页
firstPageInfo(document, dto, sfChinese, fsChinese);
// 项目基本信息
baseProjectInfo(document, dto, sfChinese, fsChinese);
// 关闭文档
document.close();
return baos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private static void firstPageInfo(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 附件编号
Paragraph paragraph = new Paragraph("附件4").setFont(bfChinese).setFontSize(16);
paragraph.setTextAlignment(TextAlignment.LEFT);
document.add(paragraph);
document.add(new Paragraph("\n"));
// 项目编号
Paragraph no = new Paragraph("项目编号:" + dto.getProjNo()).setFont(bfChinese).setFontSize(16);
no.setTextAlignment(TextAlignment.LEFT);
document.add(no);
document.add(new Paragraph("\n\n\n\n\n\n"));
// 添加标题
Paragraph title = new Paragraph("省级临床医学中心科研项目合同书").setFont(bfChinese).setFontSize(22);
title.setTextAlignment(TextAlignment.CENTER);
document.add(title);
document.add(new Paragraph("\n\n\n\n\n\n"));
float[] columnWidths = {65f, 15f, 15f, 55f, 200f};
Table table = new Table(columnWidths);
// 设置表格水平居中
table.setHorizontalAlignment(HorizontalAlignment.CENTER);
table.setWidth(UnitValue.createPointValue(400f));
// table.setBorder(unitedBorder);
// 添加表格内容
addTablePageCell(table, "项目名称:", dto.getProjName(), null, 4, bfChinese);
addTablePageCell(table, "项目下达单位(甲方):", dto.getAppUnitName(), 4, null, bfChinese);
addTablePageCell(table, "项目承担单位(乙方):", dto.getAppUnitName(), 4, null, bfChinese);
addTablePageCell(table, "项目负责人:", dto.getAppPersonName(), 2, 3, bfChinese);
addTablePageCell(table, "项目起止年限:", sdf.format(dto.getStartDate()) + " 至 " + sdf.format(dto.getEndDate()), 3, 2, bfChinese);
document.add(table);
}
private static void baseProjectInfo(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
// document.setMargins(72f, 54f, 72f, 54f);
// 添加段落标题
setParagraph(document, "一、项目基本情况", bfChinese, 12f, true);
// 创建表格
float[] column = {80f, 80f, 30f, 60f, 60f, 80f, 30f, 100f};
Table table = new Table(column);
table.setWidth(UnitValue.createPercentValue(100));
table.setBorderTop(unitedBorder);
table.setBorderLeft(unitedBorder);
// 添加表格内容
addValueCell(table, "单位名称:", null, dto.getAppUnitName(), 7, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "注册单位类型", null, "医疗机构", 4, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "组织机构代码/统一社会信用代码", 2, dto.getOrganizationCode(), null, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "通讯地址", null, dto.getUnitAddress(), 7, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "注册所在地", null, dto.getRegisteredAddress(), 2, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "邮编", null, dto.getPostCode(), null, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "法定代表人", null, dto.getLegalPerson(), 2, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addCell(table, "职工总数 " + dto.getWorkCount() + " (人)", 2, null, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addCell(table, "其中专科以上人员 " + dto.getSpecializedPersonnel() + " (人)", 4, null, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addCell(table, "研究开发人员 " + dto.getResearchPersonnel() + " (人)", 2, null, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "开户银行", null, dto.getDepositBank(), 4, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "银行账号", null, dto.getBankAccount(), 2, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "开户银行地址", null, dto.getDepositBankAddress(), 4, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "银行联行号", null, dto.getInterbankNumber(), 2, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
document.add(table);
// 添加项目内容章节
setParagraph(document, "二、项目基本情况", bfChinese, 12f, true);
// 创建表格
float[] column2 = {40f, 80f, 60f, 90f, 20f, 20f, 100f, 80f, 20f, 60f};
Table projTable = new Table(column2);
projTable.setWidth(UnitValue.createPercentValue(100));
addValueCell(projTable, "项目编号:", 2, dto.getProjNo(), 8, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "项目名称", 2, dto.getProjName(), 8, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "所属我省重点领域", 2, dto.getKeyAreas(), 8, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "项目开始时间", 2, sdf.format(dto.getStartDate()), 2, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "项目结束时间", 3, sdf.format(dto.getEndDate()), 3, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "项目负责人", 2, dto.getAppUnitName(), 2, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "联系电话", 3, dto.getMobile(), 3, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "项目联系人姓名", 2, dto.getLinkName(), 2, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "联系人电话", 3, dto.getLinkMobile(), 3, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "传真", 2, dto.getLinkFax(), 2, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "电子邮箱", 3, dto.getLinkEmail(), 3, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "项目总经费(万元)", 2, Objects.nonNull(dto.getTotalFunding()) ? dto.getTotalFunding().toString() : "", 2, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "财政经费(万元)", 2, Objects.nonNull(dto.getGovFunding()) ? dto.getGovFunding().toString() : "", null, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "自筹经费(万元)", null, Objects.nonNull(dto.getSelfFunding()) ? dto.getSelfFunding().toString() : "", 2, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "是否科技报告:", 2, dto.getIsTechnologyReport().equals(1) ? "是" : "否", 8, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(projTable, "科技报告类型:", 2, "", 8, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addCell(projTable, "项目主要参与单位及分工", 10, null, null, bfChinese,null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addCell(projTable, "序号", null, null, null, null, null, null,null);
addCell(projTable, "单位名称", 2, null, null, null, null, null,null);
addCell(projTable, "单位地址", 2, null, null, null, null, null,null);
addCell(projTable, "组织机构代码/统一社会信用代码", 2, null, null, null, null, null,null);
addCell(projTable, "分 工", 2, null, null, null, null, null,null);
addCell(projTable, "签字", null, null, null, null, null, null,null);
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, null, null, null, null,null);
addCell(projTable, dto.getCooperativeUnits().get(i).getUnitName(), 2, null, null, null, null, null,null);
addCell(projTable, dto.getCooperativeUnits().get(i).getUnitAddress(), 2, null, null, null, null, null,null);
addCell(projTable, dto.getCooperativeUnits().get(i).getOrganizationCode(), 2, null, null, null, null, null,null);
addCell(projTable, dto.getCooperativeUnits().get(i).getProjectWork(), 2, null, null, null, null, null,null);
addCell(projTable, "", null, null, null, null, null, null,null);
}
document.add(projTable);
}
private static void addTablePageCell(Table table, String label, String value, Integer labelColspan, Integer valueColspan, PdfFont font) {
if (Objects.isNull(labelColspan))
labelColspan = 1;
if (Objects.isNull(valueColspan))
valueColspan = 1;
Cell labelCell = new Cell(1, labelColspan);
labelCell.setMinHeight(36f);
labelCell.setVerticalAlignment(VerticalAlignment.BOTTOM);
labelCell.setHorizontalAlignment(HorizontalAlignment.LEFT);
labelCell.setBorder(new SolidBorder(new DeviceRgb(0, 0, 0), 0.1f)); // 设置边框宽度
labelCell.add(new Paragraph(label != null ? label.toString() : "").setFont(font).setFontSize(15));
labelCell.setBorder(Border.NO_BORDER);
table.addCell(labelCell);
Cell valueCell = new Cell(1, valueColspan);
valueCell.setPadding(3f);
valueCell.setMinHeight(36f);
valueCell.setVerticalAlignment(VerticalAlignment.BOTTOM);
valueCell.setHorizontalAlignment(HorizontalAlignment.LEFT);
// 只设置下边框
valueCell.setBorderTop(Border.NO_BORDER);
valueCell.setBorderLeft(Border.NO_BORDER);
valueCell.setBorderRight(Border.NO_BORDER);
valueCell.setBorderBottom(unitedBorder);
valueCell.add(new Paragraph(value != null ? value.toString() : "").setFont(font).setFontSize(15));
table.addCell(valueCell);
}
private static void addValueCell(Table table, String label, Integer labelColspan, String value, Integer valueColspan, Float height, PdfFont font, Float fontSize, VerticalAlignment vertical, HorizontalAlignment horizontal) {
addCell(table, label, labelColspan, null, height, font, fontSize, vertical, horizontal);
addCell(table, value, valueColspan, null, height, font, fontSize, vertical, horizontal);
}
private static void addCell(Table table, Object value, Integer colspan, Integer rowspan, Float height, PdfFont font, Float fontSize, VerticalAlignment vertical, HorizontalAlignment horizontal) {
if (Objects.isNull(font))
font = createFont("simsun.ttc");
if (Objects.isNull(fontSize))
fontSize = 10.5f;
if (Objects.isNull(height))
height = 25.5f;
if (Objects.isNull(colspan))
colspan = 1;
if (Objects.isNull(rowspan))
rowspan = 1;
if (Objects.isNull(vertical))
vertical = VerticalAlignment.MIDDLE;
if (Objects.isNull(horizontal))
horizontal = HorizontalAlignment.CENTER;
Cell cell = new Cell(rowspan, colspan);
cell.setPadding(5f);
cell.setMinHeight(height);
cell.setVerticalAlignment(vertical);
cell.setHorizontalAlignment(horizontal);
cell.setBorderRight(unitedBorder);
cell.setBorderBottom(unitedBorder);
// 创建段落并检查字体
cell.add(new Paragraph(value != null ? value.toString() : "").setFont(font).setFontSize(fontSize));
table.addCell(cell);
}
// 为了保持兼容性,添加原有方法的重载
private static void setParagraph(Document document, Object value, PdfFont font, float FontSize, boolean bold) throws DocumentException {
Paragraph paragraph = new Paragraph(value != null ? value.toString() : "")
.setFont(font)
.setFontSize(FontSize)
.setTextAlignment(TextAlignment.LEFT) // 设置文字对齐方式
.setMarginLeft(1f); // 设置左缩进
if (bold) {
paragraph.setBold();
}
document.add(paragraph);
}
private static String numberTo(int number) {
char[] cs = "零一二三四五六七八九".toCharArray();
String temp = "";
while (number > 0) {
temp += cs[number % 10];
number /= 10;
}
return temp;
}
} }
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<select id="getExpertListByExpertSpecIds" resultType="com.yiboshi.science.param.dto.ComExpertDTO"> <select id="getExpertListByExpertSpecIds" resultType="com.yiboshi.science.param.dto.ComExpertDTO">
select distinct a.expert_id id,c.person_name,c.cert_id,c.sex,c.birthday,e.id unit_id, select distinct a.expert_id id,c.person_name,c.cert_id,c.sex,c.birthday,e.id unit_id,
(case when e.unit_name is null then c.work_unit else e.unit_name end) as work_unit (case when e.unit_name is null then c.work_unit else e.unit_name end) as work_unit,d.tree_code
from com_expert_spec a from com_expert_spec a
left join com_expert b on a.expert_id=b.id left join com_expert b on a.expert_id=b.id
left join com_person c on b.person_id=c.id left join com_person c on b.person_id=c.id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment