月报--封面和目录
This commit is contained in:
+167
-16
@@ -36,10 +36,14 @@ import com.jero.modules.system.service.impl.SysBaseApiImpl;
|
||||
import com.jero.modules.system.service.impl.SysCategoryServiceImpl;
|
||||
import com.jero.modules.system.service.impl.SysDictItemServiceImpl;
|
||||
import com.jero.modules.system.util.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HeaderFooter;
|
||||
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
|
||||
import org.apache.poi.xwpf.usermodel.TOC;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.aspectj.util.FileUtil;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -55,6 +59,7 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -617,13 +622,24 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
//内容中文版
|
||||
XWPFDocument documentContentCn = new XWPFDocument();
|
||||
FileOutputStream outContentCn = new FileOutputStream(wordFileContentCn);
|
||||
//封面
|
||||
cover(lawsMonthlyReportWriteEOS, titleCN, documentContentCn);
|
||||
//目录
|
||||
catalogue(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, "目录", documentContentCn,CutEnum.CN.getValue());
|
||||
wordContent(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, titleCN,
|
||||
documentContentCn,CutEnum.CN.getValue(),loginUserList);
|
||||
// documentContentCn.createTOC();
|
||||
// createTOC(documentContentCn);
|
||||
documentContentCn.write(outContentCn);
|
||||
|
||||
|
||||
//内容英文版
|
||||
XWPFDocument documentContentEn = new XWPFDocument();
|
||||
FileOutputStream outContentEn = new FileOutputStream(wordFileContentEn);
|
||||
//封面
|
||||
cover(lawsMonthlyReportWriteEOS, titleEN, documentContentEn);
|
||||
//目录
|
||||
catalogue(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, "catalogue", documentContentEn,CutEnum.EN.getValue());
|
||||
wordContent(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, titleEN,
|
||||
documentContentEn,CutEnum.EN.getValue(), loginUserList);
|
||||
documentContentEn.write(outContentEn);
|
||||
@@ -633,6 +649,55 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
}
|
||||
}
|
||||
|
||||
public void createTOC(XWPFDocument document) {
|
||||
CTSdtBlock block = document.getDocument().getBody().addNewSdt();
|
||||
TOC toc = new TOC(block);
|
||||
Iterator i$ = document.getParagraphs().iterator();
|
||||
|
||||
while(i$.hasNext()) {
|
||||
XWPFParagraph par = (XWPFParagraph)i$.next();
|
||||
String parStyle = par.getStyle();
|
||||
String page = HeaderFooter.page();
|
||||
if (parStyle != null && parStyle.startsWith("Heading")) {
|
||||
try {
|
||||
int level = Integer.parseInt(parStyle.substring("Heading".length()));
|
||||
toc.addRow(level, par.getText(), 1, "112723803");
|
||||
} catch (NumberFormatException var7) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// public static void insertNextPageChar(XWPFDocument document) {
|
||||
// // 首先获取 document 的 Section 信息
|
||||
// CTBody body = document.getDocument().getBody();
|
||||
// // 放心, 这个 body 肯定不为空, 否则这个文档就有问题了
|
||||
// XWPFParagraph paragraph = document.createParagraph();
|
||||
// // 新创建的段落肯定没有 PPr, 所以需要新创建一个
|
||||
// CTPPr ctpPr = paragraph.getCTP().addNewPPr();
|
||||
// // 这一句其实就是设置下一页的分页符了
|
||||
// CTSectPr sectPr = ctpPr.addNewSectPr();
|
||||
// // 先加入到 document 的 List 中
|
||||
// Document parent = Document.getParentDocument(document);
|
||||
// if (parent != null) {
|
||||
// parent.addSectPr(sectPr);
|
||||
// }
|
||||
// if (!body.isSetSectPr()) {
|
||||
// // 文档没设置了 sectPr
|
||||
// return;
|
||||
// }
|
||||
// // 把文档上的 sectPr 中的某些属性赋值给新创建的段落的 sectPr
|
||||
// CTSectPr bodySectPr = body.getSectPr();
|
||||
// sectPr.setPgSz(bodySectPr.getPgSz());
|
||||
// sectPr.setPgMar(bodySectPr.getPgMar());
|
||||
// sectPr.setCols(bodySectPr.getCols());
|
||||
// sectPr.setDocGrid(bodySectPr.getDocGrid());
|
||||
// }
|
||||
|
||||
|
||||
|
||||
private void word(List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
List<LawsMonthlyReportTitleTemplateEO> lawsMonthlyReportTitleTemplateEOS,
|
||||
List<LawsMonthlyReportTitleTemplateEO> reportTitleOneList,
|
||||
@@ -711,24 +776,18 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
}
|
||||
}
|
||||
}
|
||||
private void wordContent(List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
private void catalogue(List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
List<LawsMonthlyReportTitleTemplateEO> lawsMonthlyReportTitleTemplateEOS,
|
||||
List<LawsMonthlyReportTitleTemplateEO> reportTitleOneList,
|
||||
String titleCN,
|
||||
String catalogue,
|
||||
XWPFDocument document,
|
||||
String cut,
|
||||
List<LoginUser> loginUserList) {
|
||||
//数据字典
|
||||
List<SysDictItem> sysDictItems = sysDictItemServiceImpl.selectItemsAll();
|
||||
String cut) {
|
||||
|
||||
//树形数据字典
|
||||
List<SysCategory> categoryList = sysCategoryService.list();
|
||||
String moth = lawsMonthlyReportWriteEOS.get(0).getMonth().replaceAll("-", "年") + "月";
|
||||
//生成页眉页脚
|
||||
WordUtil.exportHeardAndFoot(document,moth);
|
||||
//生成标题
|
||||
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 18,
|
||||
false, true, "Blue Sky Noto Regular",null);
|
||||
//单独设置每页右侧的时间
|
||||
WordUtil.exportWord(document, catalogue, null, ParagraphAlignment.LEFT, 0, 18,
|
||||
false, false, "Blue Sky Noto Regular",null);
|
||||
|
||||
int oneCount = 1;
|
||||
|
||||
for (LawsMonthlyReportTitleTemplateEO lawsMonthlyReportTitleTemplateEO : reportTitleOneList) {
|
||||
@@ -743,7 +802,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
}
|
||||
if(StringUtils.isNotBlank(oneTitle)){
|
||||
WordUtil.exportWord(document, oneNumber+" "+oneTitle, null, ParagraphAlignment.LEFT,
|
||||
0, 14, false, true, "Blue Sky Noto Regular","1");
|
||||
0, 12, false, true, "Blue Sky Noto Regular",null);
|
||||
oneCount++;
|
||||
}
|
||||
|
||||
@@ -766,7 +825,99 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
}
|
||||
if(StringUtils.isNotBlank(twoTitle)){
|
||||
WordUtil.exportWord(document, twoNumber+" "+twoTitle, null, ParagraphAlignment.LEFT,
|
||||
2, 12, false, true, "Blue Sky Noto Regular","2");
|
||||
2, 12, false, true, "Blue Sky Noto Regular",null);
|
||||
twoCount++;
|
||||
}
|
||||
|
||||
for (LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO : lawsMonthlyReportWriteEOList) {
|
||||
//月报内容标题
|
||||
String reportTitle = "";
|
||||
if(CutEnum.CN.getValue().equals(cut)){
|
||||
reportTitle = lawsMonthlyReportWriteEO.getTitleCn();
|
||||
}else{
|
||||
reportTitle = lawsMonthlyReportWriteEO.getTitleEn();
|
||||
}
|
||||
if(org.apache.commons.lang3.StringUtils.isNotBlank(reportTitle)){
|
||||
WordUtil.exportWord(document, reportCount+". "+reportTitle, null, ParagraphAlignment.LEFT,
|
||||
6, 12, false, false, "Blue Sky Noto Regular",null);
|
||||
reportCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//封面
|
||||
private void cover(List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
String titleCN,
|
||||
XWPFDocument document) {
|
||||
String moth = lawsMonthlyReportWriteEOS.get(0).getMonth().replaceAll("-", "年") + "月";
|
||||
|
||||
titleCN = "\r\n\r\n" + titleCN + "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
|
||||
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 18,
|
||||
false, false, "Blue Sky Noto Regular",null);
|
||||
WordUtil.exportWord(document, moth, null, ParagraphAlignment.CENTER, 0, 12,
|
||||
false, true, "Blue Sky Noto Regular",null);
|
||||
}
|
||||
private void wordContent(List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
List<LawsMonthlyReportTitleTemplateEO> lawsMonthlyReportTitleTemplateEOS,
|
||||
List<LawsMonthlyReportTitleTemplateEO> reportTitleOneList,
|
||||
String titleCN,
|
||||
XWPFDocument document,
|
||||
String cut,
|
||||
List<LoginUser> loginUserList) {
|
||||
//数据字典
|
||||
List<SysDictItem> sysDictItems = sysDictItemServiceImpl.selectItemsAll();
|
||||
|
||||
//树形数据字典
|
||||
List<SysCategory> categoryList = sysCategoryService.list();
|
||||
String moth = lawsMonthlyReportWriteEOS.get(0).getMonth().replaceAll("-", "年") + "月";
|
||||
//生成封面
|
||||
// WordUtil.exportHeardAndFoot(document,moth);
|
||||
|
||||
//生成页眉页脚
|
||||
WordUtil.exportHeardAndFoot(document,moth);
|
||||
//生成标题
|
||||
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 18,
|
||||
false, true, "Blue Sky Noto Regular",null);
|
||||
int oneCount = 1;
|
||||
|
||||
for (LawsMonthlyReportTitleTemplateEO lawsMonthlyReportTitleTemplateEO : reportTitleOneList) {
|
||||
int twoCount = 1;
|
||||
String oneNumber = intToRoman(oneCount);
|
||||
//一级标题
|
||||
String oneTitle = "";
|
||||
if(CutEnum.CN.getValue().equals(cut)){
|
||||
oneTitle = lawsMonthlyReportTitleTemplateEO.getTitleCn();
|
||||
}else{
|
||||
oneTitle = lawsMonthlyReportTitleTemplateEO.getTitleEn();
|
||||
}
|
||||
if(StringUtils.isNotBlank(oneTitle)){
|
||||
WordUtil.exportWord(document, oneNumber+" "+oneTitle, null, ParagraphAlignment.LEFT,
|
||||
0, 14, false, true, "Blue Sky Noto Regular","Heading1");
|
||||
oneCount++;
|
||||
}
|
||||
|
||||
List<LawsMonthlyReportTitleTemplateEO> reportTitleTwoList = lawsMonthlyReportTitleTemplateEOS.stream().filter(e -> e.getParentId().equals(lawsMonthlyReportTitleTemplateEO.getId())).collect(Collectors.toList());
|
||||
|
||||
|
||||
for (LawsMonthlyReportTitleTemplateEO monthlyReportTitleTemplateEO : reportTitleTwoList) {
|
||||
int reportCount = 1;
|
||||
//子标题对应的月报填写的内容
|
||||
List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOList = lawsMonthlyReportWriteEOS.stream().filter(e -> monthlyReportTitleTemplateEO.getId().equals(e.getMemoriesChapter())).collect(Collectors.toList());
|
||||
String twoNumber = intToRoman(twoCount);
|
||||
twoNumber = oneNumber+"."+twoNumber;
|
||||
|
||||
//二级标题
|
||||
String twoTitle = "";
|
||||
if(CutEnum.CN.getValue().equals(cut)){
|
||||
twoTitle = monthlyReportTitleTemplateEO.getTitleCn();
|
||||
}else{
|
||||
twoTitle = monthlyReportTitleTemplateEO.getTitleEn();
|
||||
}
|
||||
if(StringUtils.isNotBlank(twoTitle)){
|
||||
WordUtil.exportWord(document, twoNumber+" "+twoTitle, null, ParagraphAlignment.LEFT,
|
||||
2, 12, false, true, "Blue Sky Noto Regular","Heading2");
|
||||
twoCount++;
|
||||
}
|
||||
//二级目录下放--->新征求意见清单模板, 新发布标准清单模板
|
||||
@@ -794,7 +945,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
}
|
||||
if(StringUtils.isNotBlank(reportTitle)){
|
||||
WordUtil.exportWord(document, reportCount+". "+reportTitle, null, ParagraphAlignment.LEFT,
|
||||
6, 11, false, false, "Blue Sky Noto Regular","3");
|
||||
6, 11, false, false, "Blue Sky Noto Regular","Heading3");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user