diff --git a/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java b/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java index 5585aafe..4feee519 100644 --- a/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java +++ b/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java @@ -75,6 +75,7 @@ import java.util.*; @Service @AllArgsConstructor public class FlowEngineServiceImpl extends ServiceImpl implements FlowEngineService { + private static final String ALREADY_IN_STATE = "already in state"; private static final BpmnJsonConverter BPMN_JSON_CONVERTER = new BpmnJsonConverter(); private static final BpmnXMLConverter BPMN_XML_CONVERTER = new BpmnXMLConverter(); private final ObjectMapper objectMapper; @@ -239,14 +240,21 @@ public class FlowEngineServiceImpl extends ServiceImpl im @Override public String changeState(String state, String processId) { - if (state.equals(FlowEngineConstant.ACTIVE)) { - repositoryService.activateProcessDefinitionById(processId, true, null); - return StringUtil.format("激活ID为 [{}] 的流程成功", processId); - } else if (state.equals(FlowEngineConstant.SUSPEND)) { - repositoryService.suspendProcessDefinitionById(processId, true, null); - return StringUtil.format("挂起ID为 [{}] 的流程成功", processId); - } else { - return "暂无流程变更"; + try { + if (state.equals(FlowEngineConstant.ACTIVE)) { + repositoryService.activateProcessDefinitionById(processId, true, null); + return StringUtil.format("激活ID为 [{}] 的流程成功", processId); + } else if (state.equals(FlowEngineConstant.SUSPEND)) { + repositoryService.suspendProcessDefinitionById(processId, true, null); + return StringUtil.format("挂起ID为 [{}] 的流程成功", processId); + } else { + return "暂无流程变更"; + } + } catch (Exception e) { + if (e.getMessage().contains(ALREADY_IN_STATE)) { + return StringUtil.format("ID为 [{}] 的流程已是此状态,无需操作", processId); + } + return e.getMessage(); } }