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 index b42f447d..715940c8 100644 Binary files a/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar and b/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar differ diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/CoEPALController.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/CoEPALController.java index 81e23720..f1a7b7d0 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/CoEPALController.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/CoEPALController.java @@ -2606,6 +2606,20 @@ public class CoEPALController { } + /** + * 流程手册预览 + * + * @param me + * @param taskId + * @return + */ + // @Mapping("COE_PAL_OUTPUTREPORT_OUTPUT_PROCESS_PREVIEW") + @Mapping("com.actionsoft.apps.coe.pal_outputreport_output_process_ppt_preview") + public String COEPALOUTPUTREPORTOutputProcessPPTPreview(UserContext me, String taskId) { + return PALRepositoryQueryAPIManager.getInstance().outputReportPPTPreview(me, taskId); + } + + /** * 流程阅览 流程手册下载 * @@ -3698,4 +3712,50 @@ public class CoEPALController { } + /** + * 判断表单模型是否存在excel文件 + * + * @param me + * @param uuids + * @param teamId + * @param wsId + * @return + */ + @Mapping("com.actionsoft.apps.coe.pal.publisher_output_pr_estimateFile") + public String createOutputPrReportsByEstimateFile(UserContext me, String fileId) { + DesignerRelationShapeWeb web = new DesignerRelationShapeWeb(me); + return web.createOutputPrReportsByEstimateFile(fileId); + } + + + /** + * 判断制度模型是否存在ppt文件 + * + * @param me + * @param uuids + * @param teamId + * @param wsId + * @return + */ + @Mapping("com.actionsoft.apps.coe.pal.publisher_output_pr_estimatePPTFile") + public String createOutputPrReportsByEstimatePPTFile(UserContext me, String fileId) { + DesignerRelationShapeWeb web = new DesignerRelationShapeWeb(me); + return web.createOutputPrReportsByEstimatePPTFile(me, fileId); + } + + + /** + * 判断附件 + * + * @param me + * @param uuids + * @param teamId + * @param wsId + * @return + */ + @Mapping("com.actionsoft.apps.coe.pal.publisher_output_pr_downloadExcelFile") + public String createOutputPrReportsByDownloadExcelFile(UserContext me, String taskIds) { + DesignerRelationShapeWeb web = new DesignerRelationShapeWeb(me); + return web.createOutputPrReportsByDownloadExcelFile(taskIds); + } } 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 cd53336c..60401fc2 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 @@ -15,6 +15,7 @@ import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstan import com.actionsoft.apps.coe.pal.pal.repository.upfile.dao.UpFileDao; import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel; import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile; +import com.actionsoft.bpms.commons.mvc.view.ResponseObject; import com.actionsoft.bpms.org.model.DepartmentModel; import com.actionsoft.bpms.org.model.RoleModel; import com.actionsoft.bpms.org.model.UserModel; @@ -25,6 +26,7 @@ import com.actionsoft.bpms.server.fs.dc.DCProfileManager; import com.actionsoft.bpms.util.UtilFile; import com.actionsoft.bpms.util.UtilString; import com.actionsoft.sdk.local.SDK; +import com.actionsoft.sdk.local.api.AppAPI; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.sini.com.spire.doc.*; @@ -232,30 +234,8 @@ public class OutputWordUtil { } 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(); - } - - - //***********************************************************使用spire 生成模板后复制文件****************************************************/ +//***********************************************************使用spire 生成模板后复制文件****************************************************/ List> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容 if (wizardJsonData.getBoolean("orderNuberFirst")) { // 根据页面选择进行排序 OutputWordUtil.orderByNumber(repositoryFileElements); @@ -299,7 +279,8 @@ public class OutputWordUtil { DCContext dcContextpdf = null; File file = null; - + boolean isPPT = false; + //如果为PPT,则生成PPT手册 if (search != null && search.size() > 0) { long b1 = System.currentTimeMillis(); // 复制附件 @@ -311,9 +292,80 @@ public class OutputWordUtil { String path = dcContextpdf.getPath(); String fileName = dcContextpdf.getFileName(); + String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); + if (suffix.equals("pptx")) { + isPPT = true; + String pptUrl = docName.substring(0, docName.lastIndexOf("/") + 1); + // 调用App + String sourceAppId = "com.actionsoft.apps.coe.pal"; + // aslp服务地址 + String aslp = "aslp://com.awspaas.user.apps.new_performance_indicator_library/UpdatePptxAndExcelAslp"; + // 参数定义列表 + Map params = new HashMap(); + //文件id,必填 + params.put("pl_uuid", repositoryId); + //文件内容id,必填 + params.put("shape_uuid", search.get(0).getShape_uuid()); - //创建 Document 类的对象并从磁盘加载 Word 文档 - Document document = new Document(outFile.getPath()); + //文件保存地址,必填 + params.put("fil_path", pptUrl + search.get(0).getFileName()); + + //文件路径(不包含文件名称),必填 + params.put("file_url", pptUrl); + + //文件名称,必填 + params.put("file_data", search.get(0).getFileName()); + //sid,必填 + params.put("sid", userContext.getSessionId()); + AppAPI appAPI = SDK.getAppAPI(); + //根据上传的文件进行更新相关的excel或者ppt + ResponseObject ro = appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params); + + } + + + } + } + } + + if (isPPT == false) { + // 输出文档路径及名称 + 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(); + } + + + if (search != null && search.size() > 0) { + long b1 = System.currentTimeMillis(); + // 复制附件 + for (UpfileModel upfileModel : search) { + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); + + 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()); /*//获取最后一节 Section section = document.getLastSection(); @@ -322,481 +374,486 @@ public class OutputWordUtil { paragraph.appendBreak(BreakType.Page_Break);*/ - String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); + String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); + + if (suffix.equals("xml")) { + // 输出文档路径及名称 + File sourceFile = new UtilFile(path + fileName); + File targetFile = new UtilFile(docPath + fileName); + try { + UtilFile.copyFile(sourceFile, targetFile); + } catch (Exception e) { + System.out.println(e); + e.printStackTrace(); + } + + //创建实例,加载xml测试文档 + Document doc = new Document(); + doc.loadFromFile(docPath + fileName); + + //保存为xml格式 + String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); + //保存为Word + doc.saveToFile(docPath + substring + ".docx", FileFormat.Docx);//支持.doc + - if (suffix.equals("xml")) { - // 输出文档路径及名称 - File sourceFile = new UtilFile(path + fileName); - File targetFile = new UtilFile(docPath + fileName); - try { - UtilFile.copyFile(sourceFile, targetFile); - } catch (Exception e) { - System.out.println(e); - e.printStackTrace(); } - //创建实例,加载xml测试文档 - Document doc = new Document(); - doc.loadFromFile(docPath + fileName); - //保存为xml格式 - String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); - //保存为Word - doc.saveToFile(docPath + substring + ".docx", FileFormat.Docx);//支持.doc - - - } - - - if (suffix.equals("xml")) { - //保存为xml格式 - String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); - //保存为Word - document.insertTextFromFile(docPath + substring + ".docx", FileFormat.Docx_2013); - } else { - document.insertTextFromFile(path + fileName, FileFormat.Docx_2013); - } - // document.insertTextFromFile("/Users/sunlh/Downloads/手册格式问题测试文档(3)new.docx", FileFormat.Docx_2013); - try { - //保存结果文档 - document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); - - } catch (Exception e) { - e.printStackTrace(); - } finally { - // 关闭文档对象 - if (document != null) { - document.close(); - document.dispose(); + if (suffix.equals("xml")) { + //保存为xml格式 + String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); + //保存为Word + document.insertTextFromFile(docPath + substring + ".docx", FileFormat.Docx_2013); + } else if (suffix.equals("doc") || suffix.equals("docx")) { + document.insertTextFromFile(path + fileName, FileFormat.Docx_2013); + } else if (suffix.equals("pptx")) { + isPPT = true; } - } - - //复制页眉页脚操作 - try { - //加载纵向模板文档用于复制 - Document doc1 = new Document(); - doc1.loadFromFile(tempPath + "制度-手册5.doc"); - - //获取section - Section section1 = doc1.getSections().get(0); - - //加载文档2 - Document doc2 = new Document(); - doc2.loadFromFile(outFile.getPath()); - SectionCollection sections = doc2.getSections(); - //加载文档1 - Document doc3 = new Document(); - doc3.loadFromFile(tempPath + "横板页眉页脚模板.doc"); + if (isPPT == false) { + // document.insertTextFromFile("/Users/sunlh/Downloads/手册格式问题测试文档(3)new.docx", FileFormat.Docx_2013); + try { + //保存结果文档 + document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); - // 获取源文档的页眉页脚 + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 关闭文档对象 + if (document != null) { + document.close(); + document.dispose(); + } + } + + //复制页眉页脚操作 + try { + //加载纵向模板文档用于复制 + Document doc1 = new Document(); + doc1.loadFromFile(tempPath + "制度-手册5.doc"); + + //获取section + Section section1 = doc1.getSections().get(0); + + //加载文档2 + Document doc2 = new Document(); + doc2.loadFromFile(outFile.getPath()); + SectionCollection sections = doc2.getSections(); + + + //加载文档1 + Document doc3 = new Document(); + doc3.loadFromFile(tempPath + "横板页眉页脚模板.doc"); + + // 获取源文档的页眉页脚 /*Section sourceSection = doc1.getSections().get(0); HeaderFooter sourceHeader = sourceSection.getHeadersFooters().getHeader(); HeaderFooter sourceFooter = sourceSection.getHeadersFooters().getFooter();*/ - // 将页眉复制到目标文档的第三节以及后续节 - for (int i = 2; i < doc2.getSections().getCount(); i++) { - Section targetSection = doc2.getSections().get(i); + // 将页眉复制到目标文档的第三节以及后续节 + for (int i = 2; i < doc2.getSections().getCount(); i++) { + Section targetSection = doc2.getSections().get(i); - PageSetup pageSetup = targetSection.getPageSetup(); - PageOrientation orientation = pageSetup.getOrientation(); + PageSetup pageSetup = targetSection.getPageSetup(); + PageOrientation orientation = pageSetup.getOrientation(); - // 根据合并文档节的页面方向选择模板 - PageOrientation mergeOrientation = pageSetup.getOrientation(); - Document templateDoc = (mergeOrientation == PageOrientation.Landscape) ? doc3 : doc1; + // 根据合并文档节的页面方向选择模板 + PageOrientation mergeOrientation = pageSetup.getOrientation(); + Document templateDoc = (mergeOrientation == PageOrientation.Landscape) ? doc3 : doc1; - // 复制模板文档的页眉和页脚到新文档 - HeaderFooter sourceHeader = templateDoc.getSections().get(0).getHeadersFooters().getHeader(); + // 复制模板文档的页眉和页脚到新文档 + HeaderFooter sourceHeader = templateDoc.getSections().get(0).getHeadersFooters().getHeader(); - HeaderFooter targetHeader = targetSection.getHeadersFooters().getHeader(); - targetHeader.getChildObjects().clear(); + HeaderFooter targetHeader = targetSection.getHeadersFooters().getHeader(); + targetHeader.getChildObjects().clear(); - for (int j = 0; j < sourceHeader.getChildObjects().getCount(); j++) { + for (int j = 0; j < sourceHeader.getChildObjects().getCount(); j++) { - DocumentObject obj = sourceHeader.getChildObjects().get(j).deepClone(); - targetHeader.getChildObjects().add(obj); + DocumentObject obj = sourceHeader.getChildObjects().get(j).deepClone(); + targetHeader.getChildObjects().add(obj); + } + } + // 将页脚复制到目标文档的第三节以及后续节 + for (int i = 2; i < doc2.getSections().getCount(); i++) { + Section targetSection = doc2.getSections().get(i); + HeaderFooter targetFooter = targetSection.getHeadersFooters().getFooter(); + + PageSetup pageSetup = targetSection.getPageSetup(); + + PageOrientation mergeOrientation = pageSetup.getOrientation(); + Document templateDoc = (mergeOrientation == PageOrientation.Landscape) ? doc3 : doc1; + HeaderFooter sourceFooter = templateDoc.getSections().get(0).getHeadersFooters().getFooter(); + + targetFooter.getChildObjects().clear(); + for (int j = 0; j < sourceFooter.getChildObjects().getCount(); j++) { + DocumentObject obj = sourceFooter.getChildObjects().get(j).deepClone(); + targetFooter.getChildObjects().add(obj); + } + + } + doc2.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 关闭文档对象 + if (document != null) { + document.close(); + } } } - // 将页脚复制到目标文档的第三节以及后续节 - for (int i = 2; i < doc2.getSections().getCount(); i++) { - Section targetSection = doc2.getSections().get(i); - HeaderFooter targetFooter = targetSection.getHeadersFooters().getFooter(); - PageSetup pageSetup = targetSection.getPageSetup(); - - PageOrientation mergeOrientation = pageSetup.getOrientation(); - Document templateDoc = (mergeOrientation == PageOrientation.Landscape) ? doc3 : doc1; - HeaderFooter sourceFooter = templateDoc.getSections().get(0).getHeadersFooters().getFooter(); - - targetFooter.getChildObjects().clear(); - for (int j = 0; j < sourceFooter.getChildObjects().getCount(); j++) { - DocumentObject obj = sourceFooter.getChildObjects().get(j).deepClone(); - targetFooter.getChildObjects().add(obj); - } - - } - doc2.saveToFile(outFile.getPath(), FileFormat.Docx_2013); - - - } catch (Exception e) { - e.printStackTrace(); - } finally { - // 关闭文档对象 - if (document != null) { - document.close(); - } } } - } - long b2 = System.currentTimeMillis(); + long b2 = System.currentTimeMillis(); - System.err.println("复制附件用时:" - + (b2 - b1) / 1000 + "秒"); - } - - - /****************************插入支持文件、相关文件、附则等信息********************************************************/ - Document doc = new Document(outFile.getPath()); - //获取最后一节 - Section section = doc.getLastSection(); - - //添加段落,设置一级序列 - Paragraph paragraph = section.addParagraph(); - - - //paragraph.appendBreak(BreakType.Page_Break); - //Section section2 = doc.addSection(); - - //相关文件 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); - } + System.err.println("复制附件用时:" + + (b2 - b1) / 1000 + "秒"); } - CharacterFormat format = new CharacterFormat(); - //创建字体格式 - format.setFontName("宋体"); + + /****************************插入支持文件、相关文件、附则等信息********************************************************/ + + + Document doc = new Document(outFile.getPath()); + //获取最后一节 + Section section = doc.getLastSection(); + //添加段落,设置一级序列 - Paragraph paragraph1 = section.addParagraph(); + Paragraph paragraph = section.addParagraph(); + //paragraph.appendBreak(BreakType.Page_Break); + //Section section2 = doc.addSection(); - //paragraph1.appendBreak(BreakType.Page_Break); + //相关文件 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); - - ParagraphFormat paragraphFormat1 = paragraph1.getFormat(); - paragraphFormat1.setHorizontalAlignment(HorizontalAlignment.Left); - - TextRange tr = paragraph1.appendText("相关文件"); - tr.getCharacterFormat().setBold(true); - tr.getCharacterFormat().setFontName("宋体"); - tr.getCharacterFormat().setFontSize(12); - //tr.applyCharacterFormat(format); //应用字体格式 - paragraph1.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 - - - //定义表格数据 - 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]); + relevant_flies.add(tmp); + } } - } + + CharacterFormat format = new CharacterFormat(); + //创建字体格式 + format.setFontName("宋体"); + //添加段落,设置一级序列 + Paragraph paragraph1 = section.addParagraph(); - } + //paragraph1.appendBreak(BreakType.Page_Break); - //支持文件 - 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); + ParagraphFormat paragraphFormat1 = paragraph1.getFormat(); + paragraphFormat1.setHorizontalAlignment(HorizontalAlignment.Left); + + TextRange tr = paragraph1.appendText("相关文件"); + tr.getCharacterFormat().setBold(true); + tr.getCharacterFormat().setFontName("宋体"); + tr.getCharacterFormat().setFontSize(12); + //tr.applyCharacterFormat(format); //应用字体格式 + paragraph1.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + + + //定义表格数据 + 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; - CharacterFormat format2 = new CharacterFormat(); - //创建字体格式 - format2.setFontName("宋体"); - //添加段落,设置一级序列 - Paragraph paragraph2 = section.addParagraph(); - ParagraphFormat paragraphFormat2 = paragraph2.getFormat(); - paragraphFormat2.setHorizontalAlignment(HorizontalAlignment.Left); - TextRange tr2 = paragraph2.appendText("支持文件"); - tr2.getCharacterFormat().setBold(true); - tr2.getCharacterFormat().setFontName("宋体"); - tr2.getCharacterFormat().setFontSize(12); - paragraph2.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + //添加表格 + Table table = section.addTable(true); + table.resetCells(data.length + 1, header.length); - - //定义表格数据 - 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]); + 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); + //设置固定列宽 + row.getCells().get(0).setWidth(150); + row.getCells().get(1).setWidth(500); + Paragraph p = row.getCells().get(i).addParagraph(); + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + TextRange txtRange = p.appendText(header[i]); + txtRange.getCharacterFormat().setBold(true); } - } - - } - - /*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("宋体");*/ - - - //查询模型文件属性上传附件信息 - List search2 = upFileDao.searchByRepositoryId(repositoryModel.getId(), "f"); - - DCContext dcContextModel = null; - - - // 排序 - Collections.sort(search2, new Comparator() { - @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("附件") && p1.contains(":") && p2.contains(":")) { - return Integer.parseInt(p1.substring(2, p1.indexOf(":"))) - Integer.parseInt(p2.substring(2, p2.indexOf(":"))); - - } else { - return 0; + //将数据添加到其余行 + for (int r = 0; r < data.length; r++) { + TableRow dataRow = table.getRows().get(r + 1); + dataRow.setHeight(25); + dataRow.setHeightType(TableRowHeightType.Auto); + 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(0).setWidth(150); + dataRow.getCells().get(1).setWidth(500); + dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); + } } } - }); - - //读取模型附件插入手册中文档对象 - if (search2 != null && search2.size() > 0) { - - //附件如果为空,不插入附件标题 - CharacterFormat format4 = new CharacterFormat(); - //创建字体格式 - format4.setFontName("宋体"); - //添加段落 - Paragraph paragraph4 = section.addParagraph(); - - ParagraphFormat paragraphFormat4 = paragraph4.getFormat(); - paragraphFormat4.setHorizontalAlignment(HorizontalAlignment.Left); - - TextRange tr4 = paragraph4.appendText("附件"); - tr4.getCharacterFormat().setBold(true); - tr4.getCharacterFormat().setFontName("宋体"); - tr4.getCharacterFormat().setFontSize(12); - paragraph4.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + //支持文件 + 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); + } + } - long b1 = System.currentTimeMillis(); + CharacterFormat format2 = new CharacterFormat(); + //创建字体格式 + format2.setFontName("宋体"); + //添加段落,设置一级序列 + Paragraph paragraph2 = section.addParagraph(); + ParagraphFormat paragraphFormat2 = paragraph2.getFormat(); + paragraphFormat2.setHorizontalAlignment(HorizontalAlignment.Left); + TextRange tr2 = paragraph2.appendText("支持文件"); + tr2.getCharacterFormat().setBold(true); + tr2.getCharacterFormat().setFontName("宋体"); + tr2.getCharacterFormat().setFontSize(12); + paragraph2.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 - 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(); + //定义表格数据 + 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; + } - //加载一个图片,它将作为外部文件的符号显示在Word文档中 - //获取最后一个.的位置 - int lastIndexOf = dcContextModel.getFileName().lastIndexOf("."); - //获取文件的后缀名 .jpg - String suffix = dcContextModel.getFileName().substring(lastIndexOf); + String[][] data = strArray2; - DocPicture pdfIcon = new DocPicture(doc); + //添加表格 + Table table = section.addTable(true); + table.resetCells(data.length + 1, header.length); - InputStream stream1 = new FileInputStream(dcContextModel.getFilePath()); - DocPicture pic1 = new DocPicture(doc); + 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); + //设置固定列宽 + row.getCells().get(0).setWidth(150); + row.getCells().get(1).setWidth(500); + Paragraph p = row.getCells().get(i).addParagraph(); + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + TextRange txtRange = p.appendText(header[i]); + txtRange.getCharacterFormat().setBold(true); + } - 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"); + //将数据添加到其余行 + for (int r = 0; r < data.length; r++) { + TableRow dataRow = table.getRows().get(r + 1); + dataRow.setHeight(25); + dataRow.setHeightType(TableRowHeightType.Auto); + 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(0).setWidth(150); + dataRow.getCells().get(1).setWidth(500); + dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); + } + } + + } + + //查询模型文件属性上传附件信息 + List search2 = upFileDao.searchByRepositoryId(repositoryModel.getId(), "f"); + + DCContext dcContextModel = null; + + + // 排序 + Collections.sort(search2, new Comparator() { + @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("附件") && p1.contains(":") && p2.contains(":")) { + return Integer.parseInt(p1.substring(2, p1.indexOf(":"))) - Integer.parseInt(p2.substring(2, p2.indexOf(":"))); + + } else { + return 0; } } + }); + //读取模型附件插入手册中文档对象 + if (search2 != null && search2.size() > 0) { + + //附件如果为空,不插入附件标题 + CharacterFormat format4 = new CharacterFormat(); + //创建字体格式 + format4.setFontName("宋体"); + //添加段落 + Paragraph paragraph4 = section.addParagraph(); + + ParagraphFormat paragraphFormat4 = paragraph4.getFormat(); + paragraphFormat4.setHorizontalAlignment(HorizontalAlignment.Left); + + TextRange tr4 = paragraph4.appendText("附件"); + + + tr4.getCharacterFormat().setBold(true); + tr4.getCharacterFormat().setFontName("宋体"); + tr4.getCharacterFormat().setFontSize(12); + paragraph4.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + + + long b1 = System.currentTimeMillis(); + + 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); + + 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(".ppt") || suffix.equals(".pptx")) { + pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/ppt.png"); + paragraph5.appendText(dcContextModel.getFileName()); + if (suffix.equals(".ppt")) { + paragraph5.appendOleObject(stream1, pic1, "ppt"); + } else if (suffix.equals(".pptx")) { + paragraph5.appendOleObject(stream1, pic1, "pptx"); + } + } 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"); + } + + + } + + } + long b2 = System.currentTimeMillis(); + System.err.println("插入附件用时:" + + (b2 - b1) / 1000 + "秒"); } - long b2 = System.currentTimeMillis(); - System.err.println("插入附件用时:" - + (b2 - b1) / 1000 + "秒"); + + try { + doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 关闭文档对象 + doc.close(); + } + } - try { - doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013); - } catch (Exception e) { - e.printStackTrace(); - } finally { - // 关闭文档对象 - doc.close(); - } + } @@ -825,29 +882,115 @@ public class OutputWordUtil { } 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(); + //判断表单图是否为单一模型并且只上传excel一种附件,导出手册直接导出excel手册 + PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId); + + UpFileDao upFileDao = new UpFileDao(); + //查询模型文件属性上传附件信息 + List search = upFileDao.searchByRepositoryId(repositoryModel.getId(), "s"); + + if (search.size() > 0) { + if (search.size() == 1) { + DCContext dcContextModel = null; + //获取 + String getExcelFileName = search.get(0).getFileName(); + + //获取文件的后缀名 + int lastIndexOf = getExcelFileName.lastIndexOf("."); + String suffix = getExcelFileName.substring(lastIndexOf); + if (suffix.equals(".xls") || suffix.equals(".xlsx")) { + + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); + + UserContext userContext = DispatcherRequest.getUserContext(); + + + String excelUrl = docName.substring(0, docName.lastIndexOf("/") + 1); + + // 调用App + String sourceAppId = "com.actionsoft.apps.coe.pal"; + // aslp服务地址 + String aslp = "aslp://com.awspaas.user.apps.new_performance_indicator_library/UpdatePptxAndExcelAslp"; + // 参数定义列表 + Map params = new HashMap(); + //文件id,必填 + params.put("pl_uuid", repositoryId); + //文件内容id,必填 + params.put("shape_uuid", search.get(0).getShape_uuid()); + + //文件保存地址,必填 + params.put("fil_path", excelUrl + search.get(0).getFileName()); + + //文件路径(不包含文件名称),必填 + params.put("file_url", excelUrl); + + //文件名称,必填 + params.put("file_data", search.get(0).getFileName()); + //sid,必填 + params.put("sid", userContext.getSessionId()); + AppAPI appAPI = SDK.getAppAPI(); + //根据上传的文件进行更新相关的excel或者ppt + ResponseObject ro = appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params); + + + } else { + // 输出文档路径及名称 + 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(); + } + ConcatenationformBySpire(outFile.getPath(), search); + } + + + } else { + // 输出文档路径及名称 + 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(); + } + ConcatenationformBySpire(outFile.getPath(), search); } - } catch (TemplateException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); } + + } + + + public static void ConcatenationformBySpire(String filePath, List search) throws FileNotFoundException { /**************************************************插入文件对象**********************************************************************/ - Document doc = new Document(outFile.getPath()); + Document doc = new Document(filePath); //获取最后一节 Section section = doc.getLastSection(); @@ -871,13 +1014,6 @@ public class OutputWordUtil { //doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013); - PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId); - - UpFileDao upFileDao = new UpFileDao(); - //查询模型文件属性上传附件信息 - List search = upFileDao.searchByRepositoryId(repositoryModel.getId(), "s"); - - DCContext dcContextModel = null; UserContext userContext = DispatcherRequest.getUserContext(); if (search != null && search.size() > 0) { @@ -961,10 +1097,9 @@ public class OutputWordUtil { } - doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + doc.saveToFile(filePath, FileFormat.Docx_2013); } - /** * 将文件的扩展属性设置默认值为空字符串(防止没有设置扩展属性而使得导出文件出错) * diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/PALRepositoryQueryAPIManager.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/PALRepositoryQueryAPIManager.java index af471045..1385d9bb 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/PALRepositoryQueryAPIManager.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/PALRepositoryQueryAPIManager.java @@ -3525,6 +3525,68 @@ public class PALRepositoryQueryAPIManager { } + public String outputReportPPTPreview(UserContext _uc, String taskId) { + OutputTaskModel model = new OutputTask().getTaskReportById(taskId); + ResponseObject result = ResponseObject.newOkResponse(); + if (model != null) { + try { + UtilFile file = OutputAPIManager.getInstance().getFilePath(model.getWsId(), taskId, model.getProfileId()); + if (file.exists()) { + File[] fileList = file.listFiles(); + if (fileList.length > 0) { + File docFile = null; + for (File file2 : fileList) { + if (file2.isFile() && "pptx".equals((file2.getName().substring(file2.getName().lastIndexOf(".") + 1)))) { + docFile = file2; + break; + } + } + if (docFile == null) { + return ResponseObject.newErrResponse("没有找到文件").toString(); + } + if (SDK.getAppAPI().isActive("com.actionsoft.apps.addons.onlinedoc")) { + OutputAppProfile appFile = OutputAppManager.getProfile(model.getProfileId()); + String sourceAppId = appFile.getAppContext().getId(); + String filename = docFile.getName(); + DCContext sourceDc = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, model.getWsId(), taskId, filename); + Map aslpParams = new HashMap(); + + aslpParams.put("sid", _uc.getSessionId()); + aslpParams.put("fileNameOriginal", filename); + aslpParams.put("sourceDc", sourceDc); + aslpParams.put("isShowDefaultToolbar", true); + aslpParams.put("isShowBackbtn", false); + aslpParams.put("isEncrypt", true); + aslpParams.put("isCopy", true); + aslpParams.put("isPrint", true); + aslpParams.put("isDownload", true); + AppAPI appAPI = SDK.getAppAPI(); + ResponseObject responseObject = appAPI.callASLP(appAPI.getAppContext(sourceAppId), "aslp://com.actionsoft.apps.addons.onlinedoc/filePreview", aslpParams); + if (responseObject != null) { + if (responseObject.isOk()) { + String url = responseObject.get("url").toString(); + result.put("url", url); + result.put("filename", filename); + } else { + result = ResponseObject.newErrResponse("文档转换服务不可用,请联系管理员"); + } + } + } else { + result = ResponseObject.newErrResponse("文档转换服务不可用,请联系管理员"); + } + } + } else { + result = ResponseObject.newErrResponse("没有可预览文件"); + } + } catch (Exception e) { + e.printStackTrace(); + return ResponseObject.newErrResponse().toString(); + } + } + return result.toString(); + } + + /** * 流程手册下载 * diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/relation/web/DesignerRelationShapeWeb.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/relation/web/DesignerRelationShapeWeb.java index a4db070b..e6de512b 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/relation/web/DesignerRelationShapeWeb.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/relation/web/DesignerRelationShapeWeb.java @@ -10,6 +10,11 @@ import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache; import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel; import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodJsonModel; import com.actionsoft.apps.coe.pal.pal.method.util.PALMethodUtil; +import com.actionsoft.apps.coe.pal.pal.output.OutputAPIManager; +import com.actionsoft.apps.coe.pal.pal.output.dao.OutputTask; +import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppManager; +import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppProfile; +import com.actionsoft.apps.coe.pal.pal.output.model.OutputTaskModel; import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager; import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryPropertyCache; @@ -31,6 +36,9 @@ import com.actionsoft.apps.coe.pal.pal.repository.designer.util.ShapeUtil; import com.actionsoft.apps.coe.pal.pal.repository.model.CoeProcessLevelAutoBean; import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryPropertyModel; +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; import com.actionsoft.apps.coe.pal.pal.repository.util.CoeProcessLevelUtil; import com.actionsoft.apps.coe.pal.pal.repository.web.CoeProcessLevelWeb; import com.actionsoft.apps.coe.pal.pal.ws.web.VersionUtil; @@ -38,6 +46,7 @@ import com.actionsoft.apps.coe.pal.util.BpmOrgUtil; import com.actionsoft.apps.coe.pal.util.HighSecurityUtil; import com.actionsoft.apps.coe.pal.util.StringHandleUtil; import com.actionsoft.apps.coe.pal.util.UtilMapSort; +import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile; import com.actionsoft.bpms.bo.engine.BO; import com.actionsoft.bpms.commons.cache.Cache; import com.actionsoft.bpms.commons.database.RowMap; @@ -57,11 +66,13 @@ import com.actionsoft.bpms.org.model.UserModel; import com.actionsoft.bpms.org.web.CompanyWeb; import com.actionsoft.bpms.server.UserContext; import com.actionsoft.bpms.server.fs.DCContext; +import com.actionsoft.bpms.server.fs.dc.DCProfileManager; import com.actionsoft.bpms.util.*; import com.actionsoft.exception.AWSException; import com.actionsoft.exception.AWSObjectNotFindException; import com.actionsoft.i18n.I18nRes; import com.actionsoft.sdk.local.SDK; +import com.actionsoft.sdk.local.api.AppAPI; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -4098,19 +4109,45 @@ public class DesignerRelationShapeWeb extends ActionWeb { for (FormFile formFile : formFiles) { DCContext fileDCContext = SDK.getBOAPI().getFileDCContext(formFile); fileDCContext.setSession(_uc); - String downloadURL = fileDCContext.getDownloadURL(); - JSONObject jo = new JSONObject(); - String fileName = fileDCContext.getFileName(); - //视频支持mp4类型 - if (fileName.contains("mp4")) { - jo.put("video", downloadURL); - } else if (fileName.contains("png") || fileName.contains("gif") || fileName.contains("jpg")) { - jo.put("picture", downloadURL); + String downloadURL = ""; + Map aslpParams = new HashMap(); + + String sourceAppId = "com.actionsoft.apps.coe.pal"; + aslpParams.put("sid", _uc.getSessionId()); + aslpParams.put("fileNameOriginal", fileDCContext.getFileName()); + aslpParams.put("sourceDc", fileDCContext); + aslpParams.put("isShowDefaultToolbar", true); + aslpParams.put("isShowBackbtn", false); + aslpParams.put("isEncrypt", true); + aslpParams.put("isCopy", true); + aslpParams.put("isPrint", true); + aslpParams.put("isDownload", true); + AppAPI appAPI = SDK.getAppAPI(); + ResponseObject responseObject = appAPI.callASLP(appAPI.getAppContext(sourceAppId), "aslp://com.actionsoft.apps.addons.onlinedoc/filePreview", aslpParams); + + + if (responseObject != null) { + if (responseObject.isOk()) { + String url = responseObject.get("url").toString(); + downloadURL = SDK.getPortalAPI().getPortalUrl() + "/r" + url.substring(1, url.length()); + } + + JSONObject jo = new JSONObject(); + String fileName = fileDCContext.getFileName(); + //视频支持mp4类型 + if (fileName.contains("mp4")) { + jo.put("video", fileDCContext.getDownloadURL()); + jo.put("video_url", downloadURL); + } else if (fileName.contains("png") || fileName.contains("gif") || fileName.contains("jpg")) { + jo.put("picture", fileDCContext.getDownloadURL()); + jo.put("picture_url", downloadURL); + } + jo.put("picTitle", fileName.split("\\.")[0]); + filePathArray.add(jo); } - jo.put("picTitle", fileName.split("\\.")[0]); - filePathArray.add(jo); + macroLibraries.put("filePaths", filePathArray); + } - macroLibraries.put("filePaths", filePathArray); return HtmlPageTemplate.merge(CoEConstant.APP_ID, "carousel.map.html", macroLibraries); } @@ -4209,4 +4246,129 @@ public class DesignerRelationShapeWeb extends ActionWeb { } + /** + * 判断是否为第一个节点为excel + * + * @param wsId + * @param teamId + * @param uuids + * @return + */ + public String createOutputPrReportsByEstimateFile(String fileId) { + //判断表单图是否为单一模型并且只上传excel一种附件,导出手册直接导出excel手册 + PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(fileId); + ResponseObject ro = ResponseObject.newOkResponse(); + UpFileDao upFileDao = new UpFileDao(); + //查询模型文件属性上传附件信息 + List search = upFileDao.searchByRepositoryId(repositoryModel.getId(), "s"); + + if (search.size() > 0) { + if (search.size() == 1) { + DCContext dcContextModel = null; + //获取 + String getExcelFileName = search.get(0).getFileName(); + //获取文件的后缀名 + int lastIndexOf = getExcelFileName.lastIndexOf("."); + String suffix = getExcelFileName.substring(lastIndexOf); + if (suffix.equals(".xls") || suffix.equals(".xlsx")) { + ro.put("result", "existExcel"); + } else { + ro.put("result", "noexistExcel"); + } + } else { + ro.put("result", "noexistExcel"); + } + } + + return ro.toString(); + } + + + public String createOutputPrReportsByEstimatePPTFile(UserContext me, String fileId) { + ResponseObject ro = ResponseObject.newOkResponse(); + List> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(fileId); //流程文件内容 + PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(fileId); + String controlShapeId = ""; + if (repositoryFileElements != null) { + int index = 1;// 流程步骤序号 + int dangerIndex = 1;// 风险序号 + int regulateIndex = 1;// 控制序号 + for (Map shape : repositoryFileElements) { + String type = shape.get("type").toString(); + if ("regulation".equals(type)) { + controlShapeId = shape.get("id").toString(); + } else if ("I/O_L4".equals(type)) { + controlShapeId = shape.get("id").toString(); + } + } + } + + // 流程附件列表 + UpFileDao upFileDao = new UpFileDao(); + List search = upFileDao.search(repositoryModel.getId(), controlShapeId, null); + DCContext dcContextpdf = null; + //如果为PPT,则生成PPT手册 + if (search != null && search.size() > 0) { + long b1 = System.currentTimeMillis(); + // 复制附件 + for (UpfileModel upfileModel : search) { + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); + + if (dcProfile != null) { + dcContextpdf = new DCContext(me, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName()); + String path = dcContextpdf.getPath(); + String fileName = dcContextpdf.getFileName(); + String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); + if (suffix.equals("pptx")) { + ro.put("result", "existPPT"); + } else { + ro.put("result", "noexistPPT"); + } + } + } + } + return ro.toString(); + } + + + public String createOutputPrReportsByDownloadExcelFile(String taskIds) { + OutputTaskModel model = new OutputTask().getTaskReportById(taskIds); + ResponseObject result = ResponseObject.newOkResponse(); + if (model != null) { + try { + UtilFile file = OutputAPIManager.getInstance().getFilePath(model.getWsId(), taskIds, model.getProfileId()); + if (file.exists()) { + File[] fileList = file.listFiles(); + if (fileList.length > 0) { + System.out.println("fileList==========" + fileList); + File docFile = null; + for (File file2 : fileList) { + System.out.println("file2==============" + file2); + if (file2.isFile() && "xlsx".equals((file2.getName().substring(file2.getName().lastIndexOf(".") + 1)))) { + docFile = file2; + break; + } + } + if (docFile == null) { + return ResponseObject.newErrResponse("没有找到文件").toString(); + } + OutputAppProfile appFile = OutputAppManager.getProfile(model.getProfileId()); + String sourceAppId = appFile.getAppContext().getId(); + String filename = docFile.getName(); + DCContext sourceDc = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, model.getWsId(), taskIds, filename); + String downUrl = SDK.getConfAPI().getPortalUrl() + "/r/" + + sourceDc.getDownloadURL().replace("./", ""); + result.put("url", downUrl); + } + } else { + result = ResponseObject.newErrResponse("没有可预览文件"); + } + } catch (Exception e) { + e.printStackTrace(); + return ResponseObject.newErrResponse().toString(); + } + } + return result.toString(); + } + } \ No newline at end of file