update 优化 业务事件监听器增加流程审批参数传递 更方便的对接业务数据
| | |
| | | |
| | | import java.io.Serial; |
| | | import java.io.Serializable; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 总体流程监听 |
| | |
| | | private String status; |
| | | |
| | | /** |
| | | * 办理参数 |
| | | */ |
| | | private Map<String, Object> params; |
| | | |
| | | /** |
| | | * 当为true时为申请人节点办理 |
| | | */ |
| | | private boolean submit; |
| | |
| | | import org.dromara.workflow.common.ConditionalOnEnable; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 流程监听服务 |
| | | * |
| | |
| | | * @param status 状态 |
| | | * @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(); |
| | | log.info("发布流程事件,租户ID: {}, 流程状态: {}, 流程编码: {}, 业务ID: {}, 是否申请人节点办理: {}", tenantId, status, flowCode, businessId, submit); |
| | | ProcessEvent processEvent = new ProcessEvent(); |
| | |
| | | processEvent.setFlowCode(flowCode); |
| | | processEvent.setBusinessId(businessId); |
| | | processEvent.setStatus(status); |
| | | processEvent.setParams(params); |
| | | processEvent.setSubmit(submit); |
| | | SpringUtils.context().publishEvent(processEvent); |
| | | } |
| | |
| | | import org.dromara.workflow.service.IFlwTaskService; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 全局任务办理监听 |
| | |
| | | Definition definition = listenerVariable.getDefinition(); |
| | | String businessId = instance.getBusinessId(); |
| | | 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); |
| | | if (StringUtils.isNotBlank(status)) { |
| | | flowProcessEventHandler.processHandler(definition.getFlowCode(), businessId, status, false); |
| | | flowProcessEventHandler.processHandler(definition.getFlowCode(), businessId, status, params, false); |
| | | } |
| | | } |
| | | |
| | |
| | | Definition definition = defService.getById(flowTask.getDefinitionId()); |
| | | // 检查流程状态是否为草稿、已撤销或已退回状态,若是则执行流程提交监听 |
| | | 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(); |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 请假Service业务层处理 |
| | |
| | | log.info("当前任务执行了{}", processEvent.toString()); |
| | | TestLeave testLeave = baseMapper.selectById(Long.valueOf(processEvent.getBusinessId())); |
| | | 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()) { |
| | | testLeave.setStatus(BusinessStatusEnum.WAITING.getStatus()); |
| | | } |