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);
}
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();
}
}
}
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);
}
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);
}
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());
}
Aggregations