其他分享
首页 > 其他分享> > 1、flowable-流程的基本使用API

1、flowable-流程的基本使用API

作者:互联网

Flowable.6.3.0.BPMN.userguide.zh_CN.RC1.pdf    提取码:cc42

flowable流程引擎的基本使用

1、流程部署

2、bpmn转image

3、流程部署的查询

4、流程实例启动

5、查询组任务

6、任务的申领/认领

7、完成用户任务

8、流程实例的查询

/**
 * springboot环境下测试
 *
 * @Auther: xuminggang
 * @Description: com.yxx.flowable
 * @version: 1.0
 */
@SpringBootTest
@RunWith(SpringRunner.class)
@Data
public class ProcessTest {


    private static final String IMAGE_TYPE = "png";

    @Value("宋体")
    private String activityFontName;
    @Value("宋体")
    private String labelFontName;
    @Value("宋体")
    private String annotationFontName;
    @Autowired
    private ProcessEngine processEngine;

    /**
     * 实例实例查询
     */
    @Test
    public void testQueryHistory() {
        HistoryService historyService = processEngine.getHistoryService();
        List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().finished().list();
        for (HistoricProcessInstance historicProcessInstance : list) {
            List<HistoricTaskInstance> list1 = historyService.createHistoricTaskInstanceQuery()
                    .orderByHistoricTaskInstanceEndTime()
                    .asc()
                    .processInstanceId(historicProcessInstance.getId())
                    .list();
            System.out.println("------------" + historicProcessInstance.getName());
            for (HistoricTaskInstance historicTaskInstance : list1) {
                System.out.println(historicTaskInstance.getName() + historicTaskInstance.getAssignee());
            }
            System.out.println("------------");

        }
    }


    /**
     * 完成用户任务
     */
    @Test
    public void testComplete() {
        TaskService taskService = processEngine.getTaskService();
        taskService.complete("10005");
    }

    /**
     * 认领/申领任务
     */
    @Test
    public void testClaimTask() {
        TaskService taskService = processEngine.getTaskService();
        Task task = taskService.createTaskQuery().taskId("20002").singleResult();
        System.out.println("task==>" + task.getName() + "==将被lisi认领");
        taskService.claim(task.getId(), "lisi");
    }

    /**
     * 查询组任务
     */
    @Test
    public void testQueryGroupTask() {
        TaskService taskService = processEngine.getTaskService();
        List<Task> list = taskService.createTaskQuery()
//                .taskCandidateGroup("accountancy")
                .taskCandidateGroup("management")
//                .taskAssignee("zhangsan")
                .list();
        for (Task task : list) {
            System.out.println("taskID==>" + task.getId());
            System.out.println("taskName==>" + task.getName());
            System.out.println("task-Defi-KEY==>" + task.getTaskDefinitionKey());
            System.out.println("----------------------------------");
        }
    }

    /**
     * 启动流程实例
     */
    @Test
    public void testStartProcessInstance() {
        RuntimeService runtimeService = processEngine.getRuntimeService();
        ProcessInstance financialReport = runtimeService.startProcessInstanceByKey("financialReport");

    }

    /**
     * 查询部署
     */
    @Test
    public void testQueryDeployment() {
        RepositoryService repositoryService = processEngine.getRepositoryService();
        List<Deployment> list = repositoryService.createDeploymentQuery().list();
        for (Deployment deployment : list) {
            System.out.println("部署ID===》" + deployment.getId());
            System.out.println("部署key===》" + deployment.getKey());
            System.out.println("部署名称===》" + deployment.getName());
            System.out.println("部署时间===》" + deployment.getDeploymentTime());
        }

    }

    /**
     * 流程定义
     * 通过bpmnmodel转xml
     * 转图片
     */
    @Test
    public void testBpmn2Img() throws IOException {
        DefaultProcessDiagramGenerator defaultProcessDiagramGenerator = new DefaultProcessDiagramGenerator();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        ProcessDefinition financialReport = repositoryService.createProcessDefinitionQuery().latestVersion().processDefinitionKey("financialReport").singleResult();
        BpmnModel bpmnModel = repositoryService.getBpmnModel(financialReport.getId());
        // bpmnxml文件下载
        BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
        byte[] bytes = bpmnXMLConverter.convertToXML(bpmnModel);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        FileOutputStream fileOutputStream = new FileOutputStream(new File("E:\\ideaProject\\study\\flowable\\flowable-boot\\src\\main\\resources\\demo.xml"));
        IOUtils.copy(byteArrayInputStream, fileOutputStream);
        // 获取图片
        InputStream inputStream = defaultProcessDiagramGenerator
                .generateDiagram(bpmnModel, IMAGE_TYPE, Collections.<String>emptyList(), Collections.<String>emptyList(),
                        activityFontName, labelFontName, annotationFontName, null, 2.0);
        // 直接转图片会存在问题,乱码
        //InputStream inputStream = defaultProcessDiagramGenerator
        //      .generatePngDiagram(bpmnModel);
         fileOutputStream = new FileOutputStream(new File("E:\\ideaProject\\study\\flowable\\flowable-boot\\src\\main\\resources\\demo.png"));
        IOUtils.copy(inputStream, fileOutputStream);

    }


    /**
     * 部署
     */
    @Test
    public void testDeploy() {
        RepositoryService repositoryService = processEngine.getRepositoryService();
        repositoryService.createDeployment()
                .addClasspathResource("flow/FinancialReportProcess.bpmn20.xml")
                .deploy();

    }

}

 

标签:flowable,流程,list,System,API,println,processEngine,public,out
来源: https://www.cnblogs.com/aismvy/p/15114714.html