定制封面模版应用代码提交

This commit is contained in:
yujh 2024-10-02 10:04:33 +08:00
parent 61404d5dfb
commit f2a509bfff
4 changed files with 203 additions and 0 deletions

View File

@ -0,0 +1,84 @@
package com.awspaas.user.apps.output.template;
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.formfile.model.delegate.FormFile;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.bind.annotation.Controller;
import com.actionsoft.bpms.server.bind.annotation.Mapping;
import com.actionsoft.bpms.server.conf.portal.AWSPortalConf;
import com.actionsoft.bpms.server.fs.DCContext;
import com.actionsoft.bpms.server.fs.dc.DCUtil;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.BOAPI;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.awspaas.user.apps.output.template.util.HttpPostUtil;
import com.awspaas.user.apps.output.template.util.WPS4Util;
import com.awspaas.user.apps.output.template.util.YiliWpsConst;
import java.io.File;
import java.io.FileInputStream;
import java.util.Map;
import java.util.UUID;
@Controller
public class TestController {
/**
* 打开可编辑的页面
* @param me
* @return
* @throws Exception
*/
@Mapping("com.awspaas.user.apps.output.template.mergeFile")
public String mergeFile(UserContext me,String bindId) throws Exception{
try {
BO bo = SDK.getBOAPI().query("BO_EU_TEST_FILEMERGE").bindId(bindId).detail();
BOAPI boapi = SDK.getBOAPI();
FormFile file1 = boapi.getFiles(bo.getId(), "FILE1").get(0);
DCContext fileDCContext1 = boapi.getFileDCContext(file1);
fileDCContext1.setSession(me);
FormFile file2 = boapi.getFiles(bo.getId(), "FILE2").get(0);
DCContext fileDCContext2 = boapi.getFileDCContext(file2);
fileDCContext2.setSession(me);
WPS4Util.initAppInfo(YiliWpsConst.AK, YiliWpsConst.SK);
String url = String.format("/api/cps/sync/v1/merge");
JSONObject result = new JSONObject();
JSONArray array = new JSONArray();
JSONObject merged_file_obj1 = new JSONObject();
JSONObject merged_file_obj2 = new JSONObject();
result.put("task_id", UUID.randomUUID());
merged_file_obj1.put("doc_url",SDK.getAppAPI().getProperty(YiliWpsConst.APPID,"targetPortal")+"/r"+fileDCContext1.getDownloadURL().substring(1));
merged_file_obj1.put("doc_filename",fileDCContext1.getFileName());
array.add(merged_file_obj1);
merged_file_obj2.put("doc_url",SDK.getAppAPI().getProperty(YiliWpsConst.APPID,"targetPortal")+"/r"+fileDCContext2.getDownloadURL().substring(1));
merged_file_obj2.put("doc_filename",fileDCContext2.getFileName());
array.add(merged_file_obj2);
result.put("merged_file_list",array);
Map<String,String> headers = WPS4Util.getSignatureHeaders(url, "POST",result.toString(), YiliWpsConst.CONTENT_TYPE);
JSONObject json = HttpPostUtil.sendPostRequest(YiliWpsConst.HOST + "/open" + url, result.toString(), headers, JSONObject.class);
System.out.println("jsonObject = " + json.toString());
if(json.getString("code").equals("200")){
System.out.println(">>>>>>>已合并成功");
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 = fileDCContext1.getPath()+"/"+fileDCContext1.getFileName();
System.out.println("savePath = " + savePath);
operateDocumentResultDownload(YiliWpsConst.HOST,download_id,route_key,savePath);
return savePath;
}
return json.toString();
}catch (Exception e){
e.printStackTrace();
}
return "";
}
public static void operateDocumentResultDownload(String host,String downloadId,String routeKey,String savePath) throws Exception {
String url = "/api/cps/v1/download/{download_id}";
url = url.replace("{download_id}",downloadId);
Map<String,String> headers = WPS4Util.getSignatureHeaders(url, "GET",null,YiliWpsConst.CONTENT_TYPE);
headers.put("Route-Key",routeKey);
HttpPostUtil.sendGetDownloadRequest(host + "/open" + url, headers,savePath);
}
}

