Browse Source

pdfUtil

tall3
ma 4 years ago
parent
commit
deaf6d1ffa
  1. 4
      common/src/main/java/com/ccsens/common/bean/vo/CTaskVo.java
  2. 12
      common/src/main/resources/mapper_dao/ProTaskDetailDao.xml
  3. 48
      util/src/main/java/com/ccsens/util/PdfUtil.java

4
common/src/main/java/com/ccsens/common/bean/vo/CTaskVo.java

@ -24,10 +24,14 @@ public class CTaskVo {
private Long planStart;
@ApiModelProperty("计划时长")
private Long planDuration;
@ApiModelProperty("计划结束时长")
private Long planEnd;
@ApiModelProperty("实际开始时间")
private Long realStart;
@ApiModelProperty("实际时长")
private Long realDuration;
@ApiModelProperty("实际结束时长")
private Long realEnd;
@ApiModelProperty("任务状态 0未开始 1进行中 2暂停中 3已完成")
private int process;
@ApiModelProperty("任务流转策略 -1不跳转 0直接跳转 如果是其他正整数 就是多少毫秒后跳转 ")

12
common/src/main/resources/mapper_dao/ProTaskDetailDao.xml

@ -9,8 +9,10 @@
<result column="description" property="description"/>
<result column="planStart" property="planStart"/>
<result column="plan_duration" property="planDuration"/>
<result column="real_start_time" property="realStart"/>
<result column="plan_end_time" property="planEnd"/>
<result column="realStart" property="realStart"/>
<result column="real_duration" property="realDuration"/>
<result column="real_end_time" property="realEnd"/>
<result column="process" property="process"/>
<result column="skip" property="skip"/>
<result column="skipTaskId" property="skipTaskId"/>
@ -47,8 +49,10 @@
td.description,
ts.plan_start_time AS planStart,
ts.plan_duration,
ts.plan_end_time,
ts.real_start_time AS realStart,
ts.real_duration,
ts.real_end_time,
ts.task_status AS process,
tf.flow_type AS skip,
tf.jump_task_detail_id AS skipTaskId,
@ -95,6 +99,8 @@
td.description,
ts.plan_start_time AS planStart,
ts.plan_duration,
ts.plan_end_time,
ts.real_end_time,
ts.real_start_time AS realStart,
ts.real_duration,
ts.task_status AS process,
@ -163,6 +169,8 @@
td.description,
ts.plan_start_time AS planStart,
ts.plan_duration,
ts.plan_end_time,
ts.real_end_time,
ts.real_start_time AS realStart,
ts.real_duration,
ts.task_status AS process,
@ -243,6 +251,8 @@
td.description,
ts.plan_start_time AS planStart,
ts.plan_duration,
ts.plan_end_time,
ts.real_end_time,
ts.real_start_time AS realStart,
ts.real_duration,
ts.task_status AS process,

48
util/src/main/java/com/ccsens/util/PdfUtil.java

@ -28,14 +28,14 @@ public class PdfUtil {
/**
* 生成pdf
* @param parentPath
* @param title
* @param parentPath 文件夹路径
* @param title 标题
* @param subhead 副标题
* @param intros
* @param content
* @param intros 介绍
* @param contentArr 正文
* @return
*/
public static String credatePdf(String parentPath, String title, String subhead, List<Row> intros, List<Row> content, Margin margin) {
public static String createPdf(String parentPath, String title, String subhead, Margin margin, List<Row> intros, List<Row>... contentArr) {
String fileName = "pdf/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".pdf";
log.info("pdf文件名:{}", fileName );
File file = new File(parentPath, fileName);
@ -51,7 +51,7 @@ public class PdfUtil {
// 中文字体
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
// 标题字体
Font titleChinese = new Font(bfChinese, 24, Font.BOLD);
Font titleChinese = new Font(bfChinese, 14, Font.NORMAL);
//设置标题
Paragraph par = new Paragraph(title, titleChinese);
par.setAlignment(Element.ALIGN_CENTER);
@ -59,22 +59,27 @@ public class PdfUtil {
if (StrUtil.isNotBlank(subhead)) {
// 标题字体
Font subheadChinese = new Font(bfChinese, 22, Font.NORMAL);
Font subheadChinese = new Font(bfChinese, 15, Font.NORMAL);
//设置标题
Paragraph subheadPar = new Paragraph(subhead, subheadChinese);
subheadPar.setAlignment(Element.ALIGN_CENTER);
document.add(subheadPar);
}
// 每行加空白
fillBlankRow(document, titleChinese);
fillBlankRow(document, new Font(bfChinese, 3, Font.NORMAL));
//设置介绍内容
if (CollectionUtil.isNotEmpty(intros)) {
fillRow(intros, document);
}
if (CollectionUtil.isNotEmpty(content)) {
fillRow(content, document);
if (contentArr != null && contentArr.length > 0 ) {
for (List<Row> content:contentArr) {
if (CollectionUtil.isNotEmpty(content)) {
fillRow(content, document);
}
}
}
} catch (DocumentException e) {
e.printStackTrace();
log.error("导出pdf异常", e);
@ -121,7 +126,7 @@ public class PdfUtil {
PdfPTable table = new PdfPTable(size);
table.setSpacingBefore(0);
table.setWidthPercentage(90);
table.setWidthPercentage(100);
for (int j = 0; j < rows.size(); j++) {
Row row = rows.get(j);
table.setHorizontalAlignment(row.align);
@ -129,8 +134,9 @@ public class PdfUtil {
for (int i = 0; i < row.cells.size(); i++) {
Cell cell = row.cells.get(i);
PdfPCell pdfpCell = new PdfPCell(new Phrase(cell.content,font));
pdfpCell.setBorderWidthTop(cell.borderTop == null ? 0 : cell.borderTop);
pdfpCell.setBorderWidthTop(j == 0 && cell.borderTop == null && cell.borderBottom != null ? cell.borderBottom : cell.borderTop == null ? 0 : cell.borderTop);
pdfpCell.setBorderWidthLeft(cell.borderLeft == null ? 0 : cell.borderLeft);
// pdfpCell.setBorderWidthRight(i==row.cells.size() && cell.borderRight == null && cell.borderLeft != null ? cell.borderLeft : cell.borderRight == null ? 0 : cell.borderRight);
pdfpCell.setBorderWidthRight(cell.borderRight == null ? 0 : cell.borderRight);
pdfpCell.setBorderWidthBottom(cell.borderBottom == null ? 0 : cell.borderBottom);
pdfpCell.setColspan(cell.colSpan);
@ -195,6 +201,22 @@ public class PdfUtil {
// 单元格是否居中
private boolean isCenter = true;
public Cell() {
}
public Cell(String content) {
this.content = content;
}
public Cell(String content,int colSpan,int rowSpan) {
this.content = content;
this.colSpan = colSpan == 0 ? 1 : colSpan;
this.rowSpan = rowSpan == 0 ? 1 : rowSpan;
}
public Cell(String content,int colSpan,int rowSpan,Integer borderRight) {
this.content = content;
this.colSpan = colSpan == 0 ? 1 : colSpan;
this.rowSpan = rowSpan == 0 ? 1 : rowSpan;
this.borderRight = borderRight;
}
}
/**
@ -203,7 +225,7 @@ public class PdfUtil {
@Data
public static class Margin{
private float left = 72;
private float right = 0;
private float right = 72;
private float top = 32;
private float bottom = 32;
}

Loading…
Cancel
Save