法规预警--推送,定时任务

This commit is contained in:
zhn
2022-08-09 15:10:42 +08:00
parent aa0ad556a7
commit bfe0381505
3 changed files with 134 additions and 25 deletions
@@ -547,9 +547,10 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
content = "Content";
}
//单独设置每页右侧的时间
WordUtil.exportWordMonth(document, lawsMonthlyReportWriteEOS.get(0).getMonth(), null, ParagraphAlignment.RIGHT, 0, 12, false, true, "微软雅黑");
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 12, false, true, "Microsoft YaHei UI");
WordUtil.exportWord(document, content, null, ParagraphAlignment.LEFT, 0, 12, false, true, "Microsoft YaHei UI");
//生成页眉页脚
WordUtil.exportHeardAndFoot(document,lawsMonthlyReportWriteEOS.get(0).getMonth());
int oneCount = 1;
for (LawsMonthlyReportTitleTemplateEO lawsMonthlyReportTitleTemplateEO : reportTitleOneList) {
@@ -623,9 +624,8 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
content = "Content";
}
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 12, false, true, "Microsoft YaHei UI");
//单独设置每页右侧的时间
WordUtil.exportWordMonth(document, lawsMonthlyReportWriteEOS.get(0).getMonth(), null, ParagraphAlignment.RIGHT, 0, 12, false, true, "Microsoft YaHei UI");
// WordUtil.exportWord(document, content, null, ParagraphAlignment.LEFT, 0, 12, false, true, "Microsoft YaHei UI");
//生成页眉页脚
WordUtil.exportHeardAndFoot(document,lawsMonthlyReportWriteEOS.get(0).getMonth());
int oneCount = 1;
for (LawsMonthlyReportTitleTemplateEO lawsMonthlyReportTitleTemplateEO : reportTitleOneList) {
@@ -8,20 +8,35 @@ import com.jero.modules.report.entity.NewStandardTemplateEO;
import com.jero.modules.report.enums.DictCodeReportEnum;
import com.jero.modules.system.entity.SysCategory;
import com.jero.modules.system.entity.SysDictItem;
import lombok.SneakyThrows;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFFooter;
import org.apache.poi.xwpf.usermodel.XWPFHeader;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFPicture;
import org.apache.poi.xwpf.usermodel.XWPFPictureData;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.apache.xmlbeans.impl.xb.xmlschema.SpaceAttribute;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFldChar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFldCharType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
import java.io.FileInputStream;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
@@ -103,6 +118,121 @@ public class WordUtil {
}
}
// @SneakyThrows
// public static void exportHeardAndFoot(XWPFDocument document){
//// XWPFDocument document = new XWPFDocument();
//
// // create header-footer
// XWPFHeaderFooterPolicy headerFooterPolicy = document.getHeaderFooterPolicy();
// if (headerFooterPolicy == null) headerFooterPolicy = document.createHeaderFooterPolicy();
//
// // create header start
// XWPFHeader header = headerFooterPolicy.createHeader(XWPFHeaderFooterPolicy.DEFAULT);
//
// XWPFParagraph paragraph = header.createParagraph();
// paragraph.setAlignment(ParagraphAlignment.CENTER);
//
// XWPFRun run = paragraph.createRun();
// run.setText("Header");
//
// // create footer start
// XWPFFooter footer = headerFooterPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT);
//
// paragraph = footer.createParagraph();
// paragraph.setAlignment(ParagraphAlignment.CENTER);
//
// run = paragraph.createRun();
// run.setText("Footer");
//
// CTSectPr sectPr = document.getDocument().getBody().getSectPr();
// if (sectPr == null) sectPr = document.getDocument().getBody().addNewSectPr();
// CTPageMar pageMar = sectPr.getPgMar();
// if (pageMar == null) pageMar = sectPr.addNewPgMar();
// pageMar.setLeft(BigInteger.valueOf(2000)); //720 TWentieths of an Inch Point (Twips) = 720/20 = 36 pt = 36/72 = 0.5"
// pageMar.setRight(BigInteger.valueOf(720));
// pageMar.setTop(BigInteger.valueOf(1440)); //1440 Twips = 1440/20 = 72 pt = 72/72 = 1"
// pageMar.setBottom(BigInteger.valueOf(1440));
//
// pageMar.setHeader(BigInteger.valueOf(2000)); //45.4 pt * 20 = 908 = 45.4 pt header from top
// pageMar.setFooter(BigInteger.valueOf(568)); //28.4 pt * 20 = 568 = 28.4 pt footer from bottom
//
// }
@SneakyThrows
public static void exportHeardAndFoot(XWPFDocument document,String month){
XWPFHeaderFooterPolicy headerFooterPolicy = document.getHeaderFooterPolicy();
if (headerFooterPolicy == null) headerFooterPolicy = document.createHeaderFooterPolicy();
XWPFHeader header = headerFooterPolicy.createHeader(XWPFHeaderFooterPolicy.DEFAULT);
// String logoFilePath = "/jero-boot/home/weilai.png";
String logoFilePath = WordUtil.class.getClassLoader().getResource("static/home/weilai.png").getPath();
//页眉第一个段落展示logo-----------------------------------------------------------------------------------
if (org.apache.commons.lang3.StringUtils.isNotBlank(logoFilePath)) {
XWPFParagraph logo = header.createParagraph();
logo.setAlignment(ParagraphAlignment.LEFT);
XWPFRun run = logo.createRun();
String imgFile = logoFilePath;
InputStream is = new FileInputStream(imgFile);
XWPFPicture picture = run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, imgFile, Units.toEMU(95), Units.toEMU(35));
String blipID = "";
for(XWPFPictureData picturedata : header.getAllPackagePictures()) { //这段必须有,不然打开的logo图片不显示
blipID = header.getRelationId(picturedata);
}
picture.getCTPicture().getBlipFill().getBlip().setEmbed(blipID);
run.addTab();
is.close();
}
//页眉第二个段落展示日期------------------------------------------------------------
XWPFParagraph paragraph = header.createParagraph();//创建新的段落
paragraph.setAlignment(ParagraphAlignment.RIGHT);//段落文本的对齐方式
XWPFRun run = paragraph.createRun();
run.setText(month);
//页脚(三个段落分别展示3个内容)-----------------------------------------------------
XWPFFooter footer = headerFooterPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT);
paragraph = footer.createParagraph();
paragraph.setAlignment(ParagraphAlignment.CENTER);
run = paragraph.createRun();
run.setText("NIO Internal");
paragraph = footer.createParagraph();
paragraph.setAlignment(ParagraphAlignment.LEFT);
run = paragraph.createRun();
run.setText("NIO.com");
//生成页码---------------------------------------------------------------------
paragraph = footer.createParagraph();
paragraph.setAlignment(ParagraphAlignment.RIGHT);
run = paragraph.createRun();
CTFldChar fldChar = run.getCTR().addNewFldChar();
fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));
run = paragraph.createRun();
CTText ctText = run.getCTR().addNewInstrText();
ctText.setStringValue("PAGE \\* MERGEFORMAT");
ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
fldChar = run.getCTR().addNewFldChar();
fldChar.setFldCharType(STFldCharType.Enum.forString("end"));
//----------------------------------------------------------------------------
CTSectPr sectPr = document.getDocument().getBody().getSectPr();
if (sectPr == null) sectPr = document.getDocument().getBody().addNewSectPr();
CTPageMar pageMar = sectPr.getPgMar();
if (pageMar == null) pageMar = sectPr.addNewPgMar();
pageMar.setLeft(BigInteger.valueOf(720)); //720 TWentieths of an Inch Point (Twips) = 720/20 = 36 pt = 36/72 = 0.5"
pageMar.setRight(BigInteger.valueOf(720));
pageMar.setTop(BigInteger.valueOf(1440)); //1440 Twips = 1440/20 = 72 pt = 72/72 = 1"
pageMar.setBottom(BigInteger.valueOf(1440));
pageMar.setHeader(BigInteger.valueOf(500)); //页眉上边框到顶部的距离
pageMar.setFooter(BigInteger.valueOf(800)); //页脚下边框到底部的距离
}
/**
* 导出工具示例
*
@@ -126,27 +256,6 @@ public class WordUtil {
Boolean isBold,
String fontFamily) {
// CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
// XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(document, sectPr);
//
// //添加页眉
// CTP ctpHeader = CTP.Factory.newInstance();
// CTR ctrHeader = ctpHeader.addNewR();
// CTText ctHeader = ctrHeader.addNewT();
// String headerText = "Java POI create MS word file.";
// ctHeader.setStringValue(headerText);
// XWPFParagraph headerParagraph = new XWPFParagraph(ctpHeader, document);
// //设置为右对齐
// headerParagraph.setAlignment(ParagraphAlignment.RIGHT);
// XWPFParagraph[] parsHeader = new XWPFParagraph[1];
// parsHeader[0] = headerParagraph;
// try {
// policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, parsHeader);
// } catch (IOException e) {
// e.printStackTrace();
// }
//添加标题
XWPFParagraph titleParagraph = document.createParagraph();
//设置段落左对齐
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB