diff --git a/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar b/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar deleted file mode 100644 index 43fd6b74..00000000 Binary files a/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar and /dev/null differ diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java index eee9d65c..d947b584 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java @@ -1,25 +1,14 @@ package com.actionsoft.apps.coe.pal.pal.output.util; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; +import java.awt.*; +import java.io.*; +import java.util.*; import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.stream.Stream; import com.actionsoft.apps.coe.pal.constant.CoEConstant; import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager; +import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.cache.DesignerShapeRelationCache; import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstant; import com.actionsoft.apps.coe.pal.pal.repository.upfile.dao.UpFileDao; import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel; @@ -43,15 +32,27 @@ import com.actionsoft.apps.coe.pal.pal.repository.designer.util.CoeDesignerUtil; import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; import com.actionsoft.sdk.local.SDK; -import com.spire.doc.*; -import com.spire.doc.documents.*; -import com.spire.doc.fields.DocPicture; -import com.spire.doc.fields.TextRange; +import com.alibaba.fastjson.JSON; +import com.google.gson.JsonObject; +import com.sini.com.spire.doc.*; +import com.sini.com.spire.doc.documents.*; +import com.sini.com.spire.doc.fields.DocPicture; +import com.sini.com.spire.doc.fields.TextRange; +import com.sini.com.spire.doc.formatting.CharacterFormat; + +import com.sini.com.spire.doc.formatting.ParagraphFormat; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; +import org.docx4j.wml.P; +import org.pptx4j.pml.Presentation; +import org.xlsx4j.sml.Col; public class OutputWordUtil { @@ -227,7 +228,7 @@ public class OutputWordUtil { * @param tempName * @param docName */ - public static void createZdDoc2(JSONObject dataMap, String tempPath, String tempName, String docName,JSONObject wizardJsonData,String repositoryId) { + public static void createZdDoc2(JSONObject dataMap, String tempPath, String tempName, String docName,JSONObject wizardJsonData,String repositoryId) throws FileNotFoundException { Configuration configuration = new Configuration(); configuration.setDefaultEncoding("UTF-8"); @@ -268,7 +269,7 @@ public class OutputWordUtil { - //***********************************************************使用spire 生成模板后复制文件 + //***********************************************************使用spire 生成模板后复制文件****************************************************/ List> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容 if (wizardJsonData.getBoolean("orderNuberFirst")) { // 根据页面选择进行排序 OutputWordUtil.orderByNumber(repositoryFileElements); @@ -315,36 +316,315 @@ public class OutputWordUtil { // 复制附件 for (UpfileModel upfileModel : search) { DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); - if (upfileModel.getFileName().contains(".xml")) { - if (dcProfile != null) { - dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName()); - break; - } + + if (dcProfile != null) { + dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName()); + String path = dcContextpdf.getPath(); + String fileName = dcContextpdf.getFileName(); + + //创建 Document 类的对象并从磁盘加载 Word 文档 + Document document = new Document(outFile.getPath()); + + //将另一个文档插入当前文档 + document.insertTextFromFile(path+fileName, FileFormat.Docx_2013); + // document.insertTextFromFile("/Users/sunlh/Downloads/手册格式问题测试文档(3)new.docx", FileFormat.Docx_2013); + //保存结果文档 + document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + } + } + + } + + + /****************************插入支持文件、相关文件、附则等信息********************************************************/ + Document doc=new Document(outFile.getPath()); + //获取最后一节 + Section section = doc.getLastSection(); + + + //相关文件 R_relevant_flies + JSONArray relevant_flies = new JSONArray(); //组织职责Table + List relationList2 = DesignerShapeRelationCache.getListByAttrId(repositoryModel.getId(), "", "related_files"); + int count = 0; + if(relationList2.size()>0) { + for (DesignerShapeRelationModel relation : relationList2) { + String relationFileId = relation.getRelationFileId();// 支持或相关文件的ID + PALRepositoryModel model = PALRepositoryCache.getCache().get(relationFileId); + if (model != null) { + count++; + String name = model.getName(); + JSONObject tmp = new JSONObject(); + tmp.put("name", name); + tmp.put("desc", count); + + relevant_flies.add(tmp); } - if (upfileModel.getFileName().contains(".doc")||upfileModel.getFileName().contains(".docx")) { - if (dcProfile != null) { - dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName()); - String path = dcContextpdf.getPath(); - String fileName = dcContextpdf.getFileName(); + } - //创建 Document 类的对象并从磁盘加载 Word 文档 - Document document = new Document(outFile.getPath()); + CharacterFormat format = new CharacterFormat(); + //创建字体格式 + format.setFontName("宋体"); + //添加段落,设置一级序列 + Paragraph paragraph = section.addParagraph(); + + ParagraphFormat paragraphFormat1 = paragraph.getFormat(); + paragraphFormat1.setHorizontalAlignment(HorizontalAlignment.Left); + + TextRange tr = paragraph.appendText("5.相关文件"); + tr.getCharacterFormat().setBold(true); + tr.getCharacterFormat().setFontName("宋体"); + //tr.applyCharacterFormat(format); //应用字体格式 + paragraph.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式 - //将另一个文档插入当前文档 - document.insertTextFromFile(path+fileName, FileFormat.Docx_2013); - // document.insertTextFromFile("/Users/sunlh/Downloads/手册格式问题测试文档(3)new.docx", FileFormat.Docx_2013); + Section section2 = doc.addSection(); - //保存结果文档 - document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + //定义表格数据 + String[] header = {"序号", "文件名称"}; + + String[][] strArray2 = new String[relevant_flies.size()][]; + List list = new LinkedList<>(); + for (int i = 0; i < relevant_flies.size(); i++) { + JSONObject jsonObject = relevant_flies.getJSONObject(i); + String[] strArray = new String[2]; + strArray[0] = jsonObject.getString("desc").toString(); + strArray[1] = jsonObject.getString("name").toString(); + list.add(strArray); + strArray2[i]=strArray; + } + + String[][] data = strArray2; + + //添加表格 + Table table = section.addTable(true); + table.resetCells(data.length + 1, header.length); + + TableRow row = table.getRows().get(0); + row.isHeader(true); + row.setHeight(20); + row.setHeightType(TableRowHeightType.Exactly); + for (int i = 0; i < header.length; i++) { + row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + Paragraph p = row.getCells().get(i).addParagraph(); + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + TextRange txtRange = p.appendText(header[i]); + txtRange.getCharacterFormat().setBold(true); + } + + //将数据添加到其余行 + for (int r = 0; r < data.length; r++) { + TableRow dataRow = table.getRows().get(r + 1); + dataRow.setHeight(25); + dataRow.setHeightType(TableRowHeightType.Exactly); + dataRow.getRowFormat().setBackColor(Color.white); + for (int c = 0; c < data[r].length; c++) { + dataRow.getCells().get(c).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); + } + } + + + } + + + + + + //支持文件 + JSONArray supportfiles = new JSONArray(); //组织职责Table + List relationList = DesignerShapeRelationCache.getListByAttrId(repositoryModel.getId(), "", "support_files"); + int index = 0; + if(relationList.size()>0){ + for (DesignerShapeRelationModel relation : relationList) { + String relationFileId = relation.getRelationFileId();// 支持或相关文件的ID + PALRepositoryModel model = PALRepositoryCache.getCache().get(relationFileId); + if (model != null) { + index++; + String name = model.getName(); + JSONObject tmp = new JSONObject(); + tmp.put("name", name); + tmp.put("desc", index); + supportfiles.add(tmp); + } + } + + + CharacterFormat format2=new CharacterFormat(); + //创建字体格式 + format2.setFontName("宋体"); + //添加段落,设置一级序列 + 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.支持文件"); + } + + tr2.getCharacterFormat().setBold(true); + tr2.getCharacterFormat().setFontName("宋体"); + paragraph2.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式 + + + //定义表格数据 + String[] header = {"序号", "文件名称"}; + String[][] strArray2 = new String[supportfiles.size()][]; + List list = new LinkedList<>(); + for (int i = 0; i < supportfiles.size(); i++) { + JSONObject jsonObject = supportfiles.getJSONObject(i); + String[] strArray = new String[2]; + strArray[0] = jsonObject.getString("desc").toString(); + strArray[1] = jsonObject.getString("name").toString(); + list.add(strArray); + strArray2[i]=strArray; + } + + String[][] data = strArray2; + + //添加表格 + Table table = section.addTable(true); + table.resetCells(data.length + 1, header.length); + + TableRow row = table.getRows().get(0); + row.isHeader(true); + row.setHeight(20); + row.setHeightType(TableRowHeightType.Exactly); + for (int i = 0; i < header.length; i++) { + row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + Paragraph p = row.getCells().get(i).addParagraph(); + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + TextRange txtRange = p.appendText(header[i]); + txtRange.getCharacterFormat().setBold(true); + } + + //将数据添加到其余行 + for (int r = 0; r < data.length; r++) { + TableRow dataRow = table.getRows().get(r + 1); + dataRow.setHeight(25); + dataRow.setHeightType(TableRowHeightType.Exactly); + dataRow.getRowFormat().setBackColor(Color.white); + for (int c = 0; c < data[r].length; c++) { + dataRow.getCells().get(c).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); + } + } + + + } + + + + + + + + /*CharacterFormat format3=new CharacterFormat(); + //创建字体格式 + format3.setFontName("宋体"); + //添加段落,设置一级序列 + Paragraph paragraph3 = section.addParagraph(); + TextRange tr3 = paragraph3.appendText("7.附则"); + tr3.getCharacterFormat().setBold(true); + tr3.getCharacterFormat().setFontName("宋体"); + paragraph3.applyStyle(BuiltinStyle.Heading_7); //应用标题1样式 + + //添加段落 + Paragraph paragraph5 = section.addParagraph(); + + // 附则处理 + List T_supplementary_articles_table = new ArrayList<>(); + String [] tmp = dataMap.getString("pl_T_supplementary_articles").split("\n"); + for (int i = 0; i < tmp.length; i++) { + if (UtilString.isNotEmpty(tmp[i])) { + T_supplementary_articles_table.add(tmp[i]); + } + } + + TextRange tr5 = paragraph5.appendText(T_supplementary_articles_table.toString()); + tr5.getCharacterFormat().setFontName("宋体");*/ + + + CharacterFormat format4=new CharacterFormat(); + //创建字体格式 + format4.setFontName("宋体"); + //添加段落 + Paragraph paragraph4 = section.addParagraph(); + + 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.附件"); + } + tr4.getCharacterFormat().setBold(true); + tr4.getCharacterFormat().setFontName("宋体"); + paragraph4.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式 + + doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + + List search2 = upFileDao.searchByRepositoryId(repositoryModel.getId(),"f"); + int filecount=1; + DCContext dcContextModel = null; + if (search2 != null && search2.size() > 0) { + for (UpfileModel upfileModel : search2) { + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); + if (dcProfile != null) { + + // 处理DocCenter + dcContextModel = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, "file", upfileModel.getPl_uuid(), upfileModel.getFileName()); + //添加段落 + Paragraph paragraph5 = section.addParagraph(); + + //加载一个图片,它将作为外部文件的符号显示在Word文档中 + //获取最后一个.的位置 + int lastIndexOf = dcContextModel.getFileName().lastIndexOf("."); + //获取文件的后缀名 .jpg + 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); + pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/word.png"); + paragraph5.appendText("附件"+filecount+":"+dcContextModel.getFileName()); + paragraph5.appendOleObject(stream1, pic1, "docx"); } + + + filecount++; + + doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013); } } + } + if (dcContextpdf != null) { file = new File(dcContextpdf.getFilePath()); } @@ -357,39 +637,23 @@ public class OutputWordUtil { } - - - - - //自定义方法来添加图片、文字页眉及页码 - private static void AddHeaderFooter(Section sec){ - //加载图片添加到页眉,并设置图片在段落中的对齐方式 - HeaderFooter header = sec.getHeadersFooters().getHeader(); - Paragraph hpara= header.addParagraph(); - DocPicture pic =hpara.appendPicture("D:\\xxx.png"); - pic.setHorizontalAlignment(ShapeHorizontalAlignment.Right); - pic.setHeight(100); - pic.setWidth(100); - pic.setVerticalOrigin(VerticalOrigin.Inner_Margin_Area); - pic.setVerticalAlignment(ShapeVerticalAlignment.Bottom); - - //添加文字到页眉,并设置字体、字号、字体加粗、对齐方式 - TextRange txt = hpara.appendText("内蒙古伊利集团股份有限公司"); - txt.getCharacterFormat().setUnderlineStyle(UnderlineStyle.None); - txt.getCharacterFormat().setFontName("黑体"); - txt.getCharacterFormat().setFontSize(10f); - hpara.getFormat().setHorizontalAlignment(HorizontalAlignment.Left); - - - //添加页码到页脚,并设置页脚对齐方式,顶部边线粗细、间距 - HeaderFooter footer = sec.getHeadersFooters().getFooter(); - Paragraph fpara= footer.addParagraph(); - fpara.appendField("页码",FieldType.Field_Page); - fpara.appendField("总页数",FieldType.Field_Num_Pages); - fpara.getFormat().setHorizontalAlignment(HorizontalAlignment.Right); - fpara.getFormat().getBorders().getTop().setBorderType(BorderStyle.Single); - fpara.getFormat().getBorders().getTop().setLineWidth(1f); - fpara.getFormat().getBorders().getTop().setSpace(2f); + public static void removeSpireDoc(String docFilePath) { + try (FileInputStream in = new FileInputStream(docFilePath)) { + XWPFDocument doc = new XWPFDocument(OPCPackage.open(in)); + List 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) { + e.printStackTrace(); + } } diff --git a/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/js/coe.team.pal.designer.js b/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/js/coe.team.pal.designer.js index 84c34310..ef69d7f2 100644 --- a/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/js/coe.team.pal.designer.js +++ b/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/js/coe.team.pal.designer.js @@ -301,9 +301,8 @@ $(function() { * 获取流程列表信息,并跳转到dw数据试图 */ function getProcessManifestInfo() { - debugger; let url="./w?sid="+$("#sid").val()+"&cmd=CLIENT_DW_PORTAL&processGroupId=obj_4e95a7af7bf1414f9e878d013192675e&appId" - + "=com.actionsoft.apps.coe.pal.publisher&dwViewId=obj_3ebec26134e345a2894e4bf0d0c628f0&condition=" + + "=com.actionsoft.apps.coe.pal.publisher&dwViewId=obj_3ebec26134e345a2894e4bf0d0c628f0&hideSearcher=true&condition=" + encodeURIComponent("[{cp:'=',fd:'MODELID',cv:'"+ ruuid +"'}]"); //+"&condition=\"+encodeURIComponent(\"[{cp:'=',fd:'MODELID',cv:'"+ruuid+"'}]\""; $.ajax({