Search in sources :

Example 11 with ProcessInstance

use of org.flowable.engine.runtime.ProcessInstance in project Resource by lovelifeming.

the class ApproveProcessController method delete.

@ApiOperation("删除流程")
@GetMapping("delete")
public ResultSet delete(@RequestParam @ApiParam("任务流程Id") String taskId, @RequestParam(required = false) @ApiParam("用户Id") String userId, @RequestParam(required = false) @ApiParam("删除原因") String reason) {
    if (StringUtils.isBlank(taskId))
        return ResultSet.fail("taskId不能为空");
    Task task = service.getOneTaskByTaskId(taskId);
    if (task == null) {
        return ResultSet.fail("任务不存在");
    }
    ProcessInstance instance = service.getProcessByProcessId(task.getProcessInstanceId());
    service.deleteProcessInstance(task.getProcessInstanceId(), reason);
    log.info("delete成功执行流程,userId={},processId={},taskId={},businessKey={}", userId, task.getProcessInstanceId(), taskId, instance.getBusinessKey());
    ProcessInfo info = new ProcessInfo(task.getId(), task.getProcessInstanceId(), instance.getBusinessKey());
    return ResultSet.success(info);
}
Also used : Task(org.flowable.task.api.Task) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ApiOperation(io.swagger.annotations.ApiOperation)

Example 12 with ProcessInstance

use of org.flowable.engine.runtime.ProcessInstance in project Resource by lovelifeming.

the class ApproveProcessController method createProcessDiagram.

@ApiOperation("获取流程图")
@GetMapping("getProcessDiagram")
public void createProcessDiagram(HttpServletResponse response, @RequestParam @ApiParam("流程Id") String processId) throws IOException {
    if (StringUtils.isBlank(processId))
        response.getWriter().write("processId 不能为空");
    ProcessInstance pi = service.getProcessByProcessId(processId);
    // 流程走完的不显示图
    if (pi == null) {
        response.getWriter().write("任务已完成");
        return;
    }
    Task task = service.getOneTaskByProcessId(pi.getId());
    // 使用流程实例ID,查询正在执行的执行对象表,返回流程实例对象
    String InstanceId = task.getProcessInstanceId();
    List<Execution> executions = service.getExecutions(InstanceId);
    // 得到正在执行的Activity的Id
    List<String> activityIds = new ArrayList<>();
    List<String> flows = new ArrayList<>();
    for (Execution exe : executions) {
        List<String> ids = service.getActiveActivityIds(exe.getId());
        activityIds.addAll(ids);
    }
    // 获取流程图
    BpmnModel bpmnModel = service.getBpmnModel(pi.getProcessDefinitionId());
    ProcessEngineConfiguration engconf = service.getProcessEngineConfiguration();
    ProcessDiagramGenerator diagramGenerator = engconf.getProcessDiagramGenerator();
    InputStream in = diagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows, engconf.getActivityFontName(), engconf.getLabelFontName(), engconf.getAnnotationFontName(), engconf.getClassLoader(), 1.0);
    // 自定义画图类
    // InputStream in = new MyProcessDiagramGenerator().generateDiagram(bpmnModel, "png", activityIds, flows);
    OutputStream out = null;
    byte[] buf = new byte[1024];
    int legth = 0;
    try {
        out = response.getOutputStream();
        while ((legth = in.read(buf)) != -1) {
            out.write(buf, 0, legth);
        }
    } finally {
        if (in != null) {
            in.close();
        }
        if (out != null) {
            out.close();
        }
    }
}
Also used : Task(org.flowable.task.api.Task) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) BpmnModel(org.flowable.bpmn.model.BpmnModel) Execution(org.flowable.engine.runtime.Execution) ProcessEngineConfiguration(org.flowable.engine.ProcessEngineConfiguration) ProcessDiagramGenerator(org.flowable.image.ProcessDiagramGenerator) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ApiOperation(io.swagger.annotations.ApiOperation)

Example 13 with ProcessInstance

use of org.flowable.engine.runtime.ProcessInstance in project Resource by lovelifeming.

