项目地址 | https://gitee.com/lwj/flowable.git |
---|
代码分支 | flowable-base |
视频讲解地址 | https://space.bilibili.com/485524575/channel/detail?cid=94579 |
用户名 | 密码 |
---|
0000001 | test |
0000002 | test |
0000003 | test |
0000004 | test |
1. 演示
2. 代码
2.1. 删除实例命令
public class DeleteFlowableProcessInstanceCmd implements Command<Void>, Serializable {private static final long serialVersionUID = 1L;protected String processInstanceId;protected String deleteReason;protected boolean cascade = false;public DeleteFlowableProcessInstanceCmd(String processInstanceId, String deleteReason) {this.processInstanceId = processInstanceId;this.deleteReason = deleteReason;}public DeleteFlowableProcessInstanceCmd(String processInstanceId, String deleteReason,boolean cascade) {this.processInstanceId = processInstanceId;this.deleteReason = deleteReason;this.cascade = cascade;}@Overridepublic Void execute(CommandContext commandContext) {if (processInstanceId == null) {throw new FlowableIllegalArgumentException("processInstanceId is null");}ExecutionEntity processInstanceEntity = CommandContextUtil.getExecutionEntityManager(commandContext).findById(processInstanceId);if (processInstanceEntity == null) {throw new FlowableObjectNotFoundException("No process instance found for id '" + processInstanceId + "'", ProcessInstance.class);}if (processInstanceEntity.isDeleted()) {return null;}if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, processInstanceEntity.getProcessDefinitionId())) {Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();compatibilityHandler.deleteProcessInstance(processInstanceId, deleteReason);} else {CommandContextUtil.getExecutionEntityManager(commandContext).deleteProcessInstance(processInstanceEntity.getProcessInstanceId(), deleteReason, cascade);}return null;}}
2.2. 执行删除动作
public ReturnVo<String> deleteProcessInstanceById(String processInstanceId) {ReturnVo<String> returnVo = null;long count = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).count();if (count > 0) {DeleteFlowableProcessInstanceCmd cmd = new DeleteFlowableProcessInstanceCmd(processInstanceId, "删除流程实例", true);managementService.executeCommand(cmd);returnVo = new ReturnVo<>(ReturnCode.SUCCESS, "删除成功");} else {historyService.deleteHistoricProcessInstance(processInstanceId);returnVo = new ReturnVo<>(ReturnCode.SUCCESS, "删除成功");}return returnVo;}