update 优化 业务事件监听器增加流程审批参数传递 更方便的对接业务数据
This commit is contained in:
parent
6c28f8a0dd
commit
a22dc9537f
@ -4,6 +4,7 @@ import lombok.Data;
|
|||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 总体流程监听
|
* 总体流程监听
|
||||||
@ -36,6 +37,11 @@ public class ProcessEvent implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 办理参数
|
||||||
|
*/
|
||||||
|
private Map<String, Object> params;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当为true时为申请人节点办理
|
* 当为true时为申请人节点办理
|
||||||
*/
|
*/
|
||||||
|
@ -9,6 +9,8 @@ import org.dromara.common.tenant.helper.TenantHelper;
|
|||||||
import org.dromara.workflow.common.ConditionalOnEnable;
|
import org.dromara.workflow.common.ConditionalOnEnable;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流程监听服务
|
* 流程监听服务
|
||||||
*
|
*
|
||||||
@ -28,7 +30,7 @@ public class FlowProcessEventHandler {
|
|||||||
* @param status 状态
|
* @param status 状态
|
||||||
* @param submit 当为true时为申请人节点办理
|
* @param submit 当为true时为申请人节点办理
|
||||||
*/
|
*/
|
||||||
public void processHandler(String flowCode, String businessId, String status, boolean submit) {
|
public void processHandler(String flowCode, String businessId, String status, Map<String, Object> params, boolean submit) {
|
||||||
String tenantId = TenantHelper.getTenantId();
|
String tenantId = TenantHelper.getTenantId();
|
||||||
log.info("发布流程事件,租户ID: {}, 流程状态: {}, 流程编码: {}, 业务ID: {}, 是否申请人节点办理: {}", tenantId, status, flowCode, businessId, submit);
|
log.info("发布流程事件,租户ID: {}, 流程状态: {}, 流程编码: {}, 业务ID: {}, 是否申请人节点办理: {}", tenantId, status, flowCode, businessId, submit);
|
||||||
ProcessEvent processEvent = new ProcessEvent();
|
ProcessEvent processEvent = new ProcessEvent();
|
||||||
@ -36,6 +38,7 @@ public class FlowProcessEventHandler {
|
|||||||
processEvent.setFlowCode(flowCode);
|
processEvent.setFlowCode(flowCode);
|
||||||
processEvent.setBusinessId(businessId);
|
processEvent.setBusinessId(businessId);
|
||||||
processEvent.setStatus(status);
|
processEvent.setStatus(status);
|
||||||
|
processEvent.setParams(params);
|
||||||
processEvent.setSubmit(submit);
|
processEvent.setSubmit(submit);
|
||||||
SpringUtils.context().publishEvent(processEvent);
|
SpringUtils.context().publishEvent(processEvent);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@ import org.dromara.workflow.service.IFlwInstanceService;
|
|||||||
import org.dromara.workflow.service.IFlwTaskService;
|
import org.dromara.workflow.service.IFlwTaskService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局任务办理监听
|
* 全局任务办理监听
|
||||||
@ -81,10 +83,17 @@ public class WorkflowGlobalListener implements GlobalListener {
|
|||||||
Definition definition = listenerVariable.getDefinition();
|
Definition definition = listenerVariable.getDefinition();
|
||||||
String businessId = instance.getBusinessId();
|
String businessId = instance.getBusinessId();
|
||||||
String flowStatus = instance.getFlowStatus();
|
String flowStatus = instance.getFlowStatus();
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
// 历史任务扩展(通常为附件)
|
||||||
|
params.put("hisTaskExt", listenerVariable.getFlowParams().getHisTaskExt());
|
||||||
|
// 办理人
|
||||||
|
params.put("handler", listenerVariable.getFlowParams().getHandler());
|
||||||
|
// 办理意见
|
||||||
|
params.put("message", listenerVariable.getFlowParams().getMessage());
|
||||||
// 判断流程状态(发布:撤销,退回,作废,终止,已完成事件)
|
// 判断流程状态(发布:撤销,退回,作废,终止,已完成事件)
|
||||||
String status = determineFlowStatus(instance, flowStatus);
|
String status = determineFlowStatus(instance, flowStatus);
|
||||||
if (StringUtils.isNotBlank(status)) {
|
if (StringUtils.isNotBlank(status)) {
|
||||||
flowProcessEventHandler.processHandler(definition.getFlowCode(), businessId, status, false);
|
flowProcessEventHandler.processHandler(definition.getFlowCode(), businessId, status, params, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|||||||
Definition definition = defService.getById(flowTask.getDefinitionId());
|
Definition definition = defService.getById(flowTask.getDefinitionId());
|
||||||
// 检查流程状态是否为草稿、已撤销或已退回状态,若是则执行流程提交监听
|
// 检查流程状态是否为草稿、已撤销或已退回状态,若是则执行流程提交监听
|
||||||
if (BusinessStatusEnum.isDraftOrCancelOrBack(ins.getFlowStatus())) {
|
if (BusinessStatusEnum.isDraftOrCancelOrBack(ins.getFlowStatus())) {
|
||||||
flowProcessEventHandler.processHandler(definition.getFlowCode(), ins.getBusinessId(), ins.getFlowStatus(), true);
|
flowProcessEventHandler.processHandler(definition.getFlowCode(), ins.getBusinessId(), ins.getFlowStatus(), null, true);
|
||||||
}
|
}
|
||||||
// 构建流程参数,包括变量、跳转类型、消息、处理人、权限等信息
|
// 构建流程参数,包括变量、跳转类型、消息、处理人、权限等信息
|
||||||
FlowParams flowParams = new FlowParams();
|
FlowParams flowParams = new FlowParams();
|
||||||
|
@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请假Service业务层处理
|
* 请假Service业务层处理
|
||||||
@ -131,6 +132,14 @@ public class TestLeaveServiceImpl implements ITestLeaveService {
|
|||||||
log.info("当前任务执行了{}", processEvent.toString());
|
log.info("当前任务执行了{}", processEvent.toString());
|
||||||
TestLeave testLeave = baseMapper.selectById(Long.valueOf(processEvent.getBusinessId()));
|
TestLeave testLeave = baseMapper.selectById(Long.valueOf(processEvent.getBusinessId()));
|
||||||
testLeave.setStatus(processEvent.getStatus());
|
testLeave.setStatus(processEvent.getStatus());
|
||||||
|
// 用于例如审批附件 审批意见等 存储到业务表内 自行根据业务实现存储流程
|
||||||
|
Map<String, Object> params = processEvent.getParams();
|
||||||
|
// 历史任务扩展(通常为附件)
|
||||||
|
String hisTaskExt = params.getOrDefault("hisTaskExt", "").toString();
|
||||||
|
// 办理人
|
||||||
|
String handler = params.getOrDefault("handler", "").toString();
|
||||||
|
// 办理意见
|
||||||
|
String message = params.getOrDefault("message", "").toString();
|
||||||
if (processEvent.isSubmit()) {
|
if (processEvent.isSubmit()) {
|
||||||
testLeave.setStatus(BusinessStatusEnum.WAITING.getStatus());
|
testLeave.setStatus(BusinessStatusEnum.WAITING.getStatus());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user