View File

@ -0,0 +1,16 @@
package com.awspaas.user.apps.output.template.constants;
/**
* @Author:yujh
* @Date: 2024/9/27 16:06
*/
public class TemplateConstant {
/**
* dw相关
*/
public static final String mapping_dw_id= "obj_8336e820b1c848cfa47b86abfc52fac5";
/**
* bo相关
*/
public static final String BO_EU_TPL_PAL_MAPPING= "BO_EU_TPL_PAL_MAPPING";
}

View File

@ -0,0 +1,31 @@
package com.awspaas.user.apps.output.template.controller;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.bind.annotation.Controller;
import com.actionsoft.bpms.server.bind.annotation.Mapping;
import com.awspaas.user.apps.output.template.web.TemplateWeb;
@Controller
public class TemplateController {
/**
* 获取模版配置
* @param me
* @return
*/
@Mapping("com.awspaas.user.apps.output.template.getCoverTpl")
public String getCoverTpl(UserContext me,String palId){
TemplateWeb web = new TemplateWeb(me);
return web.getCoverTpl(palId);
}
/**
* 保存模版映射
* @param me
* @return
*/
@Mapping("com.awspaas.user.apps.output.template.saveTplMappingPal")
public String saveTplMappingPal(UserContext me,String tplId,String palId){
TemplateWeb web = new TemplateWeb(me);
return web.saveTplMappingPal(tplId,palId);
}
}

View File

@ -0,0 +1,72 @@
package com.awspaas.user.apps.output.template.web;
import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
import com.actionsoft.bpms.commons.mvc.view.ActionWeb;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.sdk.local.SDK;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.awspaas.user.apps.output.template.constants.TemplateConstant;
import com.awspaas.user.apps.output.template.controller.TemplateController;
import java.util.List;
public class TemplateWeb extends ActionWeb {
public TemplateWeb(UserContext userContext) {
super(userContext);
}
public TemplateWeb() {
}
/**
* 获取模版配置
* @return
*/
public String getCoverTpl(String palId){
ResponseObject ro = ResponseObject.newOkResponse();
UserContext me = super.getContext();
String deptId = me.getDepartmentModel().getId();
//先查询是否已经选择过定制模版
//先查询有无模版Id
//默认的tplBo
BO tplBo = SDK.getBOAPI().query("BO_EU_TPL_PAL_MAPPING").addQuery("PALID=", palId).orderByCreated().desc().detail();
BO defaultBo = null;
if(tplBo!=null){
defaultBo = SDK.getBOAPI().query("BO_EU_OUTPUT_TEMPLATE").detailById(tplBo.getString("TPLID"));
}
//先查询模版文件中有无配置模版
List<BO> boList = SDK.getBOAPI().query("BO_EU_OUTPUT_TEMPLATE", true).addQuery("APPLYDEPTID=", deptId).list();
BO bo = SDK.getBOAPI().query("BO_EU_OUTPUT_TEMPLATE", true).addQuery("APPLYTYPE=", "默认").detail();
boList.add(bo);
JSONArray resultList = new JSONArray();
for (BO boModel : boList) {
JSONObject json =new JSONObject();
json.put("id",boModel.getId());
json.put("text",boModel.getString("APPLYNO"));
resultList.add(json);
}
//增加默认模版
JSONObject defaultJson =new JSONObject();
if(null != defaultBo){
defaultJson.put("id",defaultBo.getId());
defaultJson.put("text",defaultBo.getString("APPLYNO"));
ro.put("defaultJson",defaultJson);
}
ro.put("list",resultList);
return ro.toString();
}
public String saveTplMappingPal(String tplId,String palId){
ResponseObject ro =ResponseObject.newOkResponse();
UserContext me = super.getContext();
ProcessInstance processInstance = SDK.getProcessAPI().createProcessInstance(TemplateConstant.mapping_dw_id,me.getUID(), "新增");
BO bo =new BO();
bo.set("TPLID",tplId);
bo.set("PALID",palId);
SDK.getBOAPI().create(TemplateConstant.BO_EU_TPL_PAL_MAPPING, bo, processInstance, me);
return ro.toString();
}
}