diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/garden/listener/AutoCompleteExecutionListener.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/garden/listener/AutoCompleteExecutionListener.java new file mode 100644 index 0000000..e5a9544 --- /dev/null +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/garden/listener/AutoCompleteExecutionListener.java @@ -0,0 +1,43 @@ +package com.zteits.urbanops.module.workorder.service.garden.listener; + +import org.flowable.common.engine.api.FlowableException; +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.ExecutionListener; +import org.flowable.common.engine.impl.identity.Authentication; // 关键导入 +import org.springframework.stereotype.Component; + +/** + * 流程启动时的执行监听器:设置自动完成变量 + */ +@Component("autoCompleteExecutionListener") +public class AutoCompleteExecutionListener implements ExecutionListener { + + @Override + public void notify(DelegateExecution execution) { + try { + // 1. 获取发起人ID:使用Authentication工具类(适配新版本) + String initiator = null; + // 获取当前认证的用户ID(静态方法) + if (Authentication.getAuthenticatedUserId() != null) { + initiator = Authentication.getAuthenticatedUserId(); + } else { + // 备选:从流程变量中获取 + initiator = (String) execution.getVariable("initiator"); + } + + // 容错:默认用户 + if (initiator == null || initiator.isEmpty()) { + initiator = "system_admin"; + } + + // 2. 设置skipExpression需要的变量:autoComplete=true(表示跳过用户任务) + execution.setVariable("autoComplete", true); + // 3. 存储发起人ID和备注变量(用于追溯) + execution.setVariable("initiator", initiator); + execution.setVariable("completeRemark", "系统自动完成,办理人:" + initiator); + + } catch (Exception e) { + throw new FlowableException("设置自动完成变量失败:" + e.getMessage(), e); + } + } +}