Activiti Exploer工作流控制台使用指南!使用Activiti Explorer定义部署执行工作流 (3)

执行流程最后的结果就是reportData变量,保存数据

<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="activiti-report"> <process isExecutable="true"> <startEvent /> <sequenceFlow sourceRef="startevent1" targetRef="generateDataset" /> <scriptTask scriptFormat="JavaScript" activiti:autoStoreVariables="false"> <script><![CDATA[ importPackage(java.sql); importPackage(java.lang); importPackage(org.activiti.explorer.reporting); var result = ReportingUtil.executeSelectSqlQuery("SELECT PD.NAME_, PD.VERSION_ , count(*) FROM ACT_HI_PROCINST PI inner join ACT_RE_PROCDEF PD on PI.PROC_DEF_ID_ = PD.ID_ group by PROC_DEF_ID_"); var reportData = {}; reportData.datasets = []; var dataset = {}; dataset.type = "pieChart"; dataset.description = "Process instance overview (" + new java.util.Date() + ")"; dataset.data = {}; while (result.next()) { // process results one row at a time var name = result.getString(1); var version = result.getLong(2) var count = result.getLong(3); dataset.data[name + " (v" + version + ")"] = count; } reportData.datasets.push(dataset); execution.setVariable("reportData", new java.lang.String(JSON.stringify(reportData)).getBytes("UTF-8")); ]]></script> </scriptTask> <sequenceFlow sourceRef="generateDataset" targetRef="theEnd" /> <endEvent /> </process> </definitions>

除了流程xml顶部的标准xml,主要区别是targetNamespace设置为activiti-report,分类设置为与部署的流程定义一样的名称

脚本的第一行是进行一些导入,避免每次使用时,都要写包名

第一个有意义的代码是使用ReportingUtil读取activiti数据库.返回结果是一个JDBC 结果集

查询语句下面 ,javascript创建了使用的json.json是符合上面描述的需求的

最后一行脚本,首先需要把json对象转换成字符串,使用javascript函数JSON.stringify(). 字符串需要保存为二进制数组类型的变量

这是一个技术问题:

二进制数组的大小是无限的,但是字符串的长度有限制

这就是为什么javascript字符串必须转换成一个java字符串以获得转换成二进制的功能

原生json功能无法使用,这里提供了一些帮助类ReportDataDataset:

<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="activiti-report"> <process isExecutable="true"> <startEvent /> <sequenceFlow sourceRef="startevent1" targetRef="generateDataset" /> <scriptTask scriptFormat="js" activiti:autoStoreVariables="false"> <script><![CDATA[ importPackage(java.sql); importPackage(java.lang); importPackage(org.activiti.explorer.reporting); var result = ReportingUtil.executeSelectSqlQuery("SELECT PD.NAME_, PD.VERSION_ , count(*) FROM ACT_HI_PROCINST PI inner join ACT_RE_PROCDEF PD on PI.PROC_DEF_ID_ = PD.ID_ group by PROC_DEF_ID_"); var reportData = new ReportData; var dataset = reportData.newDataset(); dataset.type = "pieChart"; dataset.description = "Process instance overview (" + new java.util.Date() + ")" while (result.next()) { // process results one row at a time var name = result.getString(1); var version = result.getLong(2); var count = result.getLong(3); dataset.add(name + " (v" + version + ")", count); } execution.setVariable("reportData", reportData.toBytes()); ]]></script> </scriptTask> <sequenceFlow sourceRef="generateDataset" targetRef="theEnd" /> <endEvent /> </process> </definitions> 报告开始表单

报表是使用普通流程来生成的,所以表单功能也可以使用

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zysggz.html