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 995442e9..079eff42 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 @@ -30,10 +30,7 @@ import com.actionsoft.bpms.server.UserContext; import com.actionsoft.bpms.server.conf.portal.AWSPortalConf; import com.actionsoft.bpms.server.fs.DCContext; import com.actionsoft.bpms.server.fs.dc.DCProfileManager; -import com.actionsoft.bpms.util.DBSql; -import com.actionsoft.bpms.util.UtilDate; -import com.actionsoft.bpms.util.UtilFile; -import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.bpms.util.*; import com.actionsoft.sdk.local.SDK; import com.actionsoft.sdk.local.api.AppAPI; import com.alibaba.fastjson.JSONArray; @@ -596,40 +593,46 @@ public class OutputWordUtil { /*document.insertTextFromFile(path + fileName, FileFormat.Docx_2013); //保存结果文档 document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);*/ - - //此处在合并文档,着重处理此处 - //先获取第一个文件的下载地址 - /*String taskId = UUID.randomUUID().toString(); - String thisFileName = taskId+".doc"; - String fileURL = outFile.getPath(); // 下载文件的URL - String saveDir = "./test"; // 保存文件的目录 - downloadFile(fileURL, saveDir,thisFileName); - //修改成调用wps文件发送 - mergeFileForWPS(fileURL, thisFileName,dcContextpdf.getDownloadURL(),fileName,taskId);*/ - Document docs1 = new Document(); - docs1.loadFromFile(outFile.getPath()); - - // 加载文档2 - Document docs2 = new Document(); - docs2.loadFromFile(path + fileName); - - SectionCollection sections2 = docs2.getSections(); - sections2.insert(0, docs1.getSections().get(1).deepClone()); - sections2.insert(0, docs1.getSections().get(0).deepClone()); - - // 保存文档2 - docs2.saveToFile(outFile.getPath(), FileFormat.Docx_2013); - docs2.dispose(); - + //此处在合并文档,着重处理此处 逻辑:大于50M走wps合并,小于50M的走jar合并 + //判断用户上传的文件的大小有多大 + String fileLength = String.valueOf(dcContextpdf.length()); + String maxFileLength = SDK.getAppAPI().getProperty(CoEConstant.APP_ID, "wps_export_file_size"); + String maxFileLength_B = UtilNumber.mul(UtilNumber.mul(maxFileLength, "1024.0"),"1024"); + System.out.println(">>fileLength = " + fileLength); + System.out.println(">>maxFileLength_B = " + maxFileLength_B); + if(Double.parseDouble(UtilNumber.sub(fileLength,maxFileLength_B))>0){//大于设置的值,则走wps逻辑 + //先获取第一个文件的下载地址 + String fileURL = outFile.getPath(); // 下载文件的URL + //..\doccenter\com.awspaas.user.apps.coe.pal.output.zd\output\11dd43d0-a3c7-4ba7-860f-6eac3383e0b0\0f4c6420-cd5d-41b6-a5b3-9c4cd5464c64\测试超级大文件_1.0.doc + //构建dc对象 + System.out.println(">>>>>>>>fileURL = " + fileURL); + String appId =fileURL.split("/")[2]; + String groupValue =fileURL.split("/")[4]; + String fileValue =fileURL.split("/")[5]; + String dcFileName = fileURL.split("/")[6]; + String dcReposirotyName = "output"; + System.out.println("dc = " + appId + "|"+groupValue+"|"+fileValue+"|"+dcFileName); + DCPluginProfile dcPluginProfile =SDK.getDCAPI().getDCProfile(appId,dcReposirotyName); + DCContext dc =new DCContext(userContext,dcPluginProfile,"com.awspaas.user.apps.coe.pal.output.zd",groupValue,fileValue,dcFileName); + System.out.println("dc.getDownloadURL() = " + dc.getDownloadURL()); + //修改成调用wps文件发送 + mergeFileForWPS(dc,dc.getDownloadURL(), dcFileName,dcContextpdf.getDownloadURL(),fileName); + }else{//小于设定的值,则走第三方类库逻辑 + Document docs1 = new Document(); + docs1.loadFromFile(outFile.getPath()); + // 加载文档2 + Document docs2 = new Document(); + docs2.loadFromFile(path + fileName); + SectionCollection sections2 = docs2.getSections(); + sections2.insert(0, docs1.getSections().get(1).deepClone()); + sections2.insert(0, docs1.getSections().get(0).deepClone()); + // 保存文档2 + docs2.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + docs2.dispose(); + } } else if (suffix.equals("pptx")) { isPPT = true; } - - - - - - if (isPPT == false) { @@ -672,7 +675,29 @@ public class OutputWordUtil { targetHeader.getChildObjects().clear(); for (int j = 0; j < sourceHeader.getChildObjects().getCount(); j++) { - + //定制页眉 + Table table = (Table)sourceHeader.getChildObjects().get(0); + if (table.getRows().getCount() > 0 && table.getRows().get(0).getCells().getCount() > 0) { + //页眉文字 + TableCell cell = table.getRows().get(0).getCells().get(0); + String text = cell.getParagraphs().get(0).getText();// 假设单元格中只有一个TextRange + System.out.println("HEADERFONT = " + text); + cell.getParagraphs().get(0).setText(dataMap.getString("HEADERFONT")); + //页眉logo + TableCell cellImg = table.getRows().get(0).getCells().get(1); + //创建 DocPicture 类的对象 + DocPicture picture = new DocPicture(templateDoc); + //从磁盘加载图片 + String logoUrl = dataMap.getString("LOGOURL"); + picture.loadImage(logoUrl); + //设置图片大小 + picture.setWidth(75); + picture.setHeight(90); + //将图片文本环绕方式设置为四周环绕 + picture.setTextWrappingStyle(TextWrappingStyle.Square); + //将图片插入到第二段 + cellImg.getChildObjects().insert(0,picture); + } DocumentObject obj = sourceHeader.getChildObjects().get(j).deepClone(); targetHeader.getChildObjects().add(obj); } @@ -690,6 +715,16 @@ public class OutputWordUtil { targetFooter.getChildObjects().clear(); for (int j = 0; j < sourceFooter.getChildObjects().getCount(); j++) { + //定制页脚 + Table table = (Table)sourceFooter.getChildObjects().get(1); + if (table.getRows().getCount() > 0 && table.getRows().get(0).getCells().getCount() > 0) { + // 定位到第一行第一列的单元格 + TableCell cell = table.getRows().get(0).getCells().get(0); + // 修改单元格中的文本 + String text = cell.getParagraphs().get(0).getText();// 假设单元格中只有一个TextRange + System.out.println("FOOTERFONT = " + text); + cell.getParagraphs().get(0).setText(dataMap.getString("FOOTERFONT")); + } DocumentObject obj = sourceFooter.getChildObjects().get(j).deepClone(); targetFooter.getChildObjects().add(obj); } @@ -1233,7 +1268,6 @@ public class OutputWordUtil { dcContextModel = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, "file", upfileModel.getPl_uuid(), upfileModel.getFileName()); //添加段落 Paragraph paragraph5 = section.addParagraph(); - //加载一个图片,它将作为外部文件的符号显示在Word文档中 //获取最后一个.的位置 int lastIndexOf = dcContextModel.getFileName().lastIndexOf("."); @@ -2511,7 +2545,7 @@ public class OutputWordUtil { * 合并文档,wps形式 * @return */ - public static String mergeFileForWPS(String docUrl1, String docFileName1, String docUrl2, String docFileName2,String taskId) { + public static String mergeFileForWPS(DCContext dc,String docUrl1, String docFileName1, String docUrl2, String docFileName2) { try { String url = String.format("/api/cps/sync/v1/merge"); WPS4Util.initAppInfo(YiliWpsConst.AK, YiliWpsConst.SK); @@ -2520,7 +2554,7 @@ public class OutputWordUtil { JSONArray array = new JSONArray(); JSONObject merged_file_obj1 = new JSONObject(); JSONObject merged_file_obj2 = new JSONObject(); - result.put("task_id", taskId); + result.put("task_id", UUIDGener.getUUID()); merged_file_obj1.put("doc_url",SDK.getAppAPI().getProperty(YiliWpsConst.APPID,"targetPortal")+"/r" + docUrl1.substring(1)); merged_file_obj1.put("doc_filename",docFileName1); array.add(merged_file_obj1); @@ -2538,7 +2572,7 @@ public class OutputWordUtil { String download_id = json.getJSONObject("data").getString("download_id"); String route_key = json.getJSONObject("data").getString("route_key"); //String savePath = AWSPortalConf.getUrl() +"/test/123.doc"; - String savePath = docUrl1; + String savePath = dc.getPath()+"/"+dc.getFileName();; System.out.println("savePath = " + savePath); operateDocumentResultDownload(YiliWpsConst.HOST,download_id,route_key,savePath); return savePath; @@ -2577,11 +2611,9 @@ public class OutputWordUtil { // 创建输出流到文件 File outputFile = new File(file, fileName); FileOutputStream fos = new FileOutputStream(outputFile); - URL url = new URL(fileURL); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); int responseCode = httpConn.getResponseCode(); - // 检查响应码是否为HTTP_OK if (responseCode == HttpURLConnection.HTTP_OK) { // 通过输入流读取数据 diff --git a/com.actionsoft.apps.coe.pal/template/page/pal.pl.repository.designer.htm b/com.actionsoft.apps.coe.pal/template/page/pal.pl.repository.designer.htm index 7adf9937..15f12ceb 100755 --- a/com.actionsoft.apps.coe.pal/template/page/pal.pl.repository.designer.htm +++ b/com.actionsoft.apps.coe.pal/template/page/pal.pl.repository.designer.htm @@ -537,7 +537,7 @@ $("#dock_btn_richtext").hide(); checkUserFirstCreateModel(); //定制模版 - //initCoverTpl() + initCoverTpl(); }); @@ -547,16 +547,56 @@ url: "./jd?sid=" + sid + "&cmd=com.awspaas.user.apps.output.template.getCoverTpl", type: 'GET', success: function (data) { + debugger; console.log(data); var opt = { width : 100, data : data }; - $("#tpl_list").select2($.extend({}, opt, {minimumResultsForSearch:-1})); + $("#tpl_list").popBox({ + cache:false, + title:'请选择模版', + content: initContentHtml(data), + position:'bottom-left', + callback:function(item){ + debugger; + $("input[name='tplRadio']") + $("input[name='tplRadio']").check(); + $("input[name='tplRadio']").on("ifChanged",function(){ + var historyRadioBoxArr = $('input[name="tplRadio"]:checked'); + debugger; + //把选择的记录存上 + $.ajax({ + url: "./jd?sid=" + sid + "&cmd=com.awspaas.user.apps.output.template.saveTplMappingPal", + type: 'GET', + data: { + tplId:$(historyRadioBoxArr[0]).attr("id"), + palId: ruuid + + }, + success: function (data) { + $("#tpl_list").attr("value",$(historyRadioBoxArr[0]).attr("id")); + $("#tpl_list").text("封皮模版:"+$(historyRadioBoxArr[0]).attr("showText")); + } + }) + + }); + } + }); } }); } + function initContentHtml(obj){ + var checkHtml = ''; + obj.forEach(function(model, index) { + checkHtml += '
'; + checkHtml += ''; + checkHtml += ''; + }); + return checkHtml; + } + //检查用户是否第一次创建对应类型的模型 function checkUserFirstCreateModel(){ var data_type = window.performance.navigation.type; @@ -874,8 +914,8 @@ await saveWps(); updateShapePanel(); //更新画布 + $.simpleAlert("正在解析更新画布中,请稍后",'loading'); reloadFile(); - } } //切换视图页面 @@ -898,7 +938,7 @@ } function openWpsUrl(){ - debugger; + debugger; $.ajax({ url: "./jd?sid=" + sid + "&cmd=com.awspaas.user.apps.yiliwps.previewUrl&palId=" + ruuid +"&fileName="+updatedPolicyFileList, type: 'GET', @@ -993,8 +1033,9 @@ -->
- +