手册方式优化

This commit is contained in:
zhal 2023-07-07 11:29:29 +08:00
parent ebd83ebb42
commit 2935707204
3 changed files with 251 additions and 78 deletions

View File

@ -2,6 +2,7 @@ package com.actionsoft.apps.coe.pal.pal.output.util;
import java.awt.*;
import java.io.*;
import java.sql.Timestamp;
import java.util.*;
import java.util.List;
import java.util.stream.Stream;
@ -269,6 +270,11 @@ public class OutputWordUtil {
//***********************************************************使用spire 生成模板后复制文件****************************************************/
List<Map<String, Object>> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容
if (wizardJsonData.getBoolean("orderNuberFirst")) { // 根据页面选择进行排序
@ -370,7 +376,7 @@ public class OutputWordUtil {
ParagraphFormat paragraphFormat1 = paragraph.getFormat();
paragraphFormat1.setHorizontalAlignment(HorizontalAlignment.Left);
TextRange tr = paragraph.appendText("5.相关文件");
TextRange tr = paragraph.appendText("相关文件");
tr.getCharacterFormat().setBold(true);
tr.getCharacterFormat().setFontName("宋体");
//tr.applyCharacterFormat(format); //应用字体格式
@ -428,12 +434,6 @@ public class OutputWordUtil {
}
//支持文件
JSONArray supportfiles = new JSONArray(); //组织职责Table
List<DesignerShapeRelationModel> relationList = DesignerShapeRelationCache.getListByAttrId(repositoryModel.getId(), "", "support_files");
@ -460,13 +460,7 @@ public class OutputWordUtil {
Paragraph paragraph2 = section.addParagraph();
ParagraphFormat paragraphFormat2 = paragraph2.getFormat();
paragraphFormat2.setHorizontalAlignment(HorizontalAlignment.Left);
TextRange tr2;
if(relationList2.size()==0){
tr2= paragraph2.appendText("5.支持文件");
}else{
tr2 = paragraph2.appendText("6.支持文件");
}
TextRange tr2=paragraph2.appendText("支持文件");
tr2.getCharacterFormat().setBold(true);
tr2.getCharacterFormat().setFontName("宋体");
paragraph2.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式
@ -518,12 +512,6 @@ public class OutputWordUtil {
}
/*CharacterFormat format3=new CharacterFormat();
//创建字体格式
format3.setFontName("宋体");
@ -559,24 +547,38 @@ public class OutputWordUtil {
ParagraphFormat paragraphFormat4 = paragraph4.getFormat();
paragraphFormat4.setHorizontalAlignment(HorizontalAlignment.Left);
TextRange tr4;
if(relationList2.size()==0 && relationList.size()==0){
tr4= paragraph4.appendText("5.附件");
}else if(relationList2.size()>0 && relationList.size()>0){
tr4 = paragraph4.appendText("7.附件");
}else{
tr4 = paragraph4.appendText("6.附件");
}
TextRange tr4 = paragraph4.appendText("附件");;
tr4.getCharacterFormat().setBold(true);
tr4.getCharacterFormat().setFontName("宋体");
paragraph4.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式
doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
//doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
//查询模型文件属性上传附件信息
List<UpfileModel> search2 = upFileDao.searchByRepositoryId(repositoryModel.getId(),"f");
int filecount=1;
DCContext dcContextModel = null;
// 排序
Collections.sort(search2, new Comparator<UpfileModel>() {
@Override
public int compare(UpfileModel o1, UpfileModel o2) {
String p1=o1.getFileName();
String p2=o2.getFileName();
if(p1.substring(0,2).equals("附件") && p2.substring(0,2).equals("附件")){
return Integer.parseInt(p1.substring(2,p1.indexOf(""))) - Integer.parseInt(p2.substring(2,p2.indexOf("")));
}else{
return 0;
}
}
});
//读取模型附件插入手册中文档对象
if (search2 != null && search2.size() > 0) {
for (UpfileModel upfileModel : search2) {
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
@ -594,67 +596,238 @@ public class OutputWordUtil {
String suffix = dcContextModel.getFileName().substring(lastIndexOf);
DocPicture pdfIcon = new DocPicture(doc);
if (suffix.contains(".doc") ) {
InputStream stream1 = new FileInputStream(dcContextModel.getFilePath());
DocPicture pic1 = new DocPicture(doc);
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/word.png");
paragraph5.appendText("附件"+filecount+":"+dcContextModel.getFileName());
paragraph5.appendOleObject(stream1, pic1, "doc");
}else if(suffix.contains(".pdf")){
InputStream stream1 = new FileInputStream(dcContextModel.getFilePath());
DocPicture pic1 = new DocPicture(doc);
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/pdf.png");
paragraph5.appendText("附件"+filecount+":"+dcContextModel.getFileName());
paragraph5.appendOleObject(stream1, pic1, "pdf");
}else if(suffix.contains(".docx")){
InputStream stream1 = new FileInputStream(dcContextModel.getFilePath());
DocPicture pic1 = new DocPicture(doc);
InputStream stream1 = new FileInputStream(dcContextModel.getFilePath());
DocPicture pic1 = new DocPicture(doc);
if (suffix.equals(".doc") || suffix.equals(".docx")) {
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/word.png");
paragraph5.appendText("附件"+filecount+":"+dcContextModel.getFileName());
paragraph5.appendOleObject(stream1, pic1, "docx");
paragraph5.appendText(dcContextModel.getFileName());
if(suffix.equals(".doc")){
paragraph5.appendOleObject(stream1, pic1, "doc");
}else if(suffix.equals(".docx")){
paragraph5.appendOleObject(stream1, pic1, "docx");
}
}else if(suffix.equals(".pdf")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/pdf.png");
paragraph5.appendText(dcContextModel.getFileName());
paragraph5.appendOleObject(stream1, pic1, "pdf");
}else if(suffix.equals(".xls") || suffix.equals(".xlsx")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/xls.png");
paragraph5.appendText(dcContextModel.getFileName());
if(suffix.equals(".xls")){
paragraph5.appendOleObject(stream1, pic1, "xls");
}else if(suffix.equals(".xlsx")){
paragraph5.appendOleObject(stream1, pic1, "xlsx");
}
}else if(suffix.equals(".png") || suffix.equals(".jgp")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/png.png");
paragraph5.appendText(dcContextModel.getFileName());
if(suffix.equals(".png")){
paragraph5.appendOleObject(stream1, pic1, "png");
}else if(suffix.equals(".jpg")){
paragraph5.appendOleObject(stream1, pic1, "jpg");
}
}else if(suffix.equals(".zip") || suffix.equals(".rar")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/zip.png");
paragraph5.appendText(dcContextModel.getFileName());
if(suffix.equals(".zip")){
paragraph5.appendOleObject(stream1, pic1, "zip");
}else if(suffix.equals(".rar")){
paragraph5.appendOleObject(stream1, pic1, "rar");
}
}else if(suffix.equals(".mp3") || suffix.equals(".mp4")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/mp3.png");
paragraph5.appendText(dcContextModel.getFileName());
if(suffix.equals(".mp3")){
paragraph5.appendOleObject(stream1, pic1, "mp3");
}else if(suffix.equals(".mp4")){
paragraph5.appendOleObject(stream1, pic1, "mp4");
}
}else if(suffix.equals(".txt")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/txt.png");
paragraph5.appendText(dcContextModel.getFileName());
paragraph5.appendOleObject(stream1, pic1, "txt");
}
filecount++;
doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
}
}
}
if (dcContextpdf != null) {
file = new File(dcContextpdf.getFilePath());
}
if (file != null) {
}
doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
}
public static void removeSpireDoc(String docFilePath) {
try (FileInputStream in = new FileInputStream(docFilePath)) {
XWPFDocument doc = new XWPFDocument(OPCPackage.open(in));
List<XWPFParagraph> paragraphs = doc.getParagraphs();
if (paragraphs.size() < 1) {
return;
}
XWPFParagraph firstParagraph = paragraphs.get(0);
if (firstParagraph.getText().contains("Spire.Doc")) {
doc.removeBodyElement(doc.getPosOfParagraph(firstParagraph));
}
OutputStream out = new FileOutputStream(docFilePath);
doc.write(out);
out.close();
} catch (Exception e) {
/**
* 生成word文件
*
* @param dataMap
* @param tempPath
* @param tempName
* @param docName
*/
public static void createBdDoc2(JSONObject dataMap, String tempPath, String tempName, String docName,String repositoryId) throws FileNotFoundException {
Configuration configuration = new Configuration();
configuration.setDefaultEncoding("UTF-8");
// 设置模本装置方法和路径
try {
UtilFile temps = new UtilFile(tempPath);
configuration.setDirectoryForTemplateLoading(temps);
} catch (IOException e2) {
e2.printStackTrace();
}
Template t = null;
try {
t = configuration.getTemplate(tempName, "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
}
// 输出文档路径及名称
File outFile = new File(docName);
Writer out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"));
} catch (Exception e1) {
e1.printStackTrace();
}
try {
if (t!= null && out != null) {
t.process(dataMap, out);
out.flush();
out.close();
}
} catch (TemplateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
/**************************************************插入文件对象**********************************************************************/
Document doc=new Document(outFile.getPath());
//获取最后一节
Section section = doc.getLastSection();
CharacterFormat format4=new CharacterFormat();
//创建字体格式
format4.setFontName("宋体");
//添加段落
Paragraph paragraph = section.addParagraph();
ParagraphFormat paragraphFormat4 = paragraph.getFormat();
paragraphFormat4.setHorizontalAlignment(HorizontalAlignment.Left);
TextRange tr4 = paragraph.appendText("表单/模板");
tr4.getCharacterFormat().setBold(true);
tr4.getCharacterFormat().setFontName("宋体");
paragraph.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式
//doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId);
UpFileDao upFileDao = new UpFileDao();
//查询模型文件属性上传附件信息
List<UpfileModel> search = upFileDao.searchByRepositoryId(repositoryModel.getId(),"s");
DCContext dcContextModel = null;
UserContext userContext=DispatcherRequest.getUserContext();
if (search != null && search.size() > 0) {
// 复制附件
for (UpfileModel upfileModel : search) {
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
if (dcProfile != null) {
dcContextModel = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName());
String path = dcContextModel.getPath();
String fileName = dcContextModel.getFileName();
//添加段落
Paragraph paragraph5 = section.addParagraph();
//加载一个图片它将作为外部文件的符号显示在Word文档中
//获取最后一个.的位置
int lastIndexOf = dcContextModel.getFileName().lastIndexOf(".");
//获取文件的后缀名 .jpg
String suffix = dcContextModel.getFileName().substring(lastIndexOf);
DocPicture pdfIcon = new DocPicture(doc);
InputStream stream1 = new FileInputStream(dcContextModel.getFilePath());
DocPicture pic1 = new DocPicture(doc);
if (suffix.equals(".doc") || suffix.equals(".docx")) {
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/word.png");
paragraph5.appendText(dcContextModel.getFileName());
if(suffix.equals(".doc")){
paragraph5.appendOleObject(stream1, pic1, "doc");
}else if(suffix.equals(".docx")){
paragraph5.appendOleObject(stream1, pic1, "docx");
}
}else if(suffix.equals(".pdf")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/pdf.png");
paragraph5.appendText(dcContextModel.getFileName());
paragraph5.appendOleObject(stream1, pic1, "pdf");
}else if(suffix.equals(".xls") || suffix.equals(".xlsx")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/xls.png");
paragraph5.appendText(dcContextModel.getFileName());
if(suffix.equals(".xls")){
paragraph5.appendOleObject(stream1, pic1, "xls");
}else if(suffix.equals(".xlsx")){
paragraph5.appendOleObject(stream1, pic1, "xlsx");
}
}else if(suffix.equals(".png") || suffix.equals(".jgp")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/png.png");
paragraph5.appendText(dcContextModel.getFileName());
if(suffix.equals(".png")){
paragraph5.appendOleObject(stream1, pic1, "png");
}else if(suffix.equals(".jpg")){
paragraph5.appendOleObject(stream1, pic1, "jpg");
}
}else if(suffix.equals(".zip") || suffix.equals(".rar")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/zip.png");
paragraph5.appendText(dcContextModel.getFileName());
if(suffix.equals(".zip")){
paragraph5.appendOleObject(stream1, pic1, "zip");
}else if(suffix.equals(".rar")){
paragraph5.appendOleObject(stream1, pic1, "rar");
}
}else if(suffix.equals(".mp3") || suffix.equals(".mp4")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/mp3.png");
paragraph5.appendText(dcContextModel.getFileName());
if(suffix.equals(".mp3")){
paragraph5.appendOleObject(stream1, pic1, "mp3");
}else if(suffix.equals(".mp4")){
paragraph5.appendOleObject(stream1, pic1, "mp4");
}
}else if(suffix.equals(".txt")){
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/txt.png");
paragraph5.appendText(dcContextModel.getFileName());
paragraph5.appendOleObject(stream1, pic1, "txt");
}
}
}
}
doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
}
/**