Commit 9ce50e30971245001d0080d0ba8106eb2672bef1

Authored by 颜惠青
1 parent 3d502441

APP端待办接口重构

urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/garden/listener/AutoCompleteExecutionListener.java 0 → 100644
  1 +package com.zteits.urbanops.module.workorder.service.garden.listener;
  2 +
  3 +import org.flowable.common.engine.api.FlowableException;
  4 +import org.flowable.engine.delegate.DelegateExecution;
  5 +import org.flowable.engine.delegate.ExecutionListener;
  6 +import org.flowable.common.engine.impl.identity.Authentication; // 关键导入
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +/**
  10 + * 流程启动时的执行监听器:设置自动完成变量
  11 + */
  12 +@Component("autoCompleteExecutionListener")
  13 +public class AutoCompleteExecutionListener implements ExecutionListener {
  14 +
  15 + @Override
  16 + public void notify(DelegateExecution execution) {
  17 + try {
  18 + // 1. 获取发起人ID:使用Authentication工具类(适配新版本)
  19 + String initiator = null;
  20 + // 获取当前认证的用户ID(静态方法)
  21 + if (Authentication.getAuthenticatedUserId() != null) {
  22 + initiator = Authentication.getAuthenticatedUserId();
  23 + } else {
  24 + // 备选:从流程变量中获取
  25 + initiator = (String) execution.getVariable("initiator");
  26 + }
  27 +
  28 + // 容错:默认用户
  29 + if (initiator == null || initiator.isEmpty()) {
  30 + initiator = "system_admin";
  31 + }
  32 +
  33 + // 2. 设置skipExpression需要的变量:autoComplete=true(表示跳过用户任务)
  34 + execution.setVariable("autoComplete", true);
  35 + // 3. 存储发起人ID和备注变量(用于追溯)
  36 + execution.setVariable("initiator", initiator);
  37 + execution.setVariable("completeRemark", "系统自动完成,办理人:" + initiator);
  38 +
  39 + } catch (Exception e) {
  40 + throw new FlowableException("设置自动完成变量失败:" + e.getMessage(), e);
  41 + }
  42 + }
  43 +}
... ...