use of org.flowable.engine.runtime.ProcessInstance in project plumdo-work by wengwh.
the class ProcessInstanceActivateResource method activateProcessInstance.
@RequestMapping(value = "/process-instance/{processInstanceId}/activate", method = RequestMethod.PUT, name = "流程实例激活")
@ResponseStatus(value = HttpStatus.OK)
public void activateProcessInstance(@PathVariable String processInstanceId, @RequestBody(required = false) ProcessInstanceActionRequest actionRequest) {
ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
if (!processInstance.isSuspended()) {
throw new FlowableConflictException("Process instance with id '" + processInstance.getId() + " ' is already active");
}
runtimeService.activateProcessInstanceById(processInstance.getId());
}
use of org.flowable.engine.runtime.ProcessInstance in project yyl_example by Relucent.
the class FlowableExample method main.
public static void main(String[] args) {
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("yyl/example/demo/flowable/flowable.cfg.xml");
// configuration.setJdbcUrl("jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000");
// configuration.setJdbcDriver("org.h2.Driver");
// configuration.setJdbcUsername("sa");
// configuration.setJdbcPassword("");
// configuration.setDatabaseSchemaUpdate("true");
// configuration.setAsyncExecutorActivate(false);
// configuration.setMailServerHost("localhost");
// configuration.setMailServerPort(25);
// 创建流程引擎
ProcessEngine processEngine = configuration.buildProcessEngine();
// 创建了一个新的部署
RepositoryService repositoryService = processEngine.getRepositoryService();
Deployment deployment = //
repositoryService.createDeployment().addClasspathResource(//
"yyl/example/demo/flowable/holiday-request.bpmn20.xml").deploy();
// 部署流程定义
ProcessDefinition processDefinition = //
repositoryService.createProcessDefinitionQuery().deploymentId(//
deployment.getId()).singleResult();
System.out.println("Found process definition : " + processDefinition.getName());
// 参数传递
Map<String, Object> variables = new LinkedHashMap<String, Object>();
System.out.println("Enter employee:");
variables.put("employee", SCANNER.nextLine());
System.out.println("Enter holidays:");
variables.put("holidays", SCANNER.nextLine());
RuntimeService runtimeService = processEngine.getRuntimeService();
// 通过RuntimeService启动流程实例
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holidayRequest", variables);
TaskService taskService = processEngine.getTaskService();
List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("managers").list();
System.out.println("You have " + tasks.size() + " tasks:");
for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + ") " + tasks.get(i).getName());
}
// 获取特定的流程实例变量
System.out.println("Which task would you like to complete?");
int taskIndex = Integer.valueOf(SCANNER.nextLine());
Task task = tasks.get(taskIndex - 1);
Map<String, Object> processVariables = taskService.getVariables(task.getId());
System.out.println(processVariables);
// 完成任务,传递排他网关条件
boolean approved = SCANNER.nextLine().toLowerCase().equals("y");
variables = new LinkedHashMap<String, Object>();
variables.put("approved", approved);
taskService.complete(task.getId(), variables);
// 查询完成的活动,按结束时间排序
HistoryService historyService = processEngine.getHistoryService();
List<HistoricActivityInstance> activities = //
historyService.createHistoricActivityInstanceQuery().processInstanceId(//
processInstance.getId()).finished().orderByHistoricActivityInstanceEndTime().asc().list();
for (HistoricActivityInstance activity : activities) {
System.out.println(activity.getActivityId() + " took " + activity.getDurationInMillis() + " milliseconds");
}
}
use of org.flowable.engine.runtime.ProcessInstance in project Resource by lovelifeming.
the class ApproveProcessController method create.
@ApiOperation("创建流程")
@PostMapping("create")
public ResultSet create(@RequestParam @ApiParam("当前业务流程key") String businessKey, @RequestParam @ApiParam("下一步执行用户Id") String userId) {
if (StringUtils.isBlank(businessKey) || StringUtils.isBlank(userId)) {
return ResultSet.fail("businessKey 或 userId 参数为空");
}
HashMap<String, Object> processVariable = new HashMap<>();
processVariable.put("handler", userId);
processVariable.put("userId", userId);
processVariable.put("businessKey", businessKey);
ProcessInstance instance = service.startProcessInstanceByKey(PROCESS_NAME, businessKey, processVariable);
Task task = service.getOneTaskByProcessId(instance.getId());
ProcessInfo info = new ProcessInfo(task.getId(), task.getProcessInstanceId(), instance.getBusinessKey());
return ResultSet.success(info);
}
use of org.flowable.engine.runtime.ProcessInstance in project Resource by lovelifeming.
the class ApproveProcessController method successLevel.
@ApiOperation("执行同意流程(部门经理)")
@PostMapping("successLevel")
public ResultSet successLevel(@RequestBody @Valid SuccessLevelVO levelVO, BindingResult results) {
if (results.hasErrors())
return ResultSet.fail(results.getFieldError().getDefaultMessage());
Task task = service.getOneTaskByTaskId(levelVO.getTaskId());
if (task == null) {
return ResultSet.fail("任务不存在");
}
HashMap<String, Object> map = new HashMap<>();
map.put("handler", levelVO.getUserId());
map.put("userId", levelVO.getNextUserId());
map.put("approve", "yes");
map.put("level", levelVO.getLevel());
map.put("due", "no");
service.complete(levelVO.getTaskId(), map);
ProcessInstance instance = service.getProcessByProcessId(task.getProcessInstanceId());
service.setProcessVariable(instance.getId(), "level", levelVO.getLevel());
log.info("successLevel成功执行流程,userId={},nextUserId={},level={},processId={},taskId={},businessKey={}", levelVO.getUserId(), levelVO.getNextUserId(), levelVO.getLevel(), instance.getId(), levelVO.getTaskId(), instance.getBusinessKey());
if (StringUtils.isNotBlank(levelVO.getVerify()) && "yes".equals(levelVO.getVerify())) {
service.setProcessVariable(instance.getId(), "verify", levelVO.getVerify());
}
Task task1 = service.getOneTaskByProcessId(task.getProcessInstanceId());
if (task1 == null) {
return ResultSet.success("流程已完结");
}
ProcessInfo info = new ProcessInfo(task1.getId(), task1.getProcessInstanceId(), instance.getBusinessKey());
return ResultSet.success(info);
}
use of org.flowable.engine.runtime.ProcessInstance in project Resource by lovelifeming.
the class ApproveProcessController method pastDue.
@ApiOperation("过期流程")
@PostMapping("pastDue")
public ResultSet pastDue(@RequestBody @Valid SuccessVO successVO, BindingResult results) {
if (results.hasErrors())
return ResultSet.fail(results.getFieldError().getDefaultMessage());
Task task = service.getOneTaskByTaskId(successVO.getTaskId());
if (task == null) {
return ResultSet.fail("任务不存在");
}
HashMap<String, Object> map = new HashMap<>();
map.put("handler", successVO.getUserId());
map.put("userId", successVO.getNextUserId());
map.put("due", "yes");
ProcessInstance instance = service.getProcessByProcessId(task.getProcessInstanceId());
service.complete(successVO.getTaskId(), map);
log.info("pastDue成功执行流程,userId={},nextUserId={},processId={},taskId={},businessKey={}", successVO.getUserId(), successVO.getNextUserId(), instance.getId(), successVO.getTaskId(), instance.getBusinessKey());
Task task1 = service.getOneTaskByProcessId(task.getProcessInstanceId());
ProcessInfo info = new ProcessInfo(task1.getId(), task1.getProcessInstanceId(), instance.getBusinessKey());
return ResultSet.success(info);
}
Aggregations