定制封皮页眉页脚优化,上下游以及子流程代码

This commit is contained in:
yujh 2024-10-02 09:26:33 +08:00
parent a5f8594fa7
commit 61404d5dfb
3 changed files with 141 additions and 49 deletions

View File

@ -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) {
// 通过输入流读取数据

View File

@ -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 += '<p>';
checkHtml += '<input class="awsui-checkbox" name="tplRadio" id="'+model.id+'" showText="'+model.text+'" type="radio"/>';
checkHtml += '<label class="awsui-checkbox-label">'+model.text+'</label>';
});
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 @@
-->
</ul>
<div id="saving_tip"></div>
<!-- <div style="display: inline-block;float: left;margin-left: 10px;line-height: 28px;">
封面模版:<select id="tpl_list"></select></div>-->
<div id="tpl_list" value="" style="display:inline-block; float: left;margin-left: 10px;line-height: 28px;">
封皮模版:默认
</div>
<!-- 倒计时显示 -->
<div id="autoSave_countdown"></div>
</div>

View File

@ -4334,7 +4334,25 @@ function outputReport() {
//设置等待时间
setTime = 2000;
}
$.simpleAlert(msg, 'loading');
//先查询正文大小,如果超过设置值,则弹框提醒逻辑修改
$.ajax({
type: "POST",
url: "./jd?sid="
+ CLB.sid
+ "&cmd=com.awspaas.user.apps.yiliwps.checkFileSize",
data: {
palId: ruuid
},
success: function (r) {
debugger;
if (r.result == "ok") {
if(r.data.state == true){
msg+="<br>您好,您的文件已超过"+r.data.maxFileLength+"M导出时间可能大于3min请您耐心等待"
}
}
$.simpleAlert(msg, 'loading');
}
});
setTimeout(function(){
$.ajax({
type: "POST",
@ -4806,6 +4824,7 @@ function reloadFile(){
palId:ruuid
},
success: function(data) {
$.simpleAlert("close");
$.simpleAlert("刷新画布成功");
definition = data;
Designer.open(definition);