话不多说,直接上代码,这是项目目录结构,DDD领域驱动模型,流程实例单独一个package
发起流程的代码如下,如要传入流程定义的key,流程实例名称,和发起人id
@ApiOperation(value = "发起流程", httpMethod = "POST") @PostMapping("start") public ResultDTO<ProcessInstanceDTO> start(String processDefinitionKey, String processInstanceName, String userId){ ResultDTO<ProcessInstanceDTO> resultDTO = new ResultDTO<>(ReturnCode.SUCCESS, "启动成功"); ProcessInstance processInstance = processInstanceApplicationService.start(processDefinitionKey, processInstanceName, userId); if(Objects.isNull(processInstance)){ return new ResultDTO<>(ReturnCode.FAIL, "启动失败"); } resultDTO.setData(ProcessInstanceAssembler.convertToProcessInstanceDTO(processInstance)); return resultDTO; }
流程发起后还需要查询我发我的流程列表,代码如下,需要传入发起人id即可
@ApiOperation(value = "我发起的流程列表", httpMethod = "POST") @PostMapping("list") public ResultDTO<ProcessInstanceDTO> list(String userId){ ResultDTO<ProcessInstanceDTO> resultDTO = new ResultDTO<>(ReturnCode.SUCCESS, "查询成功"); List<HistoricProcessInstance> historicProcessInstanceList = processInstanceApplicationService.list(userId); if(CollUtil.isEmpty(historicProcessInstanceList)){ return new ResultDTO<>(ReturnCode.FAIL, "查询无数据"); } resultDTO.setDataList(ProcessInstanceAssembler.convertToProcessInstanceDTO(historicProcessInstanceList)); return resultDTO; }
下面是swagger接口测试:
填入发起流程的参数,点击execute,页面显示发起成功
下面查询我发起的流程,填入参数,点击execute
返回的数据就是我们刚刚发起的流程,测试成功