the class ApproveProcessController method successVerify.

@ApiOperation("执行同意流程(职员)")
@PostMapping("successVerify")
public ResultSet successVerify(@RequestBody @Valid SuccessVerifyVO 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("due", "no");
    service.complete(levelVO.getTaskId(), map);
    ProcessInstance instance = service.getProcessByProcessId(task.getProcessInstanceId());
    if (StringUtils.isNotBlank(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);
}
Also used : Task(org.flowable.task.api.Task) HashMap(java.util.HashMap) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ApiOperation(io.swagger.annotations.ApiOperation)

Example 14 with ProcessInstance

use of org.flowable.engine.runtime.ProcessInstance in project Resource by lovelifeming.

the class ApproveProcessController method reject.

@ApiOperation("驳回流程")
@PostMapping("reject")
public ResultSet reject(@RequestParam @ApiParam("任务流程Id") String taskId, @RequestParam @ApiParam("用户Id") String userId) {
    if (StringUtils.isBlank(taskId))
        return ResultSet.fail("taskId不能为空");
    Task task = service.getOneTaskByTaskId(taskId);
    if (task == null) {
        return ResultSet.fail("任务不存在");
    }
    int index = PROCESS_NODE.indexOf(task.getName()) - 1;
    if (index < 0) {
        return ResultSet.fail("无法驳回");
    }
    String nodeName = PROCESS_NODE.get(index);
    ProcessInstance instance = service.getProcessByProcessId(task.getProcessInstanceId());
    List<HistoricTaskInstance> list = service.getHistoricTaskInstances(instance.getId(), nodeName);
    HashMap<String, Object> map = new HashMap<>();
    map.put("handler", userId);
    map.put("approve", "no");
    map.put("userId", list.get(0).getAssignee());
    map.put("due", "no");
    service.complete(taskId, map);
    log.info("reject成功执行流程,userId={},nextUserId={},processId={},taskId={},businessKey={}", userId, list.get(0).getAssignee(), instance.getId(), taskId, instance.getBusinessKey());
    Task task1 = service.getOneTaskByProcessId(task.getProcessInstanceId());
    if (task1 == null) {
        return ResultSet.success("流程已完结");
    }
    log.info("驳回流程到上一级节点处理人:" + task1.getAssignee());
    ProcessInfo info = new ProcessInfo(task1.getId(), task1.getProcessInstanceId(), instance.getBusinessKey());
    return ResultSet.success(info);
}
Also used : Task(org.flowable.task.api.Task) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) HashMap(java.util.HashMap) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ApiOperation(io.swagger.annotations.ApiOperation)

Example 15 with ProcessInstance

use of org.flowable.engine.runtime.ProcessInstance in project plumdo-work by wengwh.

the class ProcessInstanceSuspendResource method suspendProcessInstance.

@RequestMapping(value = "/process-instance/{processInstanceId}/suspend", method = RequestMethod.PUT, name = "流程实例挂起")
@ResponseStatus(value = HttpStatus.OK)
public void suspendProcessInstance(@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 suspend");
    }
    runtimeService.suspendProcessInstanceById(processInstance.getId());
}
Also used : ProcessInstance(org.flowable.engine.runtime.ProcessInstance) FlowableConflictException(com.plumdo.flow.exception.FlowableConflictException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ProcessInstance (org.flowable.engine.runtime.ProcessInstance)20 Task (org.flowable.task.api.Task)12 ApiOperation (io.swagger.annotations.ApiOperation)8 HashMap (java.util.HashMap)8 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)7 HistoricProcessInstance (org.flowable.engine.history.HistoricProcessInstance)5 FlowableConflictException (com.plumdo.flow.exception.FlowableConflictException)2 ProcessEngineConfiguration (org.flowable.engine.ProcessEngineConfiguration)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 PutMapping (org.springframework.web.bind.annotation.PutMapping)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 RestVariable (com.plumdo.flow.rest.variable.RestVariable)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Scanner (java.util.Scanner)1 User (org.apache.syncope.core.persistence.api.entity.user.User)1 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)1 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)1