替换标签,生成文档。将自动存储到doccenter目录调用方应用ID DC根目录内,并支持DC根目录是否加密、4级存储命名规则。
如下为示例上传的模板。
// 调用App
String sourceAppId = "调用方应用ID";
// aslp服务地址
String aslp = "aslp://com.actionsoft.apps.addons.docgenerator/documentGenerate";
// 参数定义列表
Map params = new HashMap<String, Object>();
//sessionId,必填
params.put("sid", ctx.getUserContext().getSessionId());
//模板Id,必填
params.put("tempId", tempId);
//生成文档类型(word或pdf),默认为word(生成pdf需安装“文档预览服务”应用),非必填
params.put("gtype", "word");
//调用方应用文档仓库根目录,必填
params.put("repositoryName", repositoryName);
//DC groupValue,必填
params.put("groupValue", groupValue);
//DC fileValue,必填
params.put("fileValue", fileValue);
//生成的文档名,非必填
params.put("fileName", fileName);
//标签类型为字符串示例-start--------------------------------
JSONArray dataParams = new JSONArray();
JSONObject labelDataString = new JSONObject();
//type为固定key,其值可为string、table,string代表标签类型为字符串;table代表标签类型为表格
labelDataString.put("type","string");
JSONObject stringData = new JSONObject();
stringData.put("TITLE", "这是标题");
stringData.put("TEST1", "这是test1值");
stringData.put("TEST2", "这是test2值");
//data为固定key,其可为相应标签值,当不为标签赋值时,将自动以页面数据源相关配置取值
labelDataString.put("data",stringData);
dataParams.add(labelDataString);
//标签类型为字符串示例-end--------------------------------
//标签类型为表格示例-start--------------------------------
Object labelDataTable = new JSONObject();
labelDataTable.put("type", "table");
JSONArray tableData = new JSONArray();
for (int i = 0; i < 5; i++) {
JSONObject object = new JSONObject();
object.put("A1", "列1" + "行" + i);
object.put("A2", "列2" + "行" + i);
object.put("A3", "列3" + "行" + i);
object.put("A4", "列4" + "行" + i);
object.put("A5", "列5" + "行" + i);
object.put("A6", "列6" + "行" + i);
object.put("A7", "列7" + "行" + i);
tableData.add(object);
}
labelDataTable.put("data", tableData);
dataParams.add(labelDataTable);
//标签类型为表格示例-end--------------------------------
//标签为图片-start--------------------------------
JSONObject chart1 = new JSONObject();
JSONObject chart1Obj = new JSONObject();
//1、本地图片
String urlimg ="E:\\actionsoft\\awspaas.png"; //图片可正常访问的地址
//2、doccenter下图片
/*DCContext dc = new DCContext(me, DCProfileManager.getDCProfile(TaskmgtConstant.APP_TASKMGT, TaskmgtConstant.APP_FILE_REPOSITORYNAME), TaskmgtConstant.APP_TASKMGT, "taskfile", "admin", "myfile_31dda87b-76d5-481f-bc84-7f5db567e57d.png");
DCContext dc2 = new DCContext(me, SDK.getDCAPI().getDCProfile(TaskmgtConstant.APP_TASKMGT, "tmp"), TaskmgtConstant.APP_TASKMGT, Integer.toString(UtilDate.getYear(new Date())), Integer.toString(UtilDate.getMonth(new Date())), System.currentTimeMillis() + ".png");
InputStream inputStream = ReadDCFile.getInstance().read(dc);
//加密文件先把文件复制到临时目录tmp下,生成文档成功后删除tmp文件
SDK.getDCAPI().write(inputStream,dc2);
dc.setFileNameShow("myfile.png");
urlimg=dc2.getFilePath();*/
chart1Obj.put("MYIMG", urlimg);
chart1.put("type", "image");
chart1.put("data", chart1Obj);
dataParams.add(chart1);
//标签为图片-end--------------------------------
//数据,非必填
params.put("labelData", dataParams);
//流程实例Id,非必填
params.put("bindId", ctx.getProcessInstance().getId());
//替换标签,生成文档
ResponseObject ro = SDK.getAppAPI().callASLP(SDK.getAppAPI().getAppContext(sourceAppId), aslp, params);
有关DC文件处理器的详细介绍参见https://docs.awspaas.com/reference-guide/aws-paas-plugin-development-reference-guide/plugins/dc.html