feat(流程实例): 新增 流程状态变量参数
This commit is contained in:
@@ -67,6 +67,11 @@ public class ProcessConstants {
|
||||
*/
|
||||
public static final String PROCESS_FORM_LOCAL_SCOPE = "localScope";
|
||||
|
||||
/**
|
||||
* 自定义属性 流程状态
|
||||
*/
|
||||
public static final String PROCESS_STATUS_KEY = "processStatus";
|
||||
|
||||
|
||||
/**
|
||||
* 流程跳过
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.ruoyi.flowable.common.enums;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author konbai
|
||||
* @since 2023/3/9 00:45
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ProcessStatus {
|
||||
|
||||
/**
|
||||
* 进行中(审批中)
|
||||
*/
|
||||
RUNNING("running"),
|
||||
/**
|
||||
* 已终止
|
||||
*/
|
||||
TERMINATED("terminated"),
|
||||
/**
|
||||
* 已完成
|
||||
*/
|
||||
COMPLETED("completed"),
|
||||
/**
|
||||
* 已取消
|
||||
*/
|
||||
CANCELED("canceled");
|
||||
|
||||
private final String status;
|
||||
|
||||
public static ProcessStatus getProcessStatus(String str) {
|
||||
if (StringUtils.isNotBlank(str)) {
|
||||
for (ProcessStatus value : values()) {
|
||||
if (StringUtils.equalsIgnoreCase(str, value.getStatus())) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ruoyi.flowable.config;
|
||||
|
||||
import com.ruoyi.flowable.listener.GlobalEventListener;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
|
||||
/**
|
||||
* flowable全局监听配置
|
||||
*
|
||||
* @author ssc
|
||||
*/
|
||||
@Configuration
|
||||
@AllArgsConstructor
|
||||
public class GlobalEventListenerConfig implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
private final GlobalEventListener globalEventListener;
|
||||
private final RuntimeService runtimeService;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
// 流程正常结束
|
||||
runtimeService.addEventListener(globalEventListener, FlowableEngineEventType.PROCESS_COMPLETED);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ruoyi.flowable.listener;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.flowable.common.constant.ProcessConstants;
|
||||
import com.ruoyi.flowable.common.enums.ProcessStatus;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Flowable 全局监听器
|
||||
*
|
||||
* @author konbai
|
||||
* @since 2023/3/8 22:45
|
||||
*/
|
||||
@Component
|
||||
public class GlobalEventListener extends AbstractFlowableEngineEventListener {
|
||||
|
||||
@Autowired
|
||||
private RuntimeService runtimeService;
|
||||
|
||||
/**
|
||||
* 流程结束监听器
|
||||
*/
|
||||
@Override
|
||||
protected void processCompleted(FlowableEngineEntityEvent event) {
|
||||
String processInstanceId = event.getProcessInstanceId();
|
||||
Object variable = runtimeService.getVariable(processInstanceId, ProcessConstants.PROCESS_STATUS_KEY);
|
||||
ProcessStatus status = ProcessStatus.getProcessStatus(Convert.toStr(variable));
|
||||
if (ObjectUtil.isNotNull(status) && ProcessStatus.RUNNING == status) {
|
||||
runtimeService.setVariable(processInstanceId, ProcessConstants.PROCESS_STATUS_KEY, ProcessStatus.COMPLETED.getStatus());
|
||||
}
|
||||
super.processCompleted(event);